internal void AddReply(BroadCastReply reply) { this._repliesList.Add(reply, null, null, null); try { this._repliesTable.Add(reply.ReplyIDName, reply); } catch (Exception) { } }
public void Button2_Click(System.Object sender, System.EventArgs e) { try { this.Cursor = Cursors.WaitCursor; this.txtREsult.Text = ""; this.txtReceivedReplies.Text = ""; this.txtDataREpliedAsXML.Text = ""; this.lstDataReplied.Items.Clear(); if (this.txtBroadCastIDName.Text.Length <= 0) { throw (new Exception("No broad cast id specified")); } Data data = default(Data); data = this.CfDataManagerContainer1.SelectedData; if (data == null) { throw (new Exception("No available data to bro")); } BroadCastRepliesContainer broadCastRepliesReceived = default(BroadCastRepliesContainer); int timeout = (int)this.nudTimeOut.Value; broadCastRepliesReceived = this._client.BroadCastDataAndWaitSeveralRepliesWithinTimeIntervall(this.txtBroadCastIDName.Text, data.DataName, System.Convert.ToString(data.data), timeout); //print the replies received if (broadCastRepliesReceived.Count > 0) { BroadCastReply reply = default(BroadCastReply); IEnumerator enumm = broadCastRepliesReceived.GetEnumerator(); while (enumm.MoveNext()) { reply = (CommunicationsLibrary.Services.BroadCasting.Data.BroadCastReply)enumm.Current; this.lstDataReplied.Items.Add(reply); } } this.txtReceivedReplies.Text = System.Convert.ToString(broadCastRepliesReceived.Count); if (chkCheckReplyIDName.Checked && this.txtReplyIDName.Text.Length > 0) { if (broadCastRepliesReceived.ContainsReplyIDName(this.txtReplyIDName.Text)) { this.txtREsult.Text = "It contains the Reply"; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.Cursor = Cursors.Default; } }
public void lstDataReplied_SelectedIndexChanged(System.Object sender, System.EventArgs e) { try { if (this.lstDataReplied.SelectedIndex >= 0) { BroadCastReply reply = (BroadCastReply)this.lstDataReplied.SelectedItem; this.CfDataDisplayCtrl1.ShowData(reply.Value); this.txtDataREpliedAsXML.Text = reply.XMLDataString; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
internal static BroadCastReply ParseAndGet_BroadCastReply_FromXMLDataString(string XMLString) { System.IO.StringReader sr = null; System.Xml.XmlTextReader m_xmlr = null; BroadCastReply parsedBroadCartReplyfromXMLString = default(BroadCastReply); try { sr = new System.IO.StringReader(XMLString); m_xmlr = new System.Xml.XmlTextReader(sr); m_xmlr.WhitespaceHandling = System.Xml.WhitespaceHandling.None; } catch (System.Xml.XmlException) { string msg; msg = "Error trying to get XML format from Broad Cast Reply data string [" + XMLString + "]"; } catch (Exception ex) { string msg = ""; msg = "Error trying to parse Broad Cast Reply XML string : " + ex.Message; throw (new Exception(msg)); } m_xmlr.Read(); string HeaderIdentifier = m_xmlr.Name; if (HeaderIdentifier != "BROADCAST_REPLY") { throw (new System.Xml.XmlException("Invalid data socket header " + HeaderIdentifier + ". Must be \'BROADCAST_REPLY\'")); } else { string replyIDName = ""; replyIDName = m_xmlr.GetAttribute("replyIDName"); if (replyIDName == null) { throw (new Exception("Invalid XML string for a BroadCastReply, the attribute replyIDName is missing. CanĀ“t parse the string")); } string dataXMLString = ""; dataXMLString = m_xmlr.ReadInnerXml(); DataVariable var = default(DataVariable); var = XMLDataFormatting.RetrieveDataVariableFromXMLString(dataXMLString); parsedBroadCartReplyfromXMLString = new BroadCastReply(replyIDName, System.Convert.ToString(var.Name), var.Data); } return(parsedBroadCartReplyfromXMLString); }
public void SendReplyToBroadcaster(BroadCastReply replyData) { try { switch (this._mode) { case BroadCastMode.BroadCasterIsNotWaitingReply: throw (new Exception("Can\'t send a reply to Broad Caster because it distributed without waiting a reply from listeners")); case BroadCastMode.BroadCasterIsWaitingReply: string host = this._broadCastableData.BroadCasterInformation.Host; int listeningTCPPortNumber = this.BroadCastedData.BroadCasterInformation.ReplyListeningPort; TcpClient _tcpClient = new TcpClient(host, listeningTCPPortNumber); NetworkStream stream = _tcpClient.GetStream(); //transforms the replyw response objetct from its xml representation into byte byte[] handlerAsByte = replyData.Serialize(); //sends the data to the broad cast listener client stream.Write(handlerAsByte, 0, handlerAsByte.Length); stream.Close(); _tcpClient.Close(); break; case BroadCastMode.undefined: throw (new Exception("Can\'t send a reply to Broad Caster because of a undefined behavior")); default: throw (new Exception("Can\'t send a reply to Broad Caster because of a undefined behavior")); } } catch (Exception ex) { string msg = "Error sending a broad cast reply to broad caster : [" + ex.Message + "]"; throw (new Exception(msg)); } }
private void SendBroadCastReply(DataBroadCastHandler handler) { if (this.chkReplyToBroadcaster.Checked) { switch (handler.BroadcastingMode) { case DataBroadCastHandler.BroadCastMode.BroadCasterIsNotWaitingReply: break; case DataBroadCastHandler.BroadCastMode.BroadCasterIsWaitingReply: if (this.CfDataManagerContainer1.DataCount > 0) { Data dat = this.GetAvailableSelectedData(this.CfDataManagerContainer1); if (dat != null) { BroadCastReply reply = default(BroadCastReply); string dataType = dat.data.GetType().ToString(); switch (dataType) { case "System.String": reply = new BroadCastReply(this.txtReplayNameID.Text, dat.DataName, System.Convert.ToString(dat.data)); break; case "System.Int32": reply = new BroadCastReply(this.txtReplayNameID.Text, dat.DataName, System.Convert.ToInt32(dat.data)); break; case "System.Decimal": reply = new BroadCastReply(this.txtReplayNameID.Text, dat.DataName, System.Convert.ToDecimal(dat.data)); break; case "System.Boolean": reply = new BroadCastReply(this.txtReplayNameID.Text, dat.DataName, System.Convert.ToBoolean(dat.data)); break; case "System.Data.DataTable": reply = new BroadCastReply(this.txtReplayNameID.Text, dat.DataName, (DataTable)dat.data); break; case "UtilitiesLibrary.Data.CustomHashTable": reply = new BroadCastReply(this.txtReplayNameID.Text, dat.DataName, (CustomHashTable)dat.data); break; case "UtilitiesLibrary.Data.CustomList": reply = new BroadCastReply(this.txtReplayNameID.Text, dat.DataName, (CustomList)dat.data); break; case "UtilitiesLibrary.Data.CustomSortedList": reply = new BroadCastReply(this.txtReplayNameID.Text, dat.DataName, (CustomSortedList)dat.data); break; } handler.SendReplyToBroadcaster(reply); } else { throw new Exception("No data selected from Data List"); } } break; default: break; } } }
public Services.DiscoverableServiceHandling.Data.DiscoverableServiceDefinitionsContainer DiscoverServicesNumOfInstances(string ServiceNameToFind, int numberOfInstances) { Services.DiscoverableServiceHandling.Data.DiscoverableServiceDefinitionsContainer servicesFoundContainer = new Services.DiscoverableServiceHandling.Data.DiscoverableServiceDefinitionsContainer(); BroadCasting.Data.BroadCastRepliesContainer replies = default(BroadCasting.Data.BroadCastRepliesContainer); try { replies = this._DataBroadcastClient.BroadCastDataAndWaitSpecifiedNumberOfReplies(DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME_QUERY_BROADCAST_ID_NAME_STRING, DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME, ServiceNameToFind, numberOfInstances); IEnumerator enumm = replies.GetEnumerator(); BroadCastReply reply = default(BroadCastReply); while (enumm.MoveNext()) { reply = (BroadCastReply)enumm.Current; //evaluates if the reply contains the reply from the service searched if (reply.ReplyIDName == DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME_QUERY_REPLYIDNAME_STRING) { BroadCasting.Data.BroadCastReply STXSErviceReply = default(BroadCasting.Data.BroadCastReply); STXSErviceReply = reply; //evaluates for the service parameters table attached with the data name specified //by the constant SERVICE_PARAMETERS_TABLE if (STXSErviceReply.DataName == DiscoverableServiceHandlingOperativeDefs.SERVICE_PARAMETERS_TABLE) { CustomHashTable paramsTable = (CustomHashTable)STXSErviceReply.Value; DiscoverableServiceDefinitionParametersContainer serviceParams = new DiscoverableServiceDefinitionParametersContainer(paramsTable); DiscoverableServiceHandlingOperativeDefs.DiscoverableServiceDefinition serviceDEfiniton = new DiscoverableServiceHandlingOperativeDefs.DiscoverableServiceDefinition(); DiscoverableServiceParameter param = default(DiscoverableServiceParameter); //retrieves the service name from the parameters list //and removes it from the parameters list param = serviceParams.GetParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME); if (param == null) { throw (new DiscoverableServiceDefinitionHandlingException(ServiceNameToFind, DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME)); } serviceDEfiniton.ServiceName = param.Value; serviceParams.RemoveParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME); //retrieves the service id from the parameters table and removes it param = serviceParams.GetParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_ID); if (param == null) { throw (new DiscoverableServiceDefinitionHandlingException(ServiceNameToFind, DiscoverableServiceHandlingOperativeDefs.SERVICE_ID)); } serviceDEfiniton.ServiceIDString = param.Value; serviceParams.RemoveParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_ID); //retrieves the service operation mode param = serviceParams.GetParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_OPERATION_MODE); if (param == null) { throw (new DiscoverableServiceDefinitionHandlingException(ServiceNameToFind, DiscoverableServiceHandlingOperativeDefs.SERVICE_OPERATION_MODE)); } serviceDEfiniton.ServiceOperationMode = DiscoverableServiceHandlingOperativeDefs.GetServiceOperationModeFromString(param.Value); serviceParams.RemoveParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_OPERATION_MODE); serviceDEfiniton.ServiceParameters = serviceParams; servicesFoundContainer.AddDefinition(serviceDEfiniton); } } } return(servicesFoundContainer); } catch (Exception) { return(servicesFoundContainer); } }
private void broadcastDataReceived(Services.BroadCasting.Handling.DataBroadCastHandler broadcastDataReceptionHandler) { bool raiseTheSuccesfullQueryEvent = false; string serviceNameBeingLooking = "UNDEFINED"; this._clientQueriesReceived++; if (broadcastDataReceptionHandler.BroadcastingMode == Services.BroadCasting.Handling.DataBroadCastHandler.BroadCastMode.BroadCasterIsWaitingReply) { //evaluates if the received broadcast corresponds to a event to find a STX network service over the network if (broadcastDataReceptionHandler.broadcastIDName == DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME_QUERY_BROADCAST_ID_NAME_STRING) { //because the service name comes in the broadcasted data in the dataname evaluates //if the dataname received correspond to the estandard dataname defined to //retrieve the service name who is being lookig for a broadcast client if (broadcastDataReceptionHandler.BroadCastedData.DataName == DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME) { serviceNameBeingLooking = System.Convert.ToString(broadcastDataReceptionHandler.BroadCastedData.Value); serviceNameBeingLooking = serviceNameBeingLooking.ToUpper(); //operation to evaluate if the service being looked corresponds to the service //name defined within the handler if (this.ServiceName == serviceNameBeingLooking) { //the local service corresponds to the query, so the handler replyes // the service parameters list to the broadcaster try { BroadCastReply serviceReply = new BroadCastReply(DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME_QUERY_REPLYIDNAME_STRING, DiscoverableServiceHandlingOperativeDefs.SERVICE_PARAMETERS_TABLE, this._serviceParameters.ParametersTable); broadcastDataReceptionHandler.SendReplyToBroadcaster(serviceReply); raiseTheSuccesfullQueryEvent = true; this._succesfullQueriesResulted++; } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } } } } } else { //save the error that the object can respond to a reply from the broadcast client } try { if (STXServiceQueryReceivedEvent != null) { STXServiceQueryReceivedEvent(serviceNameBeingLooking, broadcastDataReceptionHandler.BroadCastedData.BroadCasterInformation.BroadcasterName, broadcastDataReceptionHandler.BroadCastedData.BroadCasterInformation.Host); } } catch (Exception) { } if (raiseTheSuccesfullQueryEvent) { try { if (STXServiceSuccesfullQueryResultEvent != null) { STXServiceSuccesfullQueryResultEvent(serviceNameBeingLooking, broadcastDataReceptionHandler.BroadCastedData.BroadCasterInformation.BroadcasterName, broadcastDataReceptionHandler.BroadCastedData.BroadCasterInformation.Host); } } catch (Exception) { } } }