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();
        }
        private void Cleanup(bool requested)
        {
            // TODO: Read and log messages written to STDERR, for cases where, for example, the VM exits with errors before the stitch script is executed
            //var contents = _process.StandardError.ReadToEnd();
            if (_process != null && !_process.HasExited)
            {
                _process.CancelErrorRead();
                _process.CancelOutputRead();
                _process.Kill();
                _process = null;
            }

            _channel.Dispose();
            _channel = null;

            _observer.StitchStateChanged(_stitchInstance.Id, false, requested);
        }
Esempio n. 3
0
 private void Cleanup(bool requested)
 {
     // TODO: Read and log messages written to STDERR, for cases where, for example, the VM exits with errors before the stitch script is executed
     //var contents = _process.StandardError.ReadToEnd();
     if (_process != null && !_process.HasExited)
     {
         _process.CancelErrorRead();
         _process.CancelOutputRead();
         _process.Kill();
         _process = null;
     }
     if (_channel != null)
     {
         _channel.Dispose();
         _channel = null;
     }
     StitchContext.RaiseProcessEvent(false, requested);
 }
Esempio n. 4
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);
        }