public static void SubmitModInfo(string modName, ISet <string> modTags, Action <Exception, string> onError, Action <bool, string> onCompletion = null) { string url = "http://hamstar.pw/hamstarhelpers/mod_info_submit/"; var json = new PostModTagsData { modname = modName, modtags = string.Join(",", modTags) }; string jsonStr = JsonConvert.SerializeObject(json, Formatting.Indented); Action <bool, string> wrappedOnCompletion = (success, output) => { string processedOutput = ""; if (success) { JObject respJson = JObject.Parse(output); JToken msg = respJson.SelectToken("Msg"); success = msg != null; if (success) { processedOutput = msg.ToObject <string>(); } else { processedOutput = "Failure."; } } onCompletion(success, processedOutput); }; Action <Exception, string> wrappedOnError = (Exception e, string str) => { LogHelpers.Log("!ModHelpers.PostModInfo.SubmitModInfo - Failed for post: " + jsonStr); onError(e, str); }; WebConnectionHelpers.MakePostRequestAsync(url, jsonStr, e => wrappedOnError(e, ""), wrappedOnCompletion); }
public static void ReportIssue(Mod mod, string issueTitle, string issueBody, Action <Exception, string> onError, Action <bool, string> onCompletion) { if (!ModFeaturesHelpers.HasGithub(mod)) { throw new ModHelpersException("Mod is not eligable for submitting issues."); } int maxLines = ModHelpersMod.Config.ModIssueReportErrorLogMaxLines; IEnumerable <Mod> mods = ModListHelpers.GetAllLoadedModsPreferredOrder(); string bodyInfo = string.Join("\n \n", FormattedGameInfoHelpers.GetFormattedGameInfo(mods).ToArray()); string bodyErrors = string.Join("\n", GameInfoHelpers.GetErrorLog(maxLines).ToArray()); string url = "http://hamstar.pw/hamstarhelpers/issue_submit/"; string title = "Reported from in-game: " + issueTitle; string body = bodyInfo; body += "\n \n \n \n" + "Recent error logs:\n```\n" + bodyErrors + "\n```"; body += "\n \n" + issueBody; var json = new GithubModIssueReportData { githubuser = ModFeaturesHelpers.GetGithubUserName(mod), githubproject = ModFeaturesHelpers.GetGithubProjectName(mod), title = title, body = body }; string jsonStr = JsonConvert.SerializeObject(json, Formatting.Indented); Action <bool, string> wrappedOnCompletion = (success, output) => { string processedOutput = ""; if (success) { JObject respJson = JObject.Parse(output); JToken data = respJson.SelectToken("Data.html_url"); JToken msg = respJson.SelectToken("Msg"); if (data != null) { string issueUrl = data.ToObject <string>(); if (!string.IsNullOrEmpty(issueUrl)) { SystemHelpers.OpenUrl(issueUrl); } } success = msg != null; if (success) { processedOutput = msg.ToObject <string>(); } else { processedOutput = "Failure."; } } onCompletion(success, processedOutput); }; Action <Exception, string> wrappedOnError = (Exception e, string str) => { LogHelpers.Log("!ModHelpers.PostGithubModIssueReports.ReportIssue - Failed for POST to " + url + " : " + jsonStr); onError(e, str); }; WebConnectionHelpers.MakePostRequestAsync(url, jsonStr, e => wrappedOnError(e, ""), wrappedOnCompletion); }