예제 #1
0
        public bool Equals(GeocoderResult resultToCompareTo)
        {
            bool addressIsEqual = !string.IsNullOrEmpty(AddressLineOne) &&
                                  !string.IsNullOrEmpty(resultToCompareTo.AddressLineOne) &&
                                  AddressLineOne.ToLower() == resultToCompareTo.AddressLineOne.ToLower();

            bool zipCodeIsEqual = !string.IsNullOrEmpty(ZipCode) && !string.IsNullOrEmpty(resultToCompareTo.ZipCode) &&
                                  ZipCode.Length >= 5 && resultToCompareTo.ZipCode.Length >= 5 &&
                                  resultToCompareTo.ZipCode.Substring(0, 5) == ZipCode.Substring(0, 5);

            bool cityAndStateEqual = !string.IsNullOrEmpty(City) && !string.IsNullOrEmpty(State) &&
                                     !string.IsNullOrEmpty(resultToCompareTo.City) &&
                                     !string.IsNullOrEmpty(resultToCompareTo.State) &&
                                     City.ToLower() == resultToCompareTo.City.ToLower() && State.ToLower() ==
                                     resultToCompareTo.State.ToLower();

            return addressIsEqual && (cityAndStateEqual || zipCodeIsEqual);
        }
예제 #2
0
        public LocationVM(Location entity)
        {
            #region Register Commands

            SearchCommand = new RelayCommand(OnSearch);
            SetLocationToGeocoderResultCommand = new RelayCommand(OnSetLocation,
                                                                  () =>
                                                                  SelectedGeocoderResult != null &&
                                                                  !String.IsNullOrEmpty(SelectedGeocoderResult.Latitude) &&
                                                                  !String.IsNullOrEmpty(SelectedGeocoderResult.Longitude));
            ManuallySetLatitudeLongitude = new RelayCommand<Tuple<decimal, decimal>>(OnManuallySetLatitudeLongitude,
                                                                                     (latitudeLongitude) =>
                                                                                     SelectedGeocoderResult != null &&
                                                                                     SelectedGeocoderResult.Name ==
                                                                                     ManuallySelectLocationString);

            #endregion

            #region Entity logic

            _entity = entity;

            //Setup the ContactInfoVM
            ContactInfoVM = new ContactInfoVM(ContactInfoType.Locations, entity != null ? entity.ContactInfoSet : null);

            ManuallySelectGeocoderResult = new GeocoderResult { Name = ManuallySelectLocationString, AddressLineOne = ClickOnTheMapString };

            var depot = ContextManager.ServiceProvider.Depots.FirstOrDefault();
            var ipInformation = ((string)Application.Current.Resources["IPInformation"]);

            //Set ManuallySelectGeocoderResult to the Entity if it has a Latitude/Longitude
            if (entity != null && entity.Latitude != null && entity.Longitude != null)
            {
                ManuallySelectGeocoderResult.Latitude = entity.Latitude.Value.ToString();
                ManuallySelectGeocoderResult.Longitude = entity.Longitude.Value.ToString();
                SelectedGeocoderResult = ManuallySelectGeocoderResult;
                if (SelectedGeocoderResult.TelerikLocation != null)
                    MessageBus.Current.SendMessage(new LocationSetMessage(SelectedGeocoderResult.TelerikLocation.Value));
            }
            //Otherwise set it to the depot if there is one
            else if (depot != null && depot.Latitude.HasValue && depot.Longitude.HasValue)
            {
                ManuallySelectGeocoderResult.Latitude = depot.Latitude.Value.ToString();
                ManuallySelectGeocoderResult.Longitude = depot.Longitude.Value.ToString();
            }
            //Otherwise use the IPInfo if there is any
            else if (ipInformation != null)
            {
                var ipInformationDelimited = ipInformation.Split(';');
                var latitude = ipInformationDelimited[8];
                var longitude = ipInformationDelimited[9];

                ManuallySelectGeocoderResult.Latitude = latitude;
                ManuallySelectGeocoderResult.Longitude = longitude;
            }

            #endregion

            if (entity == null)
                return;

            //Set the default SearchText
            SearchText = string.Format("{0}, {1}, {2}, {3}", entity.AddressLineOne, entity.AdminDistrictTwo, entity.AdminDistrictOne, entity.PostalCode);

            #region Subscribe to Location state validation
            //Setup ValidLatitudeLongitude observable, it will be valid as long as the Entity's lat & long have a value
            //Start with a value
            ValidLatitudeLongitudeState = new BehaviorSubject<bool>(Entity.Latitude.HasValue && Entity.Longitude.HasValue);
            // Subscribe to changes
            Observable2.FromPropertyChangedPattern(Entity, x => x.Latitude).CombineLatest(
                Observable2.FromPropertyChangedPattern(Entity, x => x.Longitude), (a, b) => a.HasValue && b.HasValue).Throttle(new TimeSpan(0, 0, 0, 0, 250))
                .Subscribe((BehaviorSubject<bool>)ValidLatitudeLongitudeState);

            #endregion
        }
예제 #3
0
        private static IEnumerable<GeocoderResult> BingGeocodeServiceDownloadStringCompleted(string data)
        {
            string xmlContent = data;
            XDocument xmlResultSet = XDocument.Parse(xmlContent);
            XNamespace xmlns = "http://schemas.microsoft.com/search/local/ws/rest/v1";

            var results =
                xmlResultSet.Descendants(xmlns + "Location")
                .Select(
                    result =>
                    {
                        var geocoderResult = new GeocoderResult();

                        var name = result.Element(xmlns + "Name");
                        if (name != null)
                            geocoderResult.Name = name.Value;

                        var precision = result.Element(xmlns + "Confidence");
                        if (precision != null)
                            geocoderResult.Precision = precision.Value;

                        var pointElement = result.Element(xmlns + "Point");
                        if (pointElement != null)
                        {
                            var latitude = pointElement.Element(xmlns + "Latitude");
                            if (latitude != null)
                                geocoderResult.Latitude = latitude.Value;

                            var longitude = pointElement.Element(xmlns + "Longitude");
                            if (longitude != null)
                                geocoderResult.Longitude = longitude.Value;
                        }

                        var addressElement = result.Element(xmlns + "Address");
                        if (addressElement != null)
                        {
                            var addressLineOne = addressElement.Element(xmlns + "AddressLine");
                            if (addressLineOne != null)
                                geocoderResult.AddressLineOne = addressLineOne.Value;

                            var city = addressElement.Element(xmlns + "Locality");
                            if (city != null)
                                geocoderResult.City = city.Value;

                            var state = addressElement.Element(xmlns + "AdminDistrict");
                            if (state != null)
                                geocoderResult.State = state.Value;

                            var countryCode = addressElement.Element(xmlns + "CountryRegion");
                            if (countryCode != null)
                                geocoderResult.CountryCode = countryCode.Value;

                            var zipCode = addressElement.Element(xmlns + "PostalCode");
                            if (zipCode != null)
                                geocoderResult.ZipCode = zipCode.Value;
                        }

                        return geocoderResult;
                    }).ToArray();

            return results;
        }