protected override void ProcessRecord() { ProviderInfo provider; PSDriveInfo drive; var psPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(UnattendFile, out provider, out drive); var details = ServiceControlInstanceMetadata.Load(psPath); details.ServiceAccount = ServiceAccount; details.ServiceAccountPwd = Password; var zipfolder = Path.GetDirectoryName(MyInvocation.MyCommand.Module.Path); var logger = new PSLogger(Host); var installer = new UnattendInstaller(logger, zipfolder); try { logger.Info("Installing Service Control instance..."); if (installer.Add(details, PromptToProceed)) { var instance = ServiceControlInstance.FindByName(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)); } }
public void DuplicateQueueNamesAreAllowedOnDifferentTransports_ShouldNotThrow() { var newInstance = new ServiceControlInstanceMetadata { TransportPackage = "RabbitMQ", AuditLogQueue = "auditlog", ErrorLogQueue = "errorlog", AuditQueue = "audit", ErrorQueue = "error" }; var p = new QueueNameValidator(newInstance) { instances = instances }; var ex = Assert.Throws <EngineValidationException>(() => p.CheckQueueNamesAreNotTakenByAnotherInstance()); Assert.That(ex.Message, Is.StringContaining("Some queue names specified are already assigned to another ServiceControl instance - Correct the values for")); // null queues will default to default names p = new QueueNameValidator(new ServiceControlInstanceMetadata()) { instances = instances }; ex = Assert.Throws <EngineValidationException>(() => p.CheckQueueNamesAreNotTakenByAnotherInstance()); Assert.That(ex.Message, Is.StringContaining("Some queue names specified are already assigned to another ServiceControl instance - Correct the values for")); }
public void EnsureDuplicateQueueNamesAreAllowedOnSameTransportWithDifferentConnectionString() { var newInstance = new ServiceControlInstanceMetadata { TransportPackage = "RabbitMQ", AuditQueue = "RMQaudit", AuditLogQueue = "RMQauditlog", ErrorQueue = "RMQerror", ErrorLogQueue = "RMQerrorlog", ConnectionString = "afakeconnectionstring" }; var p = new QueueNameValidator(newInstance) { instances = instances }; var ex = Assert.Throws <EngineValidationException>(() => p.CheckQueueNamesAreNotTakenByAnotherInstance()); Assert.That(ex.Message, Is.StringContaining("Some queue names specified are already assigned to another ServiceControl instance - Correct the values for")); newInstance.ConnectionString = "differentconnectionstring"; p = new QueueNameValidator(newInstance) { instances = instances }; Assert.DoesNotThrow(() => p.CheckQueueNamesAreNotTakenByAnotherInstance()); }
protected override void ProcessRecord() { var details = new ServiceControlInstanceMetadata { InstallPath = InstallPath, LogPath = LogPath, DBPath = DBPath, Name = Name, DisplayName = string.IsNullOrWhiteSpace(DisplayName) ? Name : DisplayName, ServiceDescription = Description, HostName = HostName, Port = Port, VirtualDirectory = VirtualDirectory, AuditLogQueue = AuditLogQueue, AuditQueue = AuditQueue, ErrorLogQueue = ErrorLogQueue, ErrorQueue = ErrorQueue, ForwardAuditMessages = ForwardAuditMessages, ForwardErrorMessages = ForwardErrorMessages, ConnectionString = ConnectionString, TransportPackage = Transport, AuditRetentionPeriod = AuditRetentionPeriod, ErrorRetentionPeriod = ErrorRetentionPeriod }; details.Save(OutputFile); }
public void CreateInstanceMSMQ() { var installer = new UnattendInstaller(new TestLogger(), deploymentCache); var instanceName = "Test.ServiceControl.Msmq"; var root = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"Test", instanceName); var details = new ServiceControlInstanceMetadata { DisplayName = instanceName.Replace(".", " "), Name = instanceName, ServiceDescription = "Test SC Instance", DBPath = Path.Combine(root, "Database"), LogPath = Path.Combine(root, "Logs"), InstallPath = Path.Combine(root, "Binaries"), HostName = "localhost", Port = 33335, VirtualDirectory = null, AuditLogQueue = "audit.log", AuditQueue = "audit", ForwardAuditMessages = false, ErrorQueue = "error", ErrorLogQueue = "error.log", TransportPackage = "MSMQ", ReportCard = new ReportCard() }; details.Validate(s => false); if (details.ReportCard.HasErrors) { throw new Exception($"Validation errors: {string.Join("\r\n", details.ReportCard.Errors)}"); } Assert.DoesNotThrow(() => installer.Add(details, s => false)); }
private 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 instanceMetadata = new ServiceControlInstanceMetadata { DisplayName = viewModel.InstanceName, Name = viewModel.InstanceName.Replace(' ', '.'), ServiceDescription = viewModel.Description, DBPath = viewModel.DatabasePath, LogPath = viewModel.LogPath, InstallPath = viewModel.DestinationPath, HostName = viewModel.HostName, Port = Convert.ToInt32(viewModel.PortNumber), VirtualDirectory = null, // TODO AuditLogQueue = viewModel.AuditForwarding.Value ? viewModel.AuditForwardingQueueName : null, AuditQueue = viewModel.AuditQueueName, ForwardAuditMessages = viewModel.AuditForwarding.Value, ErrorQueue = viewModel.ErrorQueueName, ErrorLogQueue = viewModel.ErrorForwarding.Value ? viewModel.ErrorForwardingQueueName : null, TransportPackage = viewModel.SelectedTransport.Name, ConnectionString = viewModel.ConnectionString, ErrorRetentionPeriod = viewModel.ErrorRetentionPeriod, AuditRetentionPeriod = viewModel.AuditRetentionPeriod, ServiceAccount = viewModel.ServiceAccount, ServiceAccountPwd = viewModel.Password }; using (var progress = viewModel.GetProgressObject("ADDING INSTANCE")) { var reportCard = await Task.Run(() => installer.Add(instanceMetadata, 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; } if (reportCard.CancelRequested) { return; } } viewModel.TryClose(true); eventAggregator.PublishOnUIThread(new RefreshInstances()); }
public static bool Validate(ServiceControlInstanceMetadata instance, Func <PathInfo, bool> promptToProceed) { var validator = new PathsValidator(instance) { Instances = ServiceControlInstance.Instances().AsEnumerable <IContainInstancePaths>().ToList() }; return(validator.RunValidation(true, promptToProceed)); }
public static void Validate(ServiceControlInstanceMetadata instance) { var validator = new QueueNameValidator(instance) { instances = ServiceControlInstance.Instances().Where(p => p.Name != instance.Name & p.TransportPackage.Equals(instance.TransportPackage, StringComparison.OrdinalIgnoreCase)).AsEnumerable <IContainTransportInfo>().ToList() }; validator.RunValidation(); }
protected override void ProcessRecord() { var details = new ServiceControlInstanceMetadata { InstallPath = InstallPath, LogPath = LogPath, DBPath = DBPath, Name = Name, DisplayName = string.IsNullOrWhiteSpace(DisplayName) ? Name : DisplayName, ServiceDescription = Description, ServiceAccount = ServiceAccount, ServiceAccountPwd = ServiceAccountPassword, HostName = HostName, Port = Port, VirtualDirectory = VirtualDirectory, AuditQueue = AuditQueue, ErrorQueue = ErrorQueue, AuditLogQueue = string.IsNullOrWhiteSpace(AuditLogQueue) ? null : AuditLogQueue, ErrorLogQueue = string.IsNullOrWhiteSpace(ErrorLogQueue) ? null : ErrorLogQueue, ForwardAuditMessages = ForwardAuditMessages.ToBool(), ForwardErrorMessages = ForwardErrorMessages.ToBool(), AuditRetentionPeriod = AuditRetentionPeriod, ErrorRetentionPeriod = ErrorRetentionPeriod, ConnectionString = ConnectionString, TransportPackage = Transport }; var zipfolder = Path.GetDirectoryName(MyInvocation.MyCommand.Module.Path); var logger = new PSLogger(Host); var installer = new UnattendInstaller(logger, zipfolder); try { logger.Info("Installing Service Control instance..."); if (installer.Add(details, PromptToProceed)) { var instance = ServiceControlInstance.FindByName(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)); } }
public void CheckPathsNotUsedInOtherInstances_ShouldSuceed() { var newInstance = new ServiceControlInstanceMetadata { InstallPath = @"c:\test\2\bin", LogPath = @"c:\test\2\logs", DBPath = @"c:\test\2\db" }; var p = new PathsValidator(newInstance) { Instances = instances }; Assert.DoesNotThrow(() => p.CheckPathsNotUsedInOtherInstances()); }
public void CheckPathsAreUnique_ShouldSucceed() { var newInstance = new ServiceControlInstanceMetadata { InstallPath = @"c:\test\1\bin", LogPath = @"c:\test\1\log", DBPath = @"c:\test\1\db" }; var p = new PathsValidator(newInstance) { Instances = instances }; Assert.DoesNotThrow(() => p.CheckPathsAreUnique()); }
public void CheckNoNestedSiblingPaths_ShouldSucceed() { var newInstance = new ServiceControlInstanceMetadata { InstallPath = @"c:\test\1\servicecontrol", LogPath = @"c:\test\1\servicecontrollog", DBPath = @"c:\test\1\servicecontroldb" }; var p = new PathsValidator(newInstance) { Instances = instances }; Assert.DoesNotThrow(() => p.CheckNoNestedPaths()); }
public void CheckPathsNotUsedInOtherInstances_ShouldThrow() { var newInstance = new ServiceControlInstanceMetadata { InstallPath = @"c:\test\1\bin", //This one is bad LogPath = @"c:\test\2\logs", DBPath = @"c:\test\2\db" }; var p = new PathsValidator(newInstance) { Instances = instances }; var ex = Assert.Throws <EngineValidationException>(() => p.CheckPathsNotUsedInOtherInstances()); Assert.That(ex.Message, Is.EqualTo("The install path specified is already assigned to another instance")); }
public void CheckPathsAreUnique_ShouldThrow() { var newInstance = new ServiceControlInstanceMetadata { InstallPath = @"c:\test\1\bin", LogPath = @"c:\test\1\bin", DBPath = @"c:\test\1\bin" }; var p = new PathsValidator(newInstance) { Instances = instances }; var ex = Assert.Throws <EngineValidationException>(() => p.CheckPathsAreUnique()); Assert.That(ex.Message, Is.EqualTo("The installation path, log path and database path must be unique")); }
public void CheckNoNestedPaths_ShouldThrow() { var newInstance = new ServiceControlInstanceMetadata { InstallPath = @"c:\test\1", LogPath = @"c:\test\1\log", DBPath = @"c:\test\1\db" }; var p = new PathsValidator(newInstance) { Instances = instances }; var ex = Assert.Throws <EngineValidationException>(() => p.CheckNoNestedPaths()); Assert.That(ex.Message, Is.StringContaining("Nested paths are not supported")); }
public void CheckQueueNamesAreUnique_ShouldSucceed() { var newInstance = new ServiceControlInstanceMetadata { TransportPackage = "MSMQ", AuditLogQueue = "auditlog", ErrorLogQueue = "errorlog", AuditQueue = "audit", ErrorQueue = "error" }; var p = new QueueNameValidator(newInstance) { instances = new List <IContainTransportInfo>() }; Assert.DoesNotThrow(() => p.CheckQueueNamesAreUniqueWithinInstance()); }
public void CheckQueueNamesAreNotTakenByAnotherInstance_ShouldSucceed() { var newInstance = new ServiceControlInstanceMetadata { TransportPackage = "MSMQ", AuditLogQueue = "auditlog2", ErrorLogQueue = "errorlog2", AuditQueue = "audit2", ErrorQueue = "error2" }; var p = new QueueNameValidator(newInstance) { instances = instances }; Assert.DoesNotThrow(() => p.CheckQueueNamesAreNotTakenByAnotherInstance()); }
public void CheckQueueNamesAreUnique_ShouldThrow() { var newInstance = new ServiceControlInstanceMetadata { TransportPackage = "MSMQ", AuditLogQueue = "audit", ErrorLogQueue = "error", AuditQueue = "audit", ErrorQueue = "error" }; var p = new QueueNameValidator(newInstance) { instances = new List <IContainTransportInfo>() }; var ex = Assert.Throws <EngineValidationException>(() => p.CheckQueueNamesAreUniqueWithinInstance()); Assert.That(ex.Message, Is.StringContaining("Each of the queue names specified for a instance should be unique")); }
internal ReportCard Add(ServiceControlInstanceMetadata 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 = ServiceControlInstance.FindByName(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); }
static void UnattendedInstall(Session session, MSILogger logger, UnattendInstaller unattendedInstaller) { logger.Info("Checking for unattended file"); var unattendedFilePropertyValue = session["UNATTENDEDFILE"]; if (string.IsNullOrWhiteSpace(unattendedFilePropertyValue)) { return; } var serviceAccount = session["SERVICEACCOUNT"]; var password = session["PASSWORD"]; logger.Info($"UNATTENDEDFILE: {unattendedFilePropertyValue}"); var currentDirectory = session["CURRENTDIRECTORY"]; var unattendedFilePath = Environment.ExpandEnvironmentVariables(Path.IsPathRooted(unattendedFilePropertyValue) ? unattendedFilePropertyValue : Path.Combine(currentDirectory, unattendedFilePropertyValue)); logger.Info($"Expanded unattended filepath to : {unattendedFilePropertyValue}"); if (File.Exists(unattendedFilePath)) { logger.Info($"File Exists : {unattendedFilePropertyValue}"); var instanceToInstallDetails = ServiceControlInstanceMetadata.Load(unattendedFilePath); if (!string.IsNullOrWhiteSpace(serviceAccount)) { instanceToInstallDetails.ServiceAccount = serviceAccount; instanceToInstallDetails.ServiceAccountPwd = password; } unattendedInstaller.Add(instanceToInstallDetails, s => false); } else { logger.Error($"The specified unattended install file was not found : '{unattendedFilePath}'"); } }
public bool Add(ServiceControlInstanceMetadata 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 = ServiceControlInstance.FindByName(instanceInstaller.Name); if (!instance.TryStartService()) { logger.Warn("The service failed to start"); } return(true); }