Example #1
0
        object ICustomTextConverter.Parse(Type resultType, string s, IFormatProvider provider)
        {
            if (resultType == null)
            {
                throw new ArgumentNullException("resultType");
            }
            s = (s ?? string.Empty);
            object obj = this.PreParseObject(resultType, s, provider);

            if (obj != null && obj.GetType() != resultType)
            {
                if (obj.GetType() == typeof(string))
                {
                    obj = this.ParseObject((string)obj, provider);
                }
                if (obj != null && obj.GetType() != resultType)
                {
                    try
                    {
                        obj = ValueConvertor.ConvertValue(obj, resultType, provider);
                    }
                    catch (NotImplementedException)
                    {
                    }
                }
            }
            return(obj);
        }
Example #2
0
        internal void SetCmdletProperty(object ffoTask, object value)
        {
            PropertyInfo property = ffoTask.GetType().GetProperty(this.propertyName);

            if (property == null)
            {
                throw new NullReferenceException("Property does not exist.");
            }
            if (typeof(IList).IsAssignableFrom(property.PropertyType))
            {
                IList list = ODataInput.ConvertToList(value);
                if (list == null || list.Count <= 0)
                {
                    return;
                }
                IList list2 = (IList)property.GetValue(ffoTask, null);
                list2.Clear();
                using (IEnumerator enumerator = list.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        object value2 = enumerator.Current;
                        list2.Add(value2);
                    }
                    return;
                }
            }
            object value3 = ValueConvertor.ConvertValue(value, property.PropertyType, null);

            property.SetValue(ffoTask, value3);
        }
Example #3
0
        private static ICollection ConvertValue(object value, ArrayList newValues)
        {
            if (newValues == null)
            {
                newValues = new ArrayList();
            }
            ApprovedApplication approvedApplication = (ApprovedApplication)ValueConvertor.ConvertValue(value, typeof(ApprovedApplication), null);

            if (approvedApplication != null)
            {
                if (approvedApplication.IsCab)
                {
                    MultiValuedProperty <ApprovedApplication> multiValuedProperty = ApprovedApplication.ParseCab(approvedApplication.CabName);
                    using (MultiValuedProperty <ApprovedApplication> .Enumerator enumerator = multiValuedProperty.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            ApprovedApplication value2 = enumerator.Current;
                            newValues.Add(value2);
                        }
                        return(newValues);
                    }
                }
                newValues.Add(value);
                return(newValues);
            }
            throw new DataValidationException(new PropertyValidationError(DirectoryStrings.ExceptionInvalidApprovedApplication(value.ToString()), MobileMailboxPolicySchema.ADApprovedApplicationList, value));
        }
Example #4
0
        private void ValueFromTask(object reportingObject, PropertyInfo property, object dalObject, object task)
        {
            Type   type   = task.GetType();
            object value  = type.GetProperty(this.dalPropertyName).GetValue(task, null);
            object value2 = ValueConvertor.ConvertValue(value, property.PropertyType, null);

            property.SetValue(reportingObject, value2, null);
        }
Example #5
0
        private object PreParseObject(Type resultType, string s, IFormatProvider formatProvider)
        {
            object result = s;

            if (typeof(IList).IsAssignableFrom(resultType))
            {
                throw new NotSupportedException();
            }
            if (resultType.IsGenericType)
            {
                Type type = resultType.GetGenericArguments()[0];
                if (resultType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Unlimited <>))
                    {
                        resultType = type;
                        type       = resultType.GetGenericArguments()[0];
                    }
                    else if (string.IsNullOrEmpty(s))
                    {
                        result = null;
                    }
                    else
                    {
                        result = ValueConvertor.ConvertValue(this.Parse(type, s, formatProvider), resultType, formatProvider);
                    }
                }
                if (resultType.GetGenericTypeDefinition() == typeof(Unlimited <>))
                {
                    if (string.Compare(Strings.UnlimitedString.ToString(), s) == 0)
                    {
                        result = TextConverter.GetPropertyValue(resultType, null, "UnlimitedValue");
                    }
                    else
                    {
                        result = ValueConvertor.ConvertValue(this.Parse(type, s, formatProvider), resultType, formatProvider);
                    }
                }
            }
            else if (resultType == typeof(bool) && s != null)
            {
                bool flag;
                if (bool.TryParse(s, out flag))
                {
                    result = flag;
                }
                else if (string.Compare(s, Strings.TrueString) == 0)
                {
                    result = true;
                }
                else if (string.Compare(s, Strings.FalseString) == 0)
                {
                    result = false;
                }
            }
            return(result);
        }
