private async Task <bool> RunAPITest(string serviceBaseURL, int testIterations)
        {
            this.ServiceBaseURL = serviceBaseURL;

            int lat = 52;
            int lng = 1;

            SearchFilters filters = new SearchFilters {
                Distance = 100, MaxResults = 1000, Latitude = lat, Longitude = lng, EnableCaching = false, IncludeUserComments = false
            };

            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();

            for (int i = 1; i < testIterations; i++)
            {
                System.Diagnostics.Debug.WriteLine(i);
                //TODO; pass same sample lat/lng list to tests
                var r = new Random(DateTime.Now.Second);
                filters.Latitude  = r.Next(50, 55);
                filters.Longitude = r.Next(-1, 1);

                var list = await this.GetPOIListAsync(filters);

                System.Diagnostics.Debug.WriteLine(i + ": POIs: " + list.Count());
            }

            stopwatch.Stop();

            System.Diagnostics.Debug.WriteLine("total ms " + this.ServiceBaseURL + " : " + stopwatch.Elapsed.TotalMilliseconds + " for " + testIterations + " iterations. avg " + (stopwatch.Elapsed.TotalMilliseconds / testIterations) + "ms per request");
            return(true);
        }
Esempio n. 2
0
        private async Task<bool> RunAPITest(string serviceBaseURL, int testIterations)
        {
            this.ServiceBaseURL = serviceBaseURL;

            int lat = 52;
            int lng = 1;

            SearchFilters filters = new SearchFilters{Distance=100, MaxResults=1000, Latitude=lat, Longitude=lng, EnableCaching=false, IncludeUserComments=false};
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();

            for (int i = 1; i < testIterations; i++)
            {
                System.Diagnostics.Debug.WriteLine(i);
                //TODO; pass same sample lat/lng list to tests
                var r = new Random(DateTime.Now.Second);
                filters.Latitude = r.Next(50, 55);
                filters.Longitude = r.Next(-1,1);

                var list = await this.GetLocations(filters);
                System.Diagnostics.Debug.WriteLine(i+": POIs: "+list.Count);
            }
            
            stopwatch.Stop();

            System.Diagnostics.Debug.WriteLine("total ms "+this.ServiceBaseURL+" : "+stopwatch.Elapsed.TotalMilliseconds +" for "+testIterations+" iterations. avg "+(stopwatch.Elapsed.TotalMilliseconds/testIterations)+"ms per request" );
            return true;
        }
        /// <summary>
        /// get list of matching POIs via API
        /// </summary>
        /// <param name="cp">  </param>
        /// <returns>  </returns>
        public async Task <IEnumerable <ChargePoint> > GetPOIListAsync(SearchFilters filters)
        {
            string url = ServiceBaseURL + "/poi/?output=json";

            if (filters.Latitude != null && filters.Longitude != null)
            {
                url += "&latitude=" + filters.Latitude + "&longitude=" + filters.Longitude;
            }

            if (filters.Distance != null)
            {
                url += "&distance=" + filters.Distance + "&distanceunit=" + filters.DistanceUnit.ToString();
            }

            if (filters.EnableCaching == false)
            {
                url += "&enablecaching=false";
            }

            if (filters.IncludeUserComments == true)
            {
                url += "&includecomments=true";
            }

            if (filters.SubmissionStatusTypeIDs != null && filters.SubmissionStatusTypeIDs.Any())
            {
                url += "&submissionstatustypeid=" + string.Join(",", filters.SubmissionStatusTypeIDs.Select(i => i.ToString()));
            }

            if (filters.DataProviderIDs != null && filters.DataProviderIDs.Any())
            {
                url += "&dataproviderid=" + string.Join(",", filters.DataProviderIDs.Select(i => i.ToString()));
            }

            if (filters.CountryIDs != null && filters.CountryIDs.Any())
            {
                url += "&countryid=" + string.Join(",", filters.CountryIDs.Select(i => i.ToString()));
            }

            if (filters.ModifiedSince.HasValue)
            {
                url += "&modifiedsince=" + filters.ModifiedSince.Value.ToString("s", CultureInfo.InvariantCulture);
            }

            if (filters.CreatedSince.HasValue)
            {
                url += "&createdsince=" + filters.CreatedSince.Value.ToString("s", CultureInfo.InvariantCulture);
            }

            if (filters.GreaterThanId.HasValue)
            {
                url += "&greaterthanid=" + filters.GreaterThanId;
            }

            if (!string.IsNullOrEmpty(filters.SortBy))
            {
                url += "&sortby=" + filters.SortBy;
            }

            url += "&verbose=" + filters.Verbose;

            url += "&maxresults=" + filters.MaxResults;

            var stopwatch = Stopwatch.StartNew();

            try
            {
                _logger?.LogInformation($"Client: Fetching data from {url}");
                string data = await FetchDataStringFromURLAsync(url);

                _logger?.LogInformation($"Client: fetch completed: { stopwatch.Elapsed.TotalSeconds}s");

                return(JsonConvert.DeserializeObject <List <ChargePoint> >(data));
            }
            catch (Exception exp)
            {
                //failed!
                _logger?.LogInformation($"Client: fetch failed: { stopwatch.Elapsed.TotalSeconds}s {exp.ToString()}");
                return(null);
            }
            stopwatch.Stop();
        }
