Ejemplo n.º 1
0
        public static T GetSettings <T>(string fileLocation)
        {
            T _result = default(T);

            string stringified = "";
            var    json        = new JSONProcessor();

            try
            {
                stringified = FileReader.ReadFileIntoString(fileLocation);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            try
            {
                _result = json.ConvertJsonToType <T>(stringified);
            }
            catch (Exception ex)
            {
                Console.WriteLine(json.ErrorMessages[0], " [FilePath: " + fileLocation + "]");
                Console.WriteLine(ex);
            }

            return(_result);
        }
Ejemplo n.º 2
0
        T IREST <T> .GetDataAsync(T payload)
        {
            //must meet minimum parts of an rec
            if (
                !string.IsNullOrEmpty(payload.Address) &&
                !string.IsNullOrEmpty(payload.City) &&
                !string.IsNullOrEmpty(payload.Region)
                )
            {
                string _strAddress = StringifyPayload(payload);

                var _requestUri = new UriBuilder();
                _requestUri.Scheme = restProtocol;
                _requestUri.Host   = restLink;
                _requestUri.Path   = _strAddress.Replace(" ", "+");
                var query = !string.IsNullOrEmpty(_strAddress) ? string.Concat("o=", responseFormat) : "";
                query             = !string.IsNullOrEmpty(restKey) ? query + string.Concat("&key=", restKey) : "";
                _requestUri.Query = query;

                var _jsonText = CallProvider(_requestUri.ToString());

                var json = new JSONProcessor();
                json.PrepJSONSafely(_jsonText);

                if (json.IsJSONValid)
                {
                    dynamic obj = json.ConvertJsonToType <dynamic>(_jsonText);

                    if (obj.status == "OK")
                    {
                        if (obj["resourceSets"][0]["resources"][0]["entityType"].ToString() == "Address" ||
                            obj["resourceSets"][0]["resources"][0]["confidence"].ToString() == "High" ||
                            obj["resourceSets"][0]["resources"][0]["confidence"].ToString() == "Medium"
                            )
                        {
                            //update model
                            payload.Latitude              = Single.Parse(obj["resourceSets"][0]["resources"][0]["geocodePoints"][0]["coordinates"][0].ToString());
                            payload.Longitude             = Single.Parse(obj["resourceSets"][0]["resources"][0]["geocodePoints"][0]["coordinates"][1].ToString());
                            payload.LocationType          = obj["resourceSets"][0]["resources"][0]["entityType"].ToString();
                            payload.ServiceAPIEndPointUID = restUID;
                        }
                        else
                        {
                            //TODO: add bad match code
                            // payload.LocationType = "no_good_match";  //TODO: a retry operation should be added (but lower priority than changed RecordSet)
                        }
                        //}
                        //else //if not OK
                        //{
                        //    //payload.LocationType = obj.status;
                        //}
                        //else if (obj.status == "ZERO_RESULTS")
                        //{ //non-existant rec
                        //}
                        //else if (obj.status == "OVER_QUERY_LIMIT")
                        //{ //
                        //}
                        //else if (obj.status == "REQUEST_DENIED")
                        //{ //
                        //}
                        //else if (obj.status == "INVALID_REQUEST")
                        //{ //
                        //}
                        //else if (obj.status == "UNKNOWN_ERROR")
                        //{ //
                    }
                }
            }

            return(payload);
        }
Ejemplo n.º 3
0
        T IREST <T> .GetDataAsync(T payload)
        {
            //must meet minimum parts of an rec
            if (
                !string.IsNullOrEmpty(payload.Address) &&
                !string.IsNullOrEmpty(payload.City) &&
                !string.IsNullOrEmpty(payload.Region)
                )
            {
                string _strAddress = StringifyPayload(payload);

                var _requestUri = new UriBuilder();
                _requestUri.Scheme = restProtocol;
                _requestUri.Host   = restLink;
                _requestUri.Path   = responseFormat;
                var query = !string.IsNullOrEmpty(_strAddress) ? string.Concat("address=", _strAddress) : "";
                query             = !string.IsNullOrEmpty(restKey) ? query + string.Concat("&key=", restKey) : "";
                _requestUri.Query = query;

                var _jsonText = CallProvider(_requestUri.ToString());

                var json = new JSONProcessor();
                json.PrepJSONSafely(_jsonText);

                if (json.IsJSONValid)
                {
                    dynamic obj = json.ConvertJsonToType <dynamic>(_jsonText);

                    if (obj.status == "OK")
                    {
                        if (!json.IsPropertyInJSON(_jsonText, "PropertyName", "partial_match") ||
                            obj.results[0].geometry.location_type == "ROOFTOP" ||
                            obj.results[0].geometry.location_type == "RANGE_INTERPOLATED"    //center of street block
                            )
                        {
                            //update model
                            payload.Latitude              = obj.results[0].geometry.location.lat;
                            payload.Longitude             = obj.results[0].geometry.location.lng;
                            payload.LocationType          = obj.results[0].geometry.location_type;
                            payload.ServiceAPIEndPointUID = restUID;
                        }
                        else
                        {
                            //TODO: add bad match code
                            payload.LocationType = "no_good_match";  //TODO: a retry operation should be added (but lower priority than changed RecordSet)
                        }
                    }
                    else //if not OK
                    {
                        //payload.LocationType = obj.status;
                    }
                    //else if (obj.status == "ZERO_RESULTS")
                    //{ //non-existant rec
                    //}
                    //else if (obj.status == "OVER_QUERY_LIMIT")
                    //{ //
                    //}
                    //else if (obj.status == "REQUEST_DENIED")
                    //{ //
                    //}
                    //else if (obj.status == "INVALID_REQUEST")
                    //{ //
                    //}
                    //else if (obj.status == "UNKNOWN_ERROR")
                    //{ //
                    //}
                }
            }



            return(payload);
        }