/// <summary> /// Gets an object with the latest release info /// </summary> public static void CheckForUpdate(bool alwaysGetFeedBack) { if (_latestReleaseInfo != null) { // we already checked and there is a new version if (!_warnedUserAboutUpdateAvail || alwaysGetFeedBack) { NotifyUpdateAvailable(); } return; } if (_checking) { return; } try { var wb = new WebServiceJson(WebServiceJson.WebRequestMethod.Get, Config.ReleasesApi); wb.TimeOut = 3000; wb.OnRequestEnded += json => WbOnOnRequestEnded(json, alwaysGetFeedBack); wb.Execute(); } catch (Exception e) { ErrorHandler.ShowErrors(e, "Error when checking for updates"); } }
public static void DisplayBugs() { var wb = new WebServiceJson(WebServiceJson.WebRequestMethod.Get, Config.BugsGetWebWervice); wb.OnRequestEnded += webServ => { if (webServ.StatusCodeResponse != HttpStatusCode.OK) { UserCommunication.Notify(webServ.ResponseException.ToString()); } else { UserCommunication.Notify(webServ.JsonResponse); } }; wb.Execute(); }
/// <summary> /// Sends the given report to the web service of 3P /// </summary> private static void SendBugReport(ExceptionInfo bugReport) { var wb = new WebServiceJson(WebServiceJson.WebRequestMethod.Post, Config.BugsPostWebWervice); wb.Serialize(bugReport); // save the request in a file var fileName = Path.Combine(Config.FolderLog, "unreported_" + DateTime.Now.ToString("yy.MM.dd_HH-mm-ss_") + _nbErrors++ + ".json"); Utils.FileWriteAllText(fileName, wb.JsonRequest.ToString()); wb.OnRequestEnded += webServ => { // request ok -> delete the json if (webServ.StatusCodeResponse == HttpStatusCode.OK) { Utils.DeleteFile(fileName); } }; wb.Execute(); }
/// <summary> /// This method pings a webservice deployed for 3P, it simply allows to do /// statistics on the number of users of the software /// </summary> public static void Ping() { try { DateTime lastPing; if (!DateTime.TryParseExact(Config.Instance.TechnicalLastPing, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out lastPing)) { lastPing = DateTime.MinValue; } // ping once every hour if (DateTime.Now.Subtract(lastPing).TotalMinutes > 59) { var webServiceJson = new WebServiceJson(WebServiceJson.WebRequestMethod.Post, Config.PingPostWebWervice); webServiceJson.AddToReq("UUID", UniqueId); webServiceJson.AddToReq("userName", Name); webServiceJson.AddToReq("version", AssemblyInfo.Version); webServiceJson.OnRequestEnded += req => { if (req.StatusCodeResponse == HttpStatusCode.OK) { Config.Instance.TechnicalLastPing = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } }; webServiceJson.Execute(); } } catch (Exception e) { if (Config.IsDevelopper) ErrorHandler.ShowErrors(e); } }
/// <summary> /// Sends an comment to a given GITHUB issue url /// </summary> /// <param name="message"></param> /// <param name="url"></param> public static bool SendComment(string message, string url) { // https://api.github.com/repos/jcaillon/3p/issues/1/comments // handle spam (10s min between 2 posts) if (Utils.IsSpamming("SendComment", 10000)) return false; var wb = new WebServiceJson(WebServiceJson.WebRequestMethod.Post, url); // Convert.ToBase64String(Encoding.ASCII.GetBytes("user:mdp")); wb.OnInitHttpWebRequest += request => request.Headers.Add("Authorization", "Basic " + Config._3PUserCredentials); wb.AddToReq("body", "### " + Environment.UserName + " (" + Environment.MachineName + ") ###\r\n" + "#### 3P version : " + AssemblyInfo.Version + ", Notepad++ version : " + Npp.GetNppVersion + " ####\r\n" + message ); wb.Execute(); return false; }
/// <summary> /// Sends the given report to the web service of 3P /// </summary> private static void SendBugReport(ExceptionInfo bugReport) { var wb = new WebServiceJson(WebServiceJson.WebRequestMethod.Post, Config.BugsPostWebWervice); wb.Serialize(bugReport); // save the request in a file var fileName = Path.Combine(Config.FolderLog, "unreported_" + DateTime.Now.ToString("yy.MM.dd_HH-mm-ss_") + _nbErrors++ + ".json"); Utils.FileWriteAllText(fileName, wb.JsonRequest.ToString()); wb.OnRequestEnded += webServ => { // request ok -> delete the json if (webServ.StatusCodeResponse == HttpStatusCode.OK) Utils.DeleteFile(fileName); }; wb.Execute(); }
/// <summary> /// Gets an object with the latest release info /// </summary> public static void CheckForUpdate(bool alwaysGetFeedBack) { if (_latestReleaseInfo != null) { // we already checked and there is a new version if (!_warnedUserAboutUpdateAvail || alwaysGetFeedBack) NotifyUpdateAvailable(); return; } if (_checking) return; try { var wb = new WebServiceJson(WebServiceJson.WebRequestMethod.Get, Config.ReleasesApi); wb.TimeOut = 3000; wb.OnRequestEnded += json => WbOnOnRequestEnded(json, alwaysGetFeedBack); wb.Execute(); } catch (Exception e) { ErrorHandler.ShowErrors(e, "Error when checking for updates"); } }