Beispiel #1
0
        /// <summary>
        /// The main loop. Arguments are used to setup Inter-Process Communication, so follow the instructions!
        /// </summary>
        /// <param name="arg0">The first command line argument to the program.</param>
        /// <param name="arg1">The second command line argument to the program</param>
        public static void Loop(String arg0, String arg1)
        {
            pipeIn = new AnonymousPipeClientStream(PipeDirection.In, arg0);
            pipeOut = new AnonymousPipeClientStream(PipeDirection.Out, arg1);
            messageReceiver = new MessageReceiver(pipeIn);
            messageSender = new MessageSender(pipeOut);

            while (thinking)
            {
                Message m = messageReceiver.WaitForMessage();
                if (m is InitMessage)
                    RunInitMessage((InitMessage)m);
                else if (m is ExitMessage)
                    RunExitMessage((ExitMessage)m);
                else if (m is MethodCallMessage)
                    RunMethodCallMessage((MethodCallMessage)m);
                else
                    throw new Exception("Shouldn't have received that kind of message!");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Constructor. Starts external process.
        /// </summary>
        /// <param name="t">The type of the external class to manage.</param>
        protected InProcessAgent(Type t)
        {
            //Fire up instance of exe, with pipes set up.
            clientProcess = new Process();
            clientProcess.StartInfo.FileName = t.Assembly.Location;
            pipeOut = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable);
            pipeIn = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);
            clientProcess.StartInfo.Arguments = pipeOut.GetClientHandleAsString() + " " + pipeIn.GetClientHandleAsString();
            clientProcess.StartInfo.UseShellExecute = false;
            clientProcess.Start();
            pipeOut.DisposeLocalCopyOfClientHandle();
            pipeIn.DisposeLocalCopyOfClientHandle();

            //initialise an instance of the object

            messageSender = new MessageSender(pipeOut);
            messageReceiver = new MessageReceiver(pipeIn);
        }