예제 #1
0
        /// <summary>
        /// Check for updates synchronouly
        /// </summary>
        /// <param name="source">Updates source to use</param>
        /// <param name="callback">Callback function to call when done</param>
        /// <returns>true if successful and updates exist</returns>
        private bool CheckForUpdates(IUpdateSource source, Action <int> callback)
        {
            LatestError = null;

            if (UpdateFeedReader == null)
            {
                throw new ArgumentException("An update feed reader is required; please set one before checking for updates");
            }

            if (source == null)
            {
                throw new ArgumentException("An update source was not specified");
            }

            lock (UpdatesToApply)
            {
                UpdatesToApply.Clear();
                var tasks = UpdateFeedReader.Read(source.GetUpdatesFeed());
                foreach (var t in tasks)
                {
                    if (ShouldStop)
                    {
                        return(false);
                    }
                    if (t.UpdateConditions.IsMet(t)) // Only execute if all conditions are met
                    {
                        UpdatesToApply.Add(t);
                    }
                }
            }

            if (ShouldStop)
            {
                return(false);
            }

            State = UpdateProcessState.Checked;
            if (callback != null)
            {
                callback.BeginInvoke(UpdatesToApply.Count, null, null);
            }

            if (UpdatesToApply.Count > 0)
            {
                return(true);
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// Check for updates synchronouly
        /// </summary>
        /// <param name="source">Updates source to use</param>
        public void CheckForUpdates(IUpdateSource source)
        {
            if (IsWorking)
            {
                throw new InvalidOperationException("Another update process is already in progress");
            }

            using (WorkScope.New(isWorking => IsWorking = isWorking))
            {
                if (UpdateFeedReader == null)
                {
                    throw new ArgumentException("An update feed reader is required; please set one before checking for updates");
                }

                if (source == null)
                {
                    throw new ArgumentException("An update source was not specified");
                }

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

                lock (UpdatesToApply)
                {
                    UpdatesToApply.Clear();
                    using (Stream s = source.GetUpdatesFeed())
                    {
                        var tasks = UpdateFeedReader.Read(s);
                        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;
            }
        }
예제 #3
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;
            }
        }
예제 #4
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;
            }
        }