예제 #1
0
 internal virtual object this[PropertyDefinition propertyDefinition]
 {
     get
     {
         ProviderPropertyDefinition providerPropertyDefinition = (ProviderPropertyDefinition)propertyDefinition;
         object obj;
         try
         {
             obj = this.propertyBag[providerPropertyDefinition];
             obj = this.InternalSuppressPii(propertyDefinition, obj);
             object obj2;
             if (this.TryConvertOutputProperty(obj, providerPropertyDefinition, out obj2))
             {
                 obj = obj2;
             }
         }
         catch (DataValidationException arg)
         {
             ExTraceGlobals.ValidationTracer.TraceError <ProviderPropertyDefinition, DataValidationException>(0L, "Calculated property {0} threw an exception {1}. Returning default value.", providerPropertyDefinition, arg);
             obj = this.propertyBag.SetField(providerPropertyDefinition, providerPropertyDefinition.DefaultValue);
             this.propertyBag.ResetChangeTracking(providerPropertyDefinition);
         }
         return(obj);
     }
     set
     {
         ProviderPropertyDefinition providerPropertyDefinition = (ProviderPropertyDefinition)propertyDefinition;
         this.propertyBag[providerPropertyDefinition] = value;
         this.CleanupInstantiationErrors(providerPropertyDefinition);
     }
 }
예제 #2
0
        internal static IList <ProviderPropertyDefinition> GetPropertiesThatDiffer(ConfigurableObject objA, ConfigurableObject objB, IList <ProviderPropertyDefinition> properties)
        {
            if (objA == null)
            {
                throw new ArgumentNullException("objA");
            }
            if (objB == null)
            {
                throw new ArgumentNullException("objB");
            }
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }
            List <ProviderPropertyDefinition> list = new List <ProviderPropertyDefinition>();

            for (int i = 0; i < properties.Count; i++)
            {
                ProviderPropertyDefinition providerPropertyDefinition = properties[i];
                if (!object.Equals(objA[providerPropertyDefinition], objB[providerPropertyDefinition]))
                {
                    list.Add(providerPropertyDefinition);
                }
            }
            return(list);
        }
예제 #3
0
 private void ValidateCalculatedProperty(ProviderPropertyDefinition propertyDefinition, PropertyBag propertyBag, List <ValidationError> errors, bool useOnlyReadConstraints, bool onlyCacheValue)
 {
     try
     {
         object value = propertyBag[propertyDefinition];
         if (!onlyCacheValue)
         {
             IList <ValidationError> list = propertyDefinition.ValidateProperty(value, propertyBag, useOnlyReadConstraints);
             if (list.Count > 0)
             {
                 foreach (ValidationError item in list)
                 {
                     if (!errors.Contains(item))
                     {
                         errors.Add(item);
                     }
                 }
             }
         }
     }
     catch (DataValidationException ex)
     {
         ExTraceGlobals.ValidationTracer.TraceWarning <ProviderPropertyDefinition, DataValidationException>(0L, "Calculated property {0} threw an exception {1}.", propertyDefinition, ex);
         if (useOnlyReadConstraints && !onlyCacheValue)
         {
             errors.Add(ex.Error);
         }
     }
 }
예제 #4
0
 internal virtual void CopyChangesFrom(ConfigurableObject changedObject)
 {
     if (changedObject == null)
     {
         throw new ArgumentNullException("changedObject");
     }
     this.CheckWritable();
     ProviderPropertyDefinition[] array = new ProviderPropertyDefinition[changedObject.propertyBag.Keys.Count];
     changedObject.propertyBag.Keys.CopyTo(array, 0);
     foreach (ProviderPropertyDefinition providerPropertyDefinition in array)
     {
         if (!providerPropertyDefinition.IsReadOnly && (!providerPropertyDefinition.IsWriteOnce || this.ObjectState == ObjectState.New) && (changedObject.propertyBag.SaveCalculatedValues || !providerPropertyDefinition.IsCalculated) && changedObject.IsModified(providerPropertyDefinition))
         {
             object obj = changedObject[providerPropertyDefinition];
             MultiValuedPropertyBase multiValuedPropertyBase = obj as MultiValuedPropertyBase;
             if (!providerPropertyDefinition.IsMultivalued || multiValuedPropertyBase == null || multiValuedPropertyBase.IsChangesOnlyCopy)
             {
                 this[providerPropertyDefinition] = obj;
             }
             else
             {
                 MultiValuedPropertyBase multiValuedPropertyBase2 = (MultiValuedPropertyBase)this[providerPropertyDefinition];
                 multiValuedPropertyBase2.CopyChangesFrom(multiValuedPropertyBase);
                 this.CleanupInstantiationErrors(providerPropertyDefinition);
             }
         }
     }
 }
