示例#1
0
        /// <summary>
        ///     Shows the built-in UI while the updates are managed.
        /// </summary>
        public void ShowUserInterface()
        {
            if (_isTaskRunning)
            {
                return;
            }

            _isTaskRunning = true;
            var searchDialog = new UpdateSearchDialog {
                Updater = UpdateManagerInstance
            };

            searchDialog.CancelButtonClicked += UpdateSearchDialogCancelButtonClick;

            var newUpdateDialog = new NewUpdateDialog {
                Updater = UpdateManagerInstance
            };
            var noUpdateDialog = new NoUpdateFoundDialog {
                Updater = UpdateManagerInstance
            };

            var progressIndicator = new Progress <UpdateDownloadProgressChangedEventArgs>();
            var downloadDialog    = new UpdateDownloadDialog {
                Updater = UpdateManagerInstance
            };

            downloadDialog.CancelButtonClicked += UpdateDownloadDialogCancelButtonClick;

#if PROVIDE_TAP
            try
            {
                // TAP
                TaskEx.Run(async delegate
                {
                    if (!UseHiddenSearch)
                    {
                        _context.Post(searchDialog.ShowModalDialog, null);
                    }

                    try
                    {
                        _updatesAvailable = await UpdateManagerInstance.SearchForUpdatesAsync();
                    }
                    catch (OperationCanceledException)
                    {
                        return;
                    }
                    catch (Exception ex)
                    {
                        if (UseHiddenSearch)
                        {
                            _context.Send(
                                o =>
                                Popup.ShowPopup(SystemIcons.Error, _lp.UpdateSearchErrorCaption, ex,
                                                PopupButtons.Ok), null);
                        }
                        else
                        {
                            searchDialog.Fail(ex);
                            _context.Post(searchDialog.CloseDialog, null);
                        }
                        return;
                    }

                    if (!UseHiddenSearch)
                    {
                        _context.Post(searchDialog.CloseDialog, null);
                        await TaskEx.Delay(100);
                        // Prevents race conditions that cause that the UpdateSearchDialog can't be closed before further actions are done
                    }

                    if (_updatesAvailable)
                    {
                        var newUpdateDialogReference = new DialogResultReference();
                        _context.Send(newUpdateDialog.ShowModalDialog, newUpdateDialogReference);
                        if (newUpdateDialogReference.DialogResult == DialogResult.Cancel)
                        {
                            return;
                        }
                    }
                    else if (!_updatesAvailable && UseHiddenSearch)
                    {
                        return;
                    }
                    else if (!_updatesAvailable && !UseHiddenSearch)
                    {
                        var noUpdateDialogResultReference = new DialogResultReference();
                        if (!UseHiddenSearch)
                        {
                            _context.Send(noUpdateDialog.ShowModalDialog, noUpdateDialogResultReference);
                        }
                        return;
                    }

                    _context.Post(downloadDialog.ShowModalDialog, null);

                    try
                    {
                        progressIndicator.ProgressChanged += (sender, args) =>
                                                             downloadDialog.ProgressPercentage = (int)args.Percentage;

                        await UpdateManagerInstance.DownloadPackagesAsync(progressIndicator);
                    }
                    catch (OperationCanceledException)
                    {
                        return;
                    }
                    catch (Exception ex)
                    {
                        downloadDialog.Fail(ex);
                        _context.Send(downloadDialog.CloseDialog, null);
                        return;
                    }
                    _context.Send(downloadDialog.CloseDialog, null);

                    bool isValid = false;
                    try
                    {
                        isValid = UpdateManagerInstance.ValidatePackages();
                    }
                    catch (FileNotFoundException)
                    {
                        _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                                           _lp.PackageNotFoundErrorText,
                                                           PopupButtons.Ok), null);
                    }
                    catch (ArgumentException)
                    {
                        _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                                           _lp.InvalidSignatureErrorText, PopupButtons.Ok), null);
                    }
                    catch (Exception ex)
                    {
                        _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                                           ex, PopupButtons.Ok), null);
                    }

                    if (!isValid)
                    {
                        _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.InvalidSignatureErrorCaption,
                                                           _lp.SignatureNotMatchingErrorText,
                                                           PopupButtons.Ok), null);
                    }
                    else
                    {
                        UpdateManagerInstance.InstallPackage();
                    }
                });
            }
            finally
            {
                _isTaskRunning = false;
            }
