# DetailSample.cs [C#]

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

     namespace WpfApplication1
     {
         class DetailSample
         {
             ManagerServiceClient client;

             public DetailSample()
             {
                 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);
             }

             //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());
                     }
                 }
             }

             //Connect to the QL system and check credential from the SDK
             public ErrorType CheckLoginSDK(out string sessionId, out View_Manager manager, out long serverDate, string login, string password)
             {
                 //Encrypt the password
                 string passswordEncrypt = GetPasswordEncrypt(password, GlobalParam.SERVER_KEY);

                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<param name=manager>Manager to retrive</param>
                 //<param name=serverDate>Date of the server</param>
                 //<param name=login>Manager login</param>
                 //<param name=password>Manager password</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.CheckLoginSDK(out sessionId, out manager, out serverDate, login, passswordEncrypt);
             }

             //Get list of groups for a specific manager that belongs to a specific company
             public ErrorType GetGroup(out List<View_Group> listGroup, long boxId, long managerId, string sessionId)
             {
                 //<param name=listGroup>List of groups retrieved for the company</param>
                 //<param name=boxId>Company Id that binds user with group list</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetGroup(out listGroup, boxId, managerId, sessionId);
             }

             //Get list of filtered groups for a specific manager that belongs to a specific company
             public ErrorType GetFilteredGroup(out List<View_Group> listGroup, string filter, long managerId, string sessionId)
             {
                 //<param name=listGroup>List of filtered groups retrieved for the company</param>
                 //<param name=filter>Search query</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetFilteredGroup(out listGroup, filter, managerId, sessionId);
             }

             //Get list of player profile for all application
             public ErrorType GetPlayerProfil(out List<PlayerProfil> listPlayerProfil, long managerId, string sessionId, bool onlyThisBox)
             {
                 //<param name=listPlayerProfil>List of player profile</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<param name="onlyThisBox">only this box or admin profiles also </param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetPlayerProfil(out listPlayerProfil, managerId, sessionId, onlyThisBox);
             }

             //Get list of players for a specific manager that belongs to a specific company
             public ErrorType GetPlayer(out List<View_Player> listPlayer, long boxId, long managerId, string sessionId)
             {
                 //<param name=listPlayer>List of players retrieved for the company</param>
                 //<param name=boxId>Company Id that binds user with player list</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetPlayer(out listPlayer, boxId, managerId, sessionId);
             }

             //Get list of filtered players for a specific manager that belongs to a specific company
             public ErrorType GetFilteredPlayer(out List<View_Player> listPlayer, string filter, long managerId, string sessionId)
             {
                 //<param name=listPlayer>List of players retrieved for the company</param>
                 //<param name=filter>Search query</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetFilteredPlayer(out listPlayer, filter, managerId, sessionId);
             }

             //Get list of folder for specific group
             public ErrorType GetFolder(out List<View_Folder> listFolder, long groupId, long managerId, string sessionId)
             {
                 //<param name=listFolder>List of folder</param>
                 //<param name=groupId>Id of group</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetFolder(out listFolder, groupId, managerId, sessionId);
             }

             //Get list of media for specific group
             public ErrorType GetMedia(out List<View_Media> listMedia, long groupId, long managerId, string sessionId)
             {
                 //<param name=listMedia>List of media for specific group</param>
                 //<param name=groupId>Id of group</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetMedia(out listMedia, groupId, managerId, sessionId);
             }

             //Get list of filtered media for specific group
             public ErrorType GetFilteredMedia(out List<View_Media> listMedia, long groupId, string filter, long managerId, string sessionId)
             {
                 //<param name=listMedia>List of media for specific group</param>
                 //<param name=groupId>Id of group</param>
                 //<param name=filter>Search query</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetFilteredMedia(out listMedia, groupId, filter, managerId, sessionId);
             }

             //Get list of template for specific group
             public ErrorType GetTemplate(out List<View_Template> listTemplates, long groupId, long managerId, string sessionId)
             {
                 //<param name=listTemplates>List of template</param>
                 //<param name=groupId>Id of group</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetTemplate(out listTemplates, groupId, managerId, sessionId);
             }

             //Get list of filtered template for specific group
             public ErrorType GetFilteredTemplate(out List<View_Template> listTemplates, long groupId, string filter, long managerId, string sessionId)
             {
                 //<param name=listTemplates>List of filtered template</param>
                 //<param name=groupId>Id of group</param>
                 //<param name=filter>Search query</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetFilteredTemplate(out listTemplates, groupId, filter, managerId, sessionId);
             }

             //Get list of ticker for specific group
             public ErrorType GetBanner(out List<View_Banner> listBanner, long groupId, long managerId, string sessionId)
             {
                 //<param name=listBanner>List of ticker</param>
                 //<param name=groupId>Id of group</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetBanner(out listBanner, groupId, managerId, sessionId);
             }

             //Get list of filtered ticker for specific group
             public ErrorType GetFilteredBanner(out List<View_Banner> listBanner, long groupId, string filter, long managerId, string sessionId)
             {
                 //<param name=listBanner>List of ticker</param>
                 //<param name=groupId>Id of group</param>
                 //<param name=filter>Search query</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetFilteredBanner(out listBanner, groupId, filter, managerId, sessionId);
             }

             //Get list of playlist for specific group
             public ErrorType GetPlaylist(out List<View_Playlist> listPlaylist, List<long> groupId, long managerId, string sessionId)
             {
                 //<param name=listPlaylist>List of playlist</param>
                 //<param name=groupId>Id of group</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetPlaylist(out listPlaylist, groupId, managerId, sessionId);
             }

             //Get list of playlist component for specific playlist
             public ErrorType GetPlaylistComponent(out List<View_PlaylistComponent> listPlaylistComponent, long playlistId, long groupId, long managerId, string sessionId, string filter = null)
             {
                 //<param name=listPlaylistComponent>List of playlist component</param>
                 //<param name=playlistId>Id of playlist</param>
                 //<param name=groupId>Id of group</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetPlaylistComponent(out listPlaylistComponent, playlistId, groupId, managerId, sessionId, filter);
             }

             //Get list of playlist ticker for specific playlist
             public ErrorType GetPlaylistBanner(out List<View_PlaylistBanner> listPlaylistBanner, long playlistId, long managerId, string sessionId)
             {
                 //<param name=listPlaylistBanner>List of playlist ticker</param>
                 //<param name=playlistId>Id of playlist</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetPlaylistBanner(out listPlaylistBanner, playlistId, managerId, sessionId);
             }

             //Get list of player status for specific manager
             public ErrorType GetPlayerStatus(out List<View_StatusM> listPlayerStatus, ref long lastMonitoring, long managerId, string sessionId)
             {
                 //<param name=listPlayerStatus>List of player status</param>
                 //<param name=lastMonitoring>Date begin of the status list</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetPlayerStatus(out listPlayerStatus, ref lastMonitoring, managerId, sessionId);
             }

             //Update list of player status
             public ErrorType SetPlayerStatus(out Dictionary<long, long> downloadSize, List<long> listPlayerId, int methodeTypeId, int optionTypeId, long date, long time, long managerId, string sessionId)
             {
                 //<param name=listPlayerId>List of player to update</param>
                 //<param name=methodeTypeId>Update methode</param>
                 //<param name=optionTypeId>Update option</param>
                 //<param name=date>Update time (for difered update)</param>
                 //<param name=time>Update time (for difered update)</param>
                 //<param name=downloadSize>Update download size (=0)</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.SetPlayerStatus(out downloadSize, listPlayerId, methodeTypeId, optionTypeId, date, time, managerId, sessionId);
             }

             //Get list of XML media for specific group
             public ErrorType GetXMLMedia(out List<XMLMedia> listXmlMedia, long groupId, long managerId, string sessionId)
             {
                 //<param name=listXmlMedia>List of XML media</param>
                 //<param name=groupId>Id of group</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetXMLMedia(out listXmlMedia, groupId, managerId, sessionId);
             }

             //Get list of title for specific XML media
             public ErrorType GetXMLMediaTitle(out List<XMLMediaTitle> listXmlMediaTitle, long xmlMediaId, long managerId, string sessionId)
             {
                 //<param name=listXmlMediaTitle>List of title</param>
                 //<param name=xmlMediaId>XML media</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetXMLMediaTitle(out listXmlMediaTitle, xmlMediaId, managerId, sessionId);
             }

             //Get list of data for specific XML media
             public ErrorType GetXMLMediaData(out List<XMLMediaData> listXmlMediaData, long xmlMediaId, long managerId, string sessionId)
             {
                 //<param name=listXmlMediaData>list of data</param>
                 //<param name=xmlMediaId>XML media</param>
                 //<param name=managerId>Manager Id retrieved at the user's connection</param>
                 //<param name=sessionId>Session Id retrieved at the user's connection</param>
                 //<returns>ErrorType indicates the status of the transaction</returns>
                 return client.GetXMLMediaData(out listXmlMediaData, xmlMediaId, managerId, sessionId);
             }
         }
     }