internal static object CountriesGetter(IPropertyBag propertyBag) { MultiValuedProperty <CountryInfo> multiValuedProperty = null; MultiValuedProperty <string> multiValuedProperty2 = (MultiValuedProperty <string>)propertyBag[CountryListSchema.RawCountries]; if (multiValuedProperty2 != null) { multiValuedProperty = new MultiValuedProperty <CountryInfo>(); foreach (string name in multiValuedProperty2) { multiValuedProperty.Add(CountryInfo.Parse(name)); } } return(multiValuedProperty); }
internal static MbxPropertyDefinition CountryInfoFromStringPropertyDefinition(string name, MbxPropertyDefinition rawPropertyDefinition, bool multivalued = false) { return(new MbxPropertyDefinition(name, PropTag.Null, ExchangeObjectVersion.Exchange2003, typeof(CountryInfo), (multivalued ? PropertyDefinitionFlags.MultiValued : PropertyDefinitionFlags.None) | PropertyDefinitionFlags.Calculated, multivalued ? null : null, PropertyDefinitionConstraint.None, PropertyDefinitionConstraint.None, new MbxPropertyDefinition[] { rawPropertyDefinition }, delegate(IPropertyBag propertyBag) { if (propertyBag[rawPropertyDefinition] != null) { return CountryInfo.Parse((string)propertyBag[rawPropertyDefinition]); } return null; }, delegate(object value, IPropertyBag propertyBag) { propertyBag[rawPropertyDefinition] = ((CountryInfo)value).ToString(); })); }
internal static object CountryOrRegionGetter(IPropertyBag propertyBag) { string text = (string)propertyBag[ADOrgPersonSchema.C]; int countryCode = (int)propertyBag[ADOrgPersonSchema.CountryCode]; string displayName = (string)propertyBag[ADOrgPersonSchema.Co]; CountryInfo result = null; if (text != null && text.Length == 2) { try { result = CountryInfo.Parse(text, countryCode, displayName); } catch (InvalidCountryOrRegionException ex) { throw new DataValidationException(new PropertyValidationError(DirectoryStrings.CannotCalculateProperty("CountryOrRegion", ex.Message), ADOrgPersonSchema.CountryOrRegion, propertyBag[ADOrgPersonSchema.C]), ex); } } return(result); }
private static string GetRegionDisplayName(string countryCode) { string result; try { CountryInfo countryInfo = CountryInfo.Parse(countryCode); result = RtlUtil.ConvertToDecodedBidiString(Strings.GetLocalizedString((Strings.IDs)Enum.Parse(typeof(Strings.IDs), countryInfo.UniqueId)), RtlUtil.IsRtl); } catch { try { result = RtlUtil.ConvertToDecodedBidiString(Strings.GetLocalizedString((Strings.IDs)Enum.Parse(typeof(Strings.IDs), string.Format("Region_{0}", countryCode))), RtlUtil.IsRtl); } catch { result = countryCode; } } return(result); }
protected static object GetSingleProperty(object prop, Type type) { if (prop == null) { return(null); } object obj = null; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>)) { obj = MockObjectCreator.GetSingleProperty(prop, type.GetGenericArguments()[0]); } else if (type == typeof(ADObjectId) && prop is PSObject) { obj = new ADObjectId(((PSObject)prop).Members["DistinguishedName"].Value.ToString(), new Guid(((PSObject)prop).Members["ObjectGuid"].Value.ToString())); } else if (type == typeof(EnhancedTimeSpan)) { obj = EnhancedTimeSpan.Parse(prop.ToString()); } else if (type == typeof(Unlimited <EnhancedTimeSpan>)) { obj = Unlimited <EnhancedTimeSpan> .Parse(prop.ToString()); } else if (type == typeof(ByteQuantifiedSize)) { obj = ByteQuantifiedSize.Parse(prop.ToString()); } else if (type == typeof(Unlimited <ByteQuantifiedSize>)) { obj = Unlimited <ByteQuantifiedSize> .Parse(prop.ToString()); } else if (type == typeof(Unlimited <int>)) { obj = Unlimited <int> .Parse(prop.ToString()); } else if (type == typeof(ProxyAddress)) { obj = ProxyAddress.Parse(prop.ToString()); } else if (type == typeof(SmtpAddress)) { obj = new SmtpAddress(prop.ToString()); } else if (type == typeof(SmtpDomain)) { obj = SmtpDomain.Parse(prop.ToString()); } else if (type == typeof(CountryInfo)) { obj = CountryInfo.Parse(prop.ToString()); } else if (type == typeof(SharingPolicyDomain)) { obj = SharingPolicyDomain.Parse(prop.ToString()); } else if (type == typeof(ApprovedApplication)) { obj = ApprovedApplication.Parse(prop.ToString()); } else if (type == typeof(SmtpDomainWithSubdomains)) { obj = SmtpDomainWithSubdomains.Parse(prop.ToString()); } else if (type == typeof(UMLanguage)) { obj = UMLanguage.Parse(prop.ToString()); } else if (type == typeof(UMSmartHost)) { obj = UMSmartHost.Parse(prop.ToString()); } else if (type == typeof(ScheduleInterval)) { obj = ScheduleInterval.Parse(prop.ToString()); } else if (type == typeof(NumberFormat)) { obj = NumberFormat.Parse(prop.ToString()); } else if (type == typeof(DialGroupEntry)) { obj = DialGroupEntry.Parse(prop.ToString()); } else if (type == typeof(CustomMenuKeyMapping)) { obj = CustomMenuKeyMapping.Parse(prop.ToString()); } else if (type == typeof(HolidaySchedule)) { obj = HolidaySchedule.Parse(prop.ToString()); } else if (type == typeof(UMTimeZone)) { obj = UMTimeZone.Parse(prop.ToString()); } else if (type == typeof(ServerVersion)) { obj = ServerVersion.ParseFromSerialNumber(prop.ToString()); } else if (type == typeof(X509Certificate2)) { obj = new X509Certificate2(((PSObject)prop).Members["RawData"].Value as byte[]); } else if (type == typeof(LocalizedString)) { obj = new LocalizedString(prop.ToString()); } else if (type == typeof(ExchangeObjectVersion)) { obj = ExchangeObjectVersion.Parse(prop.ToString()); } else if (type == typeof(bool)) { obj = bool.Parse(prop.ToString()); } else if (type == typeof(SecurityPrincipalIdParameter)) { obj = new SecurityPrincipalIdParameter(prop.ToString()); } else if (type == typeof(ActiveDirectoryAccessRule)) { obj = (prop as ActiveDirectoryAccessRule); } else if (type == typeof(ObjectId)) { string text = prop.ToString(); if (!ADObjectId.IsValidDistinguishedName(text) && text.Contains("/")) { text = MockObjectCreator.ConvertDNFromTreeStructure(text); } obj = new ADObjectId(text); } else if (type.IsEnum) { try { obj = Enum.Parse(type, prop.ToString()); } catch (ArgumentException) { obj = Enum.GetValues(type).GetValue(0); } } return(obj ?? prop); }