/// <summary> /// Listen for new commands from the parent process. /// </summary> public void Listen() { isRunning = true; while (isRunning) { string parentInput = Console.ReadLine(); if (parentInput != string.Empty) { ioCommand command; if (ioCommand.TryParse(parentInput, out command)) { ioResult result = Execute(command); if (result != null) { string resultXml = result.Serialize(); if (result.ExceptionMessage != string.Empty) { WriteError(resultXml); } else { Write(resultXml); } } } } } }
public void ShouldSetData() { string dataTest = "testData"; ioResult result = new ioResult("testCommand", dataTest); object resultData = result.Data; Assert.That(resultData, Is.SameAs(dataTest)); }
public void ShouldSetCommandName() { string resultNameTest = "testCommand"; ioResult result = new ioResult(resultNameTest); string resultName = result.CommandName; Assert.That(resultName, Is.SameAs(resultNameTest)); }
/// <summary> /// Handles the async results. /// </summary> /// <param name="commandName">The command this the result for</param> /// <param name="asyncResult"></param> public void AsyncCallback(string commandName, object asyncResult) { ioResult result = new ioResult(commandName); result.Data = asyncResult; if (result != null) { string resultXml = result.Serialize(); if (result.ExceptionMessage != string.Empty) { WriteError(resultXml); } else { Write(resultXml); } } }
/// <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); }