Exemple #1
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;
                }
            });
        }
Exemple #2
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;
            }
        }
Exemple #3
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();
            }
        }