コード例 #1
0
 private void TryFillCountry(ExchangeAddressDetail detail, AddressDetail addressDetail)
 {
     if (string.IsNullOrEmpty(detail.CountryName) || addressDetail.CountryId != Guid.Empty)
     {
         return;
     }
     if (CountryMap.ContainsKey(detail.CountryName))
     {
         addressDetail.CountryId = CountryMap[detail.CountryName];
     }
 }
コード例 #2
0
        /// <summary>
        /// ########## ######## ###### ###### ######## ########## ######### <see cref="AddressDetail"/> ## #####,
        /// ############# ## ######## ######, ######## ####### # ######## ######.
        /// </summary>
        public Dictionary <string, AddressDetail> GetAddressesLookupMap()
        {
            var map = new Dictionary <string, AddressDetail>();

            foreach (ExchangeAddressDetail detail in _addressDetails)
            {
                string key = GetUniqueKey(detail);
                if (map.ContainsKey(key))
                {
                    continue;
                }
                var addressDetail = new AddressDetail(Guid.Empty, Guid.Empty, Guid.Empty);
                TryFillCity(detail, addressDetail);
                TryFillRegion(detail, addressDetail);
                TryFillCountry(detail, addressDetail);
                map[key] = addressDetail;
            }
            return(map);
        }
コード例 #3
0
        private void TryFillCity(ExchangeAddressDetail detail, AddressDetail addressDetail)
        {
            if (string.IsNullOrEmpty(detail.CityName))
            {
                return;
            }
            var citiesValue = CityMap.Where(e => e.Key.CityName == detail.CityName).ToList();

            if (!citiesValue.Any())
            {
                return;
            }
            if (citiesValue.Count() == 1)
            {
                FillAddressDetail(addressDetail, citiesValue.First().Value);
                return;
            }
            if (string.IsNullOrEmpty(detail.RegionName))
            {
                return;
            }
            citiesValue = citiesValue.Where(e => e.Key.RegionNameConfig.RegionName == detail.RegionName).ToList();
            if (!citiesValue.Any())
            {
                return;
            }
            if (citiesValue.Count() == 1)
            {
                FillAddressDetail(addressDetail, citiesValue.First().Value);
                return;
            }
            if (string.IsNullOrEmpty(detail.CountryName))
            {
                return;
            }
            citiesValue = citiesValue.Where(e => e.Key.RegionNameConfig.CountryName == detail.CountryName).ToList();
            if (citiesValue.Count() == 1)
            {
                FillAddressDetail(addressDetail, citiesValue.First().Value);
            }
        }
コード例 #4
0
        private void TryFillRegion(ExchangeAddressDetail detail, AddressDetail addressDetail)
        {
            if (string.IsNullOrEmpty(detail.RegionName) || addressDetail.RegionId != Guid.Empty)
            {
                return;
            }
            var regionsValue = RegionMap.Where(e => e.Key.RegionName == detail.RegionName).ToList();

            if (!regionsValue.Any())
            {
                return;
            }
            KeyValuePair <RegionNameConfig, RegionIdConfig> regionValue;

            if (regionsValue.Count() == 1)
            {
                regionValue            = regionsValue.First();
                addressDetail.RegionId = regionValue.Value.RegionId;
                if (addressDetail.CountryId == Guid.Empty)
                {
                    addressDetail.CountryId = regionValue.Value.CountryId;
                }
            }
            if (string.IsNullOrEmpty(detail.CountryName))
            {
                return;
            }
            regionsValue = regionsValue.Where(e => e.Key.CountryName == detail.CountryName).ToList();
            if (!regionsValue.Any() || regionsValue.Count() != 1)
            {
                return;
            }
            regionValue            = regionsValue.First();
            addressDetail.RegionId = regionValue.Value.RegionId;
            if (addressDetail.CountryId == Guid.Empty)
            {
                addressDetail.CountryId = regionValue.Value.CountryId;
            }
        }
コード例 #5
0
 private void FillAddressDetail(AddressDetail addressDetail, CityIdConfig cityIdConfig)
 {
     addressDetail.CityId    = cityIdConfig.CityId;
     addressDetail.RegionId  = cityIdConfig.RegionIdConfig.RegionId;
     addressDetail.CountryId = cityIdConfig.RegionIdConfig.CountryId;
 }
コード例 #6
0
        protected override void SetLocalItemValue(Entity detailItem, Exchange.PhysicalAddressKey typeKey)
        {
            var localAddr = detailItem as ContactAddress;

            if (localAddr == null)
            {
                return;
            }
            var contactProvider = Context.RemoteProvider as ExchangeContactSyncProviderImpl;

            if (contactProvider == null)
            {
                return;
            }
            Exchange.PhysicalAddressEntry exchangeAddr = ExchangeUtility.SafeGetValue <Exchange.PhysicalAddressKey,
                                                                                       Exchange.PhysicalAddressEntry, Exchange.PhysicalAddressEntry>(DetailItems, typeKey);
            if (exchangeAddr == null)
            {
                return;
            }
            Dictionary <string, AddressDetail> addressesLookupMap = (contactProvider).AddressesLookupMap;

            if (addressesLookupMap == null)
            {
                return;
            }
            var address = new StringBuilder();

            AppendToAddressString(address, exchangeAddr.Street);
            localAddr.Zip           = exchangeAddr.PostalCode;
            localAddr.AddressTypeId = TypesMap[typeKey];
            if (!addressesLookupMap.Any())
            {
                localAddr.Address = address.ToString();
                return;
            }
            string        cityName    = exchangeAddr.City;
            string        regionName  = exchangeAddr.State;
            string        countryName = exchangeAddr.CountryOrRegion;
            string        addressKey  = ExchangeContactAddressDetailHelper.GetUniqueKey(exchangeAddr);
            AddressDetail mapItem     = default(AddressDetail);

            if (addressesLookupMap.Keys.Contains(addressKey))
            {
                mapItem = addressesLookupMap[addressKey];
            }
            if (mapItem.CityId != Guid.Empty)
            {
                localAddr.CityId = mapItem.CityId;
            }
            else
            {
                localAddr.SetColumnValue("CityId", null);
                AppendToAddressString(address, cityName);
            }
            if (mapItem.RegionId != Guid.Empty)
            {
                localAddr.RegionId = mapItem.RegionId;
            }
            else
            {
                localAddr.SetColumnValue("RegionId", null);
                AppendToAddressString(address, regionName);
            }
            if (mapItem.CountryId != Guid.Empty)
            {
                localAddr.CountryId = mapItem.CountryId;
            }
            else
            {
                localAddr.SetColumnValue("CountryId", null);
                AppendToAddressString(address, countryName);
            }
            localAddr.Address = address.ToString();
        }