Exemplo n.º 1
0
        /// <summary>
        /// Triggers the installation and launches the installed app upon completion
        /// </summary>
        internal void PerformInstallation()
        {
            EventLogger.WriteInformationalMessage("Beginning Installation");
            InstallationOptions options = GetInstallationOptions();

            DownloadFromUriToLocalFile(options);
            using (ValidateLocalFile(options.LocalInstallerFile))
            {
                using (Transaction transaction = new Transaction(_productName, TransactionAttributes.ChainEmbeddedUI))
                {
                    InstallWithinTransaction(options, transaction);
                }
            }
            UpdateConfigWithNewChannel(options.NewChannel);
            LaunchPostInstallApp();
            EventLogger.WriteInformationalMessage("Completed Installation");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Download the installer to a computed local file
        /// </summary>
        /// <param name="options">The parameters to drive the install</param>
        private void DownloadFromUriToLocalFile(InstallationOptions options)
        {
            _installerDownloadStopwatch.Reset();

            using (Stream stream = new FileStream(options.LocalInstallerFile, FileMode.CreateNew))
            {
                _installerDownloadStopwatch.Start();

                try
                {
                    GitHubClient.LoadUriContentsIntoStream(options.MsiPath, stream, options.DownloadTimeout);
                }
                finally
                {
                    _installerDownloadStopwatch.Stop();
                }
            } // using

            EventLogger.WriteInformationalMessage("Successfully downloaded Installer from {0} to {1}",
                                                  options.MsiPath.ToString(), options.LocalInstallerFile);
        }
        /// <summary>
        /// Triggers the installation and launches the installed app upon completion
        /// </summary>
        internal void PerformInstallation(Action <int> progressCallback)
        {
            EventLogger.WriteInformationalMessage("Beginning Installation");
            progressCallback(0);
            InstallationOptions options = GetInstallationOptions();

            DownloadFromUriToLocalFile(options, (p) => progressCallback((p * 4) / 5));
            using (ValidateLocalFile(options.LocalInstallerFile))
            {
                using (Transaction transaction = new Transaction(_productName, TransactionAttributes.ChainEmbeddedUI))
                {
                    InstallWithinTransaction(options, transaction);
                }
            }
            progressCallback(80);
            UpdateConfigWithNewChannel(options.NewChannel);
            progressCallback(90);
            SetManifestForUIAccess(options.EnableUIAccess);
            progressCallback(95);
            LaunchPostInstallApp();
            progressCallback(100);
            EventLogger.WriteInformationalMessage("Completed Installation");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Wrap the install inside a transaction
        /// </summary>
        /// <param name="options">The parameters to drive the installation</param>
        /// <param name="transaction">The transaction to wrap the operation</param>
        private void InstallWithinTransaction(InstallationOptions options, Transaction transaction)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            bool      success   = false;

            try
            {
                RemoveOldVersion();
                InstallNewVersion(options.LocalInstallerFile);
                success = true;
            }
            finally
            {
                if (success)
                {
                    transaction.Commit();
                }
                else
                {
                    transaction.Rollback();
                }

                stopwatch.Stop();

                const string messageTemplate = "VersionSwitcher {0} in {1} ms";

                if (success)
                {
                    EventLogger.WriteInformationalMessage(messageTemplate, "succeeded", stopwatch.ElapsedMilliseconds);
                }
                else
                {
                    EventLogger.WriteErrorMessage(messageTemplate, "failed", stopwatch.ElapsedMilliseconds);
                }
            }
        }