Candy.Updater.CandyUpdater.UpdateApplicationAsync C# (CSharp) Method

UpdateApplicationAsync() public method

進捗を報告しながら、アプリケーションを更新します。
public UpdateApplicationAsync ( IProgress progress = null ) : System.Threading.Tasks.Task
progress IProgress
return System.Threading.Tasks.Task
        public async Task UpdateApplicationAsync(IProgress<ProgressStatus> progress = null)
        {
            progress = progress ?? new Progress<ProgressStatus>();

            progress.Report(20, "更新を確認しています。");
            await WaitAsync().ConfigureAwait(false);

            var latest = await GetLatestSummaryAsync().ConfigureAwait(false);

            using (var temp = new TempFile())
            {
                progress.Report(40, "パッケージをダウンロードしています。");
                await WaitAsync().ConfigureAwait(false);

                await DownloadPackageAsync(latest.PackagePath, temp.File.FullName).ConfigureAwait(false);

                var processName = Path.GetFileNameWithoutExtension(_args.ApplicationExecutionPath);

                progress.Report(60, String.Format("プロセス {0} の終了を待機しています。", processName));
                await WaitAsync().ConfigureAwait(false);

                await WaitProcessExitAsync(processName).ConfigureAwait(false);

                progress.Report(80, "ファイルを最新に更新しています。");
                await WaitAsync().ConfigureAwait(false);

                await UpdateFilesAsync(temp.File, _args.ApplicationDirectory).ConfigureAwait(false);
                await RemoveFilesAsync(latest.RemoveFiles, _args.ApplicationDirectory).ConfigureAwait(false);
            }

            if (_args.StartProcess)
            {
                progress.Report(100, "アプリケーションを起動します。");
                await WaitAsync().ConfigureAwait(false);

                Process.Start(_args.ApplicationExecutionPath);
            }
        }
        private Task WaitAsync()

Usage Example

Example #1
0
        protected override async void OnShown(EventArgs e)
        {
            base.OnShown(e);

            var progress = new Progress <ProgressStatus>();

            progress.ProgressChanged += (_, status) =>
            {
                progressBar1.Value = status.Percentage;
                lblStatus.Text     = status.Message;
            };

            await _updater.UpdateApplicationAsync(progress);

            Close();
        }