Beispiel #1
0
        public void ShouldInitializeParametersList()
        {
            ioCommand command = new ioCommand();

            command.Parameters.Add("testParam");
            Assert.That(command.Parameters.Count, Is.EqualTo(1));
        }
Beispiel #2
0
        public void ShouldSetCommandName()
        {
            string    commandNameTest = "testCommand";
            ioCommand command         = new ioCommand(commandNameTest);
            string    commandName     = command.Name;

            Assert.That(commandName, Is.SameAs(commandNameTest));
        }
Beispiel #3
0
        public void ShouldExecuteCommand()
        {
            List <object> parameters = new List <object>();

            parameters.Add(1);
            parameters.Add(3);
            ioCommand command = new ioCommand("Add", parameters);

            server.Execute(command);
            // Not testing events raised
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.FileName = "ChildClientSample.exe";

            using (Server ioServer = new Server(startInfo))
            {
                ioServer.Exited += Iorpc_Exited;
                ioServer.CommandResultReceived    += Iorpc_CommandResultReceived;
                ioServer.CommandExceptionReceived += Iorpc_CommandExceptionReceived;
                ioServer.Start();

                Console.WriteLine("[SampleServer] Server Started...");
                Thread.Sleep(1000);

                Console.WriteLine("[SampleServer] Executing async Add - will return in 5 seconds...");
                ioCommand asyncAdd = new ioCommand("AsyncAdd");
                asyncAdd.Parameters.Add(10);
                asyncAdd.Parameters.Add(8);
                ioServer.Execute(asyncAdd);

                while (Console.KeyAvailable == false)
                {
                    Console.WriteLine("[SampleServer] Server Running...");
                    Thread.Sleep(1000);

                    ioCommand add = new ioCommand("Add");
                    add.Parameters.Add(7);
                    add.Parameters.Add(5);
                    ioServer.Execute(add);
                }
                ioCommand exit = new ioCommand("Exit");
                ioServer.Execute(exit);
            }
            Console.WriteLine("[SampleServer] Done. Press any key to exit.");
            Console.ReadLine();
        }
Beispiel #5
0
        /// <summary>
        /// Execute the given RPC in the client.
        /// </summary>
        /// <param name="command">The command received from the parent</param>
        /// <returns>The call result</returns>
        private ioResult Execute(ioCommand command)
        {
            Type       type;
            ioResult   result = new ioResult(command.Name);
            MethodInfo method;
            object     methodResult;

            try
            {
                // First check if this function exists inside the client
                type         = this.GetType();
                method       = type.GetMethod(command.Name);
                methodResult = method.Invoke(this, command.Parameters.ToArray());
                result.Data  = methodResult;
            }
            catch (Exception)
            {
                try
                {
                    // Then try the rpcHandler
                    // If the method doesn't exist on the handler, an exception is thrown.
                    type   = rpcHandler.GetType();
                    method = type.GetMethod(command.Name);
                    if (method == null)
                    {
                        throw new NotImplementedException(string.Format("Method '{0}' does not exist on the RPC Handler '{1}'", command.Name, rpcHandler.GetType().ToString()));
                    }
                    methodResult = method.Invoke(rpcHandler, command.Parameters.ToArray());
                    result.Data  = methodResult;
                }
                catch (Exception ex)
                {
                    result.ExceptionMessage = ex.Message;
                }
            }
            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Sends the command to subprocess to execute.
        /// </summary>
        /// <param name="command">The command to send</param>
        public void Execute(ioCommand command)
        {
            string commandXml = command.Serialize();

            Write(commandXml);
        }