コード例 #1
0
        internal void SetExchangeVersion(ExchangeObjectVersion newVersion)
        {
            this.CheckWritable();
            if (this.propertyBag.ObjectVersionPropertyDefinition == null)
            {
                throw new NotSupportedException(DataStrings.ExceptionVersionlessObject);
            }
            ExchangeObjectVersion exchangeVersion = this.ExchangeVersion;

            if (null == newVersion)
            {
                newVersion = (ExchangeObjectVersion)this.propertyBag.ObjectVersionPropertyDefinition.DefaultValue;
            }
            if (newVersion.IsOlderThan(exchangeVersion))
            {
                List <ProviderPropertyDefinition> list = new List <ProviderPropertyDefinition>(this.propertyBag.Keys.Cast <ProviderPropertyDefinition>());
                foreach (ProviderPropertyDefinition providerPropertyDefinition in list)
                {
                    if (providerPropertyDefinition.VersionAdded.IsNewerThan(newVersion) && !providerPropertyDefinition.VersionAdded.IsNewerThan(exchangeVersion))
                    {
                        if (this.propertyBag.IsReadOnlyProperty(providerPropertyDefinition) || providerPropertyDefinition.IsCalculated)
                        {
                            this.propertyBag.SetField(providerPropertyDefinition, null);
                        }
                        else
                        {
                            this[providerPropertyDefinition] = null;
                        }
                    }
                }
            }
            this.propertyBag.SetObjectVersion(newVersion);
        }
コード例 #2
0
 internal MbxPropertyDefinition(string name, PropTag propTag, ExchangeObjectVersion versionAdded, Type type, PropertyDefinitionFlags flags, object defaultValue, PropertyDefinitionConstraint[] readConstraints, PropertyDefinitionConstraint[] writeConstraints, ProviderPropertyDefinition[] supportingProperties, GetterDelegate getterDelegate, SetterDelegate setterDelegate) : base(name, versionAdded, type, flags, defaultValue, readConstraints, writeConstraints, supportingProperties, null, getterDelegate, setterDelegate)
 {
     this.PropTag = propTag;
     if (propTag == PropTag.Null && name == "Null")
     {
         throw new ArgumentException("Name should not be 'Null' is PropTag is Null");
     }
     if (propTag == PropTag.Null != this.IsCalculated)
     {
         throw new ArgumentException("PropTag must be Null IFF Calculated property");
     }
 }
コード例 #3
0
        internal void ValidateRead(List <ValidationError> errors, IEnumerable <PropertyDefinition> propertiesToValidate)
        {
            ExchangeObjectVersion exchangeObjectVersion = (this.propertyBag.ObjectVersionPropertyDefinition == null) ? null : this.ExchangeVersion;

            if (propertiesToValidate != null)
            {
                foreach (PropertyDefinition propertyDefinition in propertiesToValidate)
                {
                    ProviderPropertyDefinition providerPropertyDefinition = (ProviderPropertyDefinition)propertyDefinition;
                    if (providerPropertyDefinition.IsCalculated)
                    {
                        bool onlyCacheValue = null != exchangeObjectVersion && exchangeObjectVersion.IsOlderThan(providerPropertyDefinition.VersionAdded);
                        this.ValidateCalculatedProperty(providerPropertyDefinition, this.propertyBag, errors, true, onlyCacheValue);
                    }
                }
            }
            List <ValidationError> list = this.instantiationErrors;

            if (list == null || list.Count == 0)
            {
                return;
            }
            list.RemoveAll(delegate(ValidationError error)
            {
                PropertyValidationError propertyValidationError = error as PropertyValidationError;
                if (propertyValidationError == null)
                {
                    return(false);
                }
                ProviderPropertyDefinition providerPropertyDefinition2 = propertyValidationError.PropertyDefinition as ProviderPropertyDefinition;
                if (providerPropertyDefinition2 == null)
                {
                    return(false);
                }
                bool flag = providerPropertyDefinition2.IsMultivalued && ((MultiValuedPropertyBase)this[providerPropertyDefinition2]).Changed;
                if (flag)
                {
                    ExTraceGlobals.ValidationTracer.TraceDebug <ValidationError>((long)this.GetHashCode(), "Removing instantiation error '{0}'.", error);
                }
                return(flag);
            });
            errors.AddRange(list);
        }
