示例#1
0
            public void ApplyTo(ServiceControlAuditNewInstance instance)
            {
                instance.InstallPath             = InstallPath;
                instance.DBPath                  = DBPath;
                instance.LogPath                 = LogPath;
                instance.Port                    = Port;
                instance.DatabaseMaintenancePort = DatabaseMaintenancePort;

                if (!string.IsNullOrWhiteSpace(ServiceAccountPassword))
                {
                    instance.ServiceAccountPwd = ServiceAccountPassword;
                }
            }
示例#2
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));
            }
        }
示例#3
0
        Result ValidateServiceAccount(Options options, ServiceControlAuditNewInstance auditDetails)
        {
            var account = UserAccount.ParseAccountName(auditDetails.ServiceAccount);

            if (!account.CheckPassword(auditDetails.ServiceAccountPwd))
            {
                return(Result.Failed(
                           string.IsNullOrWhiteSpace(options.ServiceAccountPassword)
                        ? $"A password is required for the service account: {auditDetails.ServiceAccount}"
                        : $"Incorrect password for {auditDetails.ServiceAccount}"));
            }

            return(Result.Success);
        }
示例#4
0
        async Task <bool> InstallInstance(ServiceControlAuditNewInstance instanceData, IProgressObject progress)
        {
            var reportCard = await Task.Run(() => serviceControlAuditInstaller.Add(instanceData, progress, PromptToProceed));

            if (reportCard.HasErrors || reportCard.HasWarnings)
            {
                windowManager.ShowActionReport(reportCard, "ISSUES ADDING INSTANCE", "Could not add new instance because of the following errors:", "There were some warnings while adding the instance:");
                return(true);
            }

            if (reportCard.CancelRequested)
            {
                return(true);
            }

            return(false);
        }
