/// <summary>
        /// Download the upgrade installer and close the app depending on if it is successful or not
        /// </summary>
        private async void DownLoadInstaller(IAutoUpdate autoUpdate)
        {
            UpdateResult updateResult = 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;
                updateResult = await autoUpdate.UpdateAsync().ConfigureAwait(true);

                Logger.PublishTelemetryEvent(TelemetryEventFactory.ForUpgradeDoInstallation(
                                                 autoUpdate.GetUpdateTime(), updateResult.ToString()));
                if (updateResult == 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(TelemetryEventFactory.ForUpgradeInstallationError(updateResult.ToString()));

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

            MessageDialog.Show(message);

            if (_updateOption == AutoUpdateOption.RequiredUpgrade)
            {
                this.Close();
                return;
            }
        }
        /// <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.UpdateInstallerUpdateTime, GetTimeSpanTelemetryString(autoUpdate.GetUpdateTime()) },
                    { 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() : GetMessageForOptionalUpdateFailure();

            MessageBox.Show(message);

            if (updateOption == AutoUpdateOption.RequiredUpgrade)
            {
                this.Close();
                return;
            }
        }
Пример #3
0
        /// <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;
                }
            }
            catch (Exception e)
            {
                e.ReportException();
            };

            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;
            }
        }