Exemplo n.º 1
0
        public Scan(Program.Options options)
        {
            log.Debug("creating scan host");

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

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

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

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

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

            log.Debug("create form");
            form = new Form();
            form.TopMost = true;
            form.BringToFront();

            log.Debug("create hook");
            hook = new WinFormsWindowMessageHook(form);

            log.Debug("create image acquired and image transferred events");
            imageAcquired = new ManualResetEvent(false);
            imageTransferred = new ManualResetEvent(false);

            log.Debug("scan host created");
        }
Exemplo n.º 2
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");
        }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
0
        public Relay(Program.Options options)
        {
            log.Debug("creating relay host");

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

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

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

            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;
            //// processor.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;  ???? do we really need this ????

            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("relay host created");
        }
Exemplo n.º 5
0
        public AsyncResult(Port port, AsyncCallback callback, object state)
        {
            this.port = port;
            this.callback = callback;
            this.state = state;
            wait = new ManualResetEvent(false);

            lengthIsCompleted = false;
            lengthCompletedSynchronously = false;
            lengthBuffer = null;
            lengthOffset = 0;
            lengthException = null;

            messageIsCompleted = false;
            messageCompletedSynchronously = false;
            messageBuffer = null;
            messageOffset = 0;
            messageException = null;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new instance of native messaging host.
 /// </summary>
 public Host()
 {
     port = new Port();
     stop = new ManualResetEvent(false);
 }