示例#5
0
        async Task <bool> InstallServiceControlAudit(InstanceDetailsViewModel detailsViewModel, AddNewAuditInstanceViewModel viewModel, ServiceControlInstance instance)
        {
            var auditNewInstance = new ServiceControlAuditNewInstance
            {
                //Read from user configured values
                DisplayName             = viewModel.ServiceControlAudit.InstanceName,
                Name                    = viewModel.ServiceControlAudit.InstanceName.Replace(' ', '.'),
                ServiceDescription      = viewModel.ServiceControlAudit.Description,
                DBPath                  = viewModel.ServiceControlAudit.DatabasePath,
                LogPath                 = viewModel.ServiceControlAudit.LogPath,
                InstallPath             = viewModel.ServiceControlAudit.DestinationPath,
                HostName                = viewModel.ServiceControlAudit.HostName,
                Port                    = Convert.ToInt32(viewModel.ServiceControlAudit.PortNumber),
                DatabaseMaintenancePort = Convert.ToInt32(viewModel.ServiceControlAudit.DatabaseMaintenancePortNumber),
                ServiceAccount          = viewModel.ServiceControlAudit.ServiceAccount,
                ServiceAccountPwd       = viewModel.ServiceControlAudit.Password,

                //Copy from existing ServiceControl instance
                AuditLogQueue        = instance.AuditLogQueue,
                AuditQueue           = instance.AuditQueue,
                ForwardAuditMessages = instance.ForwardAuditMessages,
                // ReSharper disable once PossibleInvalidOperationException
                AuditRetentionPeriod       = instance.AuditRetentionPeriod.Value,
                TransportPackage           = instance.TransportPackage,
                ConnectionString           = instance.ConnectionString,
                ServiceControlQueueAddress = instance.Name
            };

            using (var progress = detailsViewModel.GetProgressObject("ADDING AUDIT INSTANCE"))
            {
                var installationCancelled = await InstallInstance(auditNewInstance, progress);

                if (installationCancelled)
                {
                    return(false);
                }
            }

            return(true);
        }
        public void CheckChainingOfAuditQueues_ShouldSucceed()
        {
            var existingAudit = new Mock <IServiceControlAuditInstance>();

            existingAudit.SetupGet(p => p.TransportPackage).Returns(ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.MSMQ));
            existingAudit.SetupGet(p => p.AuditQueue).Returns(@"audit");

            var newInstance = new ServiceControlAuditNewInstance
            {
                TransportPackage = ServiceControlCoreTransports.All.First(t => t.Name == TransportNames.MSMQ),
                AuditQueue       = "audit"
            };

            var validator = new QueueNameValidator(newInstance)
            {
                AuditInstances = new List <IServiceControlAuditInstance> {
                    existingAudit.Object
                }
            };

            Assert.DoesNotThrow(() => validator.CheckQueueNamesAreNotTakenByAnotherAuditInstance());
        }
        public bool Add(ServiceControlAuditNewInstance 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();
            instanceInstaller.Version    = ZipInfo.Version;

            //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.FindServiceControlInstance(instanceInstaller.Name);

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

            return(true);
        }
        async Task Add(object arg)
        {
            viewModel.SubmitAttempted = true;
            if (!viewModel.ValidationTemplate.Validate())
            {
                viewModel.NotifyOfPropertyChange(string.Empty);
                viewModel.SubmitAttempted = false;
                windowManager.ScrollFirstErrorIntoView(viewModel);

                return;
            }

            viewModel.InProgress = true;

            var serviceControlNewInstance = new ServiceControlNewInstance
            {
                DisplayName             = viewModel.ServiceControl.InstanceName,
                Name                    = viewModel.ServiceControl.InstanceName.Replace(' ', '.'),
                ServiceDescription      = viewModel.ServiceControl.Description,
                DBPath                  = viewModel.ServiceControl.DatabasePath,
                LogPath                 = viewModel.ServiceControl.LogPath,
                InstallPath             = viewModel.ServiceControl.DestinationPath,
                HostName                = viewModel.ServiceControl.HostName,
                Port                    = Convert.ToInt32(viewModel.ServiceControl.PortNumber),
                DatabaseMaintenancePort = Convert.ToInt32(viewModel.ServiceControl.DatabaseMaintenancePortNumber),
                VirtualDirectory        = null, // TODO
                ErrorQueue              = viewModel.ServiceControl.ErrorQueueName,
                ErrorLogQueue           = viewModel.ServiceControl.ErrorForwarding.Value ? viewModel.ServiceControl.ErrorForwardingQueueName : null,
                TransportPackage        = viewModel.SelectedTransport,
                ConnectionString        = viewModel.ConnectionString,
                ErrorRetentionPeriod    = viewModel.ServiceControl.ErrorRetentionPeriod,
                ServiceAccount          = viewModel.ServiceControl.ServiceAccount,
                ServiceAccountPwd       = viewModel.ServiceControl.Password
            };

            var auditNewInstance = new ServiceControlAuditNewInstance
            {
                DisplayName                = viewModel.ServiceControlAudit.InstanceName,
                Name                       = viewModel.ServiceControlAudit.InstanceName.Replace(' ', '.'),
                ServiceDescription         = viewModel.ServiceControlAudit.Description,
                DBPath                     = viewModel.ServiceControlAudit.DatabasePath,
                LogPath                    = viewModel.ServiceControlAudit.LogPath,
                InstallPath                = viewModel.ServiceControlAudit.DestinationPath,
                HostName                   = viewModel.ServiceControlAudit.HostName,
                Port                       = Convert.ToInt32(viewModel.ServiceControlAudit.PortNumber),
                DatabaseMaintenancePort    = Convert.ToInt32(viewModel.ServiceControlAudit.DatabaseMaintenancePortNumber),
                AuditLogQueue              = viewModel.ServiceControlAudit.AuditForwarding.Value ? viewModel.ServiceControlAudit.AuditForwardingQueueName : null,
                AuditQueue                 = viewModel.ServiceControlAudit.AuditQueueName,
                ForwardAuditMessages       = viewModel.ServiceControlAudit.AuditForwarding.Value,
                TransportPackage           = viewModel.SelectedTransport,
                ConnectionString           = viewModel.ConnectionString,
                AuditRetentionPeriod       = viewModel.ServiceControlAudit.AuditRetentionPeriod,
                ServiceAccount             = viewModel.ServiceControlAudit.ServiceAccount,
                ServiceAccountPwd          = viewModel.ServiceControlAudit.Password,
                ServiceControlQueueAddress = serviceControlNewInstance.Name
            };

            serviceControlNewInstance.AddRemoteInstance(auditNewInstance.Url);

            using (var progress = viewModel.GetProgressObject("ADDING INSTANCE"))
            {
                var installationCancelled = await InstallInstance(serviceControlNewInstance, progress);

                if (installationCancelled)
                {
                    return;
                }
            }

            using (var progress = viewModel.GetProgressObject("ADDING AUDIT INSTANCE"))
            {
                var installationCancelled = await InstallInstance(auditNewInstance, progress);

                if (installationCancelled)
                {
                    return;
                }
            }

            viewModel.TryClose(true);

            eventAggregator.PublishOnUIThread(new RefreshInstances());
        }