private void CopyStructureRecursive( IScriptExecutionEnvironment environment, string sourcePathRecursive, string destinationPathRecursive, Regex inclusionRegex, Regex exclusionRegex) { if (exclusionRegex != null && exclusionRegex.IsMatch(sourcePathRecursive)) { return; } DirectoryInfo info = new DirectoryInfo(sourcePathRecursive); foreach (FileSystemInfo fileSystemInfo in info.GetFileSystemInfos()) { if (fileSystemInfo is FileInfo) { if (inclusionRegex != null && false == inclusionRegex.IsMatch(fileSystemInfo.FullName)) { continue; } if (exclusionRegex != null && exclusionRegex.IsMatch(fileSystemInfo.FullName)) { continue; } FileInfo fileInfo = fileSystemInfo as FileInfo; string filePath = Path.Combine(destinationPathRecursive, fileInfo.Name); if (false == Directory.Exists(destinationPathRecursive)) { Directory.CreateDirectory(destinationPathRecursive); } fileInfo.CopyTo(filePath, overwriteExisting); environment.LogMessage( "Copied file '{0}' to '{1}'", fileSystemInfo.FullName, filePath); copiedFilesList.Add(filePath); } else { DirectoryInfo dirInfo = fileSystemInfo as DirectoryInfo; string subdirectoryPath = Path.Combine( destinationPathRecursive, dirInfo.Name); CopyStructureRecursive( environment, dirInfo.FullName, subdirectoryPath, inclusionRegex, exclusionRegex); } } }
public static void Execute( IScriptExecutionEnvironment environment, string virtualDirectoryName, string dotNetVersion) { RegisterAspNetTask task = new RegisterAspNetTask(virtualDirectoryName, dotNetVersion); task.Execute(environment); }
/// <summary> /// Method defining the actual work for a task. /// </summary> /// <param name="environment">The script execution environment.</param> protected override void DoExecute(IScriptExecutionEnvironment environment) { string input = environment.ReceiveInput(prompt); if (configurationSettingName != null) { environment.SetConfigSetting(configurationSettingName, input); } }
/// <summary> /// Executes the <see cref="AskUserTask"/> using the specified /// user prompt string and configuration setting name. /// </summary> /// <param name="environment">The script execution environment.</param> /// <param name="prompt">The user prompt string.</param> /// <param name="configurationSettingName">Name of the configuration setting where the user input should be stored.</param> public static void Execute( IScriptExecutionEnvironment environment, string prompt, string configurationSettingName) { AskUserTask task = new AskUserTask(prompt, configurationSettingName); task.Execute(environment); }
public static void Execute( IScriptExecutionEnvironment environment, string directoryPath, bool failIfNotExists) { DeleteDirectoryTask task = new DeleteDirectoryTask(directoryPath, failIfNotExists); task.Execute(environment); }
public static void Execute( IScriptExecutionEnvironment environment, string serviceName, bool failIfNotExist) { RemoveWindowsServiceTask task = new RemoveWindowsServiceTask(serviceName, failIfNotExist); task.DoExecute(environment); }
protected override void DoExecute(IScriptExecutionEnvironment environment) { Process[] processByName = Process.GetProcessesByName(processName); foreach (Process process in processByName) { environment.LogMessage("Killing process '{0}'", process.ProcessName); process.Kill(); } }
public static void Execute( IScriptExecutionEnvironment environment, string serviceName, ControlWindowsServiceMode mode, TimeSpan timeout, bool failIfNotExist) { Execute(environment, ".", serviceName, mode, timeout, failIfNotExist); }
/// <summary> /// Transforms a specified input file to a specified output file using the specified XSLT file. /// </summary> /// <param name="environment">The script execution environment.</param> /// <param name="inputFile">The input file path.</param> /// <param name="outputFile">The output file path.</param> /// <param name="xsltFile">The XSLT file path.</param> public static void Execute( IScriptExecutionEnvironment environment, string inputFile, string outputFile, string xsltFile) { XsltTransformTask task = new XsltTransformTask(inputFile, outputFile, xsltFile); task.Execute(environment); }
public static void Execute( IScriptExecutionEnvironment environment, string serviceName, string userName, string password) { SetWindowsServiceAccountTask task = new SetWindowsServiceAccountTask(serviceName, userName, password); task.Execute(environment); }
public static void Execute( IScriptExecutionEnvironment environment, string directoryPath, string filePattern, bool recursive) { DeleteFilesTask task = new DeleteFilesTask(directoryPath, filePattern, recursive); task.Execute(environment); }
public static void Execute(IScriptExecutionEnvironment environment, string workingFolder, string assemblyToTest, string fixtureToRun, string testToRun) { GallioUnitTestTask task = new GallioUnitTestTask(workingFolder, assemblyToTest) { FixtureToRun = fixtureToRun, TestToRun = testToRun }; task.Execute(environment); }
public static void Execute( IScriptExecutionEnvironment environment, string sourceFileName, string destinationFileName, bool overwrite) { CopyFileTask task = new CopyFileTask(sourceFileName, destinationFileName, overwrite); task.Execute(environment); }
protected override void DoExecute(IScriptExecutionEnvironment environment) { using (ServiceController serviceController = new ServiceController("MSSQLSERVER", machineName)) { if (serviceController.Status != ServiceControllerStatus.Running) { serviceController.Start(); } } }
/// <summary> /// Copies a directory tree from the source to the destination. /// </summary> /// <param name="environment">The script execution environment.</param> /// <param name="sourcePath">The source path.</param> /// <param name="destinationPath">The destination path.</param> /// <param name="overwriteExisting">if set to <c>true</c> the task will overwrite existing destination files.</param> public static void Execute( IScriptExecutionEnvironment environment, string sourcePath, string destinationPath, bool overwriteExisting) { CopyDirectoryStructureTask task = new CopyDirectoryStructureTask(sourcePath, destinationPath, overwriteExisting); task.Execute(environment); }
/// <summary> /// Internal task execution code. /// </summary> /// <param name="environment">The script execution environment.</param> protected override void DoExecute(IScriptExecutionEnvironment environment) { // log important environment information environment.LogMessage("Machine name: {0}", Environment.MachineName); environment.LogMessage("OS Version: {0}", Environment.OSVersion); environment.LogMessage("User name: {0}", Environment.UserName); environment.LogMessage("User domain name: {0}", Environment.UserDomainName); environment.LogMessage("CLR version: {0}", Environment.Version); environment.LogMessage("Current directory: {0}", Environment.CurrentDirectory); }
/// <summary> /// Executes the task. /// </summary> /// <param name="environment">The environment.</param> /// <param name="executablePath">The executable path.</param> /// <param name="serviceName">Name of the service.</param> /// <param name="mode">The task mode.</param> public static void Execute( IScriptExecutionEnvironment environment, string executablePath, string serviceName, InstallWindowsServiceMode mode) { InstallWindowsServiceTask task = new InstallWindowsServiceTask(executablePath, serviceName, mode); task.Execute(environment); }
public static void Execute( IScriptExecutionEnvironment environment, CreateUserAccountMode mode, string userName, string password, string userDescription) { CreateUserAccountTask task = new CreateUserAccountTask(mode, userName, password, userDescription); task.Execute(environment); }
/// <summary> /// Internal task execution code. /// </summary> /// <param name="environment">The script execution environment.</param> protected override void DoExecute(IScriptExecutionEnvironment environment) { FileSystemSecurity security; object fileInfo; bool isDir; if (Directory.Exists(path)) { isDir = true; fileInfo = new DirectoryInfo(path); security = (fileInfo as DirectoryInfo).GetAccessControl(AccessControlSections.Access); } else { isDir = false; fileInfo = new FileInfo(path); security = (fileInfo as FileInfo).GetAccessControl(AccessControlSections.Access); } //AuthorizationRuleCollection rules = security.GetAccessRules (true, true, typeof (NTAccount)); foreach (string identity in identities) { FileSystemAccessRule accessRule; if (isDir) { accessRule = new FileSystemAccessRule( identity, fileSystemRights, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, accessControlType); } else { accessRule = new FileSystemAccessRule( identity, fileSystemRights, accessControlType); } security.SetAccessRule(accessRule); } if (isDir) { (fileInfo as DirectoryInfo).SetAccessControl((DirectorySecurity)security); } else { (fileInfo as FileInfo).SetAccessControl((FileSecurity)security); } }
/// <summary> /// Sets a file access rule for a specified file path and identities. /// </summary> /// <param name="environment">The script execution environment.</param> /// <param name="path">The file path.</param> /// <param name="identity">Identity (example: "Network Service").</param> /// <param name="fileSystemRights">File system rights.</param> /// <param name="accessControlType">Type of the access control.</param> public static void Execute( IScriptExecutionEnvironment environment, string path, string identity, FileSystemRights fileSystemRights, AccessControlType accessControlType) { SetAccessRuleTask task = new SetAccessRuleTask(path, identity, fileSystemRights, accessControlType); task.Execute(environment); }
protected override void DoExecute(IScriptExecutionEnvironment environment) { using (ServerManager serverManager = new ServerManager()) { ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools; foreach (ApplicationPool applicationPool in applicationPoolCollection) { if (applicationPool.Name == ApplicationPoolName) { switch (action) { case ControlApplicationPoolAction.Start: RunWithRetries(x => applicationPool.Start(), 3); break; case ControlApplicationPoolAction.Stop: RunWithRetries(x => applicationPool.Stop(), 3); break; case ControlApplicationPoolAction.Recycle: RunWithRetries(x => applicationPool.Recycle(), 3); break; default: throw new NotSupportedException(); } serverManager.CommitChanges(); environment.LogMessage( String.Format( System.Globalization.CultureInfo.InvariantCulture, "Application pool '{0}' has been deleted.", ApplicationPoolName)); return; } } string message = String.Format( System.Globalization.CultureInfo.InvariantCulture, "Application pool '{0}' does not exist.", applicationPoolName); if (failIfNotExist) { throw new RunnerFailedException(message); } environment.LogMessage(message); } }
protected override void DoExecute(IScriptExecutionEnvironment environment) { if (false == Directory.Exists(directoryPath)) { if (false == failIfNotExists) { return; } } Directory.Delete(directoryPath, true); }
/// <summary> /// Runs an external program using the specified command line arguments. /// </summary> /// <param name="environment">The script execution environment.</param> /// <param name="programFilePath">The program file path.</param> /// <param name="arguments">The arguments.</param> /// <param name="timeout">The timeout.</param> public static void Execute( IScriptExecutionEnvironment environment, string programFilePath, string arguments, TimeSpan timeout) { RunProgramTask task = new RunProgramTask(programFilePath, arguments, timeout) { FailOnError = true }; task.Execute(environment); }
/// <summary> /// Internal task execution code. /// </summary> /// <param name="environment">The script execution environment.</param> protected override void DoExecute(IScriptExecutionEnvironment environment) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlFileName); XmlNode node = xmlDoc.SelectSingleNode("Configuration"); if (node != null) { environment.SetConfigSetting(configurationSettingName, node.InnerText); } }
protected override void DoExecute(IScriptExecutionEnvironment environment) { RegistrationHelper regHelper = new RegistrationHelper(); string application = null; string tlbFileName = null; regHelper.InstallAssembly( assemblyFileName, ref application, ref tlbFileName, InstallationFlags.FindOrCreateTargetApplication | InstallationFlags.ReportWarningsToConsole); }
protected override void DoExecute(IScriptExecutionEnvironment environment) { using (ServerManager serverManager = new ServerManager()) { Site site = serverManager.Sites["Default Web Site"]; string vdirPath = "/" + ApplicationName; Application ourApplication = null; foreach (Application application in site.Applications) { if (application.Path == vdirPath) { if (mode == CreateWebApplicationMode.DoNothingIfExists) { environment.LogMessage( "Web application '{0}' already exists, doing nothing.", applicationName); return; } if (mode == CreateWebApplicationMode.FailIfAlreadyExists) { throw new RunnerFailedException( String.Format( System.Globalization.CultureInfo.InvariantCulture, "Web application '{0}' already exists.", applicationName)); } // otherwise we should update the existing virtual directory ourApplication = application; break; } } if (ourApplication == null) { ourApplication = site.Applications.Add(vdirPath, LocalPath); } ourApplication.ApplicationPoolName = applicationPoolName; throw new NotImplementedException(); //Microsoft.Web.Administration.Configuration configuration = ourApplication.GetWebConfiguration(); ////ConfigurationSection webServerSection = configuration.GetSection("system.webServer"); ////ConfigurationElement defaultDocEl = webServerSection.GetChildElement("defaultDocument"); //ConfigurationElement defaultDocEl = configuration.GetSection("system.webServer/defaultDocument"); //defaultDocEl["enabled"] = EnableDefaultDoc.ToString(CultureInfo.InvariantCulture); //serverManager.CommitChanges(); } }
protected override void DoExecute(IScriptExecutionEnvironment environment) { IDictionary savedState = new Hashtable(); string[] commandLine = new string[0]; using (System.Configuration.Install.AssemblyInstaller assemblyInstaller = new System.Configuration.Install.AssemblyInstaller(executablePath, commandLine)) { assemblyInstaller.UseNewContext = true; assemblyInstaller.Uninstall(savedState); } }
protected override void DoExecute(IScriptExecutionEnvironment environment) { // ReSharper disable InconsistentNaming const int GenericWrite = 0x40000000; // ReSharper restore InconsistentNaming IntPtr scHndl = IntPtr.Zero; IntPtr svcHndl = IntPtr.Zero; try { scHndl = OpenSCManager(null, null, GenericWrite); if (scHndl == IntPtr.Zero) { throw new RunnerFailedException("Service manager could not be opened!"); } // ReSharper disable InconsistentNaming const int Delete = 0x10000; // ReSharper restore InconsistentNaming svcHndl = OpenService(scHndl, ServiceName, Delete); if (svcHndl == IntPtr.Zero) { if (FailIfNotExist) { throw new RunnerFailedException("Service {0} does not exist.", ServiceName); } environment.LogMessage("Service '{0}' does not exist, doing nothing.", ServiceName); return; } int result = DeleteService(svcHndl); if (result != 0) { throw new RunnerFailedException("Uninstall windows service failed with error code:{0}", result); } } finally { if (svcHndl != IntPtr.Zero) { CloseServiceHandle(svcHndl); } if (scHndl != IntPtr.Zero) { CloseServiceHandle(scHndl); } } }
public static void Execute( IScriptExecutionEnvironment environment, RegistryKey rootKey, string registryKeyPath, string registryValueName, object registryValueValue) { EditRegistryValueTask task = new EditRegistryValueTask( rootKey, registryKeyPath, registryValueName, registryValueValue); task.Execute(environment); }
public static void Execute( IScriptExecutionEnvironment environment, RegistryKey rootKey, string registryKeyPath, string registryValueName, string configurationSettingName) { GetRegistryValueTask task = new GetRegistryValueTask( rootKey, registryKeyPath, registryValueName, configurationSettingName); task.Execute(environment); }