internal async Task <bool> InitialLoad() { LoadFileOperation storageSettings = await ResourcesModel.LoadToJSONObject(StorageDirectory + ID_SAFEFILE); if (storageSettings.Success) { if (storageSettings.Result.TryGetField(JSON_ID, out nextId)) { string[] files = Directory.GetFiles(StorageDirectory); foreach (string filename in files) { if (filename.EndsWith("json") && filename.Contains("page-")) { LoadFileOperation PageFile = await ResourcesModel.LoadToJSONObject(filename); if (PageFile.Success) { handlePageJSON(PageFile.Result); } } } return(true); } } return(false); }
internal static async Task <bool> LoadQuotes() { LoadFileOperation quoteSettings = await ResourcesModel.LoadToJSONObject(ResourcesModel.QuoteSettingsFilePath); if (quoteSettings.Success) { if (quoteSettings.Result.GetField(ref nextQuoteId, JSON_QUOTEID)) { string[] files = Directory.GetFiles(ResourcesModel.QuotesDirectory); foreach (string filename in files) { if (filename.EndsWith("json") && filename.Contains("quotes-")) { LoadFileOperation QuoteFile = await ResourcesModel.LoadToJSONObject(filename); if (QuoteFile.Success) { handleQuoteJSON(QuoteFile.Result); } } } return(true); } } return(false); }
private static async Task LoadGuildModerationLog(ulong guildId) { GuildModerationLog guildModerationLog = new GuildModerationLog(guildId); if (Directory.Exists(guildModerationLog.UserDirectory)) { foreach (string filepath in Directory.EnumerateFiles(guildModerationLog.UserDirectory, "*.json")) { LoadFileOperation load = await ResourcesModel.LoadToJSONObject(filepath); if (load.Success) { UserModerationLog userModerationLog = new UserModerationLog(guildModerationLog); if (userModerationLog.FromJSON(load.Result)) { guildModerationLog.userLogs.Add(userModerationLog.UserId, userModerationLog); if (userModerationLog.IsBanned) { if (userModerationLog.BannedUntil.Value < DateTimeOffset.MaxValue) { AddTimeLimitedInfractionReference(userModerationLog); } } else if (userModerationLog.IsMuted) { if (userModerationLog.MutedUntil.Value < DateTimeOffset.MaxValue) { AddTimeLimitedInfractionReference(userModerationLog); } } } } } } if (Directory.Exists(guildModerationLog.ChannelDirectory)) { foreach (string filepath in Directory.EnumerateFiles(guildModerationLog.ChannelDirectory, "*.json")) { LoadFileOperation load = await ResourcesModel.LoadToJSONObject(filepath); if (load.Success) { ChannelModerationLog channelModerationLog = new ChannelModerationLog(guildModerationLog); if (channelModerationLog.FromJSON(load.Result)) { guildModerationLog.channelLogs.Add(channelModerationLog.ChannelId, channelModerationLog); } } } } GuildLogs.Add(guildModerationLog.GuildId, guildModerationLog); }
private void Load(LoadFileOperation operation) { /* * filePath: C:/code/plangrid-windows/.git/COMMIT_EDITMSG * HEAD => contains branch name! * * * rebase * C:/code/plangrid-windows/.git/rebase-merge/git-rebase-todo * C:/code/plangrid-windows/.git/COMMIT_EDITMSG */ FileInfo fileInfo = new FileInfo(operation.FilePath); if (fileInfo.Exists) { this.filePath = operation.FilePath; string commitText = File.ReadAllText(operation.FilePath); string branch = GetBranchName(fileInfo.Directory.FullName); string jiraTicket = ""; if (branch?.Contains("/") ?? false) { jiraTicket = branch.Substring(branch.LastIndexOf("/") + 1).ToUpper(); } var lines = commitText.Split('\n'); bool hasContent = lines.Any(x => !string.IsNullOrEmpty(x) && !x.StartsWith("#")); // TODO: what happens with ammend if (!hasContent) { // if we are starting with a standard commit template (i.e. no user edits) // then we will start the message with a prefix of the jira ticket from the branch name switch (branch) { case "dev": case "test": case "master": case null: break; default: if (!commitText.StartsWith(jiraTicket)) { commitText = jiraTicket + ": " + commitText; } break; } } Dispatch(LastState .WithMessage(commitText) .WithHasUserEdited(false) .WithSelectionStart(Math.Max(0, commitText.IndexOf("\n"))) .WithFocus(true)); } // TODO: Rebase UI // TODO: Add button to set as git editor // TODO: show a row of emoji/help text along the top that is filtered by text from the last ':' -or- default to common picks }