public bool Run() { try { Failures = -1; string page = Options.Page; string path = Options.LocalPath; if (File.Exists(path)) { FileInfo fi = new FileInfo(path); TestService.RootDirectory = fi.DirectoryName; } else if (Directory.Exists(path)) { TestService.RootDirectory = path; } TestService.TestRunPrefix = Options.DeviceInfo.DeviceId.ToString(); TestService.Start(); if (!string.IsNullOrEmpty(Options.TagExpression)) { TestService.TagExpression = Options.TagExpression; } if (!string.IsNullOrEmpty(Options.Log)) { TestService.LogFile = Options.Log; } TargetDevice = Options.DeviceInstance ?? new TargetDevice(Options.DeviceInfo); TargetDevice.Start(Options.ApplicationProductId, Options.ApplicationGenre, Options.XapFile, Options.UpdateApplication); while (TestService.IsRunning && TargetDevice.IsRunning && TestService.Result == null) { Thread.Sleep(TimeSpan.FromMilliseconds(PollingThreadSleepMilliseconds)); } TestRunResult result = TestService.Result; if (result != null) { Total = result.Total; Log = result.Log; Failures = result.Failures; } } catch (Exception e) { Console.WriteLine(e.Message); } finally { Thread.Sleep(TimeSpan.FromMilliseconds(FinalSleepDelayMilliseconds)); TargetDevice.Close(); TestService.Stop(); } return(Failures == 0); }
/// <summary> /// Process a test run result and then begin the shutdown process. /// </summary> /// <param name="result">The test run result.</param> internal void ProcessResult(TestRunResult result) { Result = result; BeginShutdownProcess(); }
public string ProcessFunction(List<string> data, HttpListenerResponse response, string postData) { string func = data[0]; data.RemoveAt(0); Dictionary<string, string> request = new Dictionary<string, string>(); while (data.Count > 1) { string key = data[0]; string value = data[1]; data.RemoveRange(0, 2); request[key] = value; } if (postData != null) { request["post"] = postData; } string path = Environment.CurrentDirectory; if (Directory.Exists(TestServiceEngine.Current.RootDirectory)) { path = TestServiceEngine.Current.RootDirectory; } string guid = string.Empty; request.TryGetValue("guid", out guid); switch (func) { case "ping": return ServiceHelper.OK("Hello!"); case "reportTestResults": { TestRunResult trr = new TestRunResult(); trr.Log = string.Empty; trr.Total = int.Parse(request["total"], CultureInfo.InvariantCulture); trr.Failures = int.Parse(request["failures"], CultureInfo.InvariantCulture); TestRunResult result = trr; TestServiceEngine.Current.ProcessResult(result); return ServiceHelper.OK(guid); } case "getRunParameters": { StringBuilder str = new StringBuilder(); str.AppendLine("<testRun>"); str.AppendLine("<options>"); if (!string.IsNullOrEmpty(TestServiceEngine.Current.TagExpression)) { str.AppendLine(string.Format(CultureInfo.InvariantCulture, "<option name=\"{0}\" value=\"{1}\" />", "tagExpression", ServiceHelper.UrlEncode(TestServiceEngine.Current.TagExpression))); } str.AppendLine(string.Format(CultureInfo.InvariantCulture, "<option name=\"{0}\" value=\"{1}\" />", "testRunNamePrefix", TestServiceEngine.Current.TestRunPrefix)); str.AppendLine(string.Format(CultureInfo.InvariantCulture, "<option name=\"{0}\" value=\"{1}\" />", "computerName", ServiceHelper.UrlEncode(Environment.MachineName))); str.AppendLine(string.Format(CultureInfo.InvariantCulture, "<option name=\"{0}\" value=\"{1}\" />", "userName", ServiceHelper.UrlEncode(Environment.UserName))); if (!string.IsNullOrEmpty(TestServiceEngine.Current.LogFile)) { string logShortName = TestServiceEngine.Current.LogFile; string dir = Path.GetDirectoryName(TestServiceEngine.Current.LogFile); if (Directory.Exists(dir)) { logShortName = Path.GetFileName(TestServiceEngine.Current.LogFile); } str.AppendLine(string.Format(CultureInfo.InvariantCulture, "<option name=\"{0}\" value=\"{1}\" />", "log", ServiceHelper.UrlEncode(logShortName))); } str.AppendLine("</options>"); str.AppendLine("<arguments>"); str.AppendLine("</arguments>"); str.AppendLine("</testRun>"); Debug.WriteLine("getRunParameters:"); Debug.WriteLine(str.ToString()); return ServiceHelper.OK(str.ToString()); } case "saveLogFile": { string logName = request["logName"]; FileInfo logInfo = new FileInfo(Path.Combine(path, logName)); if (!Directory.Exists(logInfo.DirectoryName)) { logInfo = new FileInfo(logName); } if (!Directory.Exists(logInfo.DirectoryName)) { Console.WriteLine("Could not find directory to store " + logName); return ServiceHelper.Error("Could not store log file."); } else { File.WriteAllText(logInfo.FullName, postData); } return ServiceHelper.OK(); } // Improved code coverage transport, base 64 - store as the // simple bit character string for compatibility case "saveCodeCoverageBase64": string ba = ByteArrayToBitString(Convert.FromBase64String(postData)); Console.WriteLine("Saving code coverage information..."); File.WriteAllText(Path.Combine(path, "RawCodeCoverage.txt"), ba); return ServiceHelper.OK(); // Legacy code coverage format, simple string of raw 0 and 1 // characters over the wire. Highly inefficient. case "saveCodeCoverage": Console.WriteLine("Saving code coverage information..."); File.WriteAllText(Path.Combine(path, "RawCodeCoverage.txt"), postData); return ServiceHelper.OK(); } Console.WriteLine("No implementation for " + func); return string.Empty; }
public string ProcessFunction(List <string> data, HttpListenerResponse response, string postData) { string func = data[0]; data.RemoveAt(0); Dictionary <string, string> request = new Dictionary <string, string>(); while (data.Count > 1) { string key = data[0]; string value = data[1]; data.RemoveRange(0, 2); request[key] = value; } if (postData != null) { request["post"] = postData; } string path = Environment.CurrentDirectory; if (Directory.Exists(TestServiceEngine.Current.RootDirectory)) { path = TestServiceEngine.Current.RootDirectory; } string guid = string.Empty; request.TryGetValue("guid", out guid); switch (func) { case "ping": return(ServiceHelper.OK("Hello!")); case "reportTestResults": { TestRunResult trr = new TestRunResult(); trr.Log = string.Empty; trr.Total = int.Parse(request["total"], CultureInfo.InvariantCulture); trr.Failures = int.Parse(request["failures"], CultureInfo.InvariantCulture); TestRunResult result = trr; TestServiceEngine.Current.ProcessResult(result); return(ServiceHelper.OK(guid)); } case "getRunParameters": { StringBuilder str = new StringBuilder(); str.AppendLine("<testRun>"); str.AppendLine("<options>"); if (!string.IsNullOrEmpty(TestServiceEngine.Current.TagExpression)) { str.AppendLine(string.Format(CultureInfo.InvariantCulture, "<option name=\"{0}\" value=\"{1}\" />", "tagExpression", ServiceHelper.UrlEncode(TestServiceEngine.Current.TagExpression))); } str.AppendLine(string.Format(CultureInfo.InvariantCulture, "<option name=\"{0}\" value=\"{1}\" />", "testRunNamePrefix", TestServiceEngine.Current.TestRunPrefix)); str.AppendLine(string.Format(CultureInfo.InvariantCulture, "<option name=\"{0}\" value=\"{1}\" />", "computerName", ServiceHelper.UrlEncode(Environment.MachineName))); str.AppendLine(string.Format(CultureInfo.InvariantCulture, "<option name=\"{0}\" value=\"{1}\" />", "userName", ServiceHelper.UrlEncode(Environment.UserName))); if (!string.IsNullOrEmpty(TestServiceEngine.Current.LogFile)) { string logShortName = TestServiceEngine.Current.LogFile; string dir = Path.GetDirectoryName(TestServiceEngine.Current.LogFile); if (Directory.Exists(dir)) { logShortName = Path.GetFileName(TestServiceEngine.Current.LogFile); } str.AppendLine(string.Format(CultureInfo.InvariantCulture, "<option name=\"{0}\" value=\"{1}\" />", "log", ServiceHelper.UrlEncode(logShortName))); } str.AppendLine("</options>"); str.AppendLine("<arguments>"); str.AppendLine("</arguments>"); str.AppendLine("</testRun>"); Debug.WriteLine("getRunParameters:"); Debug.WriteLine(str.ToString()); return(ServiceHelper.OK(str.ToString())); } case "saveLogFile": { string logName = request["logName"]; FileInfo logInfo = new FileInfo(Path.Combine(path, logName)); if (!Directory.Exists(logInfo.DirectoryName)) { logInfo = new FileInfo(logName); } if (!Directory.Exists(logInfo.DirectoryName)) { Console.WriteLine("Could not find directory to store " + logName); return(ServiceHelper.Error("Could not store log file.")); } else { File.WriteAllText(logInfo.FullName, postData); } return(ServiceHelper.OK()); } // Improved code coverage transport, base 64 - store as the // simple bit character string for compatibility case "saveCodeCoverageBase64": string ba = ByteArrayToBitString(Convert.FromBase64String(postData)); Console.WriteLine("Saving code coverage information..."); File.WriteAllText(Path.Combine(path, "RawCodeCoverage.txt"), ba); return(ServiceHelper.OK()); // Legacy code coverage format, simple string of raw 0 and 1 // characters over the wire. Highly inefficient. case "saveCodeCoverage": Console.WriteLine("Saving code coverage information..."); File.WriteAllText(Path.Combine(path, "RawCodeCoverage.txt"), postData); return(ServiceHelper.OK()); } Console.WriteLine("No implementation for " + func); return(string.Empty); }
public bool Run() { try { Failures = -1; string page = Options.Page; string path = Options.LocalPath; if (File.Exists(path)) { FileInfo fi = new FileInfo(path); TestService.RootDirectory = fi.DirectoryName; page = fi.Name; } else if (Directory.Exists(path)) { TestService.RootDirectory = path; if (!File.Exists(Path.Combine(path, page))) { page = string.Empty; } } TestService.TestRunPrefix = Options.Browser.ToString(); TestService.Start(); if (!string.IsNullOrEmpty(Options.TagExpression)) { TestService.TagExpression = Options.TagExpression; } if (!string.IsNullOrEmpty(Options.Log)) { TestService.LogFile = Options.Log; } WebBrowser = Options.BrowserInstance != null ? Options.BrowserInstance : WebBrowserFactory.Create(Options.Browser); Uri uri = new Uri( string.Format( CultureInfo.InvariantCulture, StandardLocalHostingUrl, _testServiceOptions.MachineName, _testServiceOptions.Port, page, Options.RunId)); WebBrowser.Start(uri); while (TestService.IsRunning && WebBrowser.IsRunning && TestService.Result == null) { Thread.Sleep(TimeSpan.FromMilliseconds(PollingThreadSleepMilliseconds)); } TestRunResult result = TestService.Result; if (result != null) { Total = result.Total; Log = result.Log; Failures = result.Failures; } } catch (Exception e) { Console.WriteLine(e.Message); } finally { Thread.Sleep(TimeSpan.FromMilliseconds(FinalSleepDelayMilliseconds)); WebBrowser.Close(); TestService.Stop(); } return(Failures == 0); }