public IProcess StartProcess(string fileName, string arguments, IUserInterface userInterface, string workingDirectory = null, bool showOutput = true, bool showError = true, bool killOnDispose = true) { FormatterParameters parameters = new FormatterParameters(); parameters.Add(fileName, Constants.CommandKey); parameters.Add(arguments, Constants.CommandArgumentsKey); IUserInterface formatterUserInterface = formatterPool.GetFormatter(parameters, userInterface); ExecutionContext redirectedContext = executionContext.RedirectOutput(formatterUserInterface); return(new ProcessFacade(fileName, arguments, workingDirectory, redirectedContext, null, showOutput, showError, killOnDispose, environmentService.Platform, cancellationToken)); }
public IProcess StartProcessWithSetup(string fileName, string arguments, IUserInterface userInterface, string setup, string workingDirectory = null, bool showOutput = true, bool showError = true, bool killOnDispose = true) { string commandName = fileName; if (setup != null) { commandName = $"cmd.exe"; string arguments2 = $"/c \"\"{setup}\" && \"{fileName}\" {arguments}\""; if (environmentService.Platform == OSPlatform.Linux) { commandName = "/bin/sh"; arguments2 = $"-c \"'{setup}' && '{fileName}' {arguments}\""; } arguments = arguments2; } string displayName = Path.GetFileNameWithoutExtension(fileName); FormatterParameters parameters = new FormatterParameters(); parameters.Add(commandName, Constants.CommandKey); parameters.Add(arguments, Constants.CommandArgumentsKey); IUserInterface formatterUserInterface = formatterPool.GetFormatter(parameters, userInterface); ExecutionContext redirectedContext = executionContext.RedirectOutput(formatterUserInterface); if (environmentService.Platform == OSPlatform.Linux && setup != null) { var fileInfo = new UnixFileInfo(setup); fileInfo.FileAccessPermissions = fileInfo.FileAccessPermissions | FileAccessPermissions.UserExecute; } ProcessFacade facade = new ProcessFacade(commandName, arguments, workingDirectory, redirectedContext, displayName, showOutput, showError, killOnDispose, environmentService.Platform, cancellationToken); return(facade); }
/// <summary> /// Phylogenetic Tree Formatter General Tests /// </summary> /// <param name="nodeName">Xml node Name.</param> /// <param name="formatParam">Additional parameter</param> void PhylogeneticTreeFormatterGeneralTests(string nodeName, FormatterParameters formatParam) { // Gets the expected sequence from the Xml string filePath = string.Empty; using (NewickParser parser = new NewickParser()) { Tree rootTree = null; switch (formatParam) { case FormatterParameters.Object: rootTree = GetFormattedObject(false); break; case FormatterParameters.ObjectSingleNode: rootTree = GetFormattedObject(true); break; case FormatterParameters.ParseTextReader: filePath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: File Exists in the Path '{0}'.", filePath)); using (StreamReader reader = File.OpenText(filePath)) { rootTree = parser.Parse(reader); } break; case FormatterParameters.ParseStringBuilder: filePath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: File Exists in the Path '{0}'.", filePath)); using (StreamReader reader = File.OpenText(filePath)) { StringBuilder strBuilderObj = new StringBuilder(reader.ReadToEnd()); rootTree = parser.Parse(strBuilderObj); } break; default: filePath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: File Exists in the Path '{0}'.", filePath)); rootTree = parser.Parse(filePath); break; } string outputFilepath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.OutputFilePathNode); NewickFormatter format = new NewickFormatter(); switch (formatParam) { case FormatterParameters.TextWriter: using (TextWriter writer = new StreamWriter(outputFilepath)) { format.Format(rootTree, writer); } break; case FormatterParameters.FormatString: // Validate format String string formatString = format.FormatString(rootTree); string expectedFormatString = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FormatStringNode); Assert.AreEqual(expectedFormatString, formatString); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: Format string '{0}' is as expected.", formatString)); Console.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: Format string '{0}' is as expected.", formatString)); break; default: format.Format(rootTree, outputFilepath); break; } // Validate only if not a Format String if (FormatterParameters.FormatString != formatParam) { // Re-parse the created file and validate the tree. using (NewickParser newparserObj = new NewickParser()) { Tree newrootTreeObj = null; Assert.IsTrue(File.Exists(outputFilepath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: New File Exists in the Path '{0}'.", outputFilepath)); newrootTreeObj = newparserObj.Parse(outputFilepath); Node rootNode = newrootTreeObj.Root; string rootBranchCount = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.RootBranchCountNode); // Validate the root branch count Assert.AreEqual(rootBranchCount, rootNode.Children.Count.ToString((IFormatProvider)null)); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Formatter P1: Number of Root Branches found are '{0}'.", rootNode.Children.Count.ToString((IFormatProvider)null))); List <string> leavesName = new List <string>(); List <double> leavesDistance = new List <double>(); // Gets all the leaves in the root node list GetAllNodesAndEdges(rootNode, ref leavesName, ref leavesDistance); string[] expectedLeavesName = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.NodeNamesNode).Split(','); string[] expectedLeavesDistance = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.EdgeDistancesNode).Split(','); for (int i = 0; i < expectedLeavesName.Length; i++) { Assert.AreEqual(expectedLeavesName[i], leavesName[i]); } for (int i = 0; i < expectedLeavesDistance.Length; i++) { Assert.AreEqual(expectedLeavesDistance[i], leavesDistance[i].ToString((IFormatProvider)null)); } ApplicationLog.WriteLine( "Phylogenetic Tree Parser P1: The Node Names and Distance are as expected."); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine( "Phylogenetic Tree Parser P1: The Node Names and Distance are as expected."); } if (File.Exists(outputFilepath)) { File.Delete(outputFilepath); } } } }
public bool CanFormat(FormatterParameters parameters) { return(parameters.TryGet(Constants.MessageFormat, out string messageFormat) && messageFormat == "cmake-json"); }
/// <summary> /// Phylogenetic Tree Formatter General Tests /// </summary> /// <param name="nodeName">Xml node Name.</param> /// <param name="formatParam">Additional parameter</param> void PhylogeneticTreeFormatterGeneralTests(string nodeName, FormatterParameters formatParam) { // Gets the expected sequence from the Xml string filePath = string.Empty; NewickParser parser = new NewickParser(); { Tree rootTree; switch (formatParam) { case FormatterParameters.Object: rootTree = GetFormattedObject(); break; default: filePath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Parser BVT: File Exists in the Path '{0}'.", filePath)); rootTree = parser.Parse(filePath); break; } string outputFilepath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.OutputFilePathNode); NewickFormatter format = new NewickFormatter(); switch (formatParam) { case FormatterParameters.Stream: using (var writer = File.Create(outputFilepath)) { format.Format(writer, rootTree); } break; case FormatterParameters.FormatString: // Validate format String var formatString = format.FormatString(rootTree); string expectedFormatString = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FormatStringNode); Assert.AreEqual(expectedFormatString, formatString); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Parser BVT: Format string '{0}' is as expected.", formatString)); break; default: format.Format(rootTree, outputFilepath); break; } // Validate only if not a Format String if (FormatterParameters.FormatString != formatParam) { // Re-parse the created file and validate the tree. NewickParser newparserObj = new NewickParser(); { Tree newrootTreeObj = null; Assert.IsTrue(File.Exists(outputFilepath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Parser BVT: New File Exists in the Path '{0}'.", outputFilepath)); newrootTreeObj = newparserObj.Parse(outputFilepath); Node rootNode = newrootTreeObj.Root; string rootBranchCount = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.RootBranchCountNode); // Validate the root branch count Assert.AreEqual(rootBranchCount, rootNode.Children.Count.ToString((IFormatProvider)null)); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Parser BVT: Number of Root Branches found are '{0}'.", rootNode.Children.Count.ToString((IFormatProvider)null))); List<string> leavesName = new List<string>(); List<double> leavesDistance = new List<double>(); // Gets all the leaves in the root node list GetAllNodesAndEdges(rootNode, ref leavesName, ref leavesDistance); string[] expectedLeavesName = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.NodeNamesNode).Split(','); string[] expectedLeavesDistance = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.EdgeDistancesNode).Split(','); for (int i = 0; i < expectedLeavesName.Length; i++) { Assert.AreEqual(expectedLeavesName[i], leavesName[i]); } for (int i = 0; i < expectedLeavesDistance.Length; i++) { Assert.AreEqual(expectedLeavesDistance[i], leavesDistance[i].ToString((IFormatProvider)null)); } } ApplicationLog.WriteLine( "Phylogenetic Tree Parser BVT: The Node Names and Distance are as expected."); } if (File.Exists(outputFilepath)) File.Delete(outputFilepath); } }
public static async Task <CMakeConversation> Start(IProcessManager processManager, IBinariesLocator binariesLocator, IOutputFormatterPool formatterPool, VirtualDirectory tempDirectory, bool isWindowsSystem, ExecutionContext executionContext, VirtualDirectory sourceDirectory, VirtualDirectory binaryDirectory) { IProcess process = null; NamedPipeClientStream pipeClient = null; try { string pipeName = isWindowsSystem ? $"{tempDirectory.FullName}\\.cmakeserver" : $"/tmp/cmake-server-{Guid.NewGuid().ToByteString()}"; string serverCommand = isWindowsSystem ? $"-E server --experimental --pipe=\"\\\\?\\pipe\\{pipeName}\"" : $"-E server --experimental --pipe={pipeName}"; process = processManager.StartProcess(binariesLocator.GetExecutableCommand("cmake"), serverCommand, executionContext); pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.Asynchronous, TokenImpersonationLevel.Impersonation); pipeClient.Connect(CMakeServerTimeout); if (!pipeClient.IsConnected) { throw new FormattableException("Could not connect to server"); } FormatterParameters parameters = new FormatterParameters(); parameters.Add("cmake-json", MessageFormat); IUserInterface jsonCmakeInterface = formatterPool.GetFormatter(parameters, executionContext); CMakeServerStream serverStream = new CMakeServerStream(pipeClient, executionContext); CMakeHelloMessage hello = null; do { foreach (string singleMessage in await serverStream.ReadMessage() .TimeoutAfter(CMakeServerTimeout) .ConfigureAwait(false)) { hello = CMakeMessage.Parse <CMakeMessage>(singleMessage, jsonCmakeInterface) as CMakeHelloMessage; } } while (hello == null); if (hello.SupportedProtocolVersions.All(v => v.Major != 1)) { throw new FormattableException("CMake server does not support the protocol version 1.X. " + $"Supported versions are {string.Join(", ", hello.SupportedProtocolVersions)}"); } CMakeConversation conversation = new CMakeConversation(process, pipeClient, serverStream, jsonCmakeInterface); await conversation.Handshake(sourceDirectory.FullName.Replace('\\', '/'), binaryDirectory.FullName.Replace('\\', '/')) .ConfigureAwait(false); await conversation.Configure().ConfigureAwait(false); return(conversation); } catch (Exception) { pipeClient?.Dispose(); process?.Dispose(); throw; } }