BattlelogMobile.Core.Repository.FileCredentialsRepository.Load C# (CSharp) Метод

Load() публичный Метод

public Load ( ) : Credentials
Результат BattlelogMobile.Core.Model.Credentials
        public Credentials Load()
        {
            Credentials credentials = new Credentials();
            using (var reader = new StreamReader(StorageFile.OpenFile(Common.CredentialsFile, FileMode.OpenOrCreate, FileAccess.Read)))
            {
                bool isEncrypted;
                IsolatedStorageSettings.ApplicationSettings.TryGetValue("IsEncrypted", out isEncrypted);
                if (reader.Peek() > 0)
                {
                    try
                    {
                        credentials.Email = isEncrypted ? _crypto.Decrypt(reader.ReadLine()) : reader.ReadLine();
                        credentials.Password = isEncrypted ? _crypto.Decrypt(reader.ReadLine()) : reader.ReadLine();
                        credentials.Game = (SupportedGame) Convert.ToInt32(reader.ReadLine());
                        credentials.RememberMe = !string.IsNullOrEmpty(credentials.Password) && Convert.ToBoolean(reader.ReadLine());
                    }
                    catch (Exception e)
                    {
                        // If it's format exception, then user has not saved credentials in new format before
                        if (!(e is FormatException))
                            throw;
                    }
                }
            }

            if (credentials.Email == null || credentials.Password == null || credentials.Password.Length > 20)
                return new Credentials();
            return credentials;
        }

Usage Example

 public void LoadAndSaveTest()
 {
     var repository = new FileCredentialsRepository(IsolatedStorageFile.GetUserStoreForApplication());
     var expected = new Credentials()
         {
             Email = "*****@*****.**",
             Password = "******",
             RememberMe = true
         };
     repository.Save(expected);
     var actual = repository.Load();
     Assert.IsTrue(expected.Equals(actual));
 }