public void ReadMessage_Test1()
        {
            var input  = CreateInputStream("{Id: 1, Command: 'Ack'}\nend\n");
            var target = new FromStitchMessageReader(input);
            var result = target.ReadMessage();

            result.Should().NotBeNull();
            result.Id.Should().Be(1);
        }
Ejemplo n.º 2
0
        public bool Start()
        {
            var executableName = Path.Combine(_parameters.DirectoryPath, _parameters.ExecutableName);
            var executableFile = _parameters.ExecutableFormat
                                 .Replace("{ExecutableName}", _parameters.ExecutableName)
                                 .Replace("{DirectoryPath}", _parameters.DirectoryPath);

            int parentPid = Process.GetCurrentProcess().Id;

            var coreArgs  = BuildCoreArgumentsString(parentPid);
            var arguments = _parameters.ArgumentsFormat
                            .Replace("{ExecutableName}", _parameters.ExecutableName)
                            .Replace("{DirectoryPath}", _parameters.DirectoryPath)
                            .Replace("{CoreArgs}", coreArgs)
                            .Replace("{CustomArgs}", _parameters.ExecutableArguments);

            _process = new Process();

            _process.EnableRaisingEvents              = true;
            _process.StartInfo.CreateNoWindow         = true;
            _process.StartInfo.ErrorDialog            = false;
            _process.StartInfo.FileName               = executableFile;
            _process.StartInfo.WorkingDirectory       = _parameters.DirectoryPath;
            _process.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            _process.StartInfo.UseShellExecute        = false;
            _process.StartInfo.RedirectStandardError  = true;
            _process.StartInfo.RedirectStandardInput  = true;
            _process.StartInfo.RedirectStandardOutput = true;
            _process.StartInfo.Arguments              = arguments;
            _process.Exited += ProcessOnExited;

            bool ok = _process.Start();

            var fromStitchReader = new FromStitchMessageReader(_process.StandardOutput);
            var toStitchSender   = new ToStitchMessageSender(_process.StandardInput);

            _channel = new CoreMessageManager(StitchContext, fromStitchReader, toStitchSender);
            _channel.Start();

            StitchContext.RaiseProcessEvent(true, true);

            return(true);
        }