Пример #1
0
        private void OnStartUpgrade()
        {
            IsInUpgrading = true;
            string upgradeDescription = string.Empty;
            string stepDes            = Translator.GetValue("Working on updates\nPart 4 of 4: Upgrading to new version");

            try
            {
                string destAssembly = Path.Combine(_upgradeFolder, "UpgradeHost.DLL");

                if (!File.Exists(destAssembly) || !DigitalSignatureChecker.VerifySignature(destAssembly))
                {
                    throw new Exception();
                }

                UpgradeProxy proxy = new UpgradeProxy(destAssembly);
                upgradeDescription = proxy.Description();
                _wizardService.UpdateStates(_title, upgradeDescription, stepDes, DoNotTrunOff);
                string message;
                if (!proxy.CanExecute(out message))
                {
                    throw new Exception(message);
                }
                try
                {
                    Thread.Sleep(2000);
                    proxy.Execute(_upgradeFolder, out message);
                }
                catch (Exception e)
                {
                    throw new Exception(e.InnerException != null?e.InnerException.Message:e.Message);
                }

                try
                {
                    //delete upgrade folder
                    //todo KnowIssue ,UpgradeHost.dll can't be delete,as it has been loaded  into AppDomain
                    Directory.Delete(_upgradeFolder, true);
                }
                catch (Exception e)
                {
                }

                const string shutdownMessage     = "Upgrade done successfully.\nSystem will continue automatically after";
                string       shutdownAdditionDes = string.Empty;
                var          buttons             = new WizardButton[1];
                buttons[0] = new WizardButton(WizardButtonEnum.Ok, null, "Continue");
                int timeoutTicks = ResourceManager.GetValue("Upgrade", "TimeoutTicks", 10);
                _wizardService.UpdateStates(_title, upgradeDescription, shutdownMessage, shutdownAdditionDes, -1, true, buttons, timeoutTicks, buttons[0]);

                //Decide to start Main.exe or continue upgrade.
                StartOrContinue();
            }
            catch (Exception e)
            {
                var buttons = new WizardButton[1];
                buttons[0] = new WizardButton(WizardButtonEnum.Ok, null, "Shut Down");
                _wizardService.UpdateStates(_title, upgradeDescription, Translator.GetValue("Upgrade failed.\nSystem will shut down."), e.Message, -1, true, buttons);
                HostManager.ShutDown(RestartType.ShutdownOS);
            }
            finally
            {
                IsInUpgrading = false;
                HostManager.ShutDown(RestartType.None);
            }
        }