private P2PData(string dataName, object data) { this._data = data; this._dataName = dataName.ToUpper(); this._dataAttributesTable = new P2PDataAttributesTable(); this._P2PDataOperationID = Guid.NewGuid().ToString(); }
private P2PData(string P2PDataOperationID, string dataName, object data) { this._data = data; this._dataName = dataName.ToUpper(); this._dataAttributesTable = new P2PDataAttributesTable(); this._P2PDataOperationID = P2PDataOperationID; }
public void AttachAttributesTable(P2PDataAttributesTable table) { this._dataAttributesTable = table; }
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); } }