Esempio n. 1
0
        public async Task GetOutput(HttpContext context, System.IO.Stream outputStream, IEnumerable <Common.Model.ChargePoint> dataList, Common.APIRequestParams 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.Longitude, poi.AddressInfo.Latitude };

                    Common.Model.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", "https://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)
                {
                    await s.WriteAsync(settings.Callback + "(");
                }

                var serializerSettings = GetSerializerSettings(settings);

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

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

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

                await s.FlushAsync();
            }
        }
        public void GetOutput(System.IO.Stream outputStream, List<Common.Model.ChargePoint> dataList, Common.APIRequestParams 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();
            }
        }