示例#1
0
        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));
        }
示例#2
0
        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);
        }
        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;
            }
        }