internal async Task SafePages(int listLocation = -1) { JSONContainer idSettings = JSONContainer.NewObject(); idSettings.TryAddField(JSON_ID, nextId); await ResourcesModel.WriteJSONObjectToFile(StorageDirectory + ID_SAFEFILE, idSettings); if (listLocation == -1) { foreach (string file in Directory.GetFiles(StorageDirectory)) { if (file.Contains("page-") && file.EndsWith(".json")) { File.Delete(file); } } int pages = (pageStorables.Count - 1) / PAGESIZE; for (int i = 0; i <= pages; i++) { await SafePage(i); } } else { int page = listLocation / PAGESIZE; await SafePage(page); } }
internal async Task SafePage(int page) { JSONContainer entryList = JSONContainer.NewArray(); for (int i = page * PAGESIZE; i < pageStorables.Count && i < (page + 1) * PAGESIZE; i++) { entryList.Add(pageStorables[i].ToJSON()); } await ResourcesModel.WriteJSONObjectToFile(string.Format("{0}page-{1}.json", StorageDirectory, page), entryList); }
internal static async Task SafeQuotePage(int page) { JSONObject quoteListJSON = new JSONObject(); for (int i = page * QUOTE_PAGESIZE; i < QuoteList.Count && i < (page + 1) * QUOTE_PAGESIZE; i++) { quoteListJSON.Add(QuoteList[i].ToJSON()); } await ResourcesModel.WriteJSONObjectToFile(string.Format("{0}quotes-{1}.json", ResourcesModel.QuotesDirectory, page), quoteListJSON); }
public static async Task SaveAll() { JSONContainer json = JSONContainer.NewArray(); foreach (MinecraftGuild guild in guilds) { if (guild.NameAndColorFound) { json.Add(guild.ToJSON()); } } await ResourcesModel.WriteJSONObjectToFile(ResourcesModel.GuildsFilePath, json); }
internal static async Task SafeQuote(int listLocation = -1) { JSONObject quoteSettings = new JSONObject(); quoteSettings.AddField(JSON_QUOTEID, nextQuoteId); await ResourcesModel.WriteJSONObjectToFile(ResourcesModel.QuoteSettingsFilePath, quoteSettings); if (listLocation == -1) { int pages = (QuoteList.Count - 1) / QUOTE_PAGESIZE; for (int i = 0; i <= pages; i++) { await SafeQuotePage(i); } } else { int page = listLocation / QUOTE_PAGESIZE; await SafeQuotePage(page); } }
public Task Save() { JSONContainer json = ToJSON(); return(ResourcesModel.WriteJSONObjectToFile($"{Parent.UserDirectory}/{UserId}.json", json)); }