Exemple #1
0
        private async Task UpdateSilentlyAsync()
        {
            if (ModeDetector.InUnitTestRunner())
            {
                return;
            }
#if DEBUG
            return;
#endif

            ReleaseEntry appliedEntry;

            try
            {
                appliedEntry = await this.updateManager.UpdateApp();
            }

            catch (Exception ex)
            {
                this.Log().Error("Failed to update application", ex);
                AnalyticsClient.Instance.RecordNonFatalError(ex);
                return;
            }

            if (appliedEntry == null)
            {
                this.Log().Info("No update available");
                return;
            }

            await ChangelogFetcher.FetchAsync().ToObservable()
            .Timeout(TimeSpan.FromSeconds(30))
            .SelectMany(x => BlobCache.LocalMachine.InsertObject(BlobCacheKeys.Changelog, x))
            .LoggedCatch(this, Observable.Return(Unit.Default), "Could not to fetch changelog")
            .ToTask();

            lock (this.updateLock)
            {
                this.updateRun          = true;
                this.settings.IsUpdated = true;
            }

            this.Log().Info("Updated to version {0}", appliedEntry.Version);
        }
Exemple #2
0
        private async Task UpdateSilentlyAsync()
        {
            if (ModeDetector.InUnitTestRunner())
            {
                return;
            }

            this.Log().Info("Looking for application updates");

            UpdateInfo updateInfo;

            try
            {
                updateInfo = await this.updateManager.CheckForUpdate();
            }

            catch (Exception ex)
            {
                this.Log().ErrorException("Error while checking for updates", ex);
                return;
            }

            if (updateInfo.ReleasesToApply.Any())
            {
                this.Log().Info("New version available: {0}", updateInfo.FutureReleaseEntry.Version);

                Task changelogFetchTask = ChangelogFetcher.FetchAsync().ToObservable()
                                          .Timeout(TimeSpan.FromSeconds(30))
                                          .SelectMany(x => BlobCache.LocalMachine.InsertObject(BlobCacheKeys.Changelog, x))
                                          .LoggedCatch(this, Observable.Return(Unit.Default), "Could not to fetch changelog")
                                          .ToTask();

                this.Log().Info("Downloading updates...");

                try
                {
                    await this.updateManager.DownloadReleases(updateInfo.ReleasesToApply);
                }

                catch (Exception ex)
                {
                    this.Log().Error("Failed to download updates.", ex);
                    AnalyticsClient.Instance.RecordNonFatalError(ex);
                    return;
                }

                this.Log().Info("Applying updates...");

                try
                {
                    await this.updateManager.ApplyReleases(updateInfo);
                }

                catch (Exception ex)
                {
                    this.Log().Error("Failed to apply updates.", ex);
                    AnalyticsClient.Instance.RecordNonFatalError(ex);
                    return;
                }

                await changelogFetchTask;

                this.settings.IsUpdated = true;

                this.Log().Info("Updates applied.");
            }

            else
            {
                this.Log().Info("No updates found");
            }
        }