internal static object ConvertValueFromStore(EwsStoreObjectPropertyDefinition property, object originalValue)
        {
            if (originalValue == null)
            {
                return(null);
            }
            Type type = originalValue.GetType();

            if (type == typeof(EmailAddressCollection) && property.Type == typeof(ADRecipientOrAddress))
            {
                return(new MultiValuedProperty <ADRecipientOrAddress>(false, property, (from x in (EmailAddressCollection)originalValue
                                                                                        select EwsStoreValueConverter.ConvertValueFromStore(property, x)).ToArray <object>()));
            }
            if (type == typeof(PolicyTag))
            {
                return(((PolicyTag)originalValue).RetentionId);
            }
            Type type2 = property.Type;

            if (type2 == typeof(ADRecipientOrAddress))
            {
                EmailAddress emailAddress = (EmailAddress)originalValue;
                return(new ADRecipientOrAddress(new Participant(emailAddress.Name, emailAddress.Address, emailAddress.RoutingType)));
            }
            if (!(type2 != typeof(byte[])) || !(property.StorePropertyDefinition.Type == typeof(byte[])) || !(originalValue is byte[]))
            {
                return(StoreValueConverter.ConvertValueFromStore(property, originalValue));
            }
            if (type2 == typeof(ADObjectId))
            {
                return(StoreValueConverter.ConvertValueFromStore(property, originalValue));
            }
            return(Convert.ChangeType(EwsStoreValueConverter.DeserializeFromBinary((byte[])originalValue), type2));
        }
예제 #2
0
        internal static MultiValuedPropertyBase CreateGenericMultiValuedProperty(ProviderPropertyDefinition propertyDefinition, bool createAsReadOnly, ICollection values, ICollection invalidValues, LocalizedString?readOnlyErrorMessage)
        {
            MultiValuedPropertyBase result;

            if (!StoreValueConverter.TryCreateGenericMultiValuedProperty(propertyDefinition, createAsReadOnly, values, invalidValues, readOnlyErrorMessage, out result))
            {
                throw new NotImplementedException(DataStrings.ErrorMvpNotImplemented(propertyDefinition.Type.ToString(), propertyDefinition.Name));
            }
            return(result);
        }
예제 #3
0
        public static void Fill(UserConfiguration userConfiguration, ConfigurableObject configurableObject, IEnumerable <ProviderPropertyDefinition> appliedProperties)
        {
            IDictionary dictionary = userConfiguration.GetDictionary();

            foreach (ProviderPropertyDefinition providerPropertyDefinition in appliedProperties)
            {
                if (dictionary.Contains(providerPropertyDefinition.Name))
                {
                    configurableObject.propertyBag[providerPropertyDefinition] = StoreValueConverter.ConvertValueFromStore(providerPropertyDefinition, dictionary[providerPropertyDefinition.Name]);
                }
            }
        }
        internal static object ConvertValueToStore(EwsStoreObjectPropertyDefinition property, object originalValue)
        {
            if (originalValue == null)
            {
                return(null);
            }
            Type type = originalValue.GetType();

            if (type == typeof(ADRecipientOrAddress))
            {
                ADRecipientOrAddress adrecipientOrAddress = (ADRecipientOrAddress)originalValue;
                return(new EmailAddress(adrecipientOrAddress.DisplayName, adrecipientOrAddress.Address, adrecipientOrAddress.RoutingType));
            }
            if (type == typeof(MultiValuedProperty <ADRecipientOrAddress>))
            {
                return((from x in (MultiValuedProperty <ADRecipientOrAddress>) originalValue
                        select x.Address).ToArray <string>());
            }
            if (type == typeof(AuditLogSearchId))
            {
                return(((AuditLogSearchId)originalValue).Guid);
            }
            if (type == typeof(ADObjectId) && property.StorePropertyDefinition.Type == typeof(byte[]))
            {
                return(((ADObjectId)originalValue).GetBytes());
            }
            if (type == typeof(MultiValuedProperty <ADObjectId>) && property.IsMultivalued && property.StorePropertyDefinition is ExtendedPropertyDefinition && ((ExtendedPropertyDefinition)property.StorePropertyDefinition).MapiType == 3)
            {
                return((from x in (MultiValuedProperty <ADObjectId>) originalValue
                        select x.GetBytes()).ToArray <byte[]>());
            }
            if (type != typeof(byte[]) && property.StorePropertyDefinition.Type == typeof(byte[]))
            {
                return(EwsStoreValueConverter.SerializeToBinary(originalValue));
            }
            if (!(property.StorePropertyDefinition.Type == typeof(PolicyTag)))
            {
                return(ValueConvertor.ConvertValue(StoreValueConverter.ConvertValueToStore(originalValue), EwsStoreValueConverter.GetStorePropertyDefinitionActualType(property), null));
            }
            if ((Guid?)originalValue == null)
            {
                return(null);
            }
            return(new PolicyTag(true, (Guid)originalValue));
        }
