public static RunOptions Parse(string [] args) { Paths.SetStandardWorkingDirectory(); var directory = Directory.GetCurrentDirectory(); bool shouldLaunchResults = true; bool shouldPerformXslTransform = true; bool shouldShowHelp = false; string xmlResultsPath = Path.Combine(directory, "test_results.xml"); string transformedResultsPath = Path.Combine(directory, "test_results.html"); string xslTransformPath = Path.Combine("Assets", "tests.xsl"); string stdoutPath = Path.Combine(directory, "stdout.txt"); var filters = new List <ITestFilter>(); var optionSet = new OptionSet() { { "i|include=", x => filters.Add(RegexTestFilter.Parse(x, TestFilterAction.Include)) }, { "x|exclude=", x => filters.Add(RegexTestFilter.Parse(x, TestFilterAction.Exclude)) }, { "no-launch-results", x => shouldLaunchResults = false }, { "no-xsl-transform", x => shouldPerformXslTransform = false }, { "xml-results=", x => xmlResultsPath = x }, { "xsl-transform=", x => xslTransformPath = x }, { "transformed-results=", x => transformedResultsPath = x }, { "stdout=", x => stdoutPath = x }, // { "v|verbose", x => ++verbose }, { "h|?|help", x => shouldShowHelp = true }, }; List <string> extra = optionSet.Parse(args); if (extra.Count > 0) { Console.WriteLine( "Ignoring {0} unrecognized argument(s): {1}", extra.Count, string.Join(", ", extra)); } return(new RunOptions( optionSet, shouldLaunchResults, shouldPerformXslTransform, shouldShowHelp, xmlResultsPath, transformedResultsPath, xslTransformPath, stdoutPath, filters)); }
public virtual void SetUp() { Paths.SetStandardWorkingDirectory(); _game = new MockGame(); }
private void ProcessContext(IAsyncResult result) { HttpListenerContext context; try { context = _listener.EndGetContext(result); } catch { return; } _listener.BeginGetContext(ProcessContext, null); Paths.SetStandardWorkingDirectory(); var workingDirUri = new Uri(Path.GetFullPath("." + Path.DirectorySeparatorChar)); var fileUri = new Uri(workingDirUri, context.Request.Url.AbsolutePath.TrimStart('/')); var fileInfo = new FileInfo(fileUri.LocalPath); if (!fileInfo.Exists) { var dirInfo = new DirectoryInfo(fileUri.LocalPath); if (!dirInfo.Exists) { context.Response.StatusCode = 404; using (var writer = new StreamWriter(context.Response.OutputStream)) { writer.WriteLine("Not found."); } return; } context.Response.StatusCode = 200; context.Response.ContentType = "text/plain"; using (var writer = new StreamWriter(context.Response.OutputStream)) { Uri baseUri; var requestUrlString = context.Request.Url.ToString(); if (!requestUrlString.EndsWith("/")) { baseUri = new Uri(requestUrlString + "/"); } else { baseUri = context.Request.Url; } foreach (var fsInfo in dirInfo.GetFileSystemInfos()) { if ((fsInfo.Attributes & FileAttributes.Directory) != 0) { writer.Write("d: "); } else { writer.Write("f: "); } writer.WriteLine(new Uri(baseUri, fsInfo.Name).ToString()); } } return; } string contentType = MediaTypeNames.Application.Octet; switch (fileInfo.Extension.ToLowerInvariant()) { case ".png": contentType = "image/png"; break; case ".gif": contentType = "image/gif"; break; case ".jpg": case ".jpeg": contentType = "image/jpeg"; break; case ".txt": contentType = "text/plain"; break; case ".htm": case ".html": contentType = "text/html"; break; case ".xml": contentType = "text/xml"; break; } context.Response.StatusCode = 200; context.Response.ContentType = contentType; context.Response.ContentLength64 = fileInfo.Length; using (var input = fileInfo.OpenRead()) { byte [] buffer = new byte [32 * 1024]; int bytesRead; do { bytesRead = input.Read(buffer, 0, buffer.Length); context.Response.OutputStream.Write(buffer, 0, bytesRead); } while (bytesRead > 0); } context.Response.OutputStream.Close(); }