예제 #5
0
 public virtual void ValidateRow(CsvRow row)
 {
     if (row.Index > this.MaximumRowCount)
     {
         throw new CsvTooManyRowsException(this.MaximumRowCount);
     }
     foreach (KeyValuePair <string, ProviderPropertyDefinition> keyValuePair in this.RequiredColumns)
     {
         string key   = keyValuePair.Key;
         string value = row[key];
         ProviderPropertyDefinition value2 = keyValuePair.Value;
         if (value.IsNullOrBlank())
         {
             PropertyValidationError error = new PropertyValidationError(DataStrings.PropertyIsMandatory, value2, null);
             this.OnPropertyValidationError(row, key, error);
         }
     }
     foreach (KeyValuePair <string, string> keyValuePair2 in row.GetExistingValues())
     {
         string key2   = keyValuePair2.Key;
         string value3 = keyValuePair2.Value ?? "";
         ProviderPropertyDefinition propertyDefinition = this.GetPropertyDefinition(key2);
         if (propertyDefinition != null)
         {
             foreach (PropertyDefinitionConstraint propertyDefinitionConstraint in propertyDefinition.AllConstraints)
             {
                 PropertyConstraintViolationError propertyConstraintViolationError = propertyDefinitionConstraint.Validate(value3, propertyDefinition, null);
                 if (propertyConstraintViolationError != null)
                 {
                     this.OnPropertyValidationError(row, key2, propertyConstraintViolationError);
                 }
             }
         }
     }
 }
