# ServiceSample.cs [C#]

     using System;
     using System.Collections.Generic;
     using System.Linq;
     using System.Text;
     using WpfApplication1.ServiceReference1;
     using System.Security.Cryptography;
     using System.IO;
     using System.ServiceModel;

     namespace WpfApplication1
     {
         public class ServiceSample
         {
             ManagerServiceClient client;

             public ServiceSample()
             {
                 EndpointAddress address = new EndpointAddress(GlobalParam.SERVICE_URL);

                 BasicHttpBinding binding;
                 if (GlobalParam.SERVICE_URL.Contains("https:/"))
                     binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
                 else binding = new BasicHttpBinding();

                 binding.MaxBufferSize = 2147483647;
                 binding.MaxReceivedMessageSize = 2147483647;

                 client = new ManagerServiceClient(binding, address);
             }

             //Keep the manager data (after login) for all service connection
             View_Manager manager;

             //Keep the session id (after login) for all service connection
             string sessionId;

             //Get list of group for specific manager
             public ErrorType GetGroup(out List<View_Group> listResult, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<View_Group>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list all group for specific manager
                     result = client.GetGroup(out listResult, manager.BoxId ?? 0, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of group for specific manager filtered by name
             public ErrorType GetGroupByName(out List<View_Group> filteredList, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<View_Group>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of group for specific manager
                     List<View_Group> listResult;
                     result = client.GetGroup(out listResult, manager.BoxId ?? 0, manager.Id, sessionId);

                     if (result == ErrorType.GOOD)
                     {
                         //Filter the result with linq
                         filteredList = (from l1 in listResult where l1.Name.Contains(filter) select l1).ToList();

                         //For filter by id
                         //listFilterGroup = (from l1 in listGroup where l1.Id == Id select l1).ToList();
                     }
                 }

                 return result;
             }

             //Get list of profiles for specific manager
             public ErrorType GetPlayerProfile(out List<PlayerProfil> listResult, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<PlayerProfil>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of profiles for specific manager
                     bool onlyThisBox = true;
                     result = client.GetPlayerProfil(out listResult, manager.Id, sessionId, onlyThisBox);
                 }

                 return result;
             }

             //Get list of profiles for specific manager filtered by name
             public ErrorType GetPlayerProfileByName(out List<PlayerProfil> filteredList, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<PlayerProfil>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of profiles for specific manager
                     List<PlayerProfil> listResult;
                     bool onlyThisBox = true;
                     result = client.GetPlayerProfil(out listResult, manager.Id, sessionId, onlyThisBox);

                     if (result == ErrorType.GOOD)
                     {
                         //Filter the result with linq
                         filteredList = (from l1 in listResult where l1.Name.Contains(filter) select l1).ToList();

                         //For filter by id
                         //filteredList = (from l1 in listResult where l1.Id == Id select l1).ToList();
                     }
                 }

                 return result;
             }

             //Get list of players for specific manager
             public ErrorType GetPlayer(out List<View_Player> listResult, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<View_Player>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of players for specific manager
                     result = client.GetPlayer(out listResult, manager.BoxId ?? 0, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of players for specific manager filtered by name
             public ErrorType GetPlayerByName(out List<View_Player> filteredList, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<View_Player>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of players for specific manager
                     List<View_Player> listResult;
                     result = client.GetPlayer(out listResult, manager.BoxId ?? 0, manager.Id, sessionId);

                     if (result == ErrorType.GOOD)
                     {
                         //Filter the result with linq
                         filteredList = (from l1 in listResult where l1.Name.Contains(filter) select l1).ToList();

                         //For filter by id
                         //filteredList = (from l1 in listResult where l1.Id == Id select l1).ToList();
                     }
                 }

                 return result;
             }

             //Get list of players for specific manager filtered in server (by all players properties, ex: ip connection etc..)
             public ErrorType GetPlayerByFilter(out List<View_Player> filteredList, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<View_Player>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of filtered players for specific manager
                     result = client.GetFilteredPlayer(out filteredList, filter, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of players monitoring for specific manager
             public ErrorType GetMonitoring(out List<View_StatusM> listResult, out long serverDate, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<View_StatusM>();
                 serverDate = 0;

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId2(out sessionId, out manager, out serverDate, login, password)) //Get Manager connection data
                 {
                     //Get list of players monitoring for specific manager
                     long lastMonitoring = 0;
                     result = client.GetPlayerStatus(out listResult, ref lastMonitoring, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of players monitoring for specific manager filtered by name
             public ErrorType GetMonitoringByName(out List<View_StatusM> filteredList, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<View_StatusM>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of players monitoring for specific manager
                     List<View_StatusM> listResult;
                     long lastMonitoring = 0;
                     result = client.GetPlayerStatus(out listResult, ref lastMonitoring, manager.Id, sessionId);

                     if (result == ErrorType.GOOD)
                     {
                         //Filter the result with linq
                         filteredList = (from l1 in listResult where l1.PlayerName.Contains(filter) select l1).ToList();

                         //For filter by id
                         //filteredList = (from l1 in listResult where l1.Id == Id select l1).ToList();
                     }
                 }

                 return result;
             }

             //Send update to players by list of id
             public ErrorType SendUpdate(List<long> listPLayerId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Send update to players of the list
                     Dictionary<long, long> donloadSize;
                     result = client.SetPlayerStatus(out donloadSize, listPLayerId, 1, 1, 0, 0, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of folders for specific group
             public ErrorType GetFolder(out List<View_Folder> listResult, long groupId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<View_Folder>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of folders for specific group
                     result = client.GetFolder(out listResult, groupId, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of folders for specific group filtered by name
             public ErrorType GetFolderByName(out List<View_Folder> filteredList, long groupId, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<View_Folder>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of folders for specific group
                     List<View_Folder> listResult;
                     result = client.GetFolder(out listResult, groupId, manager.Id, sessionId);

                     if (result == ErrorType.GOOD)
                     {
                         //Filter the result with linq
                         filteredList = (from l1 in listResult where l1.Name.Contains(filter) select l1).ToList();

                         //For filter by id
                         //filteredList = (from l1 in listResult where l1.Id == Id select l1).ToList();
                     }
                 }

                 return result;
             }

             //Get list of medias for specific group
             public ErrorType GetMedia(out List<View_Media> listResult, long groupId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<View_Media>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of medias for specific group
                     result = client.GetMedia(out listResult, groupId, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of medias for specific group filtered by name
             public ErrorType GetMediaByName(out List<View_Media> filteredList, long groupId, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<View_Media>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of medias for specific group
                     List<View_Media> listResult;
                     result = client.GetMedia(out listResult, groupId, manager.Id, sessionId);

                     if (result == ErrorType.GOOD)
                     {
                         //Filter the result with linq
                         filteredList = (from l1 in listResult where l1.Name.Contains(filter) select l1).ToList();

                         //For filter by id
                         //filteredList = (from l1 in listResult where l1.Id == Id select l1).ToList();
                     }
                 }

                 return result;
             }

             //Upload media by packet and retrive media object
             public ErrorType UploadMedia(out View_Media media, string safeFileName, long groupId, bool isFirst, bool isLast, byte[] buffer, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 media = null;

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Upload media by packet
                     result = client.UploadMedia(out media, safeFileName, groupId, isFirst, isLast, buffer, manager.Id, sessionId);
                 }

                 return result;
             }

             //Update specific media
             public ErrorType UpdateMedia(ref View_Media media, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Update specific media
                     result = client.UpdateMedia(ref media, media.GroupId ?? 0, null, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of media triggers for specific manager
             public ErrorType GetTrigger(out List<View_Media> filteredList, long groupId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<View_Media>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of medias for specific manager
                     List<View_Media> listResult;
                     result = client.GetMedia(out listResult, groupId, manager.Id, sessionId);

                     if (result == ErrorType.GOOD)
                     {
                         //Filter the result with linq
                         filteredList = (from l1 in listResult where l1.FolderId < 0 select l1).ToList();
                     }
                 }

                 return result;
             }

             //Get list of media triggers for specific manager filtered by name
             public ErrorType GetTriggerByName(out List<View_Media> filteredList, long groupId, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<View_Media>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of medias for specific group
                     List<View_Media> listResult;
                     result = client.GetMedia(out listResult, groupId, manager.Id, sessionId);

                     if (result == ErrorType.GOOD)
                     {
                         //Filter the result with linq
                         filteredList = (from l1 in listResult where l1.FolderId < 0 && l1.Name.Contains(filter) select l1).ToList();
                     }
                 }

                 return result;
             }

             //Get list of templates for specific group
             public ErrorType GetTemplate(out List<View_Template> listResult, long groupId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<View_Template>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of templates for specific group
                     result = client.GetTemplate(out listResult, groupId, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of templates for specific group filtered by name
             public ErrorType GetTemplateByName(out List<View_Template> filteredList, long groupId, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<View_Template>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of templates for specific group
                     List<View_Template> listResult;
                     result = client.GetTemplate(out listResult, groupId, manager.Id, sessionId);

                     if (result == ErrorType.GOOD)
                     {
                         //Filter the result with linq
                         filteredList = (from l1 in listResult where l1.Name.Contains(filter) select l1).ToList();

                         //For filter by id
                         //filteredList = (from l1 in listResult where l1.Id == Id select l1).ToList();
                     }
                 }

                 return result;
             }

             //Get list of ticker for specific group
             public ErrorType GetTicker(out List<View_Banner> listResult, long groupId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<View_Banner>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of ticker for specific group
                     result = client.GetBanner(out listResult, groupId, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of ticker for specific group filtered by name
             public ErrorType GetTickerByName(out List<View_Banner> filteredList, long groupId, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<View_Banner>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of ticker for specific group
                     List<View_Banner> listResult;
                     result = client.GetBanner(out listResult, groupId, manager.Id, sessionId);

                     if (result == ErrorType.GOOD)
                     {
                         //Filter the result with linq
                         filteredList = (from l1 in listResult where l1.Name.Contains(filter) select l1).ToList();

                         //For filter by id
                         //filteredList = (from l1 in listResult where l1.Id == Id select l1).ToList();
                     }
                 }

                 return result;
             }

             //Update specific ticker
             public ErrorType UpdateTicker(ref View_Banner ticker, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Update specific ticker
                     result = client.UpdateBanner(ref ticker, ticker.GroupId ?? 0, null, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of playlist for specific group and specific manager
             public ErrorType GetPlaylist(out List<View_Playlist> listResult, List<long> listGroupId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<View_Playlist>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of playlist for specific group and specific manager
                     result = client.GetPlaylist(out listResult, listGroupId, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of playlist for specific group and specific manager filtered by name
             public ErrorType GetPlaylistByName(out List<View_Playlist> filteredList, List<long> listGroupId, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<View_Playlist>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of playlist for specific group and specific manager
                     List<View_Playlist> listResult;
                     result = client.GetPlaylist(out listResult, listGroupId, manager.Id, sessionId);

                     if (result == ErrorType.GOOD)
                     {
                         //Filter the result with linq
                         filteredList = (from l1 in listResult where l1.Name.Contains(filter) select l1).ToList();

                         //For filter by id
                         //filteredList = (from l1 in listResult where l1.Id == Id select l1).ToList();
                     }
                 }

                 return result;
             }

             //Get list of playlist component for specific playlist
             public ErrorType GetPlaylistMedia(out List<View_PlaylistComponent> listResult, long groupId, long playlistId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<View_PlaylistComponent>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of playlist component for specific playlist
                     string filter = "";
                     result = client.GetPlaylistComponent(out listResult, playlistId, groupId, manager.Id, sessionId, filter);
                 }

                 return result;
             }

             //Add playlist component for specific playlist
             public ErrorType AddPlaylistMedia(ref View_PlaylistComponent component, long groupId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Add media to playlist
                     result = client.AddPlaylistComponent(ref component, groupId, null, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of xml medias for specific group
             public ErrorType GetXMLMedia(out List<XMLMedia> listResult, long groupId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<XMLMedia>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of xml medias for specific group
                     result = client.GetXMLMedia(out listResult, groupId, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of xml medias for specific group filtered by name
             public ErrorType GetXMLMediaByName(out List<XMLMedia> filteredList, long groupId, string filter, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 filteredList = new List<XMLMedia>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of xml medias for specific group
                     List<XMLMedia> listResult;
                     result = client.GetXMLMedia(out listResult, groupId, manager.Id, sessionId);

                     if (result == ErrorType.GOOD)
                     {
                         //Filter the result with linq
                         filteredList = (from l1 in listResult where l1.Name.Contains(filter) select l1).ToList();

                         //For filter by id
                         //filteredList = (from l1 in listResult where l1.Id == Id select l1).ToList();
                     }
                 }

                 return result;
             }

             //Get list of  title for specific xml media
             public ErrorType GetXMLMediaTitle(out List<XMLMediaTitle> listResult, long xmlMediaId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<XMLMediaTitle>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of  title for specific xml media
                     result = client.GetXMLMediaTitle(out listResult, xmlMediaId, manager.Id, sessionId);
                 }

                 return result;
             }

             //Get list of data for specific xml media
             public ErrorType GetXMLMediaData(out List<XMLMediaData> listResult, long xmlMediaId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 listResult = new List<XMLMediaData>();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of data for specific xml media
                     result = client.GetXMLMediaData(out listResult, xmlMediaId, manager.Id, sessionId);
                 }

                 return result;
             }

             //update list of data for specific xml media
             public ErrorType SetXMLMediaData(List<XMLMediaData> listResult, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //update list of data for specific xml media
                     result = client.SetXMLMediaData(ref listResult, manager.Id, sessionId);
                 }

                 return result;
             }

             //Check login and retrive connection session
             private string GetSessionId(out string sessionId, out View_Manager manager, string login = "", string password = "")
             {
                 //Encrypt the password
                 string passswordEncrypt = GetPasswordEncrypt(password, GlobalParam.SERVER_KEY);

                 //Check login and retrive connection session
                 long serverDate;
                 ErrorType result = client.CheckLoginSDK(out sessionId, out manager, out serverDate, login, passswordEncrypt);

                 return GetErrorBySessionId(sessionId, manager, result);
             }

             //Check login and retrive connection session (and server date)
             private string GetSessionId2(out string sessionId, out View_Manager manager, out long serverDate, string login = "", string password = "")
             {
                 //Encrypt the password
                 string passswordEncrypt = GetPasswordEncrypt(password, GlobalParam.SERVER_KEY);

                 //Check login and retrive connection session
                 ErrorType result = client.CheckLoginSDK(out sessionId, out manager, out serverDate, login, passswordEncrypt);

                 return GetErrorBySessionId(sessionId, manager, result);
             }

             //Get error result by session id
             private static string GetErrorBySessionId(string sessionId, View_Manager manager, ErrorType result)
             {
                 if (result == ErrorType.GOOD)
                 {
                     //Result Error
                     switch (sessionId)
                     {
                         case "0": return "Wrong login or password";
                         case "-1": return "Account Expired";
                         case "-2": return "Connection not allowed";
                         case "-3": return "Server error";
                         case "-4": return "Error, Please try again";
                         case "-5": return "Error, Please try again";
                         case "-6": return "Connection not allowed";
                         case "-7": return "Installation not completed";
                     }
                     if (manager != null)
                     {
                         return "ok";
                     }
                 }
                 else
                 {
                     switch (result)
                     {
                         case ErrorType.CONNECTION_ERROR: return "Connection error";
                         case ErrorType.DISCONNECTED: return "Manager disconnected";
                         case ErrorType.MANAGEREXIST: return "Can not create manager because this name as already used";
                         case ErrorType.NOT_POSSIBLE: return "This action is not possible";
                         case ErrorType.PLAYERINGROUP: return "Can not delete this group because one or more player have in this group";
                     }
                 }

                 return "General error";
             }

             //Encrypt password
             public string GetPasswordEncrypt(string password, string serialNumber)
             {
                 byte[] hash = GetHashKey(serialNumber);
                 string passwordEncrypt = Encrypt(hash, password);
                 return passwordEncrypt;
             }

             //Get encryption key
             private byte[] GetHashKey(string hashKey)
             {
                 // Initialise
                 UTF8Encoding encoder = new UTF8Encoding();

                 // Get the salt
                 string salt = "fCycS3qSKsUlNz7wCb39XckN";
                 byte[] saltBytes = encoder.GetBytes(salt);

                 // Setup the hasher
                 Rfc2898DeriveBytes rfc = new Rfc2898DeriveBytes(hashKey, saltBytes);

                 // Return the key
                 return rfc.GetBytes(16);
             }

             //Encrypt data by AES
             private string Encrypt(byte[] key, string dataToEncrypt)
             {
                 // Initialise
                 AesManaged encryptor = new AesManaged();

                 // Set the key
                 encryptor.Key = key;
                 encryptor.IV = key;

                 // create a memory stream
                 using (MemoryStream encryptionStream = new MemoryStream())
                 {
                     // Create the crypto stream
                     using (CryptoStream encrypt = new CryptoStream(encryptionStream, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                     {
                         // Encrypt
                         byte[] utfD1 = UTF8Encoding.UTF8.GetBytes(dataToEncrypt);
                         encrypt.Write(utfD1, 0, utfD1.Length);
                         encrypt.FlushFinalBlock();
                         encrypt.Close();

                         // Return the encrypted data
                         return Convert.ToBase64String(encryptionStream.ToArray());
                     }
                 }
             }

             //Delete Media
             public ErrorType DeleteMedia (View_Media media, long groupId, string login = "", string password = "")
             {
                 //Initialize the return value(s)
                 ErrorType result = ErrorType.CONNECTION_ERROR;
                 //media = new View_Media();

                 //Check user connection
                 if ((manager != null && sessionId != "" && login == "" && password == "") //Already connected
                     || "ok" == GetSessionId(out sessionId, out manager, login, password)) //Get Manager connection data
                 {
                     //Get list of medias for specific group
                     result = client.DeleteMedia(ref media, groupId, null, manager.Id, sessionId);
                 }

                 return result;
             }
         }
     }