#else
            try
            {
                //EAP
                UpdateManagerInstance.UpdateSearchFinished            += SearchFinished;
                UpdateManagerInstance.UpdateSearchFinished            += searchDialog.Finished;
                UpdateManagerInstance.UpdateSearchFailed              += searchDialog.Failed;
                UpdateManagerInstance.PackagesDownloadProgressChanged += downloadDialog.ProgressChanged;
                UpdateManagerInstance.PackagesDownloadFinished        += downloadDialog.Finished;
                UpdateManagerInstance.PackagesDownloadFailed          += downloadDialog.Failed;

                Task.Factory.StartNew(() =>
                {
                    UpdateManagerInstance.SearchForUpdatesAsync();
                    if (!UseHiddenSearch)
                    {
                        var searchDialogResultReference = new DialogResultReference();
                        _context.Send(searchDialog.ShowModalDialog, searchDialogResultReference);
                        _context.Send(searchDialog.CloseDialog, null);
                        if (searchDialogResultReference.DialogResult == DialogResult.Cancel)
                        {
                            return;
                        }
                    }
                    else
                    {
                        _searchResetEvent.WaitOne();
                    }

                    if (_updatesAvailable)
                    {
                        var newUpdateDialogResultReference = new DialogResultReference();
                        _context.Send(newUpdateDialog.ShowModalDialog, newUpdateDialogResultReference);
                        if (newUpdateDialogResultReference.DialogResult == DialogResult.Cancel)
                        {
                            return;
                        }
                    }
                    else if (!_updatesAvailable && UseHiddenSearch)
                    {
                        return;
                    }
                    else if (!_updatesAvailable && !UseHiddenSearch)
                    {
                        _context.Send(noUpdateDialog.ShowModalDialog, null);
                        _context.Send(noUpdateDialog.CloseDialog, null);
                        return;
                    }

                    UpdateManagerInstance.DownloadPackagesAsync();

                    var downloadDialogResultReference = new DialogResultReference();
                    _context.Send(downloadDialog.ShowModalDialog, downloadDialogResultReference);
                    _context.Send(downloadDialog.CloseDialog, null);
                    if (downloadDialogResultReference.DialogResult == DialogResult.Cancel)
                    {
                        return;
                    }

                    bool isValid = false;
                    try
                    {
                        isValid = UpdateManagerInstance.ValidatePackages();
                    }
                    catch (FileNotFoundException)
                    {
                        _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                                           _lp.PackageNotFoundErrorText,
                                                           PopupButtons.Ok), null);
                    }
                    catch (ArgumentException)
                    {
                        _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                                           _lp.InvalidSignatureErrorText, PopupButtons.Ok), null);
                    }
                    catch (Exception ex)
                    {
                        _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                                           ex, PopupButtons.Ok), null);
                    }

                    if (!isValid)
                    {
                        _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.InvalidSignatureErrorCaption,
                                                           _lp.SignatureNotMatchingErrorText,
                                                           PopupButtons.Ok), null);
                    }
                    else
                    {
                        try
                        {
                            UpdateManagerInstance.InstallPackage();
                        }
                        catch (Win32Exception ex)
                        {
                            // TODO: Localize
                            _context.Send(o => Popup.ShowPopup(SystemIcons.Error, "Error while starting the installer.",
                                                               ex,
                                                               PopupButtons.Ok), null);
                        }
                        catch (Exception ex)
                        {
                            _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.InstallerInitializingErrorCaption,
                                                               ex,
                                                               PopupButtons.Ok), null);
                        }
                    }
                });
            }
            finally
            {
                _isTaskRunning = false;
            }
#endif
        }