Example #6
0
        public override string ToJavaScript(IControlResolver resolver)
        {
            object obj = this.Value ?? this.DefaultValue;

            if (this.TargetType != null)
            {
                obj = ValueConvertor.ConvertValue(obj, this.TargetType, null);
            }
            return(string.Format("new StaticBinding({0})", obj.ToJsonString(null)));
        }
        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));
        }
        private T ObjectFromItem <T>(Item item) where T : IConfigurable, new()
        {
            EwsStoreObject        ewsStoreObject  = (EwsStoreObject)((object)((default(T) == null) ? Activator.CreateInstance <T>() : default(T)));
            object                originalValue   = null;
            ExchangeObjectVersion exchangeVersion = (ExchangeObjectVersion)EwsStoreObjectSchema.ExchangeVersion.DefaultValue;

            if (item.TryGetProperty(EwsStoreObjectSchema.ExchangeVersion.StorePropertyDefinition, ref originalValue))
            {
                exchangeVersion = (ExchangeObjectVersion)ValueConvertor.ConvertValue(originalValue, typeof(ExchangeObjectVersion), null);
                ewsStoreObject.SetExchangeVersion(exchangeVersion);
                if (ewsStoreObject.ExchangeVersion.Major > ewsStoreObject.MaximumSupportedExchangeObjectVersion.Major)
                {
                    ExTraceGlobals.StorageTracer.TraceWarning <ItemId, byte, byte>(0L, "{0} has major version {1} which is greater than current one ({2}) and will be ignored", item.Id, ewsStoreObject.ExchangeVersion.Major, ewsStoreObject.MaximumSupportedExchangeObjectVersion.Major);
                    return(default(T));
                }
            }
            if (!string.IsNullOrEmpty(ewsStoreObject.ItemClass) && !ewsStoreObject.ItemClass.Equals(item.ItemClass, StringComparison.OrdinalIgnoreCase))
            {
                return(default(T));
            }
            ewsStoreObject.CopyFromItemObject(item, this.RequestedServerVersion);
            if (ewsStoreObject.MaximumSupportedExchangeObjectVersion.IsOlderThan(ewsStoreObject.ExchangeVersion))
            {
                ExTraceGlobals.StorageTracer.TraceWarning <ItemId, ExchangeObjectVersion, ExchangeObjectVersion>(0L, "{0} has version {1} which is greater than current one ({2}) and will be read-only", item.Id, ewsStoreObject.ExchangeVersion, ewsStoreObject.MaximumSupportedExchangeObjectVersion);
                ewsStoreObject.SetIsReadOnly(true);
            }
            ValidationError[] array = ewsStoreObject.ValidateRead();
            ewsStoreObject.ResetChangeTracking(true);
            if (array.Length > 0)
            {
                foreach (ValidationError validationError in array)
                {
                    PropertyValidationError propertyValidationError = validationError as PropertyValidationError;
                    ExTraceGlobals.StorageTracer.TraceDebug((long)this.GetHashCode(), "Object '{0}' read from '{1}' failed validation. Attribute: '{2}'. Invalid data: '{3}'. Error message: '{4}'.", new object[]
                    {
                        ewsStoreObject.Identity,
                        this.Mailbox.ToString() + "\\" + this.DefaultFolder.ToString(),
                        (propertyValidationError != null) ? propertyValidationError.PropertyDefinition.Name : "<null>",
                        (propertyValidationError != null) ? (propertyValidationError.InvalidData ?? "<null>") : "<null>",
                        validationError.Description
                    });
                }
            }
            return((T)((object)this.FilterObject(ewsStoreObject)));
        }
