public string RunTests(string JobName, string TestAssembliesList, List <string> TestAssembliesDirectories, string TestSettingsFile, string TestRunnerPath) { var trxTestResultsFile = ""; if (File.Exists(TestRunnerPath)) { if (!string.IsNullOrEmpty(DoServerStart) || !string.IsNullOrEmpty(DoStudioStart) || !string.IsNullOrEmpty(DomywarewolfioStart)) { this.CleanupServerStudio(); Startmywarewolfio(); if (!string.IsNullOrEmpty(DoServerStart) || !string.IsNullOrEmpty(DoStudioStart)) { StartServer(); if (!string.IsNullOrEmpty(DoStudioStart)) { StartStudio(); } } } if (ApplyDotCover && string.IsNullOrEmpty(DoServerStart) && string.IsNullOrEmpty(DoStudioStart)) { string DotCoverRunnerPath = DotCoverRunner(JobName, TestAssembliesDirectories); // Run DotCover Runner Batch File trxTestResultsFile = ProcessUtils.RunFileInThisProcess(DotCoverRunnerPath); if (!string.IsNullOrEmpty(DoServerStart) || !string.IsNullOrEmpty(DoStudioStart) || !string.IsNullOrEmpty(DomywarewolfioStart)) { this.CleanupServerStudio(false); } } else { // Run Test Runner Batch File trxTestResultsFile = ProcessUtils.RunFileInThisProcess(TestRunnerPath); if (!string.IsNullOrEmpty(DoServerStart) || !string.IsNullOrEmpty(DoStudioStart) || !string.IsNullOrEmpty(DomywarewolfioStart)) { this.CleanupServerStudio(!ApplyDotCover); } } this.MoveArtifactsToTestResults(ApplyDotCover, (!string.IsNullOrEmpty(DoServerStart) || !string.IsNullOrEmpty(DoStudioStart)), !string.IsNullOrEmpty(DoStudioStart), JobName); } return(trxTestResultsFile); }
public void StartServer() { var ServerFolderPath = Path.GetDirectoryName(ServerPath); Console.WriteLine($"Deploying New resources from {ServerFolderPath}\\Resources - {ResourcesType}\\*"); RecursiveFolderCopy(Path.Combine(ServerFolderPath, $"Resources - {ResourcesType}"), Environment.ExpandEnvironmentVariables("%ProgramData%\\Warewolf")); if (!StartServerAsConsole) { try { ServiceController.GetServices().FirstOrDefault(serviceController => serviceController.ServiceName.Equals("Warewolf Server"))?.Start(); } catch (InvalidOperationException e) { Console.WriteLine(e.InnerException == null ? e.Message : e.InnerException.Message); } var process = ProcessUtils.StartProcess("sc.exe", "interrogate \"Warewolf Server\""); var Output = process.StandardOutput.ReadToEnd() + process.StandardError.ReadToEnd(); if (!(Output.EndsWith("RUNNING "))) { Console.WriteLine(Output); process.StartInfo.Arguments = "start \"Warewolf Server\""; process.Start(); process.WaitForExit(); } } else { if (!ApplyDotCover) { Process.Start(ServerPath); } else { Process.Start(RunServerWithDotcoverScript); } } WaitForServerStart(ServerFolderPath); }
public static void CleanupServerStudio(this TestLauncher build, bool Force = true, string JobName = "") { if (!string.IsNullOrEmpty(build.ServerPath) && File.Exists(build.ServerPath)) { string serverStartedFile = Path.Combine(Path.GetDirectoryName(build.ServerPath), "ServerStarted"); if (File.Exists(serverStartedFile)) { File.Delete(serverStartedFile); } } //Find Webs if (string.IsNullOrEmpty(build.WebsPath)) { build.WebsPath = Path.Combine(build.TestRunner.TestsPath, "_PublishedWebsites", "Dev2.Web"); if (!File.Exists(build.WebsPath) && !String.IsNullOrEmpty(build.ServerPath)) { build.WebsPath = Path.Combine(Path.GetDirectoryName(build.ServerPath), "_PublishedWebsites", "Dev2.Web"); } } else { if (!Directory.Exists(build.WebsPath)) { throw new ArgumentException("No webs folder found at " + build.WebsPath); } } //Find Studio if (string.IsNullOrEmpty(build.StudioPath)) { bool foundStudio = build.TryFindWarewolfStudioExe(out string studioPath); if (foundStudio) { build.StudioPath = studioPath; } } else { if (!File.Exists(build.StudioPath)) { throw new ArgumentException("No studio found at " + build.StudioPath); } } if (!string.IsNullOrEmpty(build.StudioPath)) { string studioStartedFile = Path.Combine(Path.GetDirectoryName(build.StudioPath), "StudioStarted"); if (File.Exists(studioStartedFile)) { File.Delete(studioStartedFile); } } int WaitForCloseTimeout = Force ? 10 : 1800; int WaitForCloseRetryCount = Force ? 1 : 10; //Stop Studio Process process = ProcessUtils.StartProcess("taskkill", "/im \"Warewolf Studio.exe\""); var Output = process.StandardOutput.ReadToEnd() + process.StandardError.ReadToEnd(); //Soft Kill int i = 0; string WaitTimeoutMessage = "This command stopped operation because process "; string WaitOutput = WaitTimeoutMessage; while (!(Output.StartsWith("ERROR: ")) && WaitOutput.StartsWith(WaitTimeoutMessage) && i < WaitForCloseRetryCount) { i++; Console.WriteLine(Output); Process.GetProcessesByName("Warewolf Studio")[0].WaitForExit(WaitForCloseTimeout); var FormatWaitForCloseTimeoutMessage = WaitOutput.Replace(WaitTimeoutMessage, ""); if (FormatWaitForCloseTimeoutMessage != "" && !(FormatWaitForCloseTimeoutMessage.StartsWith("Cannot find a process with the name "))) { Console.WriteLine(FormatWaitForCloseTimeoutMessage); } process.Start(); process.WaitForExit(); Output = process.StandardOutput.ReadToEnd() + process.StandardError.ReadToEnd(); } //Force Kill process.StartInfo.Arguments = "/im \"Warewolf Studio.exe\" /f"; process.Start(); process.WaitForExit(); Output = process.StandardOutput.ReadToEnd() + process.StandardError.ReadToEnd(); if (!(Output.StartsWith("ERROR: "))) { Console.WriteLine(Output); } //Stop my.warewolf.io process.StartInfo.Arguments = "/im iisexpress.exe /f"; process.Start(); process.WaitForExit(); Output = process.StandardOutput.ReadToEnd() + process.StandardError.ReadToEnd(); if (!(Output.StartsWith("ERROR: "))) { Console.WriteLine(Output); } if (!build.StartServerAsConsole) { //Stop Server var stopServerService = new Process(); stopServerService.StartInfo.UseShellExecute = false; stopServerService.StartInfo.RedirectStandardOutput = true; stopServerService.StartInfo.RedirectStandardError = true; stopServerService.StartInfo.FileName = "sc.exe"; stopServerService.StartInfo.Arguments = "stop \"Warewolf Server\""; stopServerService.Start(); stopServerService.WaitForExit(); var ServiceOutput = stopServerService.StandardOutput.ReadToEnd() + stopServerService.StandardError.ReadToEnd(); if (ServiceOutput != "[SC] ControlService FAILED 1062:\r\n\r\nThe service has not been started.\r\n\r\n") { Console.WriteLine(ServiceOutput.TrimStart('\n')); var allServerProcesses = Process.GetProcessesByName("Warewolf Server"); if (allServerProcesses.Length > 0) { allServerProcesses[0].WaitForExit(WaitForCloseTimeout); } } } process.StartInfo.Arguments = "/im \"Warewolf Server.exe\" /f"; process.Start(); process.StartInfo.Arguments = "/im \"operadriver.exe\" /f"; process.Start(); process.StartInfo.Arguments = "/im \"geckodriver.exe\" /f"; process.Start(); process.StartInfo.Arguments = "/im \"IEDriverServer.exe\" /f"; process.Start(); //Delete Certain Studio and Server Resources foreach (var FileOrFolder in ToClean) { var ActualPath = Environment.ExpandEnvironmentVariables(FileOrFolder); if (File.Exists(ActualPath)) { WaitForFileUnlock(ActualPath); File.Delete(ActualPath); } if (Directory.Exists(ActualPath)) { WaitForFolderUnlock(ActualPath); Directory.Delete(ActualPath, true); } if ((File.Exists(FileOrFolder) || Directory.Exists(FileOrFolder))) { Console.Error.WriteLine("Cannot delete " + FileOrFolder); } } if (String.IsNullOrEmpty(JobName)) { JobName = "Test Run"; } //Publish Certain Studio and Server Resources foreach (var FileOrFolder in ToPublish) { var ActualPath = Environment.ExpandEnvironmentVariables(FileOrFolder); if (Directory.Exists(ActualPath)) { MoveFolderToTestResults(Environment.ExpandEnvironmentVariables(ActualPath), $"{JobName} Server {Path.GetFileName(ActualPath)} Folder", build.TestRunner.TestsResultsPath); } } }