Exemple #1
0
        public ActionResult CreateSiteMap(HttpContextBase httpContext, IEnumerable <SiteMapNodeModel> siteMapNodes)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }

            string baseUrl = baseUrlProvider.GetBaseUrl(httpContext);
            List <SiteMapNodeModel> nodeList = siteMapNodes != null?siteMapNodes.ToList() : new List <SiteMapNodeModel>();

            IEnumerable <XmlSerializerNamespaceModel> namespaces = xmlNamespaceProvider.GetNamespaces(nodeList);

            return(CreateSitemapInternal(baseUrl, nodeList, namespaces));
        }
Exemple #2
0
        private void SerializeToStream <T>(T data, Func <XmlWriterSettings, XmlWriter> createXmlWriter)
        {
            IXmlNamespaceProvider namespaceProvider = data as IXmlNamespaceProvider;
            IEnumerable <string>  namespaces        = namespaceProvider != null?namespaceProvider.GetNamespaces() : Enumerable.Empty <string>();

            XmlSerializerNamespaces xmlSerializerNamespaces = xmlNamespaceBuilder.Create(namespaces);

            var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));

            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings
            {
                Encoding          = Encoding.UTF8,
                NamespaceHandling = NamespaceHandling.OmitDuplicates
            };

            using (XmlWriter writer = createXmlWriter(xmlWriterSettings))
            {
                if (data is IHasStyleSheets)
                {
                    xmlProcessingInstructionHandler.AddStyleSheets(writer, data as IHasStyleSheets);
                }

                xmlSerializer.Serialize(writer, data, xmlSerializerNamespaces);
            }
        }
        public string Serialize <T>(T data)
        {
            IXmlNamespaceProvider namespaceProvider = data as IXmlNamespaceProvider;
            IEnumerable <string>  namespaces        = namespaceProvider != null?namespaceProvider.GetNamespaces() : Enumerable.Empty <string>();

            var xmlSerializerNamespaces = _xmlNamespaceBuilder.Create(namespaces);


            var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));

            using (MemoryStream memoryStream = new MemoryStream())
            {
                XmlWriterSettings xmlWriterSettings = new XmlWriterSettings
                {
                    Encoding          = Encoding.UTF8,
                    NamespaceHandling = NamespaceHandling.OmitDuplicates
                };

                using (XmlWriter writer = XmlWriter.Create(memoryStream, xmlWriterSettings))
                {
                    xmlSerializer.Serialize(writer, data, xmlSerializerNamespaces);
                    writer.Flush();
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    return(new StreamReader(memoryStream).ReadToEnd());
                }
            }
        }
        public void SerializeToStream <T>(T data, Stream stream)
        {
            IXmlNamespaceProvider namespaceProvider = data as IXmlNamespaceProvider;
            IEnumerable <string>  namespaces        = namespaceProvider != null?namespaceProvider.GetNamespaces() : Enumerable.Empty <string>();

            XmlSerializerNamespaces xmlSerializerNamespaces = _xmlNamespaceBuilder.Create(namespaces);

            var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));

            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings
            {
                Encoding          = Encoding.UTF8,
                NamespaceHandling = NamespaceHandling.OmitDuplicates
            };

            using (XmlWriter writer = XmlWriter.Create(stream, xmlWriterSettings))
            {
                xmlSerializer.Serialize(writer, data, xmlSerializerNamespaces);
            }
        }
Exemple #5
0
        private void SerializeToStream <T>(T data, Func <XmlWriterSettings, XmlWriter> createXmlWriter)
        {
            IEnumerable <string>  strs;
            IXmlNamespaceProvider xmlNamespaceProvider = (object)data as IXmlNamespaceProvider;

            strs = (xmlNamespaceProvider != null ? xmlNamespaceProvider.GetNamespaces() : Enumerable.Empty <string>());
            XmlSerializerNamespaces xmlSerializerNamespace = this._xmlNamespaceBuilder.Create(strs);

            System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
            using (XmlWriter xmlWriter = createXmlWriter(new XmlWriterSettings()
            {
                Encoding = Encoding.UTF8,
                NamespaceHandling = NamespaceHandling.OmitDuplicates
            }))
            {
                if ((object)data is IHasStyleSheets)
                {
                    this._xmlProcessingInstructionHandler.AddStyleSheets(xmlWriter, (object)data as IHasStyleSheets);
                }
                xmlSerializer.Serialize(xmlWriter, data, xmlSerializerNamespace);
            }
        }