Exemplo n.º 1
0
        private static T CreateFromXml <T>(System.Xml.XmlReader reader) where T : IGenericRecord
        {
            // reader stays on "record"
            string recordType = reader.GetAttribute("type");

            IGenericRecord record = null;

            if (recordType == "moduleConfigParamRecord")
            {
                record = new MT.pHLab.SE.V1.moduleConfigParamRecord();
                record.ReadXml(reader);
            }

            if (record is T)
            {
                return((T)record);
            }
            else
            {
                try
                {
                    return((T)Convert.ChangeType(record, typeof(T)));
                }
                catch (InvalidCastException)
                {
                    return(default(T));
                }
            }
        }
Exemplo n.º 2
0
        public byte[] CreateTelegram(IGenericRecord record)
        {
            //Encoding utf8noBOM = new UTF8Encoding(false);
            //using (MemoryStream output = new MemoryStream())
            //{
            //    using (XmlWriter writer = XmlWriter.Create(output, settings))
            //    {
            //        writer.WriteStartDocument();
            //        writer.WriteStartElement("Colors");
            //        writer.WriteElementString("Color", "RED");
            //        writer.WriteEndDocument();
            //    }
            //    result = Encoding.Default.GetString(output.ToArray());
            //}
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent   = false;
            settings.Encoding = new UTF8Encoding(false);
            using (MemoryStream output = new MemoryStream())
            {
                //using (var xw = XmlTextWriter.Create(output, new UTF8Encoding(false)))
                using (var xw = XmlWriter.Create(output, settings))
                {
                    // Build Xml with xw.
                    WriteXml(record, xw);
                }
                return(output.ToArray());
            }
        }
Exemplo n.º 3
0
 public void WriteXml(IGenericRecord record, XmlWriter writer)
 {
     writer.WriteStartDocument();
     writer.WriteStartElement("Telegram");
     writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
     writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
     writer.WriteStartElement("Request");
     writer.WriteAttributeString("requestType", MapRequest(record.GetType()));
     writer.WriteAttributeString("requestId", RequestId.ToString());
     PDKXmlWriter.WriteRecord(record, writer);
     writer.WriteEndElement();
     writer.WriteEndDocument();
 }
Exemplo n.º 4
0
        static public IGenericRecord CreateFromXml(System.Xml.XmlReader reader)
        {
            // reader stays on "record"
            string recordType = reader.GetAttribute("type");

            IGenericRecord record = null;

            if (recordType == "moduleConfigParamRecord")
            {
                record = new MT.pHLab.SE.V1.moduleConfigParamRecord();
                record.ReadXml(reader);
            }

            return(record);
        }