Ejemplo n.º 1
0
        public string Main(string str, params string[] args)
        {
            string str2 = string.Empty;

            if (!string.IsNullOrWhiteSpace(str))
            {
                using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(str)))
                {
                    using (XmlReader reader = new XmlFastInfosetReader(stream, FastInfosetCompression.GZip))
                    {
                        reader.MoveToElement();
                        bool flag = reader.Read();
                        while (flag && (reader.NodeType != XmlNodeType.Element))
                        {
                            flag = reader.Read();
                        }
                        if (flag)
                        {
                            str2 = reader.ReadOuterXml();
                        }
                    }
                }
            }
            return(str2);
        }
Ejemplo n.º 2
0
        //Deserialize from FastInfoset to DOM
        public static XmlDocument XMLDeSerialize(MemoryStream ms)
        {
            XmlDocument doc = new XmlDocument();

            if (ms.CanSeek)
            {
                ms.Position = 0;
            }
            using (XmlReader reader = XmlFastInfosetReader.Create(ms))
            {
                try
                {
                    doc.Load(reader);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("Error deserializing to XMLDocument" + ex.ToString());
                    return(null);
                }
            }
            return(doc);
        }
Ejemplo n.º 3
0
        public static MemoryStream DeSerialize(MemoryStream ms)
        {
            if (ms == null || ms.Length == 0)
            {
                throw new ArgumentNullException("ms");
            }

            ms.Seek(0, SeekOrigin.Begin);

            //Log the response before deserializing for debugging.
            bool needPrintMsg = false;

            if (null != CarConfigurationManager.AppSetting("NeedPrintResponseBeforeDeserialize"))
            {
                needPrintMsg = Boolean.Parse(CarConfigurationManager.AppSetting("NeedPrintResponseBeforeDeserialize"));
            }
            if (needPrintMsg)
            {
                Console.WriteLine(TransferTypeUtil.ObjToStr(ms));
            }

            XmlDocument doc = new XmlDocument();

            using (XmlReader reader = XmlFastInfosetReader.Create(ms))
            {
                doc.Load(reader);
            }

            //TODO: below handling is just to unblock testing, need to delete later to defect the DateTime handling bug
            //Delete the time in MinDate and MaxDate to unblock testing
            XmlNodeList minDateNodeList = doc.GetElementsByTagName("ns2:MinDate");
            XmlNodeList maxDateNodeList = doc.GetElementsByTagName("ns2:MaxDate");

            if (null != minDateNodeList && minDateNodeList.Count > 0)
            {
                foreach (XmlNode minDateNode in minDateNodeList)
                {
                    minDateNode.InnerText = minDateNode.InnerText.Substring(0, 10);
                }
            }
            if (null != maxDateNodeList && maxDateNodeList.Count > 0)
            {
                foreach (XmlNode maxDateNode in maxDateNodeList)
                {
                    maxDateNode.InnerText = maxDateNode.InnerText.Substring(0, 10);
                }
            }
            //Update 24:00 to 23:59 to unblock testing
            XmlNodeList minTimeNodeList = doc.GetElementsByTagName("ns2:MinTime");
            XmlNodeList maxTimeNodeList = doc.GetElementsByTagName("ns2:MaxTime");

            if (null != maxTimeNodeList && maxTimeNodeList.Count > 0)
            {
                foreach (XmlNode maxTimeNode in maxTimeNodeList)
                {
                    string maxTime = maxTimeNode.InnerText;
                    maxTime = maxTime.Replace("24:00", "23:59");
                    maxTimeNode.InnerText = maxTime;
                }
            }
            if (null != minTimeNodeList && minTimeNodeList.Count > 0)
            {
                foreach (XmlNode minTimeNode in minTimeNodeList)
                {
                    string minTime = minTimeNode.InnerText;
                    minTime = minTime.Replace("24:00", "23:59");
                    minTimeNode.InnerText = minTime;
                }
            }


            MemoryStream msDeserialized = new MemoryStream();

            using (XmlWriter writer = XmlWriter.Create(msDeserialized))
            {
                doc.WriteContentTo(writer);
                writer.Flush();
                writer.Close();
            }

            msDeserialized.Seek(0L, SeekOrigin.Begin);
            return(msDeserialized);
        }