public OptionSettings() { _wpfSettings = new WpfDrawingSettings(); _testsDirectory = Path.GetFullPath(Path.Combine("..\\", "Tests")); if (!Directory.Exists(_testsDirectory)) { Directory.CreateDirectory(_testsDirectory); } _pngDirectory = Path.Combine(_testsDirectory, "png"); _svgDirectory = Path.Combine(_testsDirectory, "svg"); _fontsDirectory = Path.Combine(_testsDirectory, "fonts"); _imagesDirectory = Path.Combine(_testsDirectory, "images"); _cacheDirectory = Path.GetFullPath(Path.Combine("..\\", "Cache")); if (!Directory.Exists(_cacheDirectory)) { Directory.CreateDirectory(_cacheDirectory); } _toolsDirectory = Path.GetFullPath(Path.Combine("..\\", "Tools")); if (!Directory.Exists(_toolsDirectory)) { Directory.CreateDirectory(_toolsDirectory); } _crashImageFile = Path.Combine(_testsDirectory, CrashImage); _emptyImageFile = Path.Combine(_imagesDirectory, EmptyImage); _testCssFile = Path.Combine(_testsDirectory, TestCss); _testRunnerFile = Path.Combine(_toolsDirectory, TestRunner); _magickDirectory = MagickTestHandler.GetInstalledDir(); if (!string.IsNullOrWhiteSpace(_magickDirectory) && Directory.Exists(_magickDirectory)) { _isMagickInstalled = File.Exists(Path.Combine(_magickDirectory, MagickTestHandler.FileName)); } _showInputFile = false; _showOutputFile = false; _recursiveSearch = true; // _wpfSettings.AddFontLocation(_fontDirectory); }
private string ProcessMagick(string svgFileName) { var svgInputDir = _optionSettings.SvgDirectory; var workingDir = _optionSettings.CacheDirectory; var toolsDir = _optionSettings.ToolsDirectory; var appDir = _optionSettings.MagickDirectory; var testHandler = new MagickTestHandler(svgInputDir, workingDir, appDir); testHandler.Initialize(svgFileName); if (!testHandler.IsInitialized) { return(null); } if (File.Exists(testHandler.OutputFile)) { return(testHandler.OutputFile); } var outputBuilder = new StringBuilder(); Process pipeClient = new Process(); pipeClient.StartInfo.FileName = _optionSettings.TestRunnerFile; pipeClient.StartInfo.RedirectStandardError = true; pipeClient.StartInfo.RedirectStandardOutput = true; pipeClient.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; pipeClient.StartInfo.CreateNoWindow = true; pipeClient.StartInfo.UseShellExecute = false; pipeClient.EnableRaisingEvents = false; pipeClient.OutputDataReceived += (sender, eventArgs) => { if (!string.IsNullOrWhiteSpace(eventArgs.Data)) { outputBuilder.AppendLine(eventArgs.Data); } }; pipeClient.ErrorDataReceived += (sender, eventArgs) => { if (!string.IsNullOrWhiteSpace(eventArgs.Data)) { outputBuilder.AppendLine(eventArgs.Data); } }; using (var pipeServer = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable)) { // Pass the client process a handle to the server. pipeClient.StartInfo.Arguments = pipeServer.GetClientHandleAsString(); pipeClient.Start(); pipeClient.BeginOutputReadLine(); pipeClient.BeginErrorReadLine(); pipeServer.DisposeLocalCopyOfClientHandle(); try { // Read user input and send that to the client process. using (StreamWriter writer = new StreamWriter(pipeServer)) { writer.AutoFlush = true; // Send a 'sync message' and wait for client to receive it. writer.WriteLine(SvgTestHandler.KeySync); pipeServer.WaitForPipeDrain(); // Send the console input to the client process. testHandler.Marshal(writer); } } catch (IOException ex) { // Catch the IOException that is raised if the pipe is broken or disconnected. Trace.TraceError("[Server] Error: {0}", ex.Message); } } var processExited = pipeClient.WaitForExit(WaitTime); if (processExited == false) // process is timed out... { pipeClient.Kill(); pipeClient.Close(); return(_optionSettings.CrashImageFile); } var exitCode = pipeClient.ExitCode; //Trace.WriteLine("ExitCode: " + pipeClient.ExitCode); pipeClient.Close(); //Trace.WriteLine("[Server] Client quit. Server terminating."); var outputText = outputBuilder.ToString().Trim(); if (outputText.Length != 0) { Trace.WriteLine(string.Empty); Trace.WriteLine("###***** Image Magick *****"); Trace.WriteLine(outputText); } if (exitCode == ExitSuccess && File.Exists(testHandler.OutputFile)) { return(testHandler.OutputFile); } if (exitCode == ExitStackOverflow) { return(_optionSettings.CrashImageFile); } return(_optionSettings.EmptyImageFile); }