public void NtServiceDescriptorConstructor_WhenEverythinkIsOk_AllPropertiesHavaCorrectValues() { // Arrange string serviceName = "serviceName"; string serviceExecutablePath = "serviceExecutablePath"; ServiceAccount serviceAccount = ServiceAccount.LocalSystem; ServiceStartMode serviceStartMode = ServiceStartMode.Automatic; string serviceDisplayName = "serviceDisplayName"; string serviceUserName = "******"; string servicePassword = "******"; // Act var ntServiceDescriptor = new NtServiceDescriptor(serviceName, serviceExecutablePath, serviceAccount, serviceStartMode, serviceDisplayName, serviceUserName, servicePassword); // Assert Assert.AreEqual(serviceName, ntServiceDescriptor.ServiceName); Assert.AreEqual(serviceExecutablePath, ntServiceDescriptor.ServiceExecutablePath); Assert.AreEqual(serviceAccount, ntServiceDescriptor.ServiceAccount); Assert.AreEqual(serviceStartMode, ntServiceDescriptor.ServiceStartMode); Assert.AreEqual(serviceDisplayName, ntServiceDescriptor.ServiceDisplayName); Assert.AreEqual(serviceUserName, ntServiceDescriptor.ServiceUserName); Assert.AreEqual(servicePassword, ntServiceDescriptor.ServicePassword); }
public void Test_InstallNtServiceDeploymentStep_Thows_When_MachineName_null() { var ntServiceDescriptor = new NtServiceDescriptor( "serviceName", "serviceExecutablePath", new ServiceAccount(), ServiceStartMode.Automatic); var ntServiceManager = new Mock<INtServiceManager>(MockBehavior.Strict); Assert.Throws<ArgumentException>( () => { new InstallNtServiceDeploymentStep(ntServiceManager.Object, null, ntServiceDescriptor); }); }
public void Test_InstallNtServiceDeploymentStep() { const string machineName = "machine"; var ntServiceDescriptor = new NtServiceDescriptor( "serviceName", "serviceExecutablePath", new ServiceAccount(), ServiceStartMode.Automatic); var ntServiceManager = new Mock<INtServiceManager>(MockBehavior.Strict); var installNTServiceStep = new InstallNtServiceDeploymentStep(ntServiceManager.Object, machineName, ntServiceDescriptor); ntServiceManager.Setup(k => k.InstallService(machineName, ntServiceDescriptor)); installNTServiceStep.PrepareAndExecute(); }
public void InstallService(string machineName, NtServiceDescriptor ntServiceDescriptor) { if (string.IsNullOrEmpty(machineName)) { throw new ArgumentException("Argument can't be null nor empty.", "machineName"); } if (ntServiceDescriptor == null) { throw new ArgumentNullException("ntServiceDescriptor"); } string args = string.Format( "\\\\{0} create \"{1}\" displayName= \"{2}\" binPath= \"{3}\" start= \"{4}\"", machineName, ntServiceDescriptor.ServiceName, ntServiceDescriptor.ServiceDisplayName, ntServiceDescriptor.ServiceExecutablePath, ConvertSreviceStartModeToString(ntServiceDescriptor.ServiceStartMode)); if (ntServiceDescriptor.IsUserALocalSystem() == false) { if (!string.IsNullOrEmpty(ntServiceDescriptor.ServiceUserName)) { args += string.Format(" obj= \"{0}\"", ntServiceDescriptor.ServiceUserName); } if (!string.IsNullOrEmpty(ntServiceDescriptor.ServicePassword)) { args += string.Format(" password= \"{0}\"", ntServiceDescriptor.ServicePassword); } } string stdOut; string stdErr; int processExitCode = RunScExe(args, out stdOut, out stdErr); if (processExitCode != 0) { throw CreateScExeInternalException(processExitCode, stdOut, stdErr); } }
public void InstallService(string machineName, NtServiceDescriptor ntServiceDescriptor) { if (string.IsNullOrEmpty(machineName)) { throw new ArgumentException("Argument can't be null nor empty.", "machineName"); } if (ntServiceDescriptor == null) { throw new ArgumentNullException("ntServiceDescriptor"); } string args = string.Format( "\\\\{0} create \"{1}\" displayName= \"{2}\" binPath= \"{3}\" start= \"{4}\"", machineName, ntServiceDescriptor.ServiceName, ntServiceDescriptor.ServiceDisplayName, ntServiceDescriptor.ServiceExecutablePath, ConvertSreviceStartModeToString(ntServiceDescriptor.ServiceStartMode)); if (ntServiceDescriptor.IsUserALocalSystem() == false) { if (!string.IsNullOrEmpty(ntServiceDescriptor.ServiceUserName)) { args += string.Format(" obj= \"{0}\"", ntServiceDescriptor.ServiceUserName); } if (!string.IsNullOrEmpty(ntServiceDescriptor.ServicePassword)) { args += string.Format(" password= \"{0}\"", ntServiceDescriptor.ServicePassword); } } string stdOut; string stdErr; int processExitCode = RunScExe(args, out stdOut, out stdErr); if (processExitCode != 0) { throw CreateScExeInternalException(processExitCode, stdOut, stdErr); } }
public InstallNtServiceDeploymentStep(INtServiceManager ntServiceManager, string machineName, NtServiceDescriptor ntServiceDescriptor) { if (ntServiceManager == null) { throw new ArgumentNullException("ntServiceManager"); } if (string.IsNullOrEmpty(machineName)) { throw new ArgumentException("Argument can't be null nor empty.", "machineName"); } if (ntServiceDescriptor == null) { throw new ArgumentNullException("ntServiceDescriptor"); } _ntServiceManager = ntServiceManager; _machineName = machineName; _ntServiceDescriptor = ntServiceDescriptor; }
private void DoPrepareCommonDeploymentSteps(string ntServiceName, string appServerMachineName, string ntServicesBaseDirPath, Func<string, string> getAppServerNetworkPathFunc, Lazy<string> artifactsBinariesDirPathProvider, Func<CollectedCredentials> collectCredentialsFunc, bool startServiceAfterDeployment) { // check if the service is present on the target machine bool serviceExists = _ntServiceManager .DoesServiceExist(appServerMachineName, ntServiceName); if (serviceExists) { // create a step for stopping the service AddSubTask( new StopNtServiceDeploymentStep( _ntServiceManager, appServerMachineName, _projectInfo.NtServiceName)); } // create a step for copying the binaries to the target machine string targetDirPath = Path.Combine(ntServicesBaseDirPath, _projectInfo.NtServiceDirName); /* // TODO IMM HI: xxx we don't need this for now - should we parameterize this somehow? // create a backup step if needed string targetDirNetworkPath = getAppServerNetworkPathFunc(targetDirPath); if (Directory.Exists(targetDirNetworkPath)) { AddSubTask( new BackupFilesDeploymentStep( targetDirNetworkPath)); } */ string[] excludedDirs = string.IsNullOrEmpty(_projectInfo.ExtensionsDirName) ? new string[0] : new string[] { _projectInfo.ExtensionsDirName }; AddSubTask( new CleanDirectoryDeploymentStep( _directoryAdapter, _fileAdapter, new Lazy<string>(() => getAppServerNetworkPathFunc(targetDirPath)), excludedDirs: excludedDirs)); AddSubTask( new CopyFilesDeploymentStep( _directoryAdapter, artifactsBinariesDirPathProvider, new Lazy<string>(() => getAppServerNetworkPathFunc(targetDirPath)))); if (!serviceExists) { // collect credentials CollectedCredentials collectedCredentials = collectCredentialsFunc(); // create a step for installing the service, string serviceExecutablePath = Path.Combine(targetDirPath, _projectInfo.NtServiceExeName); var ntServiceDescriptor = new NtServiceDescriptor( _projectInfo.NtServiceName, serviceExecutablePath, ServiceAccount.NetworkService, ServiceStartMode.Automatic, _projectInfo.NtServiceDisplayName, collectedCredentials.UserName, collectedCredentials.Password); AddSubTask( new InstallNtServiceDeploymentStep( _ntServiceManager, appServerMachineName, ntServiceDescriptor)); } if (startServiceAfterDeployment) { // create a step for starting the service AddSubTask( new StartNtServiceDeploymentStep( _ntServiceManager, appServerMachineName, _projectInfo.NtServiceName)); } }
private void DoPrepareCommonDeploymentSteps(string ntServiceName, string appServerMachineName, string ntServicesBaseDirPath, Func<string, string> getAppServerNetworkPathFunc, string artifactsBinariesDirPath, Func<CollectedCredentials> collectCredentialsFunc, bool startServiceAfterDeployment) { // check if the service is present on the target machine bool serviceExists = _ntServiceManager .DoesServiceExist(appServerMachineName, ntServiceName); if (serviceExists) { // create a step for stopping the service AddSubTask( new StopNtServiceDeploymentStep( _ntServiceManager, appServerMachineName, _projectInfo.NtServiceName)); } // create a step for copying the binaries to the target machine string targetDirPath = Path.Combine(ntServicesBaseDirPath, _projectInfo.NtServiceDirName); // create a backup step if needed string targetDirNetworkPath = getAppServerNetworkPathFunc(targetDirPath); if (Directory.Exists(targetDirNetworkPath)) { AddSubTask(new BackupFilesDeploymentStep(targetDirNetworkPath)); } AddSubTask( new CopyFilesDeploymentStep( artifactsBinariesDirPath, getAppServerNetworkPathFunc(targetDirPath))); if (!serviceExists) { // collect credentials CollectedCredentials collectedCredentials = collectCredentialsFunc(); // create a step for installing the service, string serviceExecutablePath = Path.Combine(targetDirPath, _projectInfo.NtServiceExeName); var ntServiceDescriptor = new NtServiceDescriptor( _projectInfo.NtServiceName, serviceExecutablePath, ServiceAccount.NetworkService, ServiceStartMode.Automatic, _projectInfo.NtServiceDisplayName, collectedCredentials.UserName, collectedCredentials.Password); AddSubTask( new InstallNtServiceDeploymentStep( _ntServiceManager, appServerMachineName, ntServiceDescriptor)); } if (startServiceAfterDeployment) { // create a step for starting the service AddSubTask( new StartNtServiceDeploymentStep( _ntServiceManager, appServerMachineName, _projectInfo.NtServiceName)); } }