예제 #5
0
        internal static void Save(ConfigurableObject configObject, SaveMode saveMode, ProviderPropertyDefinition[] appliedProperties, UserConfigurationDictionaryHelper.GetDictionaryUserConfigurationDelegate getDictionaryUserConfigurationDelegate)
        {
            Util.ThrowOnNullArgument(configObject, "configObject");
            Util.ThrowOnNullArgument(appliedProperties, "appliedProperties");
            bool flag = false;

            do
            {
                using (UserConfiguration userConfiguration = getDictionaryUserConfigurationDelegate(!flag))
                {
                    IDictionary dictionary = userConfiguration.GetDictionary();
                    foreach (ProviderPropertyDefinition providerPropertyDefinition in appliedProperties)
                    {
                        if (configObject.IsModified(providerPropertyDefinition))
                        {
                            object obj = configObject[providerPropertyDefinition];
                            if (obj == null)
                            {
                                dictionary.Remove(providerPropertyDefinition.Name);
                            }
                            else
                            {
                                dictionary[providerPropertyDefinition.Name] = StoreValueConverter.ConvertValueToStore(obj);
                            }
                        }
                    }
                    try
                    {
                        userConfiguration.Save(saveMode);
                        break;
                    }
                    catch (ObjectExistedException)
                    {
                        if (flag)
                        {
                            throw;
                        }
                        flag = true;
                    }
                }
            }while (flag);
        }
예제 #6
0
 internal override MultiValuedPropertyBase CreateMultiValuedProperty(ProviderPropertyDefinition propertyDefinition, bool createAsReadOnly, ICollection values, ICollection invalidValues, LocalizedString?readOnlyErrorMessage)
 {
     return(StoreValueConverter.CreateGenericMultiValuedProperty(propertyDefinition, createAsReadOnly, values, invalidValues, readOnlyErrorMessage));
 }
예제 #7
0
        private void SaveConfigObjectToUserConfiguration(string userConfigurationName, XsoMailboxConfigurationObject configObject)
        {
            bool flag = false;
            int  num  = 0;

            do
            {
                using (IUserConfiguration userConfiguration = this.getUserConfiguration(base.MailboxSession, userConfigurationName, UserConfigurationTypes.Dictionary, !flag))
                {
                    if (userConfiguration != null)
                    {
                        IDictionary dictionary;
                        try
                        {
                            dictionary = userConfiguration.GetDictionary();
                        }
                        catch (CorruptDataException)
                        {
                            ExTraceGlobals.StorageTracer.TraceDebug <IExchangePrincipal>((long)this.GetHashCode(), "The calendar configuration for {0} is corrupt", base.MailboxSession.MailboxOwner);
                            dictionary = new ConfigurationDictionary();
                        }
                        catch (VirusDetectedException)
                        {
                            ExTraceGlobals.StorageTracer.TraceDebug <IExchangePrincipal>((long)this.GetHashCode(), "The calendar configuration for {0} is virus infected.", base.MailboxSession.MailboxOwner);
                            dictionary = new ConfigurationDictionary();
                        }
                        foreach (PropertyDefinition propertyDefinition in configObject.Schema.AllProperties)
                        {
                            XsoDictionaryPropertyDefinition xsoDictionaryPropertyDefinition = propertyDefinition as XsoDictionaryPropertyDefinition;
                            if (xsoDictionaryPropertyDefinition != null && !xsoDictionaryPropertyDefinition.IsReadOnly && !(xsoDictionaryPropertyDefinition.UserConfigurationName != userConfigurationName) && configObject.IsModified(xsoDictionaryPropertyDefinition))
                            {
                                object obj = configObject[xsoDictionaryPropertyDefinition];
                                if (obj == null || (obj is ICollection && ((ICollection)obj).Count == 0))
                                {
                                    dictionary.Remove(xsoDictionaryPropertyDefinition.Name);
                                }
                                else
                                {
                                    dictionary[xsoDictionaryPropertyDefinition.Name] = StoreValueConverter.ConvertValueToStore(obj);
                                }
                            }
                        }
                        try
                        {
                            ExTraceGlobals.FaultInjectionTracer.TraceTest(4289080637U);
                            userConfiguration.Save();
                            break;
                        }
                        catch (ObjectExistedException)
                        {
                            if (flag)
                            {
                                throw;
                            }
                            flag = true;
                        }
                        catch (SaveConflictException)
                        {
                            if (num >= 5)
                            {
                                throw;
                            }
                            num++;
                            flag = true;
                        }
                    }
                }
            }while (flag);
        }
예제 #8
0
 private void LoadUserConfigurationToConfigObject(string userConfigurationName, XsoMailboxConfigurationObject configObject)
 {
     using (IReadableUserConfiguration readableUserConfiguration = this.getReadOnlyUserConfiguration(base.MailboxSession, userConfigurationName, UserConfigurationTypes.Dictionary, false))
     {
         if (readableUserConfiguration != null)
         {
             IDictionary dictionary = readableUserConfiguration.GetDictionary();
             foreach (PropertyDefinition propertyDefinition in configObject.Schema.AllProperties)
             {
                 XsoDictionaryPropertyDefinition xsoDictionaryPropertyDefinition = propertyDefinition as XsoDictionaryPropertyDefinition;
                 if (xsoDictionaryPropertyDefinition != null && !(xsoDictionaryPropertyDefinition.UserConfigurationName != userConfigurationName) && dictionary.Contains(xsoDictionaryPropertyDefinition.Name))
                 {
                     configObject.propertyBag.SetField(xsoDictionaryPropertyDefinition, StoreValueConverter.ConvertValueFromStore(xsoDictionaryPropertyDefinition, dictionary[xsoDictionaryPropertyDefinition.Name]));
                 }
             }
         }
     }
 }
