protected override void ProcessRecord()
        {
            var logger = new PSLogger(Host);

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

            var instance = InstanceFinder.FindInstanceByName <ServiceControlInstance>(Name);

            if (instance == null)
            {
                WriteWarning($"No action taken. An instance called {Name} was not found");
                return;
            }

            var requiredUpgradeAction = instance.GetRequiredUpgradeAction(installer.ZipInfo.Version);

            switch (requiredUpgradeAction)
            {
            case RequiredUpgradeAction.Upgrade:
                PerformUpgrade(instance, installer);
                break;

            case RequiredUpgradeAction.SplitOutAudit:
                PerformSplit(instance, logger, zipFolder);
                break;

            default:
                ThrowTerminatingError(new ErrorRecord(new Exception($"Upgrade of {instance.Name} aborted. This instance cannot be upgraded."), "UpgradeFailure", ErrorCategory.InvalidResult, null));
                break;
            }
        }
        public override async Task ExecuteAsync(InstanceDetailsViewModel model)
        {
            if (LicenseChecks)
            {
                var licenseCheckResult = serviceControlInstaller.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.FindInstanceByName <ServiceControlAuditInstance>(model.Name);

            instance.Service.Refresh();

            var upgradeInfo    = UpgradeControl.GetUpgradeInfoForTargetVersion(serviceControlInstaller.ZipInfo.Version, instance.Version);
            var upgradeOptions = new ServiceControlUpgradeOptions {
                UpgradeInfo = upgradeInfo
            };

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

            await UpgradeAuditInstance(model, instance, upgradeOptions);

            eventAggregator.PublishOnUIThread(new RefreshInstances());
        }
        protected override void ProcessRecord()
        {
            var psPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(UnattendFile, out _, out _);

            var details = ServiceControlNewInstance.Load(psPath);

            details.ServiceAccount    = ServiceAccount;
            details.ServiceAccountPwd = Password;
            var zipfolder = Path.GetDirectoryName(MyInvocation.MyCommand.Module.Path);
            var logger    = new PSLogger(Host);
            var installer = new UnattendServiceControlInstaller(logger, zipfolder);

            try
            {
                logger.Info("Installing Service Control instance...");
                if (installer.Add(details, PromptToProceed))
                {
                    //TODO: test SC unattended installed
                    var instance = InstanceFinder.FindInstanceByName <ServiceControlInstance>(details.Name);
                    if (instance != null)
                    {
                        WriteObject(PsServiceControl.FromInstance(instance));
                    }
                    else
                    {
                        throw new Exception("Unknown error creating instance");
                    }
                }
            }
            catch (Exception ex)
            {
                ThrowTerminatingError(new ErrorRecord(ex, null, ErrorCategory.NotSpecified, null));
            }
        }
        protected override void ProcessRecord()
        {
            var instance = InstanceFinder.FindInstanceByName <ServiceControlInstance>(Name);

            if (instance == null)
            {
                WriteWarning($"No action taken. An instance called {Name} was not found");
                return;
            }

            WriteObject(instance.RemoteInstances.Select(PsServiceControlRemote.FromRemote), true);
        }
Beispiel #5
0
        protected override void ProcessRecord()
        {
            var details = new ServiceControlAuditNewInstance
            {
                InstallPath                = InstallPath,
                LogPath                    = LogPath,
                DBPath                     = DBPath,
                Name                       = Name,
                DisplayName                = string.IsNullOrWhiteSpace(DisplayName) ? Name : DisplayName,
                ServiceDescription         = Description,
                ServiceAccount             = ServiceAccount,
                ServiceAccountPwd          = ServiceAccountPassword,
                HostName                   = HostName,
                Port                       = Port,
                DatabaseMaintenancePort    = DatabaseMaintenancePort,
                AuditQueue                 = AuditQueue,
                AuditLogQueue              = string.IsNullOrWhiteSpace(AuditLogQueue) ? null : AuditLogQueue,
                ForwardAuditMessages       = ForwardAuditMessages.ToBool(),
                AuditRetentionPeriod       = AuditRetentionPeriod,
                ConnectionString           = ConnectionString,
                TransportPackage           = ServiceControlCoreTransports.All.First(t => t.Matches(Transport)),
                SkipQueueCreation          = SkipQueueCreation,
                ServiceControlQueueAddress = ServiceControlQueueAddress
            };

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

            var installer = new UnattendAuditInstaller(logger, zipfolder);

            try
            {
                logger.Info("Installing Service Control Audit instance...");
                if (installer.Add(details, PromptToProceed))
                {
                    var instance = InstanceFinder.FindInstanceByName <ServiceControlAuditInstance>(details.Name);
                    if (instance != null)
                    {
                        WriteObject(PsAuditInstance.FromInstance(instance));
                    }
                    else
                    {
                        throw new Exception("Unknown error creating instance");
                    }
                }
            }
            catch (Exception ex)
            {
                ThrowTerminatingError(new ErrorRecord(ex, null, ErrorCategory.NotSpecified, null));
            }
        }
        protected override void ProcessRecord()
        {
            var logger = new PSLogger(Host);

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

            var instance = InstanceFinder.FindInstanceByName <ServiceControlInstance>(Name);

            if (instance == null)
            {
                WriteWarning($"No action taken. An instance called {Name} was not found");
                return;
            }

            WriteObject(installer.AddRemoteInstance(instance, RemoteInstanceAddress, logger));
        }
Beispiel #7
0
        public override async Task ExecuteAsync(InstanceDetailsViewModel model)
        {
            if (LicenseChecks)
            {
                var licenseCheckResult = serviceControlInstaller.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.FindInstanceByName <ServiceControlInstance>(model.Name);

            instance.Service.Refresh();

            var upgradeInfo    = UpgradeControl.GetUpgradeInfoForTargetVersion(serviceControlInstaller.ZipInfo.Version, instance.Version);
            var upgradeOptions = new ServiceControlUpgradeOptions {
                UpgradeInfo = upgradeInfo
            };


            var upgradeAction      = instance.GetRequiredUpgradeAction(serviceControlInstaller.ZipInfo.Version);
            var shouldInstallAudit = upgradeAction == RequiredUpgradeAction.SplitOutAudit;

            AddNewAuditInstanceViewModel auditViewModel = null;

            if (instance.Version < upgradeInfo.CurrentMinimumVersion)
            {
                windowManager.ShowMessage("VERSION UPGRADE INCOMPATIBLE",
                                          "<Section xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xml:space=\"preserve\" TextAlignment=\"Left\" LineHeight=\"Auto\" IsHyphenationEnabled=\"False\" xml:lang=\"en-us\">\r\n" +
                                          $"<Paragraph>You must upgrade to version {upgradeInfo.RecommendedUpgradeVersion} before upgrading to version {serviceControlInstaller.ZipInfo.Version}:</Paragraph>\r\n" +
                                          "<List MarkerStyle=\"Decimal\" Margin=\"0,0,0,0\" Padding=\"0,0,0,0\">\r\n" +
                                          $"<ListItem Margin=\"48,0,0,0\"><Paragraph>Uninstall version {serviceControlInstaller.ZipInfo.Version}.</Paragraph></ListItem>\r\n" +
                                          $"<ListItem Margin=\"48,0,0,0\"><Paragraph>Download and install version {upgradeInfo.RecommendedUpgradeVersion} from https://github.com/Particular/ServiceControl/releases/tag/{upgradeInfo.RecommendedUpgradeVersion}</Paragraph></ListItem>" +
                                          $"<ListItem Margin=\"48,0,0,0\"><Paragraph>Upgrade this instance to version {upgradeInfo.RecommendedUpgradeVersion}.</Paragraph></ListItem>\r\n" +
                                          "<ListItem Margin=\"48,0,0,0\"><Paragraph>Download and install the latest version from https://particular.net/start-servicecontrol-download</Paragraph></ListItem>\r\n" +
                                          "<ListItem Margin=\"48,0,0,0\"><Paragraph>Upgrade this instance to the latest version of ServiceControl.</Paragraph></ListItem>\r\n" +
                                          "</List>\r\n" +
                                          "</Section>",
                                          hideCancel: true);

                return;
            }

            if (instance.IsErrorQueueDisabled())
            {
                windowManager.ShowMessage("UPGRADE INCOMPATIBLE",
                                          "You cannot upgrade the instance of ServiceControl with error ingestion disabled. Please contact support.",
                                          hideCancel: true);

                return;
            }

            if (!instance.AppConfig.AppSettingExists(ServiceControlSettings.ForwardErrorMessages.Name))
            {
                var result = windowManager.ShowYesNoCancelDialog("UPGRADE QUESTION - DISABLE ERROR FORWARDING", "Error messages can be forwarded to a secondary error queue known as the Error Forwarding Queue. This queue exists to allow external tools to receive error messages. If you do not have a tool processing messages from the Error Forwarding Queue this setting should be disabled.", "So what do you want to do ?", "Do NOT forward", "Yes I want to forward");
                if (!result.HasValue)
                {
                    //Dialog was cancelled
                    eventAggregator.PublishOnUIThread(new RefreshInstances());
                    return;
                }

                upgradeOptions.OverrideEnableErrorForwarding = !result.Value;
            }

            //Grab old setting if it exists
            if (!instance.AppConfig.AppSettingExists(ServiceControlSettings.AuditRetentionPeriod.Name))
            {
                if (instance.AppConfig.AppSettingExists(ServiceControlSettings.HoursToKeepMessagesBeforeExpiring.Name))
                {
                    var i = instance.AppConfig.Read(ServiceControlSettings.HoursToKeepMessagesBeforeExpiring.Name, -1);
                    if (i != -1)
                    {
                        upgradeOptions.AuditRetentionPeriod = TimeSpan.FromHours(i);
                    }
                }

                // No setting to migrate so display dialog
                if (!upgradeOptions.AuditRetentionPeriod.HasValue)
                {
                    var viewModel = new SliderDialogViewModel("INPUT REQUIRED - DATABASE RETENTION",
                                                              "Service Control periodically purges audit messages from the database.",
                                                              "AUDIT RETENTION PERIOD",
                                                              "Please specify the age at which these records should be removed",
                                                              TimeSpanUnits.Hours,
                                                              SettingConstants.AuditRetentionPeriodMinInHours,
                                                              SettingConstants.AuditRetentionPeriodMaxInHours,
                                                              1,
                                                              24,
                                                              SettingConstants.AuditRetentionPeriodDefaultInHoursForUI);

                    if (windowManager.ShowSliderDialog(viewModel))
                    {
                        upgradeOptions.AuditRetentionPeriod = viewModel.Period;
                    }
                    else
                    {
                        //Dialog was cancelled
                        eventAggregator.PublishOnUIThread(new RefreshInstances());
                        return;
                    }
                }
            }

            if (!instance.AppConfig.AppSettingExists(ServiceControlSettings.ErrorRetentionPeriod.Name))
            {
                var viewModel = new SliderDialogViewModel("INPUT REQUIRED - DATABASE RETENTION",
                                                          "Service Control periodically purges resolved and archived error messages from the database.",
                                                          "ERROR RETENTION PERIOD",
                                                          "Please specify the age at which these records should be removed",
                                                          TimeSpanUnits.Days,
                                                          SettingConstants.ErrorRetentionPeriodMinInDays,
                                                          SettingConstants.ErrorRetentionPeriodMaxInDays,
                                                          1,
                                                          1,
                                                          SettingConstants.ErrorRetentionPeriodDefaultInDaysForUI);

                if (windowManager.ShowSliderDialog(viewModel))
                {
                    upgradeOptions.ErrorRetentionPeriod = viewModel.Period;
                }
                else
                {
                    //Dialog was cancelled
                    eventAggregator.PublishOnUIThread(new RefreshInstances());
                    return;
                }
            }

            if (!instance.AppConfig.AppSettingExists(ServiceControlSettings.DatabaseMaintenancePort.Name))
            {
                var viewModel = new TextBoxDialogViewModel("INPUT REQUIRED - MAINTENANCE PORT",
                                                           "When Service Control is set to maintenance mode it requires a prereserved port on which it exposes the RavenDB database.",
                                                           "MAINTENANCE PORT",
                                                           "Please specify an open port that will be used as the maintenance port",
                                                           new PortValidator());

                if (windowManager.ShowTextBoxDialog(viewModel))
                {
                    upgradeOptions.MaintenancePort = int.Parse(viewModel.Value);
                }
                else
                {
                    //Dialog was cancelled
                    eventAggregator.PublishOnUIThread(new RefreshInstances());
                    return;
                }
            }

            if (shouldInstallAudit)
            {
                auditViewModel = auditUpgradeViewModelFactory(instance.Name);
                auditViewModel.ServiceControlAudit.SetupServiceAccount(instance);

                if (windowManager.ShowInnerDialog(auditViewModel) != true)
                {
                    //Dialog was cancelled
                    eventAggregator.PublishOnUIThread(new RefreshInstances());
                    return;
                }
            }

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

            if (shouldInstallAudit)
            {
                var auditInstalled = await InstallServiceControlAudit(model, auditViewModel, instance);

                if (!auditInstalled)
                {
                    //Dialog was cancelled
                    eventAggregator.PublishOnUIThread(new RefreshInstances());
                    return;
                }

                var auditInstance = InstanceFinder.FindInstanceByName <ServiceControlAuditInstance>(auditViewModel.ServiceControlAudit.InstanceName);
                upgradeOptions.RemoteUrl = auditInstance.BrowsableUrl;
            }

            await UpgradeServiceControlInstance(model, instance, upgradeOptions);

            eventAggregator.PublishOnUIThread(new RefreshInstances());
        }