コード例 #4
0
        public ProviderPropertyDefinition(string name, ExchangeObjectVersion versionAdded, Type type, object defaultValue, PropertyDefinitionConstraint[] readConstraints, PropertyDefinitionConstraint[] writeConstraints, ProviderPropertyDefinition[] supportingProperties, CustomFilterBuilderDelegate customFilterBuilderDelegate, GetterDelegate getterDelegate, SetterDelegate setterDelegate) : base(name, type)
        {
            if (supportingProperties == null)
            {
                throw new ArgumentNullException("supportingProperties");
            }
            if (readConstraints == null)
            {
                throw new ArgumentNullException("readConstraints");
            }
            if (writeConstraints == null)
            {
                throw new ArgumentNullException("writeConstraints");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (versionAdded == null)
            {
                throw new ArgumentNullException("versionAdded");
            }
            if (defaultValue != null && !ReflectionHelper.IsInstanceOfType(defaultValue, type))
            {
                throw new ArgumentException(DataStrings.ExceptionDefaultTypeMismatch.ToString(), "defaultValue (" + name + ")");
            }
            if (type == typeof(bool) && defaultValue != null)
            {
                defaultValue = BoxedConstants.GetBool((bool)defaultValue);
            }
            this.defaultValue = defaultValue;
            this.customFilterBuilderDelegate = customFilterBuilderDelegate;
            this.versionAdded = versionAdded;
            if (readConstraints.Length < 1)
            {
                this.readOnlyReadConstraints = ProviderPropertyDefinition.EmptyConstraint.Collection;
            }
            else
            {
                this.readOnlyReadConstraints = new ReadOnlyCollection <PropertyDefinitionConstraint>(readConstraints);
            }
            if (writeConstraints.Length < 1 && readConstraints.Length < 1)
            {
                this.allStaticConstraints   = PropertyDefinitionConstraint.None;
                this.readOnlyAllConstraints = ProviderPropertyDefinition.EmptyConstraint.Collection;
            }
            else
            {
                this.allStaticConstraints = new PropertyDefinitionConstraint[readConstraints.Length + writeConstraints.Length];
                Array.Copy(writeConstraints, this.allStaticConstraints, writeConstraints.Length);
                Array.Copy(readConstraints, 0, this.allStaticConstraints, writeConstraints.Length, readConstraints.Length);
                this.readOnlyAllConstraints = new ReadOnlyCollection <PropertyDefinitionConstraint>(this.allStaticConstraints);
            }
            this.getterDelegate = getterDelegate;
            this.setterDelegate = setterDelegate;
            if (supportingProperties.Length < 1)
            {
                this.supportingProperties = ProviderPropertyDefinition.EmptyCollection;
            }
            else
            {
                this.supportingProperties = new ReadOnlyCollection <ProviderPropertyDefinition>(supportingProperties);
            }
            List <CollectionPropertyDefinitionConstraint> list  = new List <CollectionPropertyDefinitionConstraint>();
            List <CollectionPropertyDefinitionConstraint> list2 = new List <CollectionPropertyDefinitionConstraint>();

            for (int i = 0; i < writeConstraints.Length; i++)
            {
                CollectionPropertyDefinitionConstraint collectionPropertyDefinitionConstraint = writeConstraints[i] as CollectionPropertyDefinitionConstraint;
                if (collectionPropertyDefinitionConstraint != null)
                {
                    list.Add(collectionPropertyDefinitionConstraint);
                }
            }
            for (int j = 0; j < readConstraints.Length; j++)
            {
                CollectionPropertyDefinitionConstraint collectionPropertyDefinitionConstraint2 = readConstraints[j] as CollectionPropertyDefinitionConstraint;
                if (collectionPropertyDefinitionConstraint2 != null)
                {
                    list.Add(collectionPropertyDefinitionConstraint2);
                    list2.Add(collectionPropertyDefinitionConstraint2);
                }
            }
            if (list.Count < 1)
            {
                this.allStaticCollectionConstraints   = ProviderPropertyDefinition.EmptyCollectionConstraint.Array;
                this.readOnlyAllCollectionConstraints = ProviderPropertyDefinition.EmptyCollectionConstraint.Collection;
            }
            else
            {
                this.allStaticCollectionConstraints   = list.ToArray();
                this.readOnlyAllCollectionConstraints = new ReadOnlyCollection <CollectionPropertyDefinitionConstraint>(this.allStaticCollectionConstraints);
            }
            if (list2.Count < 1)
            {
                this.readOnlyReadCollectionConstraints = ProviderPropertyDefinition.EmptyCollectionConstraint.Collection;
            }
            else
            {
                this.readOnlyReadCollectionConstraints = new ReadOnlyCollection <CollectionPropertyDefinitionConstraint>(list2.ToArray());
            }
            this.readOnlyDependentProperties = ProviderPropertyDefinition.EmptyCollection;
            if (this.supportingProperties.Count == 0)
            {
                this.dependentProperties = new List <ProviderPropertyDefinition>();
            }
            foreach (ProviderPropertyDefinition providerPropertyDefinition in supportingProperties)
            {
                if (providerPropertyDefinition.IsCalculated)
                {
                    throw new ArgumentException(string.Format("The calculated property '{0}' cannot depend on another calculated property '{1}'", base.Name, providerPropertyDefinition.Name), "supportingProperties");
                }
                if (this.VersionAdded.IsOlderThan(providerPropertyDefinition.VersionAdded))
                {
                    throw new ArgumentException(string.Format("The calculated property '{0}' cannot depend on the newer property '{1}'", base.Name, providerPropertyDefinition.Name), "supportingProperties");
                }
                providerPropertyDefinition.AddDependency(this);
            }
            if (defaultValue != null && defaultValue != string.Empty)
            {
                PropertyValidationError propertyValidationError = this.ValidateValue(defaultValue, false);
                if (propertyValidationError != null)
                {
                    throw new ArgumentException(propertyValidationError.Description, "defaultValue");
                }
            }
        }
コード例 #5
0
 public ProviderPropertyDefinition(string name, ExchangeObjectVersion versionAdded, Type type, object defaultValue, PropertyDefinitionConstraint[] readConstraints, PropertyDefinitionConstraint[] writeConstraints) : this(name, versionAdded, type, defaultValue, readConstraints, writeConstraints, ProviderPropertyDefinition.None, null, null, null)
 {
 }
コード例 #6
0
 public ProviderPropertyDefinition(string name, ExchangeObjectVersion versionAdded, Type type, object defaultValue) : this(name, versionAdded, type, defaultValue, PropertyDefinitionConstraint.None, PropertyDefinitionConstraint.None)
 {
 }
コード例 #7
0
        internal SimpleProviderPropertyDefinition(string name, ExchangeObjectVersion versionAdded, Type type, PropertyDefinitionFlags flags, object defaultValue, PropertyDefinitionConstraint[] readConstraints, PropertyDefinitionConstraint[] writeConstraints, ProviderPropertyDefinition[] supportingProperties, CustomFilterBuilderDelegate customFilterBuilderDelegate, GetterDelegate getterDelegate, SetterDelegate setterDelegate) : base(name, versionAdded, type, defaultValue, readConstraints, writeConstraints, supportingProperties, customFilterBuilderDelegate, getterDelegate, setterDelegate)
        {
            this.flags = (int)flags;
            Type left = base.Type.GetTypeInfo().IsGenericType ? base.Type.GetTypeInfo().GetGenericTypeDefinition() : null;

            if (typeof(ICollection).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()) && typeof(byte[]) != type && !this.IsKnownFailure(type))
            {
                if (this.IsMultivalued)
                {
                    throw new ArgumentException(base.Name + ": Only specify the element type for MultiValued properties. Type: " + type.FullName, "type");
                }
                throw new ArgumentException(base.Name + ": Instead of specifying a collection type, please mark the property definition as MultiValued and specify the element type as the type Type: " + type.FullName, "type");
            }
            else
            {
                if (this.IsMultivalued && base.DefaultValue != null)
                {
                    throw new ArgumentException(base.Name + ": Multivalued properties should not have default value", "defaultValue");
                }
                if (base.DefaultValue == null && this.PersistDefaultValue)
                {
                    throw new ArgumentException(base.Name + ": Cannot persist default value when no default value is specified.", "defaultValue");
                }
                if (this.IsTaskPopulated)
                {
                    if (this.IsFilterOnly)
                    {
                        throw new ArgumentException(base.Name + ": TaskPopulated properties are not supported as FilterOnly properties at this time.", "flags");
                    }
                    if (this.IsCalculated)
                    {
                        throw new ArgumentException(base.Name + ": TaskPopulated properties should not be marked as calculated.", "flags");
                    }
                    if (this.IsReadOnly || this.IsWriteOnce)
                    {
                        throw new ArgumentException(base.Name + ": TaskPopulated properties must be modifiable from within the task and cannot be marked ReadOnly or WriteOnce.", "flags");
                    }
                }
                if (this.IsWriteOnce && this.IsReadOnly)
                {
                    throw new ArgumentException(base.Name + ": Properties cannot be marked as both ReadOnly and WriteOnce.", "flags");
                }
                if (this.IsMandatory && this.IsFilterOnly)
                {
                    throw new ArgumentException(base.Name + ": Mandatory properties should not be marked FilterOnly.", "flags");
                }
                if (this.IsFilterOnly && this.IsCalculated)
                {
                    throw new ArgumentException(base.Name + ": Calculated properties should not be marked as FilterOnly.", "flags");
                }
                if (!this.IsMultivalued && !this.IsFilterOnly && !this.IsCalculated)
                {
                    Type underlyingType = Nullable.GetUnderlyingType(type);
                    if (base.Type.GetTypeInfo().IsValueType&& left != typeof(Nullable <>) && base.DefaultValue == null)
                    {
                        throw new ArgumentException(base.Name + ": Value type properties must have default value.", "defaultValue");
                    }
                    if (left == typeof(Nullable <>) && base.DefaultValue != null)
                    {
                        throw new ArgumentException(base.Name + ": Default value for a property of Nullable type must be 'null'.", "defaultValue");
                    }
                    if (null != underlyingType && underlyingType.GetTypeInfo().IsGenericType&& underlyingType.GetGenericTypeDefinition() == typeof(Unlimited <>))
                    {
                        throw new ArgumentException(base.Name + ": Properties cannot be both Unlimited and Nullable.", "type");
                    }
                    if (left == typeof(Unlimited <>) && !(bool)base.Type.GetTypeInfo().GetDeclaredProperty("IsUnlimited").GetValue(base.DefaultValue, null))
                    {
                        throw new ArgumentException(base.Name + ": Default value for a property of Unlimited type must be 'unlimited'.", "defaultValue");
                    }
                    if (left == typeof(Unlimited <>) && this.PersistDefaultValue)
                    {
                        throw new ArgumentException(base.Name + ": Cannot persist default value for Unlimited type.", "flags");
                    }
                }
                if (this.IsCalculated != (base.GetterDelegate != null))
                {
                    throw new ArgumentException(base.Name + ": Calculated properties must have GetterDelegate, non-calculated ones must not", "getterDelegate");
                }
                if ((this.IsCalculated && !this.IsReadOnly) != (base.SetterDelegate != null))
                {
                    throw new ArgumentException(base.Name + ": Writable calculated properties must have SetterDelegate, non-calculated & readonly ones must not", "setterDelegate");
                }
                if (this.IsCalculated != (base.SupportingProperties.Count != 0))
                {
                    throw new ArgumentException(base.Name + ": Calculated properties must have supporting properties, non-calculated ones must not", "supportingProperties");
                }
                if (this.IsReadOnly && writeConstraints.Length > 0)
                {
                    throw new ArgumentException(base.Name + ": Readonly properties should not have write-only constraints", "writeConstraints");
                }
                if (base.DefaultValue != null && !this.PersistDefaultValue && !this.IsCalculated && !this.IsTaskPopulated && (base.Type == typeof(int) || base.Type == typeof(uint) || base.Type == typeof(long) || base.Type == typeof(ulong) || base.Type == typeof(ByteQuantifiedSize) || base.Type == typeof(EnhancedTimeSpan) || base.Type == typeof(DateTime)))
                {
                    throw new ArgumentException(string.Format("Property {0} has type {1} and a default value that is not persisted", base.Name, base.Type.ToString()), "flags");
                }
                if (this.IsCalculated && base.Type.GetTypeInfo().IsValueType&& left != typeof(Nullable <>) && base.DefaultValue == null && !this.IsMultivalued)
                {
                    throw new ArgumentException(string.Format("Calculated property {0} has type {1} and no default value", base.Name, base.Type.ToString()), "flags");
                }
                return;
            }
        }
コード例 #8
0
 internal static SimpleProviderPropertyDefinition CreatePropertyDefinition(string name, ExchangeObjectVersion versionAdded, Type type, PropertyDefinitionFlags flags, object defaultValue, PropertyDefinitionConstraint[] readConstraints, PropertyDefinitionConstraint[] writeConstraints)
 {
     return(new SimpleProviderPropertyDefinition(name, versionAdded, type, flags, defaultValue, readConstraints, writeConstraints));
 }