/// <summary> /// Sends a request to the executor server. /// </summary> /// <typeparam name="ReturnType">The expected return type of the request.</typeparam> /// <param name="function">The requested operation.</param> /// <param name="args">The arguments for the operation.</param> /// <returns>The return result from the object as if it were executed locally.</returns> internal ReturnType SendRequest <ReturnType>(RemoteExecutorFunction function, params object[] args) { //Connect to the server object result = null; using (MemoryStream mStream = new MemoryStream()) { //Serialise the request new BinaryFormatter().Serialize(mStream, new RemoteExecutorRequest(function, args)); //Write the request to the pipe byte[] buffer = mStream.ToArray(); client.Write(buffer, 0, buffer.Length); //Read the response from the pipe mStream.Position = 0; buffer = new byte[65536]; client.ReadMode = PipeTransmissionMode.Message; do { int lastRead = client.Read(buffer, 0, buffer.Length); mStream.Write(buffer, 0, lastRead); }while (!client.IsMessageComplete); //Check if the server says there is a response. If so, read it. if (BitConverter.ToInt32(mStream.ToArray(), 0) == 1) { mStream.Position = 0; do { int lastRead = client.Read(buffer, 0, buffer.Length); mStream.Write(buffer, 0, lastRead); }while (!client.IsMessageComplete); //Deserialise the response mStream.Position = 0; if (mStream.Length > 0) { result = new BinaryFormatter().Deserialize(mStream); } } } return((ReturnType)result); }
/// <summary> /// Sends a request to the executor server. /// </summary> /// <typeparam name="ReturnType">The expected return type of the request.</typeparam> /// <param name="function">The requested operation.</param> /// <param name="args">The arguments for the operation.</param> /// <returns>The return result from the object as if it were executed locally.</returns> private ReturnType SendRequest <ReturnType>(RemoteExecutorFunction function, params object[] args) { RemoteExecutorClient client = (RemoteExecutorClient)Owner; return(client.SendRequest <ReturnType>(function, args)); }
/// <summary> /// Constructor. /// </summary> /// <param name="func">The function this command is wanting to execute.</param> /// <param name="data">The parameters for the command, serialised using a /// BinaryFormatter</param> public RemoteExecutorRequest(RemoteExecutorFunction func, params object[] data) { Func = func; Data = data; }