Exemplo n.º 1
0
        public static async Task <Account> CreateAccount(string nickname)
        {
            CurrentAccount = RankCollection
                             .Where(e => string.Equals(e.Nickname, nickname,
                                                       StringComparison.CurrentCultureIgnoreCase))
                             .ToList()
                             .FirstOrDefault()
                             ?? new Account(nickname);
            RankCollection.Add(CurrentAccount);
            RankCollection.Sort(true);
            await SerializeNow();

            return(CurrentAccount);
        }
Exemplo n.º 2
0
        public static async Task SerializeNow()
        {
            string output = JsonConvert.SerializeObject(RankCollection.ToArray(), Formatting.Indented);
            await Task.Run(async() =>
            {
                StorageFolder storageFolder =
                    ApplicationData.Current.LocalFolder;
                StorageFile storageFile =
                    await storageFolder.CreateFileAsync("accounts.json",
                                                        CreationCollisionOption.ReplaceExisting);

                //Write data to the file
                await FileIO.WriteTextAsync(storageFile, output);
            });
        }
Exemplo n.º 3
0
        public static async Task <bool> DeSerializeNow()
        {
            StorageFolder storageFolder =
                ApplicationData.Current.LocalFolder;
            StorageFile storageFile =
                await storageFolder.GetFileAsync("accounts.json");

            if (storageFile == null)
            {
                return(false);
            }
            string rankListJson = await FileIO.ReadTextAsync(storageFile);

            if (rankListJson == null)
            {
                return(false);
            }
            var accounts = JsonConvert.DeserializeObject <Account[]>(rankListJson);

            RankCollection = new RankCollection(accounts.ToList());
            return(RankCollection != null);
        }
Exemplo n.º 4
0
 // constructor
 static Account()
 {
     RankCollection = new RankCollection();
     CurrentAccount = null;
 }