Esempio n. 1
0
        private JsonSerializerSettings GetSerializerSettings(Common.APIRequestSettings settings)
        {
            JsonSerializerSettings jsonSettings = new JsonSerializerSettings();

            if (!settings.IsVerboseOutput)
            {
                jsonSettings.NullValueHandling = NullValueHandling.Ignore;
            }

            jsonSettings.Formatting = Formatting.Indented;

            if (settings.IsCamelCaseOutput)
            {
                jsonSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            }

            return(jsonSettings);
        }
Esempio n. 2
0
        public void GetOutput(System.IO.Stream outputStream, List <Common.Model.ChargePoint> dataList, Common.APIRequestSettings settings)
        {
            output = new StreamWriter(outputStream, System.Text.Encoding.UTF8);

            System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=ocm.csv");

            //header row
            output.WriteLine("ID,UUID, LocationTitle,AddressLine1,AddressLine2,Town,StateOrProvince,Postcode,Country,Latitude,Longitude,Distance,DistanceUnit,Addr_ContactTelephone1,Addr_ContactTelephone2,Addr_ContactEmail,Addr_AccessComments,Addr_GeneralComments,Addr_RelatedURL,ConnectionType,ChargerType,UsageType,NumberOfPoints,GeneralComments,DateLastConfirmed,StatusType,DateLastStatusUpdate");
            foreach (var item in dataList)
            {
                if (item.AddressInfo != null)
                {
                    currentLine = "";
                    AppendValue(item.ID);
                    AppendValue(item.UUID);
                    AppendText(item.AddressInfo.Title);
                    AppendText(item.AddressInfo.AddressLine1);
                    AppendText(item.AddressInfo.AddressLine2);
                    AppendText(item.AddressInfo.Town);
                    AppendText(item.AddressInfo.StateOrProvince);
                    AppendText(item.AddressInfo.Postcode);

                    if (item.AddressInfo.Country != null)
                    {
                        AppendText(item.AddressInfo.Country.Title);
                    }
                    else
                    {
                        AppendValue(null);
                    }

                    AppendValue(item.AddressInfo.Latitude);
                    AppendValue(item.AddressInfo.Longitude);
                    AppendValue(item.AddressInfo.Distance);
                    AppendValue(item.AddressInfo.DistanceUnit);
                    AppendText(item.AddressInfo.ContactTelephone1);
                    AppendText(item.AddressInfo.ContactTelephone2);
                    AppendText(item.AddressInfo.ContactEmail);
                    AppendText(item.AddressInfo.AccessComments);
#pragma warning disable 0612
                    AppendText(item.AddressInfo.GeneralComments);
#pragma warning restore 0612
                    AppendText(item.AddressInfo.RelatedURL);

                    //ConnectionType,ChargerType,UsageType,NumberOfPoints,GeneralComments,DateLastConfirmed,StatusType,DateLastStatusUpdate
                    bool appendedText = false;
                    if (item.Connections != null)
                    {
                        //compile semicolon seperated items for output within column
                        string itemList = "";
                        foreach (var ct in item.Connections)
                        {
                            if (ct.ConnectionType != null)
                            {
                                itemList    += ct.ConnectionType.Title + "; ";
                                appendedText = true;
                            }
                        }

                        //output null placeholder or column values
                        if (!appendedText)
                        {
                            AppendValue(null);
                        }
                        else
                        {
                            AppendText(itemList);
                        }
                    }
                    else
                    {
                        AppendValue(null);
                    }

#pragma warning disable 0612
                    if (item.Chargers != null)
                    {
                        appendedText = false;

                        //compile semicolon seperated items for output within column
                        string itemList = "";
                        foreach (var cg in item.Chargers)
                        {
                            if (cg.ChargerType != null)
                            {
                                itemList    += cg.ChargerType.Title + "; ";
                                appendedText = true;
                            }
                        }

                        //output null placeholder or column values
                        if (!appendedText)
                        {
                            AppendValue(null);
                        }
                        else
                        {
                            AppendText(itemList);
                        }
                    }
                    else
                    {
                        AppendValue(null);
                    }

                    if (item.UsageType != null)
                    {
                        AppendText(item.UsageType.Title);
                    }
                    else
                    {
                        AppendValue(null);
                    }

                    AppendValue(item.NumberOfPoints);
                    AppendText(item.GeneralComments);
                    AppendValue(item.DateLastConfirmed.ToString());

                    if (item.StatusType != null)
                    {
                        AppendText(item.StatusType.Title);
                    }
                    else
                    {
                        AppendValue(null);
                    }

                    //last item
                    currentLine += item.DateLastStatusUpdate.ToString();

                    currentLine = currentLine.Replace(System.Environment.NewLine, " ");
                    output.WriteLine(currentLine);
                }
            }
#pragma warning restore 0612
            output.Flush();
            //output.Close();
        }
