Пример #1
0
        public static Task <AddressResponse> FromXml(XElement el)
        {
            return(SerializationHelper.FromXml <AddressResponse>(
                       el,
                       async(r) => {
                var status = el.Element("status");
                if (status != null)
                {
                    r.Exception = new GeoNamesException((string)status.Attribute("message"), (int?)status.Attribute("value"));
                }
                else
                {
#if (NET40)
                    await SyncToTaskFactory.CreateTask(
                        () => {
                        r.Items = el.Elements("address")
                                  .Select(x => Address.FromXml(x).Result)
                                  .ToArray();
                    }
                        );
#else
                    r.Items = await el.Elements("address")
                              .ToObservable()
                              .Select(x => Observable.FromAsync(async t => await Address.FromXml(x)))
                              .Merge(NGeoSettings.MaxParallelThreads)
                              .ToArray();
#endif
                }
            }
                       ));
        }
Пример #2
0
 public static Task <ErrorResponse> FromXml(XElement el)
 {
     return(SerializationHelper.FromXml <ErrorResponse>(
                el,
                r => SyncToTaskFactory.CreateTask(
                    () => {
         var status = el.Element("status");
         r.Exception = new GeoNamesException((string)status.Attribute("message"), errorCode: (int?)status.Attribute("value"));
     }
                    )
                ));
 }
Пример #3
0
 public static Task <Timezone> FromXml(XElement el)
 {
     return(SerializationHelper.FromXml <Timezone>(
                el,
                (r) => SyncToTaskFactory.CreateTask(
                    () => {
         r.GMTOffset = (decimal?)el.Attribute("gmtOffset");
         r.DSTOffset = (decimal?)el.Attribute("dstOffset");
         r.timeZoneId = (string)el;
     }
                    )
                ));
 }
Пример #4
0
 public static Task <BoundingBox> FromXml(XElement el)
 {
     return(SerializationHelper.FromXml <BoundingBox>(
                el,
                (r) => SyncToTaskFactory.CreateTask(
                    () => {
         r.North = (double)el.Element("north");
         r.East = (double)el.Element("east");
         r.South = (double)el.Element("south");
         r.West = (double)el.Element("west");
     }
                    )
                ));
 }
Пример #5
0
 public static Task <AlternateName> FromXml(XElement el)
 {
     return(SerializationHelper.FromXml <AlternateName>(
                el,
                (r) => SyncToTaskFactory.CreateTask(
                    () => {
         r.Lang = (string)el.Attribute("lang");
         r.IsPreferredName = ((bool?)el.Attribute("isPreferredName")).GetValueOrDefault(false);
         r.IsShortName = ((bool?)el.Attribute("isShortName")).GetValueOrDefault(false);
         r.Name = (string)el;
     }
                    )
                ));
 }
Пример #6
0
        public static Task <GeoNameResponse> FromXml(XElement el)
        {
            return(SerializationHelper.FromXml <GeoNameResponse>(
                       el,
                       async r => {
                var status = el.Element("status");
                if (status != null)
                {
                    r.Exception = new GeoNamesException((string)status.Attribute("message"), (int?)status.Attribute("value"));
                }
                else
                {
#if (NET40)
                    await SyncToTaskFactory.CreateTask(
                        () => {
                        r.Items = el.Elements("geoname")
                                  .AsParallel()
                                  .WithDegreeOfParallelism(NGeoSettings.MaxParallelThreads)
                                  .Select((x, i) => new { i = i, t = GeoName.FromXml(x).Result })
                                  .OrderBy(x => x.i)
                                  .Select(x => x.t)
                                  .ToArray();
                    }
                        );
#else
                    r.Items = (
                        await el.Elements("geoname")
                        .ToObservable()
                        .Select((x, i) => Observable.FromAsync(async t => new { i = i, t = await GeoName.FromXml(x) }))
                        .Merge(NGeoSettings.MaxParallelThreads)
                        .ToArray()
                        )
                              .OrderBy(x => x.i)
                              .Select(x => x.t)
                              .ToArray();
#endif
                }
            }
                       ));
        }
Пример #7
0
 public static Task <Address> FromXml(XElement el)
 {
     return(SerializationHelper.FromXml <Address>(
                el,
                (r) => SyncToTaskFactory.CreateTask(
                    () => {
         r.Street = (string)el.Element("street");
         r.MTfcc = (string)el.Element("mtfcc");
         r.StreetNumber = (string)el.Element("streetNumber");
         r.Latitude = (decimal?)el.Element("lat");
         r.Longitude = (decimal?)el.Element("lng");
         r.Distance = (decimal?)el.Element("distance");
         r.PostCode = (string)el.Element("postalcode");
         r.PlaceName = (string)el.Element("placeName");
         r.AdminCode1 = (string)el.Element("adminCode1");
         r.AdminCode2 = (string)el.Element("adminCode2");
         r.AdminName1 = (string)el.Element("adminName1");
         r.AdminName2 = (string)el.Element("adminName2");
         r.CountryCode = (string)el.Element("countryCode");
     }
                    )
                ));
 }