Exemplo n.º 1
0
        /// <summary>
        /// Installs the Windows Management Console to the specified path.
        /// </summary>
        /// <param name="completionCallback">The completion callback.</param>
        public void InstallWindowsConsole(Action <bool> completionCallback)
        {
            if (!this.CanInstallWindowsConsole(this.WindowsConsoleInstallLocation))
            {
                return;
            }

            var installTask = Task.Run(() =>
            {
                _logger.Log("Installing SACS Windows Console Manager");
                WizardManager wizard = WizardManager.Current;
                string tempPath      = Path.Combine(Path.GetTempPath(), "SACS.Windows");

                try
                {
                    wizard.ShowProgressDialog();
                    wizard.UpdateProgressValue(0);

                    wizard.UpdateProgressText("Extracting files...");
                    FileSystemUtilities.ExtractFromResource("SACS.Setup.Resources.SACS.Windows.zip", tempPath, "SACS.Windows");
                    wizard.UpdateProgressValue(0.2m);
                    Thread.Sleep(300);

                    wizard.UpdateProgressText("Backing up files...");
                    FileSystemUtilities.BackupDirectory(this.WindowsConsoleInstallLocation, "SACS.Windows");
                    wizard.UpdateProgressValue(0.5m);
                    Thread.Sleep(300);

                    wizard.UpdateProgressText("Copying over files...");
                    this.CopyServerFiles(tempPath, this.WindowsConsoleInstallLocation);
                    wizard.UpdateProgressValue(0.8m);
                    Thread.Sleep(300);

                    // create shortcut if new installation.
                    if (!this.IsWindowsConsoleUpgrade)
                    {
                        wizard.UpdateProgressText("Creating shortcut...");
                        AddWindowsShortcut(Path.Combine(this.WindowsConsoleInstallLocation, "SACS.Windows.exe"));
                    }

                    wizard.UpdateProgressValue(1m);
                    Thread.Sleep(1000);

                    wizard.HideProgressDialog();
                    wizard.PerformOnUI(() => completionCallback(true));
                }
                catch (InstallException ie)
                {
                    _logger.Log("InstallWindowsConsole exception", ie);
                    wizard.HideProgressDialog();
                    wizard.PerformOnUI(() => completionCallback(false));
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Installs the server to the specified path.
        /// </summary>
        /// <param name="completionCallback">The completion callback.</param>
        public void InstallServer(Action <bool> completionCallback)
        {
            if (!this.CanInstallServer(this.ServerInstallLocation))
            {
                return;
            }

            var installTask = Task.Run(() =>
            {
                WizardManager wizard = WizardManager.Current;
                string tempPath      = Path.Combine(Path.GetTempPath(), "SACS.WindowsService");

                try
                {
                    _logger.Log("Installing SACS server");
                    wizard.ShowProgressDialog();
                    wizard.UpdateProgressValue(0);

                    wizard.UpdateProgressText("Extracting files...");
                    FileSystemUtilities.ExtractFromResource("SACS.Setup.Resources.SACS.WindowsService.zip", tempPath, "SACS.WindowsService");
                    wizard.UpdateProgressValue(0.2m);
                    Thread.Sleep(300);

                    wizard.UpdateProgressText("Stopping agent...");
                    if (!this.TryStopService())
                    {
                        throw new InstallException("Could not stop agent");
                    }

                    wizard.UpdateProgressValue(0.4m);
                    Thread.Sleep(300);

                    wizard.UpdateProgressText("Backing up files...");
                    FileSystemUtilities.BackupDirectory(this.ServerInstallLocation, "SACS.WindowsService");
                    wizard.UpdateProgressValue(0.6m);
                    Thread.Sleep(300);

                    wizard.UpdateProgressText("Copying over files...");
                    this.CopyServerFiles(tempPath, this.ServerInstallLocation);
                    wizard.UpdateProgressValue(0.8m);
                    Thread.Sleep(300);

                    // register SACS if a new installation
                    if (!this.IsServerUpgrade)
                    {
                        _logger.Log("Registering service");
                        wizard.UpdateProgressText("Registering SACS Agent as a Windows service...");
                        FileInfo exeFile = new FileInfo(this.ServerInstallLocation + "\\SACS.WindowsService.exe");
                        if (exeFile.Exists)
                        {
                            Process.Start(new ProcessStartInfo {
                                FileName = exeFile.FullName, Arguments = "install"
                            });
                        }
                        else
                        {
                            MessageBox.Show("Installation corrupt: executable file missing from installation. Aborting.", "Server install error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw new InstallException("SACS.WindowsService.exe missing");
                        }
                    }

                    wizard.UpdateProgressValue(1m);
                    Thread.Sleep(1000);

                    wizard.HideProgressDialog();
                    wizard.PerformOnUI(() => completionCallback(true));
                }
                catch (InstallException ie)
                {
                    _logger.Log("InstallServer exception", ie);
                    wizard.HideProgressDialog();
                    wizard.PerformOnUI(() => completionCallback(false));
                }
            });
        }