예제 #1
0
        public async Task <ServiceResponse <int> > GetAddressInfoAsync(DistanceMatrixParameters parameters, InfoType info)
        {
            var result = new ServiceResponse <int>()
            {
                Success = false,
                Message = "Failed to get Buration data from service"
            };

            var response = await GetResponseAsync(parameters);

            if (response.Success)
            {
                var json = JsonConvert.DeserializeObject <DistanceMatrixResponse>(response.Value);

                var elem = json.Rows[0].Elements[0];

                var propName = Enum.GetName(typeof(InfoType), (int)info);

                var item = elem.GetType().GetProperty(propName).GetValue(elem);

                var value = item.GetType().GetProperty("Value").GetValue(item);

                result.Value   = (int)value;
                result.Success = true;
                result.Message = "";
            }
            else
            {
                throw new Exception(response.Message, new Exception(response.Value));
            }

            return(result);
        }
        public async Task<ServiceResponse<int>> GetAddressInfoAsync(DistanceMatrixParameters parameters, InfoType info)
        {
            var result = new ServiceResponse<int>()
            {
                Success = false,
                Message = "Failed to get Buration data from service"
            };

            var response = await GetResponseAsync(parameters);

            if (response.Success)
            {
                var json = JsonConvert.DeserializeObject<DistanceMatrixResponse>(response.Value);

                var elem = json.Rows[0].Elements[0];

                var propName = Enum.GetName(typeof(InfoType), (int)info);

                var item = elem.GetType().GetProperty(propName).GetValue(elem);

                var value = item.GetType().GetProperty("Value").GetValue(item);

                result.Value = (int)value;
                result.Success = true;
                result.Message = "";
            }
            else
            {
                throw new Exception(response.Message, new Exception(response.Value));
            }

            return result;
        }
예제 #3
0
        private async Task<int> GetUpdatedMatrixEntryValue(Address origin, Address destinatoin)
        {
            var parameters = new DistanceMatrixParameters();
            parameters.Origins.Add(origin.ToString());
            parameters.Destinations.Add(destinatoin.ToString());

            ServiceResponse<int> response;
            try
            {
                response = await _matrixApi.GetAddressInfoAsync(parameters, InfoType.Duration);
                if (response.Success)
                {
                    return response.Value;
                }
            }
            catch (Exception)
            {
                throw;
            }
            throw new Exception("Could not get service response");
        }