Esempio n. 3
0
 public void GetOutput(Stream outputStream, Object data, Common.APIRequestSettings settings)
 {
     throw new NotImplementedException();
 }
Esempio n. 4
0
 public void GetOutput(Stream outputStream, Common.Model.CoreReferenceData data, Common.APIRequestSettings settings)
 {
     throw new NotImplementedException();
 }
Esempio n. 5
0
        public void GetOutput(System.IO.Stream outputStream, List <Common.Model.ChargePoint> dataList, Common.APIRequestSettings 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 http://openchargemap.org/");
            foreach (var item in dataList)
            {
                if (item.AddressInfo != null)
                {
                    xml.WriteStartElement("Placemark");
                    xml.WriteAttributeString("id", "OCM-" + item.ID.ToString());
                    xml.WriteElementString("name", 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(description);
                    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();
            xml.Flush();
            //xml.Close();
        }
Esempio n. 6
0
        public void GetOutput(System.IO.Stream outputStream, List <Common.Model.ChargePoint> dataList, Common.APIRequestSettings settings)
        {
            bool isVerboseMode = true;

            XmlTextWriter xml = new XmlTextWriter(outputStream, Encoding.UTF8);

            //start xml document
            xml.WriteStartDocument();
            xml.WriteStartElement("ChargePoints");

            foreach (var item in dataList)
            {
                xml.WriteStartElement("ChargePoint");
                xml.WriteAttributeString("ID", item.ID.ToString());
                xml.WriteAttributeString("UUID", item.UUID.ToString());
                xml.WriteAttributeString("DateLastConfirmed", item.DateLastConfirmed.ToString());
                if (item.OperatorInfo != null)
                {
                    xml.WriteAttributeString("OperatorID", item.OperatorInfo.ID.ToString());
                    if (isVerboseMode)
                    {
                        xml.WriteAttributeString("OperatorTitle", item.OperatorInfo.Title.ToString());
                    }
                }
                if (item.DataProvider != null)
                {
                    xml.WriteAttributeString("DataProviderID", item.DataProvider.ID.ToString());
                }
                xml.WriteAttributeString("NumberOfPoints", item.NumberOfPoints.ToString());
                xml.WriteAttributeString("DataQualityLevel", item.DataQualityLevel.ToString());
                xml.WriteAttributeString("PercentageSimilarity", item.PercentageSimilarity.ToString());
                xml.WriteElementString("GeneralComments", item.GeneralComments);

                //output address info
                if (item.AddressInfo != null)
                {
                    xml.WriteStartElement("AddressInfo");
                    xml.WriteElementString("LocationTitle", item.AddressInfo.Title);
                    xml.WriteElementString("AddressLine1", item.AddressInfo.AddressLine1);
                    xml.WriteElementString("AddressLine2", item.AddressInfo.AddressLine2);
                    xml.WriteElementString("Town", item.AddressInfo.Town);
                    xml.WriteElementString("StateOrProvince", item.AddressInfo.StateOrProvince);
                    xml.WriteElementString("Postcode", item.AddressInfo.Postcode);

                    if (item.AddressInfo.Country != null)
                    {
                        xml.WriteElementString("Country", item.AddressInfo.Country.Title);
                    }
                    xml.WriteElementString("Latitude", item.AddressInfo.Latitude.ToString());
                    xml.WriteElementString("Longitude", item.AddressInfo.Longitude.ToString());

                    if (item.AddressInfo.Distance != null)
                    {
                        xml.WriteStartElement("Distance");
                        xml.WriteAttributeString("Unit", item.AddressInfo.DistanceUnit.ToString());
                        xml.WriteAttributeString("Value", item.AddressInfo.Distance.ToString());
                        xml.WriteEndElement();
                    }

                    if (item.AddressInfo.ContactTelephone1 != null)
                    {
                        xml.WriteElementString("ContactTelephone1", item.AddressInfo.ContactTelephone1);
                    }
                    if (item.AddressInfo.ContactTelephone2 != null)
                    {
                        xml.WriteElementString("ContactTelephone2", item.AddressInfo.ContactTelephone2);
                    }
                    if (item.AddressInfo.ContactEmail != null)
                    {
                        xml.WriteElementString("ContactEmail", item.AddressInfo.ContactEmail);
                    }
                    if (item.AddressInfo.AccessComments != null)
                    {
                        xml.WriteElementString("AccessComments", item.AddressInfo.AccessComments);
                    }
#pragma warning disable 0612
                    //if (item.AddressInfo.GeneralComments != null) xml.WriteElementString("GeneralComments", item.AddressInfo.GeneralComments);
#pragma warning restore 0612
                    if (item.AddressInfo.RelatedURL != null)
                    {
                        xml.WriteElementString("RelatedURL", item.AddressInfo.RelatedURL);
                    }

                    xml.WriteEndElement();
                }

                if (item.Connections != null)
                {
                    xml.WriteStartElement("Connections");
                    foreach (var ct in item.Connections)
                    {
                        xml.WriteStartElement("ConnectionInfo");
                        xml.WriteAttributeString("ID", ct.ID.ToString());
                        if (ct.ConnectionType != null)
                        {
                            xml.WriteAttributeString("TypeID", ct.ConnectionType.ID.ToString());
                            xml.WriteAttributeString("TypeName", ct.ConnectionType.Title);
                        }

                        if (ct.Level != null)
                        {
                            xml.WriteAttributeString("LevelID", ct.Level.ID.ToString());
                            xml.WriteAttributeString("LevelName", ct.Level.Title);
                        }

                        if (ct.StatusType != null)
                        {
                            xml.WriteAttributeString("Status", ct.StatusType.Title);
                        }

                        if (ct.Amps != null)
                        {
                            xml.WriteAttributeString("Amps", ct.Amps.ToString());
                        }

                        if (ct.Voltage != null)
                        {
                            xml.WriteAttributeString("Voltage", ct.Voltage.ToString());
                        }

                        if (ct.Quantity != null)
                        {
                            xml.WriteAttributeString("Quantity", ct.Quantity.ToString());
                        }

                        if (ct.Reference != null)
                        {
                            xml.WriteAttributeString("Reference", ct.Reference.ToString());
                        }
                        xml.WriteEndElement();
                    }
                    xml.WriteEndElement();
                }
#pragma warning disable 0612
                var chargerList = item.Chargers;
                if (chargerList == null || chargerList.Count == 0)
                {
                    if (item.Connections != null)
                    {
                        chargerList = new List <Common.Model.ChargerInfo>();
                        foreach (var con in item.Connections)
                        {
                            if (con.Level != null)
                            {
                                if (!chargerList.Exists(c => c.ChargerType == con.Level))
                                {
                                    chargerList.Add(new Common.Model.ChargerInfo()
                                    {
                                        ChargerType = con.Level
                                    });
                                }
                            }
                        }
                        chargerList = chargerList.Distinct().ToList();
                    }
                }

#pragma warning restore 0612

                if (chargerList != null)
                {
                    xml.WriteStartElement("ChargerTypes");
                    foreach (var cg in chargerList)
                    {
                        if (cg.ChargerType != null)
                        {
                            xml.WriteStartElement("ChargerType");
                            xml.WriteAttributeString("ID", cg.ChargerType.ID.ToString());
                            if (isVerboseMode)
                            {
                                xml.WriteAttributeString("Title", cg.ChargerType.Title);
                                xml.WriteAttributeString("IsFastChargeCapable", cg.ChargerType.IsFastChargeCapable.ToString());
                            }
                            xml.WriteEndElement();
                        }
                    }
                    xml.WriteEndElement();
                }

                if (item.UsageType != null)
                {
                    xml.WriteStartElement("UsageType");
                    xml.WriteAttributeString("ID", item.UsageType.ID.ToString());
                    if (isVerboseMode)
                    {
                        xml.WriteValue(item.UsageType.Title);
                    }
                    xml.WriteEndElement();
                }

                if (!String.IsNullOrEmpty(item.UsageCost))
                {
                    xml.WriteElementString("UsageCost", item.UsageCost);
                }

                /*if (!String.IsNullOrEmpty(item.MetadataTags))
                 * {
                 *  xml.WriteStartElement("MetadataTags");
                 *  xml.WriteCData(item.MetadataTags);
                 *  xml.WriteEndElement();
                 * }*/

                if (item.StatusType != null)
                {
                    xml.WriteStartElement("StatusType");
                    xml.WriteAttributeString("ID", item.StatusType.ID.ToString());
                    if (isVerboseMode)
                    {
                        xml.WriteAttributeString("Title", item.StatusType.Title);
                    }
                    xml.WriteAttributeString("DateLastStatusUpdate", item.DateLastStatusUpdate.ToString());
                    xml.WriteEndElement(); //end status
                }

                if (item.UserComments != null)
                {
                    xml.WriteStartElement("UserComments");
                    foreach (var comment in item.UserComments)
                    {
                        xml.WriteStartElement("UserComment");
                        xml.WriteAttributeString("CommentTypeID", comment.CommentType.ID.ToString());
                        if (isVerboseMode)
                        {
                            xml.WriteAttributeString("CommentType", comment.CommentType.Title);
                        }
                        xml.WriteAttributeString("UserName", comment.UserName);
                        xml.WriteAttributeString("Rating", comment.Rating.ToString());
                        xml.WriteAttributeString("RelatedURL", comment.RelatedURL);
                        xml.WriteValue(comment.Comment);
                        xml.WriteEndElement();
                    }
                    xml.WriteEndElement();
                }
                xml.WriteEndElement(); //end charge point
            }

            xml.WriteEndElement();  //end charge points list
            xml.WriteEndDocument(); //end xml
            xml.Flush();
            //xml.Close();
        }
Esempio n. 7
0
 public void GetOutput(Stream outputStream, Object data, Common.APIRequestSettings settings)
 {
     PerformSerialisationV2(outputStream, data, settings.Callback, GetSerializerSettings(settings));
 }
Esempio n. 8
0
 public void GetOutput(Stream outputStream, Common.Model.CoreReferenceData data, Common.APIRequestSettings settings)
 {
     if (settings.APIVersion >= 2)
     {
         PerformSerialisationV2(outputStream, data, settings.Callback, GetSerializerSettings(settings));
     }
     else
     {
         DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Common.Model.CoreReferenceData));
         PerformSerialisationV1(outputStream, data, settings.Callback, jsonSerializer);
     }
 }
Esempio n. 9
0
 public void GetOutput(System.IO.Stream outputStream, List <Common.Model.ChargePoint> dataList, Common.APIRequestSettings settings)
 {
     if (settings.APIVersion >= 2)
     {
         PerformSerialisationV2(outputStream, dataList, settings.Callback, GetSerializerSettings(settings));
     }
     else
     {
         DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(List <Common.Model.ChargePoint>));
         PerformSerialisationV1(outputStream, dataList, settings.Callback, jsonSerializer);
     }
 }
