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); }
internal static P2PData ParseAndGet_P2PData_FromXMLDataString(string XMLString) { System.IO.StringReader sr = null; System.Xml.XmlTextReader m_xmlr = null; 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 P2P Data string [" + XMLString + "]"; } catch (Exception ex) { string msg = ""; msg = "Error trying to parse P2P socket XML string : " + ex.Message; throw (new Exception(msg)); } m_xmlr.Read(); string HeaderIdentifier = m_xmlr.Name; if (HeaderIdentifier != "P2P_DATA") { throw (new System.Xml.XmlException("Invalid P2P data header " + HeaderIdentifier + ". Must be \'P2P_DATA\'")); } else { //********************************************************** //retrieves the data operation type //********************************************************** string operationID = ""; operationID = m_xmlr.GetAttribute("P2PDataOperationID"); if (operationID == null) { operationID = Guid.NewGuid().ToString(); } //********************************************************** //retrieves the data itself //********************************************************** m_xmlr.Read(); string dataSectionName = m_xmlr.Name; DataVariable variable = default(DataVariable); if (dataSectionName == "DATA") { string variableXMLstring = m_xmlr.ReadOuterXml(); variable = XMLDataFormatting.RetrieveDataVariableFromXMLString(variableXMLstring); } else { throw (new Exception("Invalid data XML section name \'" + dataSectionName + "\'. Is expected to be \'DATA\'")); } //********************************************************** //retrieves the attributes table and its XML attributes //********************************************************** string dataAttributesSectionName = m_xmlr.Name; P2PDataAttributesTable attrTAble = null; int AttrCount = 0; if (dataAttributesSectionName == "DATA_ATTRIBUTES") { string attributesCount = m_xmlr.GetAttribute("DataAttrCount"); if (!(attributesCount == null)) { AttrCount = System.Convert.ToInt32(attributesCount); if (AttrCount > 0) { string attrTableXMLString = m_xmlr.ReadInnerXml(); DataVariable tableVar = default(DataVariable); tableVar = XMLDataFormatting.RetrieveDataVariableFromXMLString(attrTableXMLString); attrTAble = new P2PDataAttributesTable((CustomHashTable)tableVar.Data); } } else { throw (new Exception("The parameter \'AttrCount\' is missing on the XML string in te section \'DATA_ATTRIBUTES\'")); } } else { throw (new Exception("Invalid data attributes XML section name \'" + dataSectionName + "\'. Is expected to be \'DATA_ATTRIBUTES\'")); } P2PData data = default(P2PData); data = new P2PData(operationID, System.Convert.ToString(variable.Name), variable.Data); if (AttrCount > 0) { data.AttachAttributesTable(attrTAble); } return(data); } }
internal static P2PDataRequest ParseAndGet_P2PDataRequest_FromXMLDataString(string XMLString) { System.IO.StringReader sr = null; System.Xml.XmlTextReader m_xmlr = null; 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 P2PDataRequest Data string [" + XMLString + "]"; } catch (Exception ex) { string msg = ""; msg = "Error trying to parse P2PDataRequest XML string : " + ex.Message; throw (new Exception(msg)); } m_xmlr.Read(); string HeaderIdentifier = m_xmlr.Name; if (HeaderIdentifier != "P2P_DATAREQUEST") { throw (new System.Xml.XmlException("Invalid P2PDataRequest header " + HeaderIdentifier + ". Must be \'P2P_DATAREQUEST\'")); } else { string datanameToRequest = m_xmlr.GetAttribute("datanameToRequest"); if (datanameToRequest == null) { throw (new Exception("No dataname to retrieve attribute found in the P2PDataRequest XML String")); } m_xmlr.Read(); string AttributesSectionName = m_xmlr.Name; if (AttributesSectionName != "DATA_REQUEST_PARAMETERS") { throw (new Exception("Invalid section name \'" + AttributesSectionName + "\'")); } string parametersCountStr = m_xmlr.GetAttribute("ParametersCount"); int numOfParameters = 0; CustomHashTable parametersTable = null; if (!(parametersCountStr == null)) { numOfParameters = System.Convert.ToInt32(parametersCountStr); if (numOfParameters > 0) { string attrTableXMLString = m_xmlr.ReadInnerXml(); DataVariable tableVar = default(DataVariable); tableVar = XMLDataFormatting.RetrieveDataVariableFromXMLString(attrTableXMLString); parametersTable = (CustomHashTable)tableVar.Data; } } else { throw (new Exception("The parameter \'AttrCount\' is missing on the XML string of the section \'REQUEST_ATTRIBUTES\'")); } P2PDataRequest dataRq = default(P2PDataRequest); if (numOfParameters > 0) { if (!(parametersTable == null)) { dataRq = new P2PDataRequest(datanameToRequest, parametersTable); } else { dataRq = new P2PDataRequest(datanameToRequest); } } else { dataRq = new P2PDataRequest(datanameToRequest); } return(dataRq); } }
public static SocketData ParseAndGet_SocketData_FromXMLDataString(string XMLString) { System.IO.StringReader sr = null; System.Xml.XmlTextReader m_xmlr = null; 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 data socket data string [" + XMLString + "]"; } catch (Exception ex) { string msg = ""; msg = "Error trying to parse data socket XML string : " + ex.Message; throw (new Exception(msg)); } m_xmlr.Read(); string HeaderIdentifier = m_xmlr.Name; if (HeaderIdentifier != "SD") { throw (new System.Xml.XmlException("Invalid data socket header " + HeaderIdentifier + ". Must be \'SD\'")); } else { //********************************************************** //retrieves the data transported on the XML //********************************************************** m_xmlr.Read(); string dataSectionName = m_xmlr.Name; DataVariable variable = default(DataVariable); if (dataSectionName == "DATA") { string variableXMLstring = m_xmlr.ReadOuterXml(); variable = XMLDataFormatting.RetrieveDataVariableFromXMLString(variableXMLstring); } else { throw (new Exception("Invalid data XML section name \'" + dataSectionName + "\'. Is expected to be \'DATA\'")); } //********************************************************** //retrieves the attributes table and its XML attributes //********************************************************** string dataAttributesSectionName = m_xmlr.Name; AttributesTable attributesTable = null; int AttrCount = 0; if (dataAttributesSectionName == "SDAS") { string attributesCount = m_xmlr.GetAttribute("cn"); if (!(attributesCount == null)) { AttrCount = System.Convert.ToInt32(attributesCount); if (AttrCount > 0) { string attrTableXMLString = m_xmlr.ReadInnerXml(); DataVariable tableVar = default(DataVariable); tableVar = XMLDataFormatting.RetrieveDataVariableFromXMLString(attrTableXMLString); CustomHashTable table = default(CustomHashTable); table = (CustomHashTable)tableVar.Data; attributesTable = new AttributesTable(table); } } else { throw (new Exception("The parameter \'cn\' is missing on the XML string in te section \'SDAS\'")); } } else { throw (new Exception("Invalid data attributes XML section name \'" + dataSectionName + "\'. Is expected to be \'SD_ATTRS\'")); } SocketData data = default(SocketData); data = new SocketData(System.Convert.ToString(variable.Name), variable.Data); if (AttrCount > 0) { data.AttachAttributesTable(attributesTable); } return(data); } }
internal static P2PDataDeliveryResult ParseAndGet_P2PDataDeliveryResult_FromXMLDataString(string XMLString) { System.IO.StringReader sr = null; System.Xml.XmlTextReader m_xmlr = null; 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 P2P Data string [" + XMLString + "]"; } catch (Exception ex) { string msg = ""; msg = "Error trying to parse P2P socket XML string : " + ex.Message; throw (new Exception(msg)); } m_xmlr.Read(); string HeaderIdentifier = m_xmlr.Name; if (HeaderIdentifier != "P2P_DATA_DELIVERY_RESULT") { throw (new System.Xml.XmlException("Invalid data header " + HeaderIdentifier + ". It was expected to be \'P2P_DATA_DELIVERY_RESULT\'")); } else { //********************************************************** //retrieves the data operation type //********************************************************** string P2PDataOperationID = ""; P2PDataOperationID = m_xmlr.GetAttribute("P2PDataOperationID"); if (P2PDataOperationID == null) { P2PDataOperationID = Guid.NewGuid().ToString(); } string DeliveryResultType = ""; DeliveryResultType = m_xmlr.GetAttribute("DeliveryResultType"); if (DeliveryResultType == null) { DeliveryResultType = "DeliverySucceed"; } //********************************************************** //retrieves the data itself //********************************************************** m_xmlr.Read(); string dataSectionName = m_xmlr.Name; DataVariable variable; if (dataSectionName == "DATA") { string variableXMLstring = m_xmlr.ReadOuterXml(); variable = XMLDataFormatting.RetrieveDataVariableFromXMLString(variableXMLstring); } else { throw (new Exception("Invalid data XML section name \'" + dataSectionName + "\'. Is expected to be \'DATA\'")); } string errorMEssage = System.Convert.ToString(variable.Data); P2PDataDeliveryResult result = null; switch (DeliveryResultType) { case "DeliveryFailure": result = P2PDataDeliveryResult.GetFailureDeliveryResult(P2PDataOperationID, errorMEssage); break; case "DeliverySucceed": result = P2PDataDeliveryResult.GetSucceedDeliveryResult(P2PDataOperationID); break; } return(result); } }
private void EventHandling_readTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //***************************************************************************** // STOPS THE TIMER //***************************************************************************** this._readTimer.Stop(); try { if (this._isFirstTimeRead) { //retrieves the server datetime to retrieve the data using datetime this._lastReadDatetime = this.GetPublicationsServerDAtetime(); this.dateAsstring = NowToStandardODBCStringFormat(this._lastReadDatetime); this._dataReadCommandTest = "Select * from " + this._tablename + " where datetime >= \'" + dateAsstring + "\' order by [datetime] asc"; this._isFirstTimeRead = false; } else { if (this._lastRowIDReaded > 0) { //uses the row id as to retrieve new data this._dataReadCommandTest = "Select * from " + this._tablename + " where rowID > " + System.Convert.ToString(this._lastRowIDReaded) + " order by [rowID] asc"; } else { //uses the datetime as to retrieve new data this.dateAsstring = NowToStandardODBCStringFormat(this._lastReadDatetime); this._dataReadCommandTest = "Select * from " + this._tablename + " where datetime >= \'" + dateAsstring + "\' order by [datetime] asc"; } } using (System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(this._dataBaseSonnectionString)) { try { cnn.Open(); using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand()) { cmd.Connection = cnn; //************************************************************ //PREPARES THE QUERY TO THE PUBLICATION //************************************************************ cmd.CommandText = this._dataReadCommandTest; using (System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter()) { da.SelectCommand = cmd; using (DataTable dt = new DataTable()) { //****************************************** // RETRIEVS THE DATA FROM DATA SOURCE da.Fill(dt); //****************************************** //************************************************************ //DATA TREATMENT if (dt.Rows.Count > 0) { DataRow row = default(DataRow); IEnumerator enumm = dt.Rows.GetEnumerator(); while (enumm.MoveNext()) { row = (DataRow )enumm.Current; //***************************************************** // transfors the row into a data update or data reset //***************************************************** try { long _rowID; string _dataType = ""; string _value = ""; string _dataName = ""; DateTime _dataDatetime = System.Convert.ToDateTime(null); bool _isDataReset = false; string _attributesTAble = ""; _rowID = (long)(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_ROWID]); _dataType = System.Convert.ToString(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_DATA_TYPE]); _value = System.Convert.ToString(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_VALUE]); _dataName = System.Convert.ToString(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_DATA_NAME]); _attributesTAble = System.Convert.ToString(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_ATTRIBUTES_TABLE]); try { _dataDatetime = System.Convert.ToDateTime(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_DATA_DATETIME]); } catch (Exception) { _dataDatetime = DateTime.Now; } _isDataReset = System.Convert.ToBoolean(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_IS_DATA_RESET]); //------------------------------------------------ if (!_isDataReset) { DPE_PublicationData data = default(DPE_PublicationData); data = DPE_GlobalDefinitions.GetPublicationValueFromString(this._publicationName, _dataName, _dataType, _value); AttributesTable attrTAble = default(AttributesTable); //------------------------------------------------ //verifies if there are a parameters table if (_attributesTAble.Length > 0) { DataVariable dataVar = XMLDataFormatting.RetrieveDataVariableFromXMLString(_attributesTAble); CustomHashTable table = (CustomHashTable)dataVar.Data; attrTAble = new AttributesTable(table); data.AttachAttibutesTable(attrTAble); } this._DATA_UPDATE_PCQ.Enqueue(data); } else { this._DATA_RESET_PCQ.Enqueue(_dataName); } } catch (Exception ex) { CustomEventLog.WriteEntry(ex); } } } //************************************************************ //************************************************************ //GETS THE LAST TABLE REFERENCE DATE TIME and ROWid FROM THE DATA IF IS AVAILABLE try { if (dt.Rows.Count > 0) { this.SetLastReadDateTiemeAndRowID(dt); } } catch (Exception) { } //************************************************************ } //----------- data table } //-------- SqlDataAdapter } //-------- SqlCommand } catch (System.Data.SqlClient.SqlException sqlex) { //overrides the error qhen if (sqlex.ErrorCode != -2146232060) { CustomEventLog.WriteEntry(sqlex); } } catch (Exception ex) { CustomEventLog.DisplayEvent(EventLogEntryType.Error, ex.ToString()); } finally { if (this._keepReading) { this._readTimer.Start(); } try { cnn.Close(); cnn.Dispose(); } catch (Exception) { } } } //------- sqlConnection } catch (Exception ex) { CustomEventLog.DisplayEvent(EventLogEntryType.Error, ex.ToString()); } }
internal static P2PDataRequestFailure ParseAndGet_P2PDataRequestFailure_FromXMLDataString(string XMLString) { System.IO.StringReader sr = null; System.Xml.XmlTextReader m_xmlr = null; 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 P2PDataRequest Data string [" + XMLString + "]"; } catch (Exception ex) { string msg = ""; msg = "Error trying to parse P2PDataRequest XML string : " + ex.Message; throw (new Exception(msg)); } m_xmlr.Read(); string HeaderIdentifier = m_xmlr.Name; if (HeaderIdentifier != "P2P_DATA_REQUEST_FAILURE") { throw (new System.Xml.XmlException("Invalid P2PDataRequestFailure header \'" + HeaderIdentifier + "\'. It was expected to be \'P2P_DATA_REQUEST_FAILURE\'")); } else { //********************************************************** //retrieves the data operation type //********************************************************** string P2PDataOperationID = ""; P2PDataOperationID = m_xmlr.GetAttribute("P2PDataOperationID"); if (P2PDataOperationID == null) { P2PDataOperationID = Guid.NewGuid().ToString(); } //********************************************************** //retrieves the data that holds the error message //********************************************************** m_xmlr.Read(); string dataSectionName = m_xmlr.Name; DataVariable variable = default(DataVariable); if (dataSectionName == "DATA") { string variableXMLstring = m_xmlr.ReadOuterXml(); variable = XMLDataFormatting.RetrieveDataVariableFromXMLString(variableXMLstring); } else { throw (new Exception("Invalid data XML section name \'" + dataSectionName + "\'. Is expected to be \'DATA\'")); } string errorMEssage = System.Convert.ToString(variable.Data); //creates the object to return to caller P2PDataRequestFailure reqFailure = new P2PDataRequestFailure(P2PDataOperationID, errorMEssage); return(reqFailure); } }
internal static BroadcastableData ParseAndGet_BroadcastableData_FromXMLDataString(string XMLDataString) { System.IO.StringReader sr = null; System.Xml.XmlTextReader m_xmlr = null; string broadCasterName = ""; string broadCasterHost = ""; int broadCasterListeningPort = 0; try { sr = new System.IO.StringReader(XMLDataString); 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 broadcasted data string [" + XMLDataString + "]"; } catch (Exception ex) { string msg = ""; msg = "Error trying to parse broadcasted XML string : " + ex.Message; throw (new Exception(msg)); } m_xmlr.Read(); string HeaderIdentifier = m_xmlr.Name; if (HeaderIdentifier != "BROADCASTED_DATA") { throw (new System.Xml.XmlException("Invalid data header " + HeaderIdentifier + ". Must be \'BROADCASTED_DATA\'")); } else { m_xmlr.Read(); string broadCasterHeader = m_xmlr.Name; if (broadCasterHeader != "BROADCASTER_INFO") { throw (new System.Xml.XmlException("Invalid XML structure was expected a <BROADCASTER_INFO> and was found " + broadCasterHeader)); } else { //******************************************************* //gets the data broadcaster information //******************************************************* broadCasterName = m_xmlr.GetAttribute("name"); if (broadCasterName == null) { throw (new Exception("Can\'t determine the attribute NAME of the section <BROADCASTER_INFO> from XML String [" + XMLDataString + "]")); } broadCasterHost = m_xmlr.GetAttribute("host"); if (broadCasterHost == null) { throw (new Exception("Can\'t determine the attribute HOST of the section <BROADCASTER_INFO> from XML String [" + XMLDataString + "]")); } string PORT = m_xmlr.GetAttribute("listeningPort"); if (PORT == null) { throw (new Exception("Can\'t determine the attribute LISTENINGPORT of the section <BROADCASTER_INFO> from XML String [" + XMLDataString + "]")); } broadCasterListeningPort = System.Convert.ToInt32(PORT); //******************************************************* //gets the data from the XML string //******************************************************* string dataValueAsString = ""; m_xmlr.Read(); m_xmlr.Read(); dataValueAsString = m_xmlr.ReadOuterXml(); DataVariable var = XMLDataFormatting.RetrieveDataVariableFromXMLString(dataValueAsString); BroadcastableData broadCastedData = new BroadcastableData(broadCasterName, broadCasterHost, broadCasterListeningPort, System.Convert.ToString(var.Name), var.Data); return(broadCastedData); } } }