# GetMediaByName [C#]

[C#]

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

[C#]

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

[C#]

       //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";
       }

[C#]

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

[C#]

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