Beispiel #1
0
        internal void StartChecking(string appCast = null, DoneDelegate done = null)
        {
            if (!_initialized)
            {
                done?.Invoke(); return;
            }
            _done = () =>
            {
                Running = false;
                done?.Invoke();
            };
            lock (_initLocker)
            {
                if (Running)
                {
                    Logger.Info(States.StartCheckIgnoredWhileRunning);
                    _done?.Invoke(); return;
                }
                Running = true;
            }

            if (Settings.Mandatory && _remindLaterTimer != null)
            {
                _remindLaterTimer.Stop();
                _remindLaterTimer.Close();
                _remindLaterTimer = null;
            }
            if (_remindLaterTimer != null)
            {
                Logger.Info(States.StartCheckIgnoredForRemindLater);
                _done?.Invoke(); return;
            }

            Logger.Info(States.CheckForUpdateStarted);
            _downloadAndRunWasCall = false;

            if (appCast != null)
            {
                Settings.AppCastURL = appCast;
            }

            var backgroundWorker = new BackgroundWorker();

            backgroundWorker.DoWork             += BackgroundWorkerDoWork;
            backgroundWorker.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted;

            backgroundWorker.RunWorkerAsync();
        }
Beispiel #2
0
        internal void Classify()
        {
            try
            {
                ClassificationResult result = null;
                string url = PrepareUrl();

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.AutomaticDecompression = DecompressionMethods.GZip;

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    using (Stream stream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            string json = reader.ReadToEnd();
                            result = JsonConvert.DeserializeObject <ClassificationResult>(json);
                        }
                DoneDelegate?.Invoke(result);
            }
            catch (Exception ex)
            {
                ErrorDelegate?.Invoke("Request Error", ex.Message);
            }
        }
Beispiel #3
0
 private void BackgroundWorkerOnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs workArgs)
 {
     try
     {
         if (workArgs.Cancelled || workArgs.Error != null)
         {
             if (workArgs.Error == null)
             {
                 return;
             }
             var myExc = workArgs.Error as UpdaterException;
             if (myExc != null)
             {
                 Logger.Error(myExc.State, myExc.Message, myExc.InnerException);
                 if (myExc.State == States.AppCastRetrievalError)
                 {
                     ReportToUser(ReportLevel.Error, Resources.UpdateCheckFailedCaption, Resources.UpdateCheckFailedMessage);
                 }
                 else if (myExc.State == States.AppCastInvalidDataError)
                 {
                     ReportToUser(ReportLevel.Error, Resources.UpdateManifestInvalidCaption, Resources.UpdateManifestInvalidMessage);
                 }
             }
             else
             {
                 Logger.Error(States.UnexpectedCheckProcessError, exception: workArgs.Error);
             }
         }
         else if (workArgs.Result is DateTime)
         {
             SetTimer((DateTime)workArgs.Result);
         }
         else
         {
             var updateInfo = workArgs.Result as UpdateInfoEventArgs;
             if (Settings.CustomUpdateCheckEvent != null)
             {
                 CallSync(s =>
                 {
                     try
                     {
                         Settings.CustomUpdateCheckEvent(updateInfo);
                     }
                     catch (Exception e)
                     {
                         Logger.Error(States.CustomUpdateCheckEventError, exception: e);
                     }
                 });
             }
             else
             {
                 if (updateInfo == null)
                 {
                     Logger.Error(States.UpdateCheckFailed, Resources.UpdateCheckFailedMessage);
                     ReportToUser(ReportLevel.Error, Resources.UpdateCheckFailedCaption,
                                  Resources.UpdateCheckFailedMessage);
                 }
                 else if (!updateInfo.IsUpdateAvailable)
                 {
                     Logger.Info(States.UnavailableUpdate, Resources.UpdateUnavailableMessage);
                     ReportToUser(ReportLevel.Info, Resources.UpdateUnavailableCaption,
                                  Resources.UpdateUnavailableMessage);
                 }
                 else
                 {
                     if (Settings.UnattendedMode)
                     {
                         DownloadAndRunTheUpdate();
                     }
                     else
                     {
                         LetUserToProcessTheUpdate();
                     }
                 }
             }
         }
     }
     catch (Exception exc)
     {
         Logger.Error(States.UnexpectedCheckProcessError, exception: exc);
     }
     finally
     {
         if (_downloadAndRunWasCall == false)
         {
             _done?.Invoke();
         }
     }
 }