Exemplo n.º 1
0
        /// <summary>
        /// Create the upgrade dialog based on releaseNotesUri and updateOption
        /// </summary>
        private UpdateDialog CreateUpgradeDialog(Uri releaseNotesUri, AutoUpdateOption updateOption)
        {
            UpdateDialog dialog = new UpdateDialog(releaseNotesUri);

            if (updateOption == AutoUpdateOption.RequiredUpgrade)
            {
                dialog.btnUpdateLater.Visibility = Visibility.Collapsed;
                dialog.txtUpdateNotice.Text      = Properties.Resources.MainWindow_ShowUpgradeDialog_An_update_is_required;
            }

            // center horizontally - does not work when maximized on secondary screen
            Point topLeft = this.WindowState == WindowState.Maximized ?
                            this.GetTopLeftPoint() : new Point(this.Left, this.Top);

            dialog.Top   = topLeft.Y + this.borderTitleBar.ActualHeight + 8;
            dialog.Left  = topLeft.X + this.ictMainMenu.ActualWidth;
            dialog.Width = this.ActualWidth - this.ictMainMenu.ActualWidth;
            dialog.Owner = this;

            // Block until message bar disappears
            this.modeGrid.Opacity   = 0.5;
            this.AllowFurtherAction = false;

            return(dialog);
        }
Exemplo n.º 2
0
        private AutoUpdateOption InitializeWithTimer()
        {
            _initializationStopwatch.Restart();
            AutoUpdateOption updateOption = Initialize();

            _initializationStopwatch.Stop();
            return(updateOption);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create the upgrade dialog based on releaseNotesUri and updateOption
        /// </summary>
        private UpdateContainedDialog CreateUpgradeDialog(Uri releaseNotesUri, AutoUpdateOption updateOption)
        {
            UpdateContainedDialog dialog = new UpdateContainedDialog(releaseNotesUri);

            if (updateOption == AutoUpdateOption.RequiredUpgrade)
            {
                dialog.SetModeToRequired();
            }

            AllowFurtherAction = false;

            return(dialog);
        }
        /// <summary>
        /// Download the upgrade installer and close the app depending on if it is successful or not
        /// </summary>
        private async void DownLoadInstaller(IAutoUpdate autoUpdate, AutoUpdateOption updateOption)
        {
            UpdateResult result = UpdateResult.Unknown;

            // If the window is topmost, the UAC prompt from the version switcher will appear behind the main window.
            // To prevent this, save the previous topmost state, ensure that the main window is not topmost when the
            // UAC prompt will display, then restore the previous topmost state.
            bool previousTopmostSetting = Topmost;

            try
            {
                ctrlProgressRing.Activate();
                Topmost = false;
                result  = await autoUpdate.UpdateAsync().ConfigureAwait(true);

                Logger.PublishTelemetryEvent(TelemetryAction.Upgrade_DoInstallation, new Dictionary <TelemetryProperty, string>
                {
                    { TelemetryProperty.UpdateInstallerUpdateTime, GetTimeSpanTelemetryString(autoUpdate.GetUpdateTime()) },
                    { TelemetryProperty.UpdateResult, updateOption.ToString() },
                });
                if (result == UpdateResult.Success)
                {
                    this.Close();
                    return;
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                e.ReportException();
            };
#pragma warning restore CA1031 // Do not catch general exception types

            Topmost = previousTopmostSetting;
            ctrlProgressRing.Deactivate();
            Logger.PublishTelemetryEvent(TelemetryAction.Upgrade_InstallationError, TelemetryProperty.Error, result.ToString());

            string message = updateOption == AutoUpdateOption.RequiredUpgrade
                ? GetMessageForRequiredUpdateFailure() : GetMessageForOptionalUpdateFailure();

            MessageDialog.Show(message);

            if (updateOption == AutoUpdateOption.RequiredUpgrade)
            {
                this.Close();
                return;
            }
        }
        /// <summary>
        /// Retrieve the upgrade decision status, if yes, use autoUpdateOption to update, otherwise, no need to upgrade the app
        /// </summary>
        private static bool ShouldUserUpgrade(IAutoUpdate autoUpdate, out AutoUpdateOption autoUpdateOption)
        {
            if (autoUpdate == null)
            {
                autoUpdateOption = AutoUpdateOption.Unknown;
                return(false);
            }

            AutoUpdateOption updateOption;
            Stopwatch        updateOptionStopwatch = Stopwatch.StartNew();
            bool             timeOutOccurred       = false;

            try
            {
                var t = autoUpdate.UpdateOptionAsync;
                if (!t.Wait(2000))
                {
                    timeOutOccurred  = true;
                    autoUpdateOption = AutoUpdateOption.Unknown;
                    return(false);
                }
                updateOptionStopwatch.Stop();
                updateOption = t.Result;
            }
            catch (AggregateException e)
            {
                e.ReportException();
                updateOption = AutoUpdateOption.Unknown;
            }
            finally
            {
                PublishTelemetryEventAsync(autoUpdate, updateOptionStopwatch, timeOutOccurred);
            }

            autoUpdateOption = updateOption;
            if (autoUpdateOption == AutoUpdateOption.Current || autoUpdateOption == AutoUpdateOption.Unknown)
            {
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Download the upgrade installer and close the app depending on if it is successful or not
        /// </summary>
        private async void DownLoadInstaller(IAutoUpdate autoUpdate, AutoUpdateOption updateOption)
        {
            UpdateResult result = UpdateResult.Unknown;

            try
            {
                ctrlProgressRing.Activate();
                result = await autoUpdate.UpdateAsync().ConfigureAwait(true);

                Logger.PublishTelemetryEvent(TelemetryAction.Upgrade_DoInstallation, new Dictionary <TelemetryProperty, string>
                {
                    { TelemetryProperty.UpdateInstallerDownloadTime, GetTimeSpanTelemetryString(autoUpdate.GetInstallerDownloadTime()) },
                    { TelemetryProperty.UpdateInstallerVerificationTime, GetTimeSpanTelemetryString(autoUpdate.GetInstallerVerificationTime()) },
                    { TelemetryProperty.UpdateResult, updateOption.ToString() },
                });
                if (result == UpdateResult.Success)
                {
                    this.Close();
                    return;
                }
            }
            catch (Exception) { };

            ctrlProgressRing.Deactivate();
            Logger.PublishTelemetryEvent(TelemetryAction.Upgrade_InstallationError, TelemetryProperty.Error, result.ToString());

            string message = updateOption == AutoUpdateOption.RequiredUpgrade
                ? GetMessageForRequiredUpdateFailure(result) : GetMessageForOptionalUpdateFailure(result);

            MessageBox.Show(message);

            if (updateOption == AutoUpdateOption.RequiredUpgrade)
            {
                this.Close();
                return;
            }
        }