Example #9
0
        private void ReadObject(string folderPath, string folderName, ref RegistryObject instance)
        {
            RegistryObjectSchema registrySchema = instance.RegistrySchema;

            using (RegistryKey registryKey = this.RootKey.OpenSubKey(folderPath))
            {
                if (registryKey == null || !registryKey.GetSubKeyNames().Contains(folderName, StringComparer.OrdinalIgnoreCase))
                {
                    return;
                }
                foreach (PropertyDefinition propertyDefinition in registrySchema.AllProperties)
                {
                    SimpleProviderPropertyDefinition simpleProviderPropertyDefinition = (SimpleProviderPropertyDefinition)propertyDefinition;
                    if (!simpleProviderPropertyDefinition.IsCalculated && !this.excludedPersistentProperties.Contains(simpleProviderPropertyDefinition))
                    {
                        object obj = RegistryReader.Instance.GetValue <object>(registryKey, folderName, simpleProviderPropertyDefinition.Name, simpleProviderPropertyDefinition.DefaultValue);
                        try
                        {
                            obj = ValueConvertor.ConvertValue(obj, simpleProviderPropertyDefinition.Type, null);
                        }
                        catch (Exception ex)
                        {
                            instance.AddValidationError(new PropertyValidationError(DataStrings.ErrorCannotConvertFromString(obj as string, simpleProviderPropertyDefinition.Type.Name, ex.Message), simpleProviderPropertyDefinition, obj));
                            continue;
                        }
                        try
                        {
                            instance[simpleProviderPropertyDefinition] = obj;
                        }
                        catch (DataValidationException ex2)
                        {
                            instance.AddValidationError(ex2.Error);
                        }
                    }
                }
            }
            instance.propertyBag[SimpleProviderObjectSchema.Identity] = new RegistryObjectId(folderPath, folderName);
            instance.ResetChangeTracking(true);
        }
        public override PropertyConstraintViolationError Validate(object value, PropertyDefinition propertyDefinition, IPropertyBag propertyBag)
        {
            T t;

            try
            {
                t = (T)((object)ValueConvertor.ConvertValue(value, typeof(T), null));
            }
            catch (NotImplementedException ex)
            {
                return(new PropertyConstraintViolationError(new LocalizedString(ex.Message), propertyDefinition, value, this));
            }
            catch (TypeConversionException ex2)
            {
                return(new PropertyConstraintViolationError(ex2.LocalizedString, propertyDefinition, value, this));
            }
            if (this.specifyAllowedValues)
            {
                foreach (T t2 in this.valuesArray)
                {
                    if (object.Equals(t2, t))
                    {
                        return(null);
                    }
                }
                return(new PropertyConstraintViolationError(DataStrings.ConstraintViolationValueIsNotAllowed(this.GetValuesString(this.valuesArray), t.ToString()), propertyDefinition, t, this));
            }
            foreach (T t3 in this.valuesArray)
            {
                if (object.Equals(t3, t))
                {
                    return(new PropertyConstraintViolationError(DataStrings.ConstraintViolationValueIsDisallowed(this.GetValuesString(this.valuesArray), t.ToString()), propertyDefinition, t, this));
                }
            }
            return(null);
        }
        // Token: 0x06000E7D RID: 3709 RVA: 0x00045858 File Offset: 0x00043A58
        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(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(SimpleStoreValueConverter.ConvertStringArrayToMvpString(originalValue));
            }
            if (type == typeof(ADObjectId))
            {
                if (property.IsMultivalued)
                {
                    if (originalValue is byte[][])
                    {
                        return(SimpleStoreValueConverter.ConvertByteMatrixToMvpADObjectId(originalValue));
                    }
                    return(SimpleStoreValueConverter.ConvertStringArrayToMvpADObjectId(originalValue));
                }
                else if (originalValue is byte[])
                {
                    return(new ADObjectId((byte[])originalValue));
                }
            }
            if (type == typeof(KeywordHit) && property.IsMultivalued)
            {
                return(SimpleStoreValueConverter.ConvertStringArrayToMvpKeywordHit(originalValue));
            }
            if (type == typeof(int?) && property.IsMultivalued)
            {
                return(SimpleStoreValueConverter.ConvertIntArrayToMvpNullableInt(originalValue));
            }
            if (type == typeof(DiscoverySearchStats) && property.IsMultivalued)
            {
                return(SimpleStoreValueConverter.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);
        }
 protected virtual T ConvertInput(object item)
 {
     return((T)((object)ValueConvertor.ConvertValue(item, typeof(T), null)));
 }
