예제 #1
0
파일: User.cs 프로젝트: koelblinger/3P
 /// <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 {
         // ping once x hours
         if (Utils.IsLastCallFromMoreThanXMinAgo("Ping", Config.PostPingEveryXMin))
         {
             var webServiceJson = new WebServiceJson(WebServiceJson.WebRequestMethod.Post, Config.PostPingWebWervice);
             webServiceJson.OnInitHttpWebRequest += request => {
                 request.Proxy = Config.Instance.GetWebClientProxy();
             };
             webServiceJson.AddToReq("UUID", UniqueId);
             webServiceJson.AddToReq("userName", Name);
             webServiceJson.AddToReq("version", AssemblyInfo.Version);
             webServiceJson.OnRequestEnded += req => {
                 if (req.StatusCodeResponse != HttpStatusCode.OK)
                 {
                     if (Config.IsDeveloper)
                     {
                         ErrorHandler.ShowErrors(new Exception(req.JsonResponse), "Error when pinging : " + req.StatusCodeResponse.ToString());
                     }
                 }
             };
             webServiceJson.Execute();
         }
     } catch (Exception e) {
         if (Config.IsDeveloper)
         {
             ErrorHandler.ShowErrors(e);
         }
     }
 }
예제 #2
0
파일: User.cs 프로젝트: devjerome/3P
 /// <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);
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Gets an object with the latest release info
 /// </summary>
 public void CheckForUpdates()
 {
     try {
         var wb = new WebServiceJson(WebServiceJson.WebRequestMethod.Get, GitHubReleaseApi)
         {
             TimeOut = 3000
         };
         wb.OnInitHttpWebRequest += request => {
             request.UserAgent = UserAgent ?? "unknown";
             if (Proxy != null)
             {
                 request.Proxy = Proxy;
             }
             if (!string.IsNullOrEmpty(BasicAuthenticationToken))
             {
                 request.Headers.Add("Authorization", "Basic " + BasicAuthenticationToken);
             }
             if (!string.IsNullOrEmpty(OAuth2Token))
             {
                 request.Headers.Add("Authorization", "Token " + OAuth2Token);
             }
             request.Accept      = "application/vnd.github.v3+json";
             request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
         };
         wb.OnRequestEnded += OnGithubResponse;
         wb.Execute();
     } catch (Exception e) {
         if (ErrorOccured != null)
         {
             ErrorOccured(this, e, GitHubUpdaterFailReason.RequestFailed);
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Gets an object with the latest release info
        /// </summary>
        public static void CheckForUpdate(bool periodicCheck)
        {
            _displayResultNotif = !periodicCheck;

            if (_isChecking)
            {
                return;
            }

            if (_updateAvailableOnRestart && _latestReleaseInfo != null && _displayResultNotif)
            {
                // we already checked and there is a new version
                NotifyUpdateAvailable();
                return;
            }
            _isChecking = true;
            try {
                var wb = new WebServiceJson(WebServiceJson.WebRequestMethod.Get, Config.ReleasesApi)
                {
                    TimeOut = 3000
                };
                wb.OnInitHttpWebRequest += request => { request.Headers.Add("Authorization", "Basic M3BVc2VyOnJhbmRvbXBhc3N3b3JkMTIz"); };
                wb.OnRequestEnded       += WbOnOnRequestEnded;
                wb.Execute();
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "Error when checking for updates");
                _isChecking = false;
            }

            Config.Instance.TechnicalLastCheckUpdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
예제 #5
0
파일: User.cs 프로젝트: koelblinger/3P
        /// <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);

            wb.OnInitHttpWebRequest += request => {
                request.Proxy     = Config.Instance.GetWebClientProxy();
                request.UserAgent = "3pUser";
                request.Headers.Add("Authorization", "Basic " + Config.GitHubToken);
            };
            wb.AddToReq("body", message);
            wb.OnRequestEnded += json => { UserCommunication.Notify((json.ResponseException != null ? json.ResponseException.ToString() : "") + "\r\n" + json.StatusCodeResponse + ":" + (json.StatusDescriptionResponse ?? "") + "\r\n" + (json.JsonResponse ?? "")); };
            wb.Execute();

            return(false);
        }
예제 #6
0
파일: User.cs 프로젝트: devjerome/3P
        /// <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);
        }