/// <summary>
 /// Selects a storage method by its instance, if it exists
 /// </summary>
 /// <param name="StorageMethod">The Storage Method instance to select</param>
 public void SelectStorageMethod(IStorageMethod <T> StorageMethod)
 {
     if (StorageMethods.Contains(StorageMethod))
     {
         this.StorageMethod = StorageMethod;
     }
 }
Ejemplo n.º 2
0
 public static SaveFileManifest Deserialize(IStorageMethod storage)
 {
     if (!storage.FileExists("Accounts.txt"))
         return null;
     using (var fileReadStream = storage.GetFileReadStream("Accounts.txt"))
         return Deserialize(new StreamReader(fileReadStream).ReadToEnd());
 }
Ejemplo n.º 3
0
        public virtual void UpdateDataFromOtherManager(IStorageMethod otherMethod)
        {
            var str          = manifest.LastLoggedInUser.Username;
            var saveManifest = otherMethod.GetSaveManifest();

            for (var index1 = 0; index1 < saveManifest.Accounts.Count; ++index1)
            {
                var saveAccountData1 = saveManifest.Accounts[index1];
                var flag             = false;
                for (var index2 = 0; index2 < manifest.Accounts.Count; ++index2)
                {
                    var saveAccountData2 = manifest.Accounts[index2];
                    if (saveAccountData2.Username == saveAccountData1.Username)
                    {
                        flag = true;
                        var timeSpan = saveAccountData1.LastWriteTime - saveAccountData2.LastWriteTime;
                        if (saveAccountData1.LastWriteTime > saveAccountData2.LastWriteTime &&
                            timeSpan.TotalSeconds > 5.0)
                        {
                            var fileReadStream = otherMethod.GetFileReadStream(saveAccountData1.FileUsername);
                            if (fileReadStream != null)
                            {
                                var data = Utils.ReadEntireContentsOfStream(fileReadStream);
                                if (data.Length > 100)
                                {
                                    WriteFileData(saveAccountData2.FileUsername, data);
                                }
                            }
                        }
                        break;
                    }
                }
                if (!flag)
                {
                    var fileReadStream = otherMethod.GetFileReadStream(saveAccountData1.FileUsername);
                    if (fileReadStream != null)
                    {
                        var fileNameForUsername = SaveFileManager.GetSaveFileNameForUsername(saveAccountData1.Username);
                        manifest.AddUser(saveAccountData1.Username, saveAccountData1.Password, DateTime.UtcNow,
                                         fileNameForUsername);
                        var data = Utils.ReadEntireContentsOfStream(fileReadStream);
                        WriteFileData(fileNameForUsername, data);
                    }
                }
            }
            for (var index = 0; index < manifest.Accounts.Count; ++index)
            {
                if (manifest.Accounts[index].Username == str)
                {
                    manifest.LastLoggedInUser = manifest.Accounts[index];
                }
            }
            if (manifest.LastLoggedInUser.Username == null && manifest.Accounts.Count > 0)
            {
                manifest.LastLoggedInUser = manifest.Accounts[0];
            }
            manifest.Save(this);
        }
Ejemplo n.º 4
0
        public virtual void UpdateDataFromOtherManager(IStorageMethod otherMethod)
        {
            string           username     = this.manifest.LastLoggedInUser.Username;
            SaveFileManifest saveManifest = otherMethod.GetSaveManifest();

            for (int index1 = 0; index1 < saveManifest.Accounts.Count; ++index1)
            {
                SaveAccountData account1 = saveManifest.Accounts[index1];
                bool            flag     = false;
                for (int index2 = 0; index2 < this.manifest.Accounts.Count; ++index2)
                {
                    SaveAccountData account2 = this.manifest.Accounts[index2];
                    if (account2.Username == account1.Username)
                    {
                        flag = true;
                        TimeSpan timeSpan = account1.LastWriteTime - account2.LastWriteTime;
                        if (account1.LastWriteTime > account2.LastWriteTime && timeSpan.TotalSeconds > 5.0)
                        {
                            Stream fileReadStream = otherMethod.GetFileReadStream(account1.FileUsername);
                            if (fileReadStream != null)
                            {
                                string data = Utils.ReadEntireContentsOfStream(fileReadStream);
                                if (data.Length > 100)
                                {
                                    this.WriteFileData(account2.FileUsername, data);
                                }
                            }
                            break;
                        }
                        break;
                    }
                }
                if (!flag)
                {
                    Stream fileReadStream = otherMethod.GetFileReadStream(account1.FileUsername);
                    if (fileReadStream != null)
                    {
                        string fileNameForUsername = SaveFileManager.GetSaveFileNameForUsername(account1.Username);
                        this.manifest.AddUser(account1.Username, account1.Password, DateTime.UtcNow, fileNameForUsername);
                        string data = Utils.ReadEntireContentsOfStream(fileReadStream);
                        this.WriteFileData(fileNameForUsername, data);
                    }
                }
            }
            for (int index = 0; index < this.manifest.Accounts.Count; ++index)
            {
                if (this.manifest.Accounts[index].Username == username)
                {
                    this.manifest.LastLoggedInUser = this.manifest.Accounts[index];
                }
            }
            if (this.manifest.LastLoggedInUser.Username == null && this.manifest.Accounts.Count > 0)
            {
                this.manifest.LastLoggedInUser = this.manifest.Accounts[0];
            }
            this.manifest.Save((IStorageMethod)this, false);
        }
