/// <summary> /// Initiates a new instance of Message /// </summary> /// <param name="source">Module which generated the message</param> /// <param name="destination">Module to which this message will be sent</param> /// <param name="response">Response sent</param> /// <param name="param">Param sent</param> /// <param name="id">id of the message</param> /// <param name="success">Value that indicates if the command was executed successfully</param> public Response(IModuleClient source, IModuleClient destination, string response, string param, bool success, int id) : base() { this.source = source; this.destination = destination; this.command = response; this.parameters = param; this.id = id; if (this.success = success) failReason = ResponseFailReason.None; else failReason = ResponseFailReason.Unknown; this.arrivalTime = DateTime.Now; if ((destination != null) && (source.Parent != destination.Parent)) throw new Exception("Source and destination modules does not belong to the same blackboard"); this.prototype = source.Prototypes[response]; // Check if response matchs a prototype if (this.prototype.ParamsRequired && ((param == null) || (param.Length < 1))) throw new Exception("Invalid string. The Response requires parameters"); }
/// <summary> /// Creates a response from a command data /// </summary> /// <param name="command">The command to use as base for the response</param> /// <param name="failReason">the reason for which command has failed</param> /// <returns>A generic response for the command with same parameters</returns> public static Response CreateFromCommand(Command command, ResponseFailReason failReason) { Response response = new Response(); response.commandResponded = command; response.source = command.Destination; response.destination = command.Source; response.command = command.Command; response.parameters = command.Parameters; response.id = command.Id; response.failReason = failReason; response.success = (failReason == ResponseFailReason.None); response.prototype = command.Prototype; if (command.SentTime >= DateTime.Now) response.arrivalTime = command.SentTime.AddMilliseconds(5); response.arrivalTime = DateTime.Now; return response; }