Inheritance: StationModelBase
示例#1
0
        public override async Task <List <StationModelBase> > InnerGetStationsAsync()
        {
            using (var client = new HttpClient(new NativeMessageHandler()))
            {
                HttpResponseMessage response = await client.GetAsync(new Uri(string.Format(StationsUrl + "&?" + Guid.NewGuid().ToString()))).ConfigureAwait(false);

                var responseBodyAsText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                var pattern = @"((location).*?(\[\\\"")(.*?)(\\)(.*?)(\d2.*?)(\\))+";
                if (Regex.IsMatch(responseBodyAsText, pattern))
                {
                    var regex    = new Regex(pattern, RegexOptions.None);
                    var stations = new List <StationModelBase>();
                    foreach (Match myMatch in regex.Matches(responseBodyAsText))
                    {
                        if (myMatch.Success)
                        {
                            var values = myMatch.Groups[7].Value.Split(',');
                            if (values.Length == 2)
                            {
                                var station = new CitycardCyclesModel();
                                station.Latitude  = double.Parse(values[0], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, new CultureInfo("en-US"));
                                station.Longitude = double.Parse(values[1].Trim(), NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, new CultureInfo("en-US"));
                                stations.Add(station);
                            }
                        }
                    }
                    return(stations);
                }
                return(null);
            }
        }
 public override async Task<List<StationModelBase>> InnerGetStationsAsync()
 {
     using (var client = new HttpClient(new NativeMessageHandler()))
     {
         HttpResponseMessage response = await client.GetAsync(new Uri(string.Format(StationsUrl + "&?" + Guid.NewGuid().ToString()))).ConfigureAwait(false);
         var responseBodyAsText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
         var pattern = @"((location).*?(\[\\\"")(.*?)(\\)(.*?)(\d2.*?)(\\))+";
         if (Regex.IsMatch(responseBodyAsText, pattern))
         {
             var regex = new Regex(pattern, RegexOptions.None);
             var stations = new List<StationModelBase>();
             foreach (Match myMatch in regex.Matches(responseBodyAsText))
             {
                 if (myMatch.Success)
                 {
                     var values = myMatch.Groups[7].Value.Split(',');
                     if(values.Length == 2)
                     {
                         var station = new CitycardCyclesModel();
                         station.Latitude = double.Parse(values[0], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, new CultureInfo("en-US"));
                         station.Longitude = double.Parse(values[1].Trim(), NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, new CultureInfo("en-US"));
                         stations.Add(station);
                     }
                 }
             }
             return stations;
         }
         return null;
     }
 }