Ejemplo n.º 5
0
 public static SaveFileManifest Deserialize(IStorageMethod storage)
 {
     if (!storage.FileExists("Accounts.txt"))
     {
         return(null);
     }
     using (var fileReadStream = storage.GetFileReadStream("Accounts.txt"))
         return(Deserialize(new StreamReader(fileReadStream).ReadToEnd()));
 }
 /// <summary>
 /// Selects a storage method by its name, if it exists
 /// </summary>
 /// <param name="StorageMethodName">The Name of the Storage Method to select</param>
 public void SelectStorageMethod(string StorageMethodName)
 {
     foreach (IStorageMethod <T> StorageMethod in StorageMethods)
     {
         if (StorageMethod.Name == StorageMethodName)
         {
             this.StorageMethod = StorageMethod;
         }
     }
 }
Ejemplo n.º 7
0
        public void Save(IStorageMethod storage)
        {
            var data = LastLoggedInUser.Username + "\r\n%------%";

            for (var index = 0; index < Accounts.Count; ++index)
            {
                data = data + Accounts[index].Serialize() + "\r\n%------%";
            }
            storage.WriteFileData("Accounts.txt", data);
        }
Ejemplo n.º 8
0
 public virtual void UpdateDataFromOtherManager(IStorageMethod otherMethod)
 {
     var str = manifest.LastLoggedInUser.Username;
     var saveManifest = otherMethod.GetSaveManifest();
     for (var index1 = 0; index1 < saveManifest.Accounts.Count; ++index1)
     {
         var saveAccountData1 = saveManifest.Accounts[index1];
         var flag = false;
         for (var index2 = 0; index2 < manifest.Accounts.Count; ++index2)
         {
             var saveAccountData2 = manifest.Accounts[index2];
             if (saveAccountData2.Username == saveAccountData1.Username)
             {
                 flag = true;
                 var timeSpan = saveAccountData1.LastWriteTime - saveAccountData2.LastWriteTime;
                 if (saveAccountData1.LastWriteTime > saveAccountData2.LastWriteTime &&
                     timeSpan.TotalSeconds > 5.0)
                 {
                     var fileReadStream = otherMethod.GetFileReadStream(saveAccountData1.FileUsername);
                     if (fileReadStream != null)
                     {
                         var data = Utils.ReadEntireContentsOfStream(fileReadStream);
                         if (data.Length > 100)
                         {
                             WriteFileData(saveAccountData2.FileUsername, data);
                         }
                     }
                 }
                 break;
             }
         }
         if (!flag)
         {
             var fileReadStream = otherMethod.GetFileReadStream(saveAccountData1.FileUsername);
             if (fileReadStream != null)
             {
                 var fileNameForUsername = SaveFileManager.GetSaveFileNameForUsername(saveAccountData1.Username);
                 manifest.AddUser(saveAccountData1.Username, saveAccountData1.Password, DateTime.UtcNow,
                     fileNameForUsername);
                 var data = Utils.ReadEntireContentsOfStream(fileReadStream);
                 WriteFileData(fileNameForUsername, data);
             }
         }
     }
     for (var index = 0; index < manifest.Accounts.Count; ++index)
     {
         if (manifest.Accounts[index].Username == str)
             manifest.LastLoggedInUser = manifest.Accounts[index];
     }
     if (manifest.LastLoggedInUser.Username == null && manifest.Accounts.Count > 0)
         manifest.LastLoggedInUser = manifest.Accounts[0];
     manifest.Save(this);
 }
Ejemplo n.º 9
0
 public void Save(IStorageMethod storage, bool ExpectNoAccounts = false)
 {
     if (this.Accounts.Count == 0 && !ExpectNoAccounts)
     {
         int num = 10 + 1;
     }
     else
     {
         string data = this.LastLoggedInUser.Username + "\r\n%------%";
         for (int index = 0; index < this.Accounts.Count; ++index)
         {
             data = data + this.Accounts[index].Serialize() + "\r\n%------%";
         }
         storage.WriteFileData("Accounts.txt", data);
     }
 }
Ejemplo n.º 10
0
        public static SaveFileManifest Deserialize(IStorageMethod storage)
        {
            if (!storage.FileExists("Accounts.txt"))
            {
                return((SaveFileManifest)null);
            }
            SaveFileManifest saveFileManifest = (SaveFileManifest)null;

            using (Stream fileReadStream = storage.GetFileReadStream("Accounts.txt"))
            {
                string end = new StreamReader(fileReadStream).ReadToEnd();
                if (!string.IsNullOrEmpty(end.Trim()))
                {
                    saveFileManifest = SaveFileManifest.Deserialize(end);
                }
            }
            return(saveFileManifest);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Adds a storage method
 /// </summary>
 /// <param name="StorageMethod">The Storage Method to add</param>
 public void AddStorageMethod(IStorageMethod <T> StorageMethod)
 {
     StorageMethods.Add(StorageMethod);
 }
 public static void Configure(this SubscriptionClient client, IStorageMethod storageMethod)
 {
     client.StorageMethod = storageMethod;
 }
Ejemplo n.º 13
0
 public void UpdateDataFromOtherManager(IStorageMethod otherMethod)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 14
0
 public void UpdateDataFromOtherManager(IStorageMethod otherMethod)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 15
0
 public void Save(IStorageMethod storage)
 {
     var data = LastLoggedInUser.Username + "\r\n%------%";
     for (var index = 0; index < Accounts.Count; ++index)
         data = data + Accounts[index].Serialize() + "\r\n%------%";
     storage.WriteFileData("Accounts.txt", data);
 }