private void SetupChannel(MessageChannelType channelType, MessageSerializerType serializerType)
        {
            var messageChannel = _channelFactory.Create(channelType, _process);
            var serializer     = _serializerFactory.Create(serializerType);

            _channel = new CoreMessageManager(_stitchInstance.Id, _observer, messageChannel, serializer);
            _channel.Start();
        }
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);
        }