示例#2
0
        /// <summary>
        ///     Starts the complete update process and uses the integrated user interface for user interaction.
        /// </summary>
        public void ShowUserInterface()
        {
            if (_active)
            {
                return;
            }
            _active = true;
            _searchResetEvent.Reset();

            Task.Factory.StartNew(() =>
            {
                try
                {
                    if (!UseHiddenSearch)
                    {
                        var searchDialog = new UpdateSearchDialog {
                            UpdateManager = UpdateManager
                        };
                        var searchDialogResult = new DialogResultWrapper();
                        Context.Send(d => searchDialog.ShowDialog(searchDialogResult), null);
                        if (searchDialogResult.DialogResult != DialogResult.OK)
                        {
                            return;
                        }

                        if (!searchDialog.UpdatesFound)
                        {
                            var noUpdateDialog = new NoUpdateFoundDialog {
                                UpdateManager = UpdateManager
                            };
                            var noUpdateDialogResult = new DialogResultWrapper();
                            Context.Send(d => noUpdateDialog.ShowDialog(noUpdateDialogResult), null);
                            return;
                        }
                    }
                    else
                    {
                        var failed       = false;
                        var updatesFound = false;

                        UpdateManager.UpdateSearchFailed += (sender, args) =>
                        {
                            failed = true;

                            // Important: The UI thread that we want to access using the synchronization context is blocked until we set the manual reset event.
                            // This call needs to be done first, otherwise we'll experience a deadlock as SynchronizationContext.Send is sending a synchronous message.
                            _searchResetEvent.Set();
                            Context.Send(c => Popup.ShowPopup(SystemIcons.Error, _lp.UpdateSearchErrorCaption,
                                                              args.Exception,
                                                              PopupButtons.Ok), null);
                        };

                        UpdateManager.UpdateSearchFinished += (sender, args) =>
                        {
                            updatesFound = args.UpdatesAvailable;
                            _searchResetEvent.Set();
                        };

                        UpdateManager.SearchForUpdatesAsync();
                        _searchResetEvent.WaitOne();

                        if (failed || !updatesFound)
                        {
                            return;
                        }
                    }

                    var newUpdateDialog = new NewUpdateDialog {
                        UpdateManager = UpdateManager
                    };
                    var newUpdateDialogResult = new DialogResultWrapper();
                    Context.Send(d => newUpdateDialog.ShowDialog(newUpdateDialogResult), null);
                    if (newUpdateDialogResult.DialogResult != DialogResult.OK)
                    {
                        return;
                    }

                    var downloadDialog = new UpdateDownloadDialog {
                        UpdateManager = UpdateManager
                    };
                    var downloadDialogResult = new DialogResultWrapper();
                    Context.Send(d => downloadDialog.ShowDialog(downloadDialogResult), null);
                    if (downloadDialogResult.DialogResult != DialogResult.OK)
                    {
                        return;
                    }

                    bool valid;
                    try
                    {
                        valid = UpdateManager.ValidatePackages();
                    }
                    catch (FileNotFoundException)
                    {
                        Context.Send(c => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                                          _lp.PackageNotFoundErrorText,
                                                          PopupButtons.Ok), null);
                        return;
                    }
                    catch (ArgumentException)
                    {
                        Context.Send(c => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                                          _lp.InvalidSignatureErrorText, PopupButtons.Ok), null);
                        return;
                    }
                    catch (Exception ex)
                    {
                        Context.Send(c => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                                          ex, PopupButtons.Ok), null);
                        return;
                    }

                    if (!valid)
                    {
                        Context.Send(c => Popup.ShowPopup(SystemIcons.Error, _lp.InvalidSignatureErrorCaption,
                                                          _lp.SignatureNotMatchingErrorText,
                                                          PopupButtons.Ok), null);
                    }
                    else
                    {
                        try
                        {
                            UpdateManager.InstallPackage();
                        }
                        catch (Exception ex)
                        {
                            Context.Send(c => Popup.ShowPopup(SystemIcons.Error, _lp.InstallerInitializingErrorCaption,
                                                              ex,
                                                              PopupButtons.Ok), null);
                        }
                    }
                }
                finally
                {
                    _active = false;
                }
            });
        }
