예제 #1
0
        public static VersionedXmlBase ParseFromBase64(string base64)
        {
            if (string.IsNullOrEmpty(base64))
            {
                throw new CustomSerializationException(ServerStrings.ErrorInvalidConfigurationXml, new ArgumentNullException("base64"));
            }
            VersionedXmlBase result;

            using (MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(base64)))
            {
                result = VersionedXmlBase.Deserialize(memoryStream);
            }
            return(result);
        }
예제 #2
0
        public static VersionedXmlBase Parse(string xml)
        {
            if (string.IsNullOrEmpty(xml))
            {
                throw new CustomSerializationException(ServerStrings.ErrorInvalidConfigurationXml, new ArgumentNullException("xml"));
            }
            VersionedXmlBase result;

            using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                result = VersionedXmlBase.Deserialize(memoryStream);
            }
            return(result);
        }
예제 #3
0
        private static string GetXmlString(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            string @string;

            using (MemoryStream memoryStream = new MemoryStream())
            {
                VersionedXmlBase.Serialize(memoryStream, obj);
                memoryStream.Seek(0L, SeekOrigin.Begin);
                @string = Encoding.UTF8.GetString(memoryStream.ToArray());
            }
            return(@string);
        }
예제 #4
0
        private static string GetBase64XmlString(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            string result;

            using (MemoryStream memoryStream = new MemoryStream())
            {
                VersionedXmlBase.Serialize(memoryStream, obj);
                memoryStream.Seek(0L, SeekOrigin.Begin);
                result = Convert.ToBase64String(memoryStream.ToArray());
            }
            return(result);
        }
예제 #5
0
 internal static void Serialize(Stream stream, VersionedXmlBase obj)
 {
     if (stream == null)
     {
         throw new CustomSerializationException(ServerStrings.ErrorInvalidConfigurationXml, new ArgumentNullException("stream"));
     }
     if (obj == null)
     {
         throw new ArgumentNullException("obj");
     }
     VersionedXmlBase.Serialize(stream, obj);
     try
     {
         stream.SetLength(stream.Position);
     }
     catch (NotSupportedException)
     {
     }
 }
예제 #6
0
        internal static VersionedXmlBase Deserialize(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanSeek)
            {
                throw new ArgumentException("stream");
            }
            long position = stream.Position;
            XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();

            xmlReaderSettings.ConformanceLevel = ConformanceLevel.Auto;
            string  text    = null;
            Version version = null;

            using (XmlReader xmlReader = XmlReader.Create(stream, xmlReaderSettings))
            {
                while (xmlReader.Read())
                {
                    if (XmlNodeType.Element == xmlReader.NodeType)
                    {
                        text = xmlReader.Name;
                        string attribute = xmlReader.GetAttribute("Version");
                        if (!string.IsNullOrEmpty(attribute))
                        {
                            version = new Version(attribute);
                            break;
                        }
                        break;
                    }
                }
            }
            if (string.IsNullOrEmpty(text) || null == version)
            {
                return(null);
            }
            stream.Seek(position, SeekOrigin.Begin);
            return((VersionedXmlBase)VersionedXmlBase.Deserialize(VersionedXmlTypeFactory.GetTypeInstance(text, version), stream));
        }
예제 #7
0
 public string ToBase64String()
 {
     return(VersionedXmlBase.GetBase64XmlString(this));
 }
예제 #8
0
 public override string ToString()
 {
     return(VersionedXmlBase.GetXmlString(this));
 }