Exemplo n.º 1
0
        public static void Uninstall()
        {
            _logger.Info("Detected uninstall command line. Selected 'Uninstall' as deployment");
            if (EnvironmentVariables.Configuration.UninstallSettings == null)
            {
                _logger.Trace("No uninstall arguments specified in settings.xml. Looking for uninstall.xml");
                var uninstallXmlPath = Path.Combine(DeploymentEnvironmentVariables.RootDirectory, "uninstall.xml");
                if (!File.Exists(uninstallXmlPath))
                {
                    ExitInstallation("uninstall.xml is missing", ExitCode.UninstallFileMissing);
                }

                _logger.Trace("Found uninstall.xml. Reading...");
                EnvironmentVariables.UninstallSettings = ReadXml <UninstallSettings>(uninstallXmlPath);
                _logger.Trace("Successfully read uninstall.xml");
            }
            else
            {
                _logger.Trace("Uninstall options specified inside settings.xml");
                EnvironmentVariables.UninstallSettings = EnvironmentVariables.Configuration.UninstallSettings;
            }

            _logger.Trace("Read uninstall settings. Starting uninstallation...");
            _logger.Trace("Checking CommandLine Path...");

            EnvironmentVariables.UninstallSettings.CommandLine = VerifyCommandLine(EnvironmentVariables.UninstallSettings.CommandLine);

            VerifyUninstall();

            // Detecting installation type
            try
            {
                var sequence = default(IInstallUninstallSequence);
                if (EnvironmentVariables.UninstallSettings.CommandLine.ToLower().EndsWith(".msi"))
                {
                    // Microsoft Installer
                    sequence = new MSIUninstaller(EnvironmentVariables.UninstallSettings);
                }
                else
                {
                    // Unknwon / EXE installer
                    sequence = new ExeUninstaller(EnvironmentVariables.UninstallSettings);
                }

                _mainSequence = new MainSequence(sequence);
                _mainSequence.OnSequenceCompleted += OnSequenceCompleted;
                _mainSequence.SequenceBegin();

                do
                {
                    Thread.Sleep(1000);
                }while (!_sequenceCompleted);
            }
            catch (Exception ex)
            {
                ExitInstallation(ex, "Error during uninstallation", ExitCode.ErrorDuringUninstallation);
            }

            _logger.Info("Uninstall sequence completed");
        }
Exemplo n.º 2
0
        public static void Install()
        {
            _logger.Info("Detected install command line. Selected 'Install' as deployment");
            if (EnvironmentVariables.Configuration.InstallSettings == null)
            {
                _logger.Trace("No installation arguments specified in settings.xml. Looking for install.xml");
                var installXmlPath = Path.Combine(DeploymentEnvironmentVariables.RootDirectory, "install.xml");
                if (!File.Exists(installXmlPath))
                {
                    ExitInstallation("install.xml is missing", ExitCode.InstallFileMissing);
                }

                _logger.Trace("Found install.xml. Reading...");
                EnvironmentVariables.InstallSettings = ReadXml <InstallSettings>(installXmlPath);
                _logger.Trace("Successfully read install.xml");
            }
            else
            {
                _logger.Trace("Install options specified inside settings.xml");
                EnvironmentVariables.InstallSettings = EnvironmentVariables.Configuration.InstallSettings;
            }

            _logger.Info("Read install settings. Starting installation...");
            _logger.Trace("Checking CommandLine Path...");

            EnvironmentVariables.InstallSettings.CommandLine = VerifyCommandLine(EnvironmentVariables.InstallSettings.CommandLine);

            _logger.Trace("Verifiying that file specified in CommandLine exists...");
            // CommandLine should either specify an exe file or an msi file. Either way the file has to exist
            if (!File.Exists(EnvironmentVariables.InstallSettings.CommandLine))
            {
                ExitInstallation($"File specified in CommandLine does not exists ({EnvironmentVariables.InstallSettings.CommandLine}). Aborting installation", ExitCode.InvalidCommandLineSpecified);
            }

            // Detecting installation type
            try
            {
                var sequence = default(IInstallUninstallSequence);
                if (EnvironmentVariables.InstallSettings.CommandLine.ToLower().EndsWith(".msi"))
                {
                    // Microsoft Installer
                    sequence = new MSIInstaller(EnvironmentVariables.InstallSettings);
                }
                else
                {
                    // Unknwon / EXE installer
                    sequence = new ExeInstaller(EnvironmentVariables.InstallSettings);
                }

                _mainSequence = new MainSequence(sequence);
                _mainSequence.OnSequenceCompleted += OnSequenceCompleted;
                _mainSequence.SequenceBegin();

                do
                {
                    Thread.Sleep(1000);
                }while (!_sequenceCompleted);
            }
            catch (Exception ex)
            {
                ExitInstallation(ex, "Error during installation", ExitCode.ErrorDuringInstallation);
            }

            _logger.Info("Install sequence completed");
        }