Esempio n. 4
0
        /// <summary>
        /// get list of matching POIs via API
        /// </summary>
        /// <param name="cp">  </param>
        /// <returns>  </returns>
        public async Task <List <ChargePoint> > GetLocations(SearchFilters filters)
        {
            string url = ServiceBaseURL + "/poi/?output=json&verbose=false";

            if (filters.Latitude != null && filters.Longitude != null)
            {
                url += "&latitude=" + filters.Latitude + "&longitude=" + filters.Longitude;
            }

            if (filters.Distance != null)
            {
                url += "&distance=" + filters.Distance + "&distanceunit=" + filters.DistanceUnit.ToString();
            }

            if (filters.EnableCaching == false)
            {
                url += "&enablecaching=false";
            }

            if (filters.IncludeUserComments == true)
            {
                url += "&includecomments=true";
            }

            if (filters.SubmissionStatusTypeIDs != null && filters.SubmissionStatusTypeIDs.Any())
            {
                url += "&submissionstatustypeid=";
                foreach (var id in filters.SubmissionStatusTypeIDs)
                {
                    url += id + ",";
                }
            }

            if (filters.DataProviderIDs != null && filters.DataProviderIDs.Any())
            {
                url += "&dataproviderid=";
                foreach (var id in filters.DataProviderIDs)
                {
                    url += id + ",";
                }
            }

            if (filters.CountryIDs != null && filters.CountryIDs.Any())
            {
                url += "&countryid=";
                foreach (var id in filters.CountryIDs)
                {
                    url += id + ",";
                }
            }

            url += "&maxresults=" + filters.MaxResults;

            try
            {
                System.Diagnostics.Debug.WriteLine("Client: Fetching data from " + url);
                string data = await FetchDataStringFromURLAsync(url);

                System.Diagnostics.Debug.WriteLine("Client: completed fetch");
                JObject            o          = JObject.Parse("{\"root\": " + data + "}");
                JsonSerializer     serializer = new JsonSerializer();
                List <ChargePoint> c          = (List <ChargePoint>)serializer.Deserialize(new JTokenReader(o["root"]), typeof(List <ChargePoint>));
                return(c);
            }
            catch (Exception)
            {
                //failed!
                return(null);
            }
        }
