Exemple #1
0
        public async ValueTask SerializeAsync(ISolderConfiguration document, TextWriter textWriter, CancellationToken cancellationToken = default)
        {
            XmlTextWriter xmlTextWriter;

            if ((object)document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if ((object)textWriter == null)
            {
                throw new ArgumentNullException(nameof(textWriter));
            }

            // DO NOT USE A USING BLOCK HERE (CALLER OWNS TEXTWRITER) !!!
            xmlTextWriter             = new XmlTextWriter(textWriter);
            xmlTextWriter.Formatting  = Formatting.Indented;
            xmlTextWriter.Indentation = 1;
            xmlTextWriter.IndentChar  = '\t';

            await this.SerializeAsync(document, xmlTextWriter, cancellationToken);

            await xmlTextWriter.FlushAsync();
        }
        public async Task GetOutput(HttpContext context, Stream outputStream, IEnumerable <Common.Model.ChargePoint> dataList, APIRequestParams settings)
        {
            XmlTextWriter xml = new XmlTextWriter(outputStream, Encoding.UTF8);

            //start xml document
            xml.WriteStartDocument();

            //output rss tags
            xml.WriteStartElement("rss");
            xml.WriteAttributeString("version", "2.0");

            if (EnableCarwingsMode)
            {
                xml.WriteAttributeString("xmlns", "carwings", "http://www.w3.org/2000/xmlns/", "http://www.nissan.co.jp/dtd/carwings.dtd");
            }
            if (EnableGeoRSS)
            {
                xml.WriteAttributeString("xmlns", "georss", "http://www.w3.org/2000/xmlns/", "http://www.georss.org/georss/10");
            }

            //output feed details
            xml.WriteStartElement("channel");
            xml.WriteElementString("title", "OpenChargeMap Charge Points");
            xml.WriteElementString("link", "https://openchargemap.org");
            xml.WriteElementString("description", "Charge Point data contributed by OpenChargeMap community");
            xml.WriteElementString("copyright", "openchargemap.org");

            //output feed items
            foreach (var item in dataList)
            {
                if (item.AddressInfo != null)
                {
                    xml.WriteStartElement("item");
                    xml.WriteStartElement("guid");
                    xml.WriteAttributeString("isPermaLink", "false");
                    xml.WriteString(item.UUID);
                    xml.WriteEndElement();

                    xml.WriteElementString("title", item.AddressInfo.Title);

                    if (EnableCarwingsMode)
                    {
                        xml.WriteElementString("carwings:readtitle", item.AddressInfo.Title);
                    }

                    string description = item.GetSummaryDescription(true);
                    string address     = item.GetAddressSummary(true);

                    xml.WriteElementString("description", description);

                    if (item.AddressInfo.RelatedURL != null)
                    {
                        xml.WriteElementString("link", item.AddressInfo.RelatedURL);
                    }

                    if (EnableCarwingsMode)
                    {
                        if (address != "")
                        {
                            xml.WriteElementString("carwings:address", address);
                        }
                        if (item.AddressInfo.ContactTelephone1 != null)
                        {
                            xml.WriteElementString("carwings:tel", item.AddressInfo.ContactTelephone1);
                        }
                        xml.WriteElementString("carwings:lat", item.AddressInfo.Latitude.ToString());
                        xml.WriteElementString("carwings:lon", item.AddressInfo.Longitude.ToString());
                    }

                    if (EnableGeoRSS)
                    {
                        xml.WriteElementString("georss:point", item.AddressInfo.Latitude.ToString() + " " + item.AddressInfo.Longitude.ToString());
                    }

                    xml.WriteEndElement();
                }
            }

            xml.WriteEndElement();  //end channel
            xml.WriteEndElement();  //end rss
            xml.WriteEndDocument(); //end xml
            await xml.FlushAsync();

            //xml.Close();

            #region example rss

            /*
             * <?xml version="1.0" encoding="UTF-8"?>
             * <rss version="2.0" xmlns:carwings="http://www.nissan.co.jp/dtd/carwings.dtd">
             * <channel>
             *  <title> WEB site update: NISSAN Topics </ title>
             *  <link> http://rss.nissan.co.jp/ </ link>
             *  <description> Nissan will deliver the latest information. </ Description>
             *  <language>en</ language>
             *  <copyright> Copyright NISSAN MOTOR CO., LTD. 2005 All Rights Reserved. </ copyright>
             *  <lastBuildDate> Wed, 25 Oct 2006 12:18:36 +0900 </ lastBuildDate>
             *  <docs> http://blogs.law.harvard.edu/tech/rss </ docs>
             *  <item>
             *      <title>update information</ title>
             *      <carwings:readtitle> Trail Jam update information </ carwings: readtitle>
             *      <description> X-TRAIL JAM IN TOKYO DOME general tickets on sale! ! </ Description>
             *      <carwings:readtext> Trail Jam Tokyo Dome tickets, general sale.</ Carwings: readtext>
             *      <Carwings:itemimage> http://eplus.jp/sys/web/irg/2006x-trail/images/topmain.jpg </ Carwings: Itemimage>
             *      <Carwings:data> <! [CDATA [
             *              TRAIL <body> <br> <img src="http://lab.nissan-carwings.com/CWC/images/x-trail.jpg"> </ body>
             *              ]]>
             *      </ Carwings: data>
             *      <carwings:lat> 35.70568 </ carwings: lat>
             *      <carwings:lon> 139.75187 </ carwings: lon>
             *      <link> http://blog.nissan.co.jp/X-TRAIL/?rss </ link>
             *      <guid> http://blog.nissan.co.jp/X-TRAIL/?rss </ guid>
             *      <Carwings:link> Http://Www.nissan.co.jp/Event/....../Coupon.html </ Carwings: Link>
             *      <category> content </ category>
             *      <pubDate> Mon, 16 Oct 2006 20:15:02 +0900 </ pubDate>
             *  </item>
             * </channel>
             * </rss>
             * */
            #endregion example rss
        }
        public async Task GetOutput(HttpContext context, System.IO.Stream outputStream, IEnumerable <Common.Model.ChargePoint> dataList, Common.APIRequestParams settings)
        {
            /*<Document>
             *    <Placemark>
             *      <name>Sacramento County Parking Garage</name>
             *      <description>1 SP Inductive  1 Avcon Conductive</description>
             *      <Point>
             *        <coordinates>-121.49610000,38.58460000</coordinates>
             *      </Point>
             *    </Placemark>
             *    <Placemark>
             *      <name>Sacramento City Public Parking Garage</name>
             *      <description>3 SP Inductive</description>
             *      <Point>
             *        <coordinates>-121.49382900,38.57830300</coordinates>
             *      </Point>
             *    </Placemark>
             * </Document>
             * */
            XmlTextWriter xml = new XmlTextWriter(outputStream, Encoding.UTF8);

            //start xml document
            xml.WriteStartDocument();
            if (this.SelectedKMLVersion == KMLVersion.V2)
            {
                xml.WriteStartElement("kml", "http://www.opengis.net/kml/2.2");
            }
            xml.WriteStartElement("Document");
            xml.WriteElementString("name", "Open Charge Map - Electric Vehicle Charging Locations");
            xml.WriteElementString("description", "Data from https://openchargemap.org/");
            foreach (var item in dataList)
            {
                if (item.AddressInfo != null)
                {
                    xml.WriteStartElement("Placemark");
                    xml.WriteAttributeString("id", "OCM-" + item.ID.ToString());
                    xml.WriteElementString("name", System.Security.SecurityElement.Escape(item.AddressInfo.Title));

                    //remove invalid character ranges before serializing to XML
                    //var description = Regex.Replace(item.GetSummaryDescription(true), @"[^\u0009\u000a\u000d\u0020-\uD7FF\uE000-\uFFFD]", string.Empty);
                    xml.WriteStartElement("description");
                    xml.WriteCData(System.Security.SecurityElement.Escape(item.GetSummaryDescription(true)));
                    xml.WriteEndElement();

                    xml.WriteStartElement("Point");
                    string coords = item.AddressInfo.Longitude.ToString() + "," + item.AddressInfo.Latitude.ToString();
                    xml.WriteElementString("coordinates", coords);
                    xml.WriteEndElement();

                    xml.WriteEndElement();
                }
            }
            xml.WriteEndElement();
            if (this.SelectedKMLVersion == KMLVersion.V2)
            {
                xml.WriteEndElement();                                           //</kml>
            }
            xml.WriteEndDocument();
            await xml.FlushAsync();

            //xml.Close();
        }