Example #13
0
        private static bool FilterMatchesValue(SinglePropertyFilter filter, object value)
        {
            if (filter is ExistsFilter)
            {
                return(null != value);
            }
            if (filter is GenericBitMaskFilter)
            {
                ulong num;
                try
                {
                    num = Convert.ToUInt64(value);
                }
                catch (InvalidCastException)
                {
                    return(false);
                }
                GenericBitMaskFilter genericBitMaskFilter = filter as GenericBitMaskFilter;
                if (genericBitMaskFilter is BitMaskOrFilter)
                {
                    return(0UL != (genericBitMaskFilter.Mask & num));
                }
                if (genericBitMaskFilter is BitMaskAndFilter)
                {
                    return(genericBitMaskFilter.Mask == (genericBitMaskFilter.Mask & num));
                }
            }
            if (filter is TextFilter)
            {
                TextFilter textFilter = filter as TextFilter;
                string     text       = textFilter.Text ?? string.Empty;
                string     text2      = (value == null) ? string.Empty : value.ToString();
                if (string.IsNullOrEmpty(text2))
                {
                    return(string.IsNullOrEmpty(text));
                }
                StringComparison stringComparison = OpathFilterEvaluator.GetStringComparison(textFilter.MatchFlags);
                switch (textFilter.MatchOptions)
                {
                case MatchOptions.FullString:
                    return(text2.Equals(text, stringComparison));

                case MatchOptions.SubString:
                case MatchOptions.ExactPhrase:
                    return(-1 != text2.IndexOf(text, stringComparison));

                case MatchOptions.Prefix:
                    return(text2.StartsWith(text, stringComparison));

                case MatchOptions.Suffix:
                    return(text2.EndsWith(text, stringComparison));

                case MatchOptions.WildcardString:
                    return(OpathFilterEvaluator.MatchesWildcardString(text, text2, stringComparison));
                }
                throw new NotSupportedException("Not a currently supported Match Option: " + textFilter.MatchOptions);
            }
            else
            {
                if (!(filter is ComparisonFilter))
                {
                    throw new NotSupportedException("The specified filter type \"" + filter.GetType().Name + "\" is currently not supported.");
                }
                ComparisonFilter comparisonFilter = filter as ComparisonFilter;
                object           obj = ValueConvertor.ConvertValue(comparisonFilter.PropertyValue, comparisonFilter.Property.Type, null);
                switch (comparisonFilter.ComparisonOperator)
                {
                case ComparisonOperator.Equal:
                    return(OpathFilterEvaluator.Equals(obj, value, StringComparison.OrdinalIgnoreCase));

                case ComparisonOperator.NotEqual:
                    return(!OpathFilterEvaluator.Equals(obj, value, StringComparison.OrdinalIgnoreCase));

                case ComparisonOperator.LessThan:
                    return(0 < Comparer.Default.Compare(obj, value));

                case ComparisonOperator.LessThanOrEqual:
                    return(0 <= Comparer.Default.Compare(obj, value));

                case ComparisonOperator.GreaterThan:
                    return(0 > Comparer.Default.Compare(obj, value));

                case ComparisonOperator.GreaterThanOrEqual:
                    return(0 >= Comparer.Default.Compare(obj, value));

                default:
                    throw new NotSupportedException("Not a currently supported comparison operator: " + comparisonFilter.ComparisonOperator);
                }
            }
        }