예제 #6
0
        private void RunFullPropertyValidation(List <ValidationError> errors)
        {
            IEnumerable <PropertyDefinition> enumerable = (this.ObjectSchema == null) ? ((IEnumerable <PropertyDefinition>) this.propertyBag.Keys) : this.ObjectSchema.AllProperties;

            foreach (PropertyDefinition propertyDefinition in enumerable)
            {
                ProviderPropertyDefinition providerPropertyDefinition = (ProviderPropertyDefinition)propertyDefinition;
                if (!this.SkipFullPropertyValidation(providerPropertyDefinition))
                {
                    if (providerPropertyDefinition.IsCalculated)
                    {
                        this.ValidateCalculatedProperty(providerPropertyDefinition, this.propertyBag, errors, false, false);
                    }
                    else
                    {
                        object value = null;
                        this.propertyBag.TryGetField(providerPropertyDefinition, ref value);
                        IList <ValidationError> list = providerPropertyDefinition.ValidateProperty(value, this.propertyBag, false);
                        if (list.Count > 0)
                        {
                            foreach (ValidationError item in list)
                            {
                                if (!errors.Contains(item))
                                {
                                    errors.Add(item);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #7
0
        protected ObjectSchema()
        {
            HashSet <PropertyDefinition> hashSet        = new HashSet <PropertyDefinition>();
            List <PropertyDefinition>    list           = new List <PropertyDefinition>();
            List <FieldInfo>             list2          = ReflectionHelper.AggregateTypeHierarchy <FieldInfo>(base.GetType(), new AggregateType <FieldInfo>(ReflectionHelper.AggregateStaticFields));
            IEnumerable <FieldInfo>      declaredFields = base.GetType().GetTypeInfo().DeclaredFields;

            foreach (FieldInfo fieldInfo in list2)
            {
                object value = fieldInfo.GetValue(null);
                if (typeof(ProviderPropertyDefinition).GetTypeInfo().IsAssignableFrom(fieldInfo.FieldType.GetTypeInfo()) && value == null)
                {
                    throw new InvalidOperationException(string.Format("Property definition '{0}' is not initialized. This can be caused by loop dependency between initialization of one or more static fields.", fieldInfo.Name));
                }
                ProviderPropertyDefinition providerPropertyDefinition = value as ProviderPropertyDefinition;
                if (providerPropertyDefinition != null)
                {
                    bool flag = false;
                    foreach (FieldInfo fieldInfo2 in declaredFields)
                    {
                        if (fieldInfo2.Name.Equals(fieldInfo.Name) && !this.IsSameFieldHandle(fieldInfo2, fieldInfo))
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!this.containsCalculatedProperties && providerPropertyDefinition.IsCalculated)
                    {
                        this.containsCalculatedProperties = true;
                    }
                    if (!flag)
                    {
                        if (!providerPropertyDefinition.IsFilterOnly)
                        {
                            hashSet.TryAdd(providerPropertyDefinition);
                            if (!providerPropertyDefinition.IsCalculated)
                            {
                                continue;
                            }
                            using (ReadOnlyCollection <ProviderPropertyDefinition> .Enumerator enumerator3 = providerPropertyDefinition.SupportingProperties.GetEnumerator())
                            {
                                while (enumerator3.MoveNext())
                                {
                                    ProviderPropertyDefinition item = enumerator3.Current;
                                    hashSet.TryAdd(item);
                                }
                                continue;
                            }
                        }
                        if (!providerPropertyDefinition.IsCalculated)
                        {
                            list.Add(providerPropertyDefinition);
                        }
                    }
                }
            }
            this.AllProperties           = new ReadOnlyCollection <PropertyDefinition>(hashSet.ToArray());
            this.AllFilterOnlyProperties = new ReadOnlyCollection <PropertyDefinition>(list.ToArray());
            this.InitializePropertyCollections();
        }
예제 #8
0
        internal bool TryGetOriginalValue <T>(ProviderPropertyDefinition key, out T value)
        {
            object obj;
            bool   result = this.propertyBag.TryGetOriginalValue(key, out obj);

            value = (T)((object)obj);
            return(result);
        }
예제 #9
0
 internal override void UpdatePropertyDefinition(ProviderPropertyDefinition newPropertyDefinition)
 {
     if (newPropertyDefinition == null)
     {
         throw new ArgumentNullException("newPropertyDefinition");
     }
     this.propertyDefinition = newPropertyDefinition;
 }
예제 #10
0
        internal virtual bool IsPropertyAccessible(PropertyDefinition propertyDefinition)
        {
            if (propertyDefinition == null)
            {
                throw new ArgumentNullException("propertyDefinition");
            }
            ProviderPropertyDefinition providerPropertyDefinition = propertyDefinition as ProviderPropertyDefinition;

            return(providerPropertyDefinition == null || !providerPropertyDefinition.VersionAdded.ExchangeBuild.IsNewerThan(this.ExchangeVersion.ExchangeBuild) || this.ExchangeVersionUpgradeSupported);
        }
예제 #11
0
        private ProviderPropertyDefinition GetPropertyDefinition(string columnName)
        {
            ProviderPropertyDefinition result = null;

            if (!this.OptionalColumns.TryGetValue(columnName, out result))
            {
                this.RequiredColumns.TryGetValue(columnName, out result);
            }
            return(result);
        }
예제 #12
0
        internal IList <PropertyDefinition> GetChangedPropertyDefinitions()
        {
            IEnumerable <PropertyDefinition> enumerable = (this.ObjectSchema == null) ? ((IEnumerable <PropertyDefinition>) this.propertyBag.Keys) : this.ObjectSchema.AllProperties;
            List <PropertyDefinition>        list       = new List <PropertyDefinition>();

            foreach (PropertyDefinition propertyDefinition in enumerable)
            {
                ProviderPropertyDefinition providerPropertyDefinition = (ProviderPropertyDefinition)propertyDefinition;
                if (this.propertyBag.IsChanged(providerPropertyDefinition))
                {
                    list.Add(providerPropertyDefinition);
                }
            }
            return(list);
        }
예제 #13
0
        public object[] GetProperties(ICollection <PropertyDefinition> propertyDefinitions)
        {
            if (propertyDefinitions == null)
            {
                throw new ArgumentNullException("propertyDefinitions");
            }
            ProviderPropertyDefinition[] array = new ProviderPropertyDefinition[propertyDefinitions.Count];
            int num = 0;

            foreach (PropertyDefinition propertyDefinition in propertyDefinitions)
            {
                array[num++] = (ProviderPropertyDefinition)propertyDefinition;
            }
            return(this.propertyBag.GetProperties(array));
        }
예제 #14
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);
        }
예제 #15
0
        internal void SetProperties(ICollection <PropertyDefinition> propertyDefinitions, object[] propertyValues)
        {
            if (propertyDefinitions == null)
            {
                throw new ArgumentNullException("propertyDefinitions");
            }
            if (this.IsReadOnly && this.propertyBag.ObjectVersionPropertyDefinition != null && this.MaximumSupportedExchangeObjectVersion.IsOlderThan(this.ExchangeVersion))
            {
                throw new InvalidObjectOperationException(DataStrings.ExceptionReadOnlyBecauseTooNew(this.ExchangeVersion, this.MaximumSupportedExchangeObjectVersion));
            }
            ProviderPropertyDefinition[] array = new ProviderPropertyDefinition[propertyDefinitions.Count];
            int num = 0;

            foreach (PropertyDefinition propertyDefinition in propertyDefinitions)
            {
                array[num++] = (ProviderPropertyDefinition)propertyDefinition;
            }
            this.propertyBag.SetProperties(array, propertyValues);
        }
예제 #16
0
 private MultiValuedProperty(bool readOnly, bool validate, ProviderPropertyDefinition propertyDefinition, IEnumerable values, ICollection invalidValues, LocalizedString?readOnlyErrorMessage)
 {
     if (values == null)
     {
         throw new ArgumentNullException("values");
     }
     this.propertyDefinition   = propertyDefinition;
     this.isReadOnly           = readOnly;
     this.readOnlyErrorMessage = readOnlyErrorMessage;
     this.changed        = false;
     this.wasCleared     = false;
     this.propertyValues = new List <T>();
     if (this.HasChangeTracking)
     {
         this.added   = new List <object>();
         this.removed = new List <object>();
     }
     foreach (object obj in values)
     {
         if (obj != null)
         {
             T item = this.ConvertInput(obj);
             if (validate)
             {
                 this.ValidateValueAndThrow(item);
                 if (this.Contains(item))
                 {
                     throw new InvalidOperationException(DataStrings.ErrorValueAlreadyPresent(obj.ToString()));
                 }
             }
             this.propertyValues.Add(item);
         }
     }
     this.propertyValues.TrimExcess();
     if (invalidValues != null && invalidValues.Count > 0 && !readOnly)
     {
         foreach (object item2 in invalidValues)
         {
             this.removed.Add(item2);
         }
     }
 }
예제 #17
0
        private void CleanupInstantiationErrors(ProviderPropertyDefinition property)
        {
            List <ValidationError> list = this.instantiationErrors;

            if (list == null || list.Count == 0)
            {
                return;
            }
            List <ProviderPropertyDefinition> listToClear = new List <ProviderPropertyDefinition>();

            listToClear.Add(property);
            if (property.IsCalculated)
            {
                foreach (ProviderPropertyDefinition providerPropertyDefinition in property.SupportingProperties)
                {
                    if (this.IsChanged(providerPropertyDefinition))
                    {
                        listToClear.Add(providerPropertyDefinition);
                    }
                }
            }
            list.RemoveAll(delegate(ValidationError error)
            {
                PropertyValidationError propertyValidationError        = error as PropertyValidationError;
                ProviderPropertyDefinition providerPropertyDefinition2 = (ProviderPropertyDefinition)propertyValidationError.PropertyDefinition;
                bool flag = false;
                if (providerPropertyDefinition2 != null)
                {
                    flag = listToClear.Contains(providerPropertyDefinition2);
                    if (flag)
                    {
                        this.propertyBag.MarkAsChanged(providerPropertyDefinition2);
                        if (ExTraceGlobals.ValidationTracer.IsTraceEnabled(TraceType.DebugTrace))
                        {
                            ExTraceGlobals.ValidationTracer.TraceDebug <ValidationError, string, string>((long)this.GetHashCode(), "Removing instantiation error '{0}'. Because property {1} has been modified directly or it is a supporting property of {2}.", error, providerPropertyDefinition2.Name, property.Name);
                        }
                    }
                }
                return(flag);
            });
        }
예제 #18
0
        protected void InitializePropertyCollections()
        {
            if (this.AllProperties == null)
            {
                throw new InvalidOperationException("Dev Bug: AllProperties should never be null");
            }
            if (this.AllFilterOnlyProperties == null)
            {
                throw new InvalidOperationException("Dev Bug: AllFilterOnlyProperties should never be null");
            }
            List <PropertyDefinition> list  = new List <PropertyDefinition>();
            List <PropertyDefinition> list2 = new List <PropertyDefinition>();

            foreach (PropertyDefinition propertyDefinition in this.AllProperties)
            {
                ProviderPropertyDefinition providerPropertyDefinition = (ProviderPropertyDefinition)propertyDefinition;
                if (providerPropertyDefinition.IsFilterable)
                {
                    list.Add(providerPropertyDefinition);
                }
                if (providerPropertyDefinition.IsMandatory && !providerPropertyDefinition.IsCalculated)
                {
                    list2.Add(providerPropertyDefinition);
                }
            }
            foreach (PropertyDefinition propertyDefinition2 in this.AllFilterOnlyProperties)
            {
                ProviderPropertyDefinition providerPropertyDefinition2 = (ProviderPropertyDefinition)propertyDefinition2;
                if (providerPropertyDefinition2.IsFilterable)
                {
                    list.Add(providerPropertyDefinition2);
                }
            }
            this.allFilterableProperties = new ReadOnlyCollection <PropertyDefinition>(list.ToArray());
            this.allMandatoryProperties  = new ReadOnlyCollection <PropertyDefinition>(list2.ToArray());
        }
예제 #19
0
 internal NetworkAddressCollection(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values, ICollection invalidValues, LocalizedString?readOnlyErrorMessage) : base(readOnly, propertyDefinition, values, invalidValues, readOnlyErrorMessage)
 {
 }
예제 #20
0
 internal NetworkAddressCollection(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values) : base(readOnly, propertyDefinition, values)
 {
 }
 internal ProxyAddressBaseCollection(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values) : base(readOnly, propertyDefinition, values)
 {
 }
예제 #22
0
 public override bool Equals(ProviderPropertyDefinition other)
 {
     return(object.ReferenceEquals(other, this) || (base.Equals(other) && (other as RegistryPropertyDefinition).Flags == base.Flags));
 }
예제 #23
0
 internal MultiValuedProperty(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values) : this(readOnly, true, propertyDefinition, values, null, null)
 {
 }
예제 #24
0
 internal MultiValuedProperty(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values, ICollection invalidValues, LocalizedString?readOnlyErrorMessage) : this(readOnly, false, propertyDefinition, values, invalidValues, readOnlyErrorMessage)
 {
 }
예제 #25
0
 internal virtual bool SkipFullPropertyValidation(ProviderPropertyDefinition propertyDefinition)
 {
     return(!propertyDefinition.IsMultivalued && !propertyDefinition.HasAutogeneratedConstraints && this.propertyBag.IsChanged(propertyDefinition));
 }
예제 #26
0
 internal abstract void UpdatePropertyDefinition(ProviderPropertyDefinition newPropertyDefinition);
예제 #27
0
 internal bool IsChanged(ProviderPropertyDefinition providerPropertyDefinition)
 {
     return(this.propertyBag.IsChanged(providerPropertyDefinition));
 }
 internal ProxyAddressTemplateCollection(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values) : base(readOnly, propertyDefinition, values)
 {
     this.AutoPromotionDisabled = true;
 }
 internal ProxyAddressTemplateCollection(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values, ICollection invalidValues, LocalizedString?readOnlyErrorMessage) : base(readOnly, propertyDefinition, values, invalidValues, readOnlyErrorMessage)
 {
     this.AutoPromotionDisabled = true;
 }
예제 #30
0
 internal DagNetMultiValuedProperty(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values) : base(readOnly, propertyDefinition, values)
 {
 }