예제 #9
0
        internal static object ConvertValueToStore(object originalValue)
        {
            if (originalValue == null)
            {
                return(null);
            }
            if (originalValue is Enum)
            {
                return((int)originalValue);
            }
            if (originalValue is ExTimeZoneValue)
            {
                return(((ExTimeZoneValue)originalValue).ToString());
            }
            if (originalValue is TimeSpan)
            {
                return((int)((TimeSpan)originalValue).TotalMinutes);
            }
            if (originalValue is Uri)
            {
                return(((Uri)originalValue).ToString());
            }
            if (originalValue is ADObjectId)
            {
                return(((ADObjectId)originalValue).GetBytes());
            }
            if (originalValue is MultiValuedProperty <string> )
            {
                return(StoreValueConverter.ConvertMvpStringToStringArray((MultiValuedProperty <string>)originalValue));
            }
            if (originalValue is MultiValuedProperty <ADObjectId> )
            {
                return(StoreValueConverter.ConvertMvpADObjectIdToStringArray((MultiValuedProperty <ADObjectId>)originalValue));
            }
            if (originalValue is MultiValuedProperty <KeywordHit> )
            {
                return(StoreValueConverter.ConvertMvpToStringArray <KeywordHit>((MultiValuedProperty <KeywordHit>)originalValue));
            }
            if (originalValue is MultiValuedProperty <DiscoverySearchStats> )
            {
                return(StoreValueConverter.ConvertMvpToStringArray <DiscoverySearchStats>((MultiValuedProperty <DiscoverySearchStats>)originalValue));
            }
            if (originalValue is CultureInfo)
            {
                return(originalValue.ToString());
            }
            if (originalValue is ExchangeObjectVersion)
            {
                return(((ExchangeObjectVersion)originalValue).ToInt64());
            }
            if (!(originalValue is Unlimited <EnhancedTimeSpan>))
            {
                return(originalValue);
            }
            Unlimited <EnhancedTimeSpan> value = (Unlimited <EnhancedTimeSpan>)originalValue;

            if (value == Unlimited <EnhancedTimeSpan> .UnlimitedValue)
            {
                return(null);
            }
            return(value.Value.Ticks);
        }
예제 #10
0
        internal static object ConvertValueFromStore(ProviderPropertyDefinition property, object originalValue)
        {
            if (originalValue == null)
            {
                return(null);
            }
            Type type = property.Type;

            if (type.Equals(originalValue.GetType()))
            {
                return(originalValue);
            }
            if (type.GetTypeInfo().IsEnum)
            {
                return(Enum.ToObject(type, originalValue));
            }
            if (type == typeof(ExTimeZoneValue))
            {
                return(ExTimeZoneValue.Parse(originalValue.ToString()));
            }
            if (type == typeof(TimeSpan))
            {
                return(TimeSpan.FromMinutes((double)((int)originalValue)));
            }
            if (type == typeof(Uri))
            {
                return(new Uri(originalValue.ToString(), UriKind.Absolute));
            }
            if (type == typeof(string) && property.IsMultivalued)
            {
                return(StoreValueConverter.ConvertStringArrayToMvpString(originalValue));
            }
            if (type == typeof(ADObjectId))
            {
                if (property.IsMultivalued)
                {
                    if (originalValue is byte[][])
                    {
                        return(StoreValueConverter.ConvertByteMatrixToMvpADObjectId(originalValue));
                    }
                    return(StoreValueConverter.ConvertStringArrayToMvpADObjectId(originalValue));
                }
                else if (originalValue is byte[])
                {
                    return(new ADObjectId((byte[])originalValue));
                }
            }
            if (type == typeof(KeywordHit) && property.IsMultivalued)
            {
                return(StoreValueConverter.ConvertStringArrayToMvpKeywordHit(originalValue));
            }
            if (type == typeof(DiscoverySearchStats) && property.IsMultivalued)
            {
                return(StoreValueConverter.ConvertStringArrayToMvpDiscoverySearchStats(originalValue));
            }
            if (!(type == typeof(CultureInfo)))
            {
                if (type == typeof(Unlimited <EnhancedTimeSpan>))
                {
                    if (originalValue == null)
                    {
                        return(Unlimited <EnhancedTimeSpan> .UnlimitedValue);
                    }
                    if (originalValue is long)
                    {
                        return(new Unlimited <EnhancedTimeSpan>(EnhancedTimeSpan.FromTicks((long)originalValue)));
                    }
                }
                return(ValueConvertor.ConvertValue(originalValue, type, null));
            }
            if (originalValue != null)
            {
                return(new CultureInfo((string)originalValue));
            }
            return(null);
        }