コード例 #1
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");

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

                throw;
            }

            return updateInfo.ReleasesToApply.Any() ?
                updateInfo.ReleasesToApply.MaxBy(x => x.Version).Last() :
                default(ReleaseEntry);
        }
コード例 #2
0
 /// <summary>
 /// Take an already downloaded set of releases and apply them, 
 /// copying in the new files from the NuGet package and rewriting 
 /// the application shortcuts.
 /// </summary>
 /// <param name="updateInfo">The UpdateInfo instance acquired from 
 /// CheckForUpdate</param>
 /// <param name="progress">An Action which can be used to report Progress - 
 /// will return values from 0-100</param>
 /// <returns>A list of EXEs that should be started if this is a new 
 /// installation.</returns>
 public static Task<List<string>> ApplyReleasesAsync(this IUpdateManager This, UpdateInfo updateInfo, Action<int> progress)
 {
     var subj = new Subject<int>();
     subj.Subscribe(progress, ex => { });
     return This.ApplyReleases(updateInfo, subj).ToTask();
 }
コード例 #3
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();
        }
コード例 #4
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();
        }
コード例 #5
0
ファイル: IUpdateManager.cs プロジェクト: iamnilay3/Shimmer
        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).Select(_ => x))
                .SelectMany(x => This.ApplyReleases(x).Select(_ => x.ReleasesToApply.MaxBy(y => y.Version).FirstOrDefault()))
                .Finally(() => theLock.Dispose())
                .Multicast(new AsyncSubject<ReleaseEntry>());

            ret.Connect();
            return ret;
        }