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); } }
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); }
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); } } }
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); } } } }
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); } } } } }
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); } } } } } } }
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(); }
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); }
internal override void UpdatePropertyDefinition(ProviderPropertyDefinition newPropertyDefinition) { if (newPropertyDefinition == null) { throw new ArgumentNullException("newPropertyDefinition"); } this.propertyDefinition = newPropertyDefinition; }
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); }
private ProviderPropertyDefinition GetPropertyDefinition(string columnName) { ProviderPropertyDefinition result = null; if (!this.OptionalColumns.TryGetValue(columnName, out result)) { this.RequiredColumns.TryGetValue(columnName, out result); } return(result); }
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); }
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)); }
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); }
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); }
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); } } }
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); }); }
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()); }
internal NetworkAddressCollection(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values, ICollection invalidValues, LocalizedString?readOnlyErrorMessage) : base(readOnly, propertyDefinition, values, invalidValues, readOnlyErrorMessage) { }
internal NetworkAddressCollection(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values) : base(readOnly, propertyDefinition, values) { }
internal ProxyAddressBaseCollection(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values) : base(readOnly, propertyDefinition, values) { }
public override bool Equals(ProviderPropertyDefinition other) { return(object.ReferenceEquals(other, this) || (base.Equals(other) && (other as RegistryPropertyDefinition).Flags == base.Flags)); }
internal MultiValuedProperty(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values) : this(readOnly, true, propertyDefinition, values, null, null) { }
internal MultiValuedProperty(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values, ICollection invalidValues, LocalizedString?readOnlyErrorMessage) : this(readOnly, false, propertyDefinition, values, invalidValues, readOnlyErrorMessage) { }
internal virtual bool SkipFullPropertyValidation(ProviderPropertyDefinition propertyDefinition) { return(!propertyDefinition.IsMultivalued && !propertyDefinition.HasAutogeneratedConstraints && this.propertyBag.IsChanged(propertyDefinition)); }
internal abstract void UpdatePropertyDefinition(ProviderPropertyDefinition newPropertyDefinition);
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; }
internal DagNetMultiValuedProperty(bool readOnly, ProviderPropertyDefinition propertyDefinition, ICollection values) : base(readOnly, propertyDefinition, values) { }