Example #1
0
        /// <summary>
        /// Check for updates synchronously
        /// </summary>
        public void CheckForUpdates()
        {
            if (IsWorking)
            {
                throw new InvalidOperationException("Another update process is already in progress");
            }
            else if (UpdateFeedReader == null)
            {
                throw new InvalidOperationException("UpdateFeedReader must be set before calling CheckForUpdates()");
            }
            else if (UpdateSource == null)
            {
                throw new InvalidOperationException("UpdateSource must be set before calling CheckForUpdates()");
            }

            using (WorkScope.New(isWorking => IsWorking = isWorking))
            {
                if (State != UpdateProcessState.NotChecked)
                {
                    throw new InvalidOperationException("Already checked for updates; to reset the current state call CleanUp()");
                }

                lock (UpdatesToApply)
                {
                    UpdatesToApply.Clear();
                    var tasks = UpdateFeedReader.Read(UpdateSource.GetUpdatesFeed());
                    foreach (var t in tasks)
                    {
                        if (ShouldStop)
                        {
                            throw new UserAbortException();
                        }

                        if (t.UpdateConditions == null || t.UpdateConditions.IsMet(t))                         // Only execute if all conditions are met
                        {
                            UpdatesToApply.Add(t);
                        }
                    }
                }

                State = UpdateProcessState.Checked;
            }
        }
Example #2
0
        /// <summary>
        /// Check for updates synchronously
        /// </summary>
        public void CheckForUpdates()
        {
            if (IsWorking)
            {
                throw new InvalidOperationException("Another update process is already in progress");
            }
            else if (UpdateFeedReader == null)
            {
                throw new InvalidOperationException("UpdateFeedReader must be set before calling CheckForUpdates()");
            }
            else if (UpdateSource == null)
            {
                throw new InvalidOperationException("UpdateSource must be set before calling CheckForUpdates()");
            }

            using (WorkScope.New(isWorking => IsWorking = isWorking))
            {
                if (State != UpdateProcessState.NotChecked)
                {
                    throw new InvalidOperationException("Already checked for updates; to reset the current state call CleanUp()");
                }

                lock (UpdatesToApply)
                {
                    UpdatesToApply.Clear();
                    IList <IUpdateTask> tasks = null;
                    int currentRetry          = 0;
                    while (currentRetry < MaximumRetries)
                    {
                        ++currentRetry;
                        try
                        {
                            tasks = UpdateFeedReader.Read(UpdateSource.GetUpdatesFeed());
                            break;
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(ex);

                            if (ex is WebException)
                            {
                                var e = ex as WebException;
                                if (e.Status == WebExceptionStatus.Timeout ||
                                    e.Status == WebExceptionStatus.ConnectFailure ||
                                    e.Status == WebExceptionStatus.NameResolutionFailure)
                                {
                                    throw new UpdateProcessFailedException("Failed to retrieve feed: " + ex.ToString());
                                }
                            }

                            if (currentRetry == MaximumRetries)
                            {
                                throw new UpdateProcessFailedException("Failed to retrieve feed: " + ex.ToString());
                            }

                            Thread.Sleep(RetriesTimeout);
                        }
                    }

                    foreach (var t in tasks)
                    {
                        if (ShouldStop)
                        {
                            throw new UserAbortException();
                        }

                        if (t.UpdateConditions == null || t.UpdateConditions.IsMet(t))                         // Only execute if all conditions are met
                        {
                            UpdatesToApply.Add(t);
                        }
                    }
                }

                State = UpdateProcessState.Checked;
            }
        }