示例#3
0
        /// <summary>
        ///     Starts the complete update process and uses the integrated user interface for user interaction.
        /// </summary>
        public async void ShowUserInterface()
        {
            if (_active)
            {
                return;
            }
            _active = true;

            try
            {
                if (!UseHiddenSearch)
                {
                    var searchDialog = new UpdateSearchDialog {
                        UpdateManager = UpdateManager
                    };
                    if (searchDialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    if (!searchDialog.UpdatesFound)
                    {
                        var noUpdateDialog = new NoUpdateFoundDialog {
                            UpdateManager = UpdateManager
                        };
                        noUpdateDialog.ShowDialog();
                        return;
                    }
                }
                else
                {
                    try
                    {
                        if (!await UpdateManager.SearchForUpdatesAsync())
                        {
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        Context.Send(c => Popup.ShowPopup(SystemIcons.Error, _lp.UpdateSearchErrorCaption, ex,
                                                          PopupButtons.Ok), null);
                        return;
                    }
                }

                var newUpdateDialog = new NewUpdateDialog {
                    UpdateManager = UpdateManager
                };
                if (newUpdateDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var downloadDialog = new UpdateDownloadDialog {
                    UpdateManager = UpdateManager
                };
                if (downloadDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                bool valid;
                try
                {
                    valid = UpdateManager.ValidatePackages();
                }
                catch (FileNotFoundException)
                {
                    Context.Send(c => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                                      _lp.PackageNotFoundErrorText,
                                                      PopupButtons.Ok), null);
                    return;
                }
                catch (ArgumentException)
                {
                    Context.Send(c => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                                      _lp.InvalidSignatureErrorText, PopupButtons.Ok), null);
                    return;
                }
                catch (Exception ex)
                {
                    Context.Send(c => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                                      ex, PopupButtons.Ok), null);
                    return;
                }

                if (!valid)
                {
                    Context.Send(c => Popup.ShowPopup(SystemIcons.Error, _lp.InvalidSignatureErrorCaption,
                                                      _lp.SignatureNotMatchingErrorText,
                                                      PopupButtons.Ok), null);
                }
                else
                {
                    try
                    {
                        UpdateManager.InstallPackage();
                    }
                    catch (Exception ex)
                    {
                        Context.Send(c => Popup.ShowPopup(SystemIcons.Error, _lp.InstallerInitializingErrorCaption,
                                                          ex,
                                                          PopupButtons.Ok), null);
                    }
                }
            }
            finally
            {
                _active = false;
            }
        }
示例#4
0
        /// <summary>
        ///     Shows the built-in UI while the updates are managed.
        /// </summary>
        public void ShowUserInterface()
        {
            var searchDialog = new UpdateSearchDialog {
                LanguageName = _updateManager.LanguageCulture.Name
            };

            _updateManager.UpdateSearchFinished += SearchFinishedEventHandler;
            _updateManager.UpdateSearchFinished += searchDialog.SearchFinishedEventHandler;
            _updateManager.UpdateSearchFailed   += searchDialog.SearchFailedEventHandler;
            _updateManager.SearchForUpdatesAsync();

            if (!_updateManager.UseHiddenSearch)
            {
                if (searchDialog.ShowDialog() == DialogResult.Cancel)
                {
                    searchDialog.Close();
                    _updateManager.CancelSearchAsync();
                    return;
                }
                searchDialog.Close();
            }

            _updateManager.UpdateSearchFinished -= SearchFinishedEventHandler;
            _updateManager.UpdateSearchFinished -= searchDialog.SearchFinishedEventHandler;
            _updateManager.UpdateSearchFailed   -= searchDialog.SearchFailedEventHandler;

            if (_updateAvailable)
            {
                var newUpdateDialog = new NewUpdateDialog
                {
                    LanguageName   = _updateManager.LanguageCulture.Name,
                    CurrentVersion = _updateManager.CurrentVersion,
                    PackageSize    = _updateManager.PackageSize,
                    OperationAreas = _updateManager.Operations.Select(item => item.Area).ToList(),
                    NewestVersion  = _updateManager.NewestVersion,
                    Changelog      = _updateManager.Changelog,
                    MustUpdate     = _updateManager.MustUpdate
                };

                if (newUpdateDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }
            else if (!_updateAvailable && _updateManager.UseHiddenSearch)
            {
                return;
            }
            else if (!_updateAvailable && !_updateManager.UseHiddenSearch)
            {
                var noUpdateDialog = new NoUpdateFoundDialog {
                    LanguageName = _updateManager.LanguageCulture.Name
                };
                if (noUpdateDialog.ShowDialog() == DialogResult.OK)
                {
                    return;
                }
            }

            var downloadDialog = new UpdateDownloadDialog {
                LanguageName = _updateManager.LanguageCulture.Name
            };

            _updateManager.PackageDownloadProgressChanged += downloadDialog.ProgressChangedEventHandler;
            _updateManager.PackageDownloadFinished        += downloadDialog.DownloadFinishedEventHandler;
            _updateManager.PackageDownloadFailed          += downloadDialog.DownloadFailedEventHandler;
            _updateManager.StatisticsEntryFailed          += downloadDialog.StatisticsEntryFailedEventHandler;
            _updateManager.DownloadPackageAsync();

            if (downloadDialog.ShowDialog() == DialogResult.Cancel)
            {
                if (_updateManager.IsDownloading)
                {
                    _updateManager.CancelDownloadAsync();
                }
                return;
            }

            bool isValid = false;

            try
            {
                isValid = _updateManager.CheckPackageValidity();
            }
            catch (FileNotFoundException)
            {
                Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                _lp.PackageNotFoundErrorText,
                                PopupButtons.Ok);
            }
            catch (ArgumentException)
            {
                Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                _lp.InvalidSignatureErrorText, PopupButtons.Ok);
            }
            catch (Exception ex)
            {
                Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption,
                                ex, PopupButtons.Ok);
            }

            if (!isValid)
            {
                Popup.ShowPopup(SystemIcons.Error, _lp.InvalidSignatureErrorCaption,
                                _lp.SignatureNotMatchingErrorText,
                                PopupButtons.Ok);
            }
            else
            {
                _updateManager.InstallPackage();
            }
        }