Esempio n. 1
0
        // ReSharper disable once UnusedMethodReturnValue.Global
        public bool Delete(string instanceName, bool removeLogs)
        {
            var instance = InstanceFinder.FindMonitoringInstance(instanceName);

            instance.ReportCard = new ReportCard();
            if (!instance.TryStopService())
            {
                logger.Error("Service failed to stop");
                return(false);
            }

            try
            {
                instance.BackupAppConfig();
                instance.Service.SetStartupMode("Disabled");
                instance.Service.Delete();
                instance.RemoveUrlAcl();
                instance.RemoveBinFolder();
                if (removeLogs)
                {
                    instance.RemoveLogsFolder();
                }

                foreach (var warning in instance.ReportCard.Warnings)
                {
                    logger.Warn(warning);
                }

                if (instance.ReportCard.HasErrors)
                {
                    foreach (var error in instance.ReportCard.Errors)
                    {
                        logger.Error(error);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        protected override void ProcessRecord()
        {
            var logger    = new PSLogger(Host);
            var zipfolder = Path.GetDirectoryName(MyInvocation.MyCommand.Module.Path);
            var installer = new UnattendMonitoringInstaller(logger, zipfolder);

            foreach (var name in Name)
            {
                var instance = InstanceFinder.FindMonitoringInstance(name);
                if (instance == null)
                {
                    WriteWarning($"No action taken. An instance called {name} was not found");
                    break;
                }
                WriteObject(installer.Delete(instance.Name, RemoveLogs.ToBool()));
            }
        }
        protected override void ProcessRecord()
        {
            var details = new MonitoringNewInstance
            {
                InstallPath        = InstallPath,
                LogPath            = LogPath,
                Name               = Name,
                DisplayName        = string.IsNullOrWhiteSpace(DisplayName) ? Name : DisplayName,
                ServiceDescription = Description,
                ServiceAccount     = ServiceAccount,
                ServiceAccountPwd  = ServiceAccountPassword,
                HostName           = HostName,
                Port               = Port,
                ErrorQueue         = ErrorQueue,
                ConnectionString   = ConnectionString,
                TransportPackage   = MonitoringTransports.All.First(t => t.Matches(Transport)),
                SkipQueueCreation  = SkipQueueCreation
            };

            var zipfolder = Path.GetDirectoryName(MyInvocation.MyCommand.Module.Path);
            var logger    = new PSLogger(Host);

            var installer = new UnattendMonitoringInstaller(logger, zipfolder);

            try
            {
                logger.Info("Installing Monitoring instance...");
                if (installer.Add(details, PromptToProceed))
                {
                    var instance = InstanceFinder.FindMonitoringInstance(details.Name);
                    if (instance != null)
                    {
                        WriteObject(PsMonitoringService.FromInstance(instance));
                    }
                    else
                    {
                        throw new Exception("Unknown error creating instance");
                    }
                }
            }
            catch (Exception ex)
            {
                ThrowTerminatingError(new ErrorRecord(ex, null, ErrorCategory.NotSpecified, null));
            }
        }
Esempio n. 4
0
        internal ReportCard Delete(string instanceName, bool removeLogs, IProgress <ProgressDetails> progress = null)
        {
            progress = progress ?? new Progress <ProgressDetails>();
            progress.Report(0, 7, "Stopping instance...");
            var instance = InstanceFinder.FindMonitoringInstance(instanceName);

            instance.ReportCard = new ReportCard();

            if (!instance.TryStopService())
            {
                return(new ReportCard
                {
                    Errors = { "Service failed to stop" },
                    Status = Status.Failed
                });
            }

            instance.BackupAppConfig();

            progress.Report(1, 7, "Disabling startup...");
            instance.Service.SetStartupMode("Disabled");

            progress.Report(2, 7, "Deleting service...");
            instance.Service.Delete();

            progress.Report(3, 7, "Removing URL ACL...");
            instance.RemoveUrlAcl();

            progress.Report(4, 7, "Deleting install...");
            instance.RemoveBinFolder();

            if (removeLogs)
            {
                progress.Report(5, 7, "Deleting logs...");
                instance.RemoveLogsFolder();
            }

            progress.Report(new ProgressDetails());

            instance.ReportCard.SetStatus();
            return(instance.ReportCard);
        }
Esempio n. 5
0
        internal ReportCard Add(MonitoringNewInstance details, IProgress <ProgressDetails> progress, Func <PathInfo, bool> promptToProceed)
        {
            ZipInfo.ValidateZip();

            var instanceInstaller = details;

            instanceInstaller.ReportCard = new ReportCard();

            //Validation
            instanceInstaller.Validate(promptToProceed);
            if (instanceInstaller.ReportCard.HasErrors || instanceInstaller.ReportCard.CancelRequested)
            {
                instanceInstaller.ReportCard.Status = Status.FailedValidation;
                return(instanceInstaller.ReportCard);
            }

            progress.Report(3, 9, "Copying files...");
            instanceInstaller.CopyFiles(ZipInfo.FilePath);
            progress.Report(4, 9, "Writing configurations...");
            instanceInstaller.WriteConfigurationFile();
            progress.Report(5, 9, "Registering URL ACLs...");
            instanceInstaller.RegisterUrlAcl();
            progress.Report(6, 9, "Creating queues...");
            instanceInstaller.SetupInstance();

            if (!instanceInstaller.ReportCard.HasErrors)
            {
                progress.Report(7, 9, "Registering service...");
                instanceInstaller.RegisterService();
                //Post Installation
                progress.Report(8, 9, "Starting service...");
                var instance = InstanceFinder.FindMonitoringInstance(instanceInstaller.Name);
                if (!instance.TryStartService())
                {
                    instanceInstaller.ReportCard.Warnings.Add($"New instance did not startup - please check configuration for {instance.Name}");
                }
            }

            instanceInstaller.ReportCard.SetStatus();
            return(instanceInstaller.ReportCard);
        }
Esempio n. 6
0
        internal ReportCard Upgrade(string instanceName, IProgress <ProgressDetails> progress = null)
        {
            progress = progress ?? new Progress <ProgressDetails>();

            var instance = InstanceFinder.FindMonitoringInstance(instanceName);

            instance.ReportCard = new ReportCard();
            ZipInfo.ValidateZip();

            progress.Report(0, 5, "Stopping instance...");
            if (!instance.TryStopService())
            {
                return(new ReportCard
                {
                    Errors = { "Service failed to stop" },
                    Status = Status.Failed
                });
            }

            instance.UpgradeTransportSeam();

            progress.Report(1, 5, "Backing up app.config...");
            var backupFile = instance.BackupAppConfig();

            try
            {
                progress.Report(2, 5, "Upgrading Files...");
                instance.UpgradeFiles(ZipInfo.FilePath);
            }
            finally
            {
                progress.Report(3, 5, "Restoring app.config...");
                instance.RestoreAppConfig(backupFile);
            }

            progress.Report(4, 5, "Running Queue Creation...");
            instance.SetupInstance();
            instance.ReportCard.SetStatus();
            return(instance.ReportCard);
        }
Esempio n. 7
0
        protected override void ProcessRecord()
        {
            var logger = new PSLogger(Host);

            var zipFolder = Path.GetDirectoryName(MyInvocation.MyCommand.Module.Path);
            var installer = new UnattendMonitoringInstaller(logger, zipFolder);

            foreach (var name in Name)
            {
                var instance = InstanceFinder.FindMonitoringInstance(name);
                if (instance == null)
                {
                    WriteWarning($"No action taken. An instance called {name} was not found");
                    break;
                }

                if (!installer.Upgrade(instance))
                {
                    ThrowTerminatingError(new ErrorRecord(new Exception($"Upgrade of {instance.Name} failed"), "UpgradeFailure", ErrorCategory.InvalidResult, null));
                }
            }
        }
        public override async Task ExecuteAsync(InstanceDetailsViewModel model)
        {
            var licenseCheckResult = installer.CheckLicenseIsValid();

            if (!licenseCheckResult.Valid)
            {
                windowManager.ShowMessage("LICENSE ERROR", $"Upgrade could not continue due to an issue with the current license. {licenseCheckResult.Message}.  Contact [email protected]", hideCancel: true);
                return;
            }

            var instance = InstanceFinder.FindMonitoringInstance(model.Name);


            instance.Service.Refresh();

            var confirm = instance.Service.Status == ServiceControllerStatus.Stopped ||
                          windowManager.ShowYesNoDialog($"STOP INSTANCE AND UPGRADE TO {installer.ZipInfo.Version}", $"{model.Name} needs to be stopped in order to upgrade to version {installer.ZipInfo.Version}.", "Do you want to proceed?", "Yes I want to proceed", "No");

            if (confirm)
            {
                using (var progress = model.GetProgressObject($"UPGRADING {model.Name}"))
                {
                    var reportCard   = new ReportCard();
                    var restartAgain = model.IsRunning;

                    var stopped = await model.StopService(progress);

                    if (!stopped)
                    {
                        eventAggregator.PublishOnUIThread(new RefreshInstances());

                        reportCard.Errors.Add("Failed to stop the service");
                        reportCard.SetStatus();
                        windowManager.ShowActionReport(reportCard, "ISSUES UPGRADING INSTANCE", "Could not upgrade instance because of the following errors:");

                        return;
                    }

                    reportCard = await Task.Run(() => installer.Upgrade(model.Name, progress));

                    if (reportCard.HasErrors || reportCard.HasWarnings)
                    {
                        windowManager.ShowActionReport(reportCard, "ISSUES UPGRADING INSTANCE", "Could not upgrade instance because of the following errors:", "There were some warnings while upgrading the instance:");
                    }
                    else
                    {
                        if (restartAgain)
                        {
                            var serviceStarted = await model.StartService(progress);

                            if (!serviceStarted)
                            {
                                reportCard.Errors.Add("The Service failed to start. Please consult the  logs for this instance");
                                windowManager.ShowActionReport(reportCard, "UPGRADE FAILURE", "Instance reported this error after upgrade:");
                            }
                        }
                    }
                }
                eventAggregator.PublishOnUIThread(new RefreshInstances());
            }
        }
Esempio n. 9
0
        public bool Add(MonitoringNewInstance details, Func <PathInfo, bool> promptToProceed)
        {
            ZipInfo.ValidateZip();

            var checkLicenseResult = CheckLicenseIsValid();

            if (!checkLicenseResult.Valid)
            {
                logger.Error($"Install aborted - {checkLicenseResult.Message}");
                return(false);
            }

            var instanceInstaller = details;

            instanceInstaller.ReportCard = new ReportCard();

            //Validation
            instanceInstaller.Validate(promptToProceed);
            if (instanceInstaller.ReportCard.HasErrors)
            {
                foreach (var error in instanceInstaller.ReportCard.Errors)
                {
                    logger.Error(error);
                }

                return(false);
            }

            try
            {
                instanceInstaller.CopyFiles(ZipInfo.FilePath);
                instanceInstaller.WriteConfigurationFile();
                instanceInstaller.RegisterUrlAcl();
                instanceInstaller.SetupInstance();
                instanceInstaller.RegisterService();
                foreach (var warning in instanceInstaller.ReportCard.Warnings)
                {
                    logger.Warn(warning);
                }

                if (instanceInstaller.ReportCard.HasErrors)
                {
                    foreach (var error in instanceInstaller.ReportCard.Errors)
                    {
                        logger.Error(error);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                return(false);
            }

            //Post Installation
            var instance = InstanceFinder.FindMonitoringInstance(instanceInstaller.Name);

            if (!instance.TryStartService())
            {
                logger.Warn("The service failed to start");
            }

            return(true);
        }