Esempio n. 10
0
        public void GetOutput(System.IO.Stream outputStream, List <Common.Model.ChargePoint> dataList, Common.APIRequestSettings settings)
        {
            if (settings.APIVersion >= 2)
            {
                var featureCollection = new GeoJSONFeatureCollection();
                foreach (var poi in dataList)
                {
                    var feature = new GeoJSONFeature();
                    feature.ID = poi.ID.ToString();
                    feature.Geometry.Coordinates = new double[] { poi.AddressInfo.Latitude, poi.AddressInfo.Longitude };

                    ConnectionInfo maxConnection = null;
                    if (poi.Connections != null)
                    {
                        maxConnection = poi.Connections.OrderByDescending(p => p.LevelID).FirstOrDefault();
                    }

                    var featureProperties = new Dictionary <string, object> {
                        { "Name", poi.AddressInfo.Title },
                        { "Description", poi.AddressInfo.ToString() },
                        { "URL", "http://openchargemap.org/site/poi/details/" + poi.ID },
                        { "Level", (maxConnection != null && maxConnection.LevelID != null?maxConnection.LevelID.ToString():null) },
                        { "ConnectionType", (maxConnection != null && maxConnection.ConnectionType != null?maxConnection.ConnectionType.Title:null) },
                    };

                    if (settings.IsVerboseOutput)
                    {
                        featureProperties.Add("POI", poi);
                    }
                    feature.Properties = featureProperties;

                    featureCollection.Features.Add(feature);
                }

                System.IO.StreamWriter s = new StreamWriter(outputStream);

                if (settings.Callback != null)
                {
                    s.Write(settings.Callback + "(");
                }

                var serializerSettings = GetSerializerSettings(settings);

                //enforce camelcasing
                serializerSettings.ContractResolver  = new CamelCasePropertyNamesContractResolver();
                serializerSettings.NullValueHandling = NullValueHandling.Ignore;

                string json = JsonConvert.SerializeObject(featureCollection, serializerSettings);
                s.Write(json);

                if (settings.Callback != null)
                {
                    s.Write(")");
                }

                s.Flush();
            }
        }
Esempio n. 11
0
        public void GetOutput(System.IO.Stream outputStream, List <Common.Model.ChargePoint> dataList, Common.APIRequestSettings settings)
        {
            if (dataList != null)
            {
                foreach (var item in dataList)
                {
                    if (item.AddressInfo != null)
                    {
                        /* xml.WriteStartElement("Placemark");
                         * xml.WriteElementString("name", item.AddressInfo.Title);
                         *
                         * xml.WriteElementString("description", item.GetSummaryDescription(true));
                         * if (item.AddressInfo.Latitude != null)
                         * {
                         *   xml.WriteStartElement("Point");
                         *   string coords = item.AddressInfo.Longitude.ToString() + "," + item.AddressInfo.Latitude.ToString();
                         *   xml.WriteElementString("coordinates", coords);
                         *   xml.WriteEndElement();
                         * }
                         *
                         *
                         * */
                    }
                }
            }

            Image outputImage = null;

            if (outputImage != null)
            {
                outputImage.Save(outputStream, System.Drawing.Imaging.ImageFormat.Png);
            }
        }