/// <summary> /// Parses a received message /// </summary> /// <param name="message">String received</param> protected override void Parse(ITextMessage message) { if (message is ITextCommand) { ITextCommand cmd = (ITextCommand)message; OnCommandReceived(new Command(this, cmd.Command, cmd.Parameters, cmd.Id)); } else if (message is ITextResponse) { ITextResponse rsp = (ITextResponse)message; OnResponseReceived(new Response(this, rsp.Command, rsp.Parameters, rsp.Success, rsp.Id)); } }
/// <summary> /// Synchronusly sends a command response to the module /// </summary> /// <param name="response">Response to send</param> /// <returns>true if the response has been sent, false otherwise</returns> public override bool Send(ITextResponse response) { // Check if this module is the destination module for the response if (this != response.Destination) { throw new Exception("Response marked to be sent through other module"); } // Simulation mode #region Simulation Mode if (simOptions != ModuleSimulationOptions.SimulationDisabled) { return(true); } #endregion return(true); }
/// <summary> /// Synchronusly sends a command response to the module /// </summary> /// <param name="response">Response to send</param> /// <returns>true if the response has been sent, false otherwise</returns> public override bool Send(ITextResponse response) { // Check if this module is the destination module for the response if (this != response.Destination) throw new Exception("Response marked to be sent through other module"); // Simulation mode #region Simulation Mode if (simOptions != ModuleSimulationOptions.SimulationDisabled) { return true; } #endregion return true; }
/// <summary> /// Asignates the provided Response as Response for the current Command and this Command as CommandResponded for the provided response. /// After asignation the Response is sent to its Destination module which must match this Command Source module /// </summary> /// <param name="response">Response to asign</param> /// <returns>true if response was asigned and sent successfully, false otherwise</returns> public bool SendResponse(ITextResponse response) { if (response is Response) return SendResponse((Response)response); return false; }
/// <summary> /// Gets a value indicating if provided Response is a response for current command /// </summary> /// <param name="response">Response to check</param> /// <returns>true if provided Response is a response for command, false otherwise</returns> public bool IsMatch(ITextResponse response) { // This one is if the response destination is known if (response.Destination != null) { //bool matchId = ((this.Id != -1) && (response.Id != -1)) ? (this.Id == response.Id) : true; return (this.Source == response.Destination) && (this.Destination == response.Source) && (this.Command == response.Command) //&& matchId && (this.SentTime <= response.ArrivalTime); } // This one is for search for an adequate command-response match return false; }
private void module_ResponseReceived(IModuleClient sender, ITextResponse r) { Response rsp = r as Response; if (rsp == null) return; // A response has been received so it is stored lock (responses) { responses.Add(rsp); } if(sender == virtualModule) Log.WriteLine(6, "<- [" + r.Source.Name + "]: " + r.ToString()); else Log.WriteLine(5, "<- [" + r.Source.Name + "]: " + r.ToString()); }
private void ModuleClient_ResponseReceived(IModuleClient sender, ITextResponse r) { base.ProduceData(r); }
/// <summary> /// Synchronusly sends a command response to the module /// </summary> /// <param name="response">Response to send</param> /// <returns>true if the response has been sent, false otherwise</returns> public virtual bool Send(ITextResponse response) { if (response is Response) return Send((Response)response); return false; }
private void blackboard_ResponseRedirected(ITextCommand command, ITextResponse response, bool sendResponseSuccess) { try { if (this.InvokeRequired) { if (!this.IsHandleCreated || this.Disposing || this.IsDisposed) return; this.BeginInvoke(dlgBlackboardResponseRedirected, command, response, sendResponseSuccess); return; } if (command == null) return; //if ((command.Response == null) && (response != null)) //command.Response = null; dispatchedCommands.Add(command); AddRedirectionListItem(command, response); } catch { } }
private ListViewItem CreateRedirectionListItem(ITextCommand command, ITextResponse response) { ListViewItem item; int index; if (command == null) { item = new ListViewItem("#Corrupt#"); item.SubItems.Add("#Corrupt#"); item.SubItems.Add("#Corrupt#"); item.SubItems.Add("#Corrupt#"); item.SubItems.Add("#Corrupt#"); item.SubItems.Add("#Corrupt#"); item.SubItems.Add("#Corrupt#"); item.SubItems.Add("#Unknown#"); item.BackColor = Color.Red; return item; } if ((response == null) && (command.Response != null)) response = command.Response; item = new ListViewItem(command.ToString()); index = lvwRedirectionHistory.Items.Count; item.Tag = command; if (response != null) item.SubItems.Add(response.ToString()); else item.SubItems.Add("#Corrupt#"); item.SubItems.Add(command.Source.Name); item.SubItems.Add(command.Destination.Name); item.SubItems.Add(command.SentTime.ToString()); if (response != null) { item.SubItems.Add(response.ArrivalTime.ToString()); item.SubItems.Add(response.FailReason.ToString()); item.SubItems.Add((response.SentStatus == SentStatus.SentSuccessfull ? "Yes" : "No")); if (response.FailReason == ResponseFailReason.ExecutedButNotSucceded) { if (index % 2 == 0) item.BackColor = Color.Lime; else item.BackColor = Color.LightGreen; } else if (response.SentStatus != SentStatus.SentSuccessfull) { if (index % 2 == 0) item.BackColor = Color.LightYellow; else item.BackColor = Color.LightGoldenrodYellow; } else if (response.FailReason != ResponseFailReason.None) { if (index % 2 == 0) item.BackColor = Color.LightPink; else item.BackColor = Color.LightSalmon; } else { if (index % 2 == 0) item.BackColor = Color.White; else item.BackColor = Color.WhiteSmoke; } } else { item.SubItems.Add("#Corrupt#"); item.SubItems.Add("#Corrupt#"); item.SubItems.Add("#Unknown#"); } return item; }
private void AddRedirectionListItem(ITextCommand command, ITextResponse response) { if (this.InvokeRequired) { if (!IsHandleCreated || IsDisposed || Disposing) return; this.BeginInvoke(dlgAddRedirectionListItem, command, response); return; } lvwRedirectionHistory.Items.Add(CreateRedirectionListItem(command, response)); lvwRedirectionHistory.Refresh(); }