Esempio n. 5
0
        public void GeocodingTest()
        {
            OCMClient client = new OCMClient(IsSandboxedAPIMode);

            //get a few OCM listings
            SearchFilters filters = new SearchFilters { SubmissionStatusTypeIDs = new int[] { (int)StandardSubmissionStatusTypes.Submitted_Published }, CountryIDs = new int[] { 1 }, DataProviderIDs = new int[] { 1 }, MaxResults = 2000, EnableCaching = false };

            var poiList = client.GetLocations(filters);
            /*
            GeocodingService g = new GeocodingService();
            List<GeolocationResult> list = new List<GeolocationResult>();

            //attempt OSM geocoding
            foreach (var poi in poiList)
            {
                try
                {
                    System.Diagnostics.Debug.WriteLine("OCM-" + poi.ID + " : [" + poi.AddressInfo.Title + "] " + poi.AddressInfo.ToString());

                    System.Diagnostics.Debug.WriteLine("OCM : LL: " + poi.AddressInfo.Latitude + "," + poi.AddressInfo.Longitude);

                    var osm = g.GeolocateAddressInfo_OSM(poi.AddressInfo);
                    System.Diagnostics.Debug.WriteLine("OSM : LL: " + osm.Latitude + "," + osm.Longitude);
                    list.Add(osm);

                    var mpq = g.GeolocateAddressInfo_MapquestOSM(poi.AddressInfo);
                    System.Diagnostics.Debug.WriteLine("MPQ : LL: " + mpq.Latitude + "," + mpq.Longitude);
                    list.Add(mpq);
                }
                catch (Exception exp)
                {
                    System.Diagnostics.Debug.WriteLine("Exception during geocoding:" + exp.ToString());
                }
                System.Threading.Thread.Sleep(1000);
            }

            string json = JsonConvert.SerializeObject(list, Formatting.Indented);
            System.IO.File.WriteAllText("C:\\temp\\GeocodingResult.json", json);
             * */
        }
Esempio n. 6
0
        /// <summary>
        /// get list of matching POIs via API 
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        public async Task<List<ChargePoint>> GetLocations(SearchFilters filters)
        {
            string url = ServiceBaseURL + "/poi/?output=json&verbose=false";

            if (filters.Latitude != null && filters.Longitude != null)
            {
                url += "&latitude=" + filters.Latitude + "&longitude=" + filters.Longitude;
            }

            if (filters.Distance != null)
            {
                url += "&distance=" + filters.Distance + "&distanceunit=" + filters.DistanceUnit.ToString();

            }

            if (filters.EnableCaching == false)
            {
                url += "&enablecaching=false";
            }

            if (filters.IncludeUserComments == true)
            {
                url += "&includecomments=true";
            }

            if (filters.SubmissionStatusTypeIDs != null && filters.SubmissionStatusTypeIDs.Any())
            {
                url += "&submissionstatustypeid=";
                foreach(var id in filters.SubmissionStatusTypeIDs)
                {
                    url += id + ",";
                }
            }

            if (filters.DataProviderIDs != null && filters.DataProviderIDs.Any())
            {
                url += "&dataproviderid=";
                foreach (var id in filters.DataProviderIDs)
                {
                    url += id + ",";
                }
            }

            if (filters.CountryIDs != null && filters.CountryIDs.Any())
            {
                url += "&countryid=";
                foreach (var id in filters.CountryIDs)
                {
                    url += id + ",";
                }
            }

            url += "&maxresults=" + filters.MaxResults;

            try
            {
                System.Diagnostics.Debug.WriteLine("Client: Fetching data from "+url);
                string data = await FetchDataStringFromURLAsync(url);
                System.Diagnostics.Debug.WriteLine("Client: completed fetch");
                JObject o = JObject.Parse("{\"root\": " + data + "}");
                JsonSerializer serializer = new JsonSerializer();
                List<ChargePoint> c = (List<ChargePoint>)serializer.Deserialize(new JTokenReader(o["root"]), typeof(List<ChargePoint>));
                return c;
            }
            catch (Exception)
            {
                //failed!
                return null;
            }
        }