Пример #1
0
        public Echo(Options options)
        {
            log.Info("creating echo host");

            log.DebugFormat("create interprocess input pipe (handle={0})", options.pipeIn);
            pipeIn = new AnonymousPipeClientStream(PipeDirection.In, options.pipeIn);
            pipeReader = new StreamReader(pipeIn);

            log.DebugFormat("create interprocess output pipe (handle={0})", options.pipeOut);
            pipeOut = new AnonymousPipeClientStream(PipeDirection.Out, options.pipeOut);
            pipeWriter = new StreamWriter(pipeOut);

            log.Debug("create native messaging port");
            port = new Port(pipeIn, pipeOut);

            log.Debug("create stop event");
            stop = new ManualResetEvent(false);

            log.Debug("synchronize processes");
            string sync = pipeReader.ReadLine();
            log.DebugFormat("sent {0}", sync);
            pipeWriter.WriteLine(sync);
            pipeWriter.Flush();
            log.DebugFormat("received {0}", sync);
            pipeOut.WaitForPipeDrain();

            log.Info("created echo host");
        }
Пример #2
0
        public Relay(Options options)
        {
            log.Info("creating relay host");

            log.Debug("create interprocess input pipe");
            pipeIn = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);
            pipeReader = new StreamReader(pipeIn);

            log.Debug("create interprocess output pipe");
            pipeOut = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable);
            pipeWriter = new StreamWriter(pipeOut);

            log.Debug("create processor host");
            processor = new Process();
            processor.StartInfo.FileName = System.Reflection.Assembly.GetExecutingAssembly().Location;
            log.DebugFormat("StartInfo.FileName={0}", processor.StartInfo.FileName);
            processor.StartInfo.Arguments = String.Format("--pipe-in={0} --pipe-out={1} process", pipeOut.GetClientHandleAsString(), pipeIn.GetClientHandleAsString());
            log.DebugFormat("StartInfo.Arguments={0}", processor.StartInfo.Arguments);
            processor.StartInfo.UseShellExecute = false;

            log.Debug("start processor host");
            try
            {
                processor.Start();
            }
            catch (Exception ex)
            {
                log.Fatal("Exception while starting processor host.", ex);
                throw ex;
            }
            log.DebugFormat("processor host process id : {0}", processor.Id);

            log.Debug("join processes into a job so processor host dies together with relay host");
            job = new Job();
            job.AddProcess(Process.GetCurrentProcess().Id);
            job.AddProcess(processor.Id);

            log.Debug("create native messaging ports");
            portA = new Port();
            portB = new Port(pipeIn, pipeOut);
            portsExceptions = new List<Exception>();

            log.Debug("create stop event");
            stop = new ManualResetEvent(false);

            log.Debug("synchronize processes");
            string sync = "SYNC";
            pipeWriter.WriteLine(sync);
            pipeWriter.Flush();
            log.DebugFormat("sent {0}", sync);
            pipeOut.WaitForPipeDrain();
            sync = pipeReader.ReadLine();
            log.DebugFormat("received {0}", sync);

            log.Info("created relay host");
        }