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); }
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); }); }
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); }
// constructor static Account() { RankCollection = new RankCollection(); CurrentAccount = null; }