private async Task <bool> CheckForUpdate()
        {
            log.Info("Checking for update.");
            var updateInfo = await updateManager.CheckForUpdate();

            return(updateInfo.FutureReleaseEntry != updateInfo.CurrentlyInstalledVersion);
        }
예제 #2
0
        /// <summary>
        /// Fetch the remote store for updates and compare against the current
        /// version to determine what updates to download.
        /// </summary>
        /// <param name="ignoreDeltaUpdates">Set this flag if applying a release
        /// fails to fall back to a full release, which takes longer to download
        /// but is less error-prone.</param>
        /// <param name="progress">An Action which can be used to report Progress -
        /// will return values from 0-100</param>
        /// <returns>An UpdateInfo object representing the updates to install.
        /// </returns>
        public static Task <UpdateInfo> CheckForUpdateAsync(this IUpdateManager This, bool ignoreDeltaUpdates, Action <int> progress)
        {
            var subj = new Subject <int>();

            subj.Subscribe(progress);
            return(This.CheckForUpdate(ignoreDeltaUpdates, subj).ToTask());
        }
예제 #3
0
        private async Task CheckForUpdate()
        {
            try
            {
                ShowMessage("Checking new versions...");
                var update = await _updateManager.CheckForUpdate(false, x => ShowMessage($"Checking updates: {x}%"));

                try
                {
                    var semanticVersion = update.CurrentlyInstalledVersion?.Version ?? new SemanticVersion(0, 0, 0, 0);
                    var version         = update.FutureReleaseEntry.Version;
                    if (semanticVersion < version)
                    {
                        ShowMessage($"Updating to [{version}]...");
                        await _updateManager.DownloadReleases(update.ReleasesToApply, x => ShowMessage($"Download update: {x}%"));

                        await _updateManager.ApplyReleases(update, x => ShowMessage($"Applying update: {x}%"));

                        ShowMessage($"Done update to [{version}]");
                    }
                    else
                    {
                        ShowMessage("The latest version is installed");
                    }
                }
                catch (Exception ex)
                {
                    ShowMessage($"[{_currentVersion}]: Fail updating - {ex.Message}");
                }
            }
            catch (Exception ex)
            {
                ShowMessage($"[{_currentVersion}]: Can't check for update - {ex.Message}");
            }
        }
예제 #4
0
        public async Task <bool> HasNewUpdateAsync()
        {
            bool hasUpdate = false;

            try
            {
                UpdateInfo info = await _updateManager.CheckForUpdate();

                hasUpdate = IsNewVersionAvailable(info);
            }
            catch (System.Net.WebException ex)
            {
                System.Diagnostics.Trace.WriteLine($"HasNewUpdate failed with web expetion {ex.Message}");
                hasUpdate = false;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine($"HasNewUpdate failed with unexpected error {ex.Message}");
                hasUpdate = false;
            }
            return(hasUpdate);
        }
예제 #5
0
        public void CheckForUpdates(Action <string> callback, Action <Exception> errCallback)
        {
            if (!Enabled)
            {
                callback(null);
                return;
            }

            var checkForUpdateTask = _updateManager.CheckForUpdate();

            checkForUpdateTask.ContinueWith(t => CheckForUpdateCallback(callback, t.Result), TaskContinuationOptions.OnlyOnRanToCompletion);
            checkForUpdateTask.ContinueWith(t => HandleAsyncError(errCallback, t.Exception), TaskContinuationOptions.OnlyOnFaulted);
        }
        /// <summary>
        /// Updates this instance.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception">Update manager can not be null</exception>
        private async Task Update()
        {
            if (updateManager == null)
            {
                throw new Exception("Update manager can not be null");
            }

            Log.InfoFormat("Automatic-renewal was launched ({0})", curversion);

            {
                while (true)
                {
                    await Task.Delay(checkUpdatePeriod);

                    try
                    {
                        // Check for update
                        var update = await updateManager.CheckForUpdate();

                        try
                        {
                            var oldVersion = update.CurrentlyInstalledVersion?.Version ?? new SemanticVersion(0, 0, 0, 0);
                            Log.InfoFormat("Installed version: {0}", oldVersion);
                            var newVersion = update.FutureReleaseEntry.Version;
                            if (oldVersion < newVersion)
                            {
                                Log.InfoFormat("Found a new version: {0}", newVersion);

                                // Downlaod Release
                                await updateManager.DownloadReleases(update.ReleasesToApply);

                                // Apply Release
                                await updateManager.ApplyReleases(update);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.ErrorFormat("Error on update ({0}): {1}", curversion, ex);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.ErrorFormat("Error on check for update ({0}): {1}", curversion, ex);
                    }
                }
            }
        }
        private async Task Update()
        {
            if (updateManager == null)
            {
                throw new Exception("Update manager can not be null");
            }
            Trace.TraceInformation("Automatic-renewal was launched ({0})", curversion);

            {
                while (true)
                {
                    await Task.Delay(checkUpdatePeriod);

                    try
                    {
                        //Проверяем наличие новой версии
                        var update = await updateManager.CheckForUpdate();

                        try
                        {
                            var oldVersion = update.CurrentlyInstalledVersion?.Version ?? new SemanticVersion(0, 0, 0, 0);
                            var newVersion = update.FutureReleaseEntry.Version;
                            if (oldVersion < newVersion)
                            {
                                Trace.TraceInformation("Found a new version: {0}", newVersion);

                                //Скачиваем новую версию
                                await updateManager.DownloadReleases(update.ReleasesToApply);

                                //Распаковываем новую версию
                                await updateManager.ApplyReleases(update);
                            }
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceError("Error on update ({0}): {1}", curversion, ex);
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Error on check for update ({0}): {1}", curversion, ex);
                    }
                }
            }
        }
예제 #8
0
        public static async Task <ReleaseEntry> UpdateApp(this IUpdateManager This, Action <int> progress = null)
        {
            progress = progress ?? (_ => {});

            This.Log().Info("Starting automatic update");

            var updateInfo = await This.ErrorIfThrows(() => This.CheckForUpdate(false, x => progress(x / 3)),
                                                      "Failed to check for updates");

            await This.ErrorIfThrows(() =>
                                     This.DownloadReleases(updateInfo.ReleasesToApply, x => progress(x / 3 + 33)),
                                     "Failed to download updates");

            await This.ErrorIfThrows(() =>
                                     This.ApplyReleases(updateInfo, x => progress(x / 3 + 66)),
                                     "Failed to apply updates");

            return(updateInfo.ReleasesToApply.MaxBy(x => x.Version).LastOrDefault());
        }
예제 #9
0
        public async void DoCheckForUpdate()
        {
            try
            {
                var updateInfo = await InBusy(() => _updateManager.CheckForUpdate());

                if (updateInfo.CurrentlyInstalledVersion == null)
                {
                    throw new InvalidOperationException("Could not determine currently installed version");
                }

                var currentVersion = updateInfo.CurrentlyInstalledVersion.Version;
                var newVersion     = updateInfo.FutureReleaseEntry.Version;
                if (newVersion > currentVersion)
                {
                    if (_messageService.Show("Update " + newVersion + " available. Dou you want to update now?",
                                             "Update", MessageButton.YesNo, MessageImage.Question) != MessageResult.Yes)
                    {
                        return;
                    }

                    await InUpdate(() => _updateManager.UpdateApp(p => Progress = p));

                    if (_messageService.Show("Update applied. Restart application to take effect.",
                                             "Information", MessageButton.YesNo, MessageImage.Question) == MessageResult.Yes)
                    {
                        Program.Restart();
                    }
                }
                else
                {
                    _messageService.Show("You are up to date: " + currentVersion, "Information", MessageButton.Ok,
                                         MessageImage.Information);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceWarning("Could not check for update: " + ex);
                _messageService.Show("Could not check for update: " + ex.Message, "Error", MessageButton.Ok, MessageImage.Error);
            }
        }
예제 #10
0
        public static async Task <ReleaseEntry> UpdateApp(this IUpdateManager This, Action <int> progress = null)
        {
            progress = progress ?? (_ => { });
            This.Log().Info("Starting automatic update");

            bool ignoreDeltaUpdates = false;

retry:
            var updateInfo = default(UpdateInfo);

            try {
                updateInfo = await This.ErrorIfThrows(() => This.CheckForUpdate(ignoreDeltaUpdates, x => progress(x / 3)),
                                                      "Failed to check for updates");

                await This.ErrorIfThrows(() =>
                                         This.DownloadReleases(updateInfo.ReleasesToApply, x => progress(x / 3 + 33)),
                                         "Failed to download updates");

                await This.ErrorIfThrows(() =>
                                         This.ApplyReleases(updateInfo, x => progress(x / 3 + 66)),
                                         "Failed to apply updates");

                This.ErrorIfThrows(() =>
                                   This.UpdateUninstallerVersionRegistryEntry(),
                                   "Failed to set up uninstaller");
            } catch {
                if (ignoreDeltaUpdates == false)
                {
                    ignoreDeltaUpdates = true;
                    goto retry;
                }

                throw;
            }

            return(updateInfo.ReleasesToApply.Any() ?
                   updateInfo.ReleasesToApply.MaxBy(x => x.Version).Last() :
                   default(ReleaseEntry));
        }
예제 #11
0
        public static Task <ReleaseEntry> UpdateAppAsync(this IUpdateManager This, Action <int> progress)
        {
            var checkSubj    = new Subject <int>();
            var downloadSubj = new Subject <int>();
            var applySubj    = new Subject <int>();

            var ret = This.CheckForUpdate(false, checkSubj)
                      .SelectMany(x => This.DownloadReleases(x.ReleasesToApply, downloadSubj).TakeLast(1).Select(_ => x))
                      .SelectMany(x => This.ApplyReleases(x, applySubj).TakeLast(1).Select(_ => x.ReleasesToApply.MaxBy(y => y.Version).LastOrDefault()))
                      .PublishLast();

            var allProgress = Observable.Merge(
                checkSubj.Select(x => (double)x / 3.0),
                downloadSubj.Select(x => (double)x / 3.0),
                applySubj.Select(x => (double)x / 3.0))
                              .Scan(0.0, (acc, x) => acc + x);

            allProgress.Subscribe(x => progress((int)x));

            ret.Connect();
            return(ret.ToTask());
        }
예제 #12
0
        public static IObservable <ReleaseEntry> UpdateApp(this IUpdateManager This)
        {
            IDisposable theLock;

            try {
                theLock = This.AcquireUpdateLock();
            } catch (TimeoutException _) {
                // TODO: Bad Programmer!
                return(Observable.Return(default(ReleaseEntry)));
            } catch (Exception ex) {
                return(Observable.Throw <ReleaseEntry>(ex));
            }

            var ret = This.CheckForUpdate()
                      .SelectMany(x => This.DownloadReleases(x.ReleasesToApply).TakeLast(1).Select(_ => x))
                      .SelectMany(x => This.ApplyReleases(x).TakeLast(1).Select(_ => x.ReleasesToApply.MaxBy(y => y.Version).LastOrDefault()))
                      .Finally(() => theLock.Dispose())
                      .Multicast(new AsyncSubject <ReleaseEntry>());

            ret.Connect();
            return(ret);
        }