コード例 #1
0
        private PropertyValidationError ValidateSingleValue(object value, bool useOnlyReadConstraints, IPropertyBag propertyBag)
        {
            if (this.IsMandatory)
            {
                if (value == null)
                {
                    return(new PropertyValidationError(DataStrings.PropertyIsMandatory, this, null));
                }
                if (value.GetType() == typeof(string) && value.ToString().Length == 0)
                {
                    return(new PropertyValidationError(DataStrings.PropertyIsMandatory, this, value));
                }
            }
            if (value != null && !ReflectionHelper.IsInstanceOfType(value, base.Type))
            {
                return(new PropertyValidationError(DataStrings.PropertyTypeMismatch(value.GetType().FullName, base.Type.FullName), this, value));
            }
            ReadOnlyCollection <PropertyDefinitionConstraint> readOnlyCollection = useOnlyReadConstraints ? this.readOnlyReadConstraints : this.readOnlyAllConstraints;
            int count = readOnlyCollection.Count;

            for (int i = 0; i < count; i++)
            {
                PropertyDefinitionConstraint propertyDefinitionConstraint = readOnlyCollection[i];
                if (!(propertyDefinitionConstraint is CollectionPropertyDefinitionConstraint))
                {
                    PropertyValidationError propertyValidationError = propertyDefinitionConstraint.Validate(value, this, propertyBag);
                    if (propertyValidationError != null)
                    {
                        return(propertyValidationError);
                    }
                }
            }
            return(null);
        }
コード例 #2
0
ファイル: CsvSchema.cs プロジェクト: YHZX2013/exchange_diff
 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);
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: CsvSchema.cs プロジェクト: YHZX2013/exchange_diff
        protected void OnPropertyValidationError(CsvRow row, string columnName, PropertyValidationError error)
        {
            row.SetError(columnName, error);
            Action <CsvRow, string, PropertyValidationError> propertyValidationError = this.PropertyValidationError;

            if (propertyValidationError != null)
            {
                propertyValidationError(row, columnName, error);
            }
        }
コード例 #4
0
 internal void OverrideCorruptedValuesWithDefault()
 {
     ValidationError[] array = this.Validate();
     foreach (ValidationError validationError in array)
     {
         PropertyValidationError propertyValidationError = validationError as PropertyValidationError;
         if (propertyValidationError != null)
         {
             this[propertyValidationError.PropertyDefinition] = (propertyValidationError.PropertyDefinition as ProviderPropertyDefinition).DefaultValue;
         }
     }
 }
コード例 #5
0
        public virtual IList <ValidationError> ValidateProperty(object value, IPropertyBag propertyBag, bool useOnlyReadConstraints)
        {
            List <ValidationError> list = new List <ValidationError>();

            if (value == null)
            {
                if (this.IsMandatory)
                {
                    list.Add(new PropertyValidationError(DataStrings.PropertyIsMandatory, this, null));
                }
                return(list);
            }
            if (this.IsMultivalued)
            {
                IEnumerable enumerable = value as IEnumerable;
                if (enumerable == null)
                {
                    list.Add(new PropertyValidationError(DataStrings.PropertyNotACollection(value.GetType().Name), this, value));
                    return(list);
                }
                int num = 0;
                foreach (object value2 in enumerable)
                {
                    num++;
                    PropertyValidationError propertyValidationError = this.ValidateSingleValue(value2, useOnlyReadConstraints, propertyBag);
                    if (propertyValidationError != null)
                    {
                        list.Add(propertyValidationError);
                    }
                }
                if (num == 0 && this.IsMandatory)
                {
                    list.Add(new PropertyValidationError(DataStrings.PropertyIsMandatory, this, null));
                }
                PropertyValidationError propertyValidationError2 = this.ValidateCollection(enumerable, useOnlyReadConstraints, propertyBag);
                if (propertyValidationError2 != null)
                {
                    list.Add(propertyValidationError2);
                }
            }
            else
            {
                PropertyValidationError propertyValidationError3 = this.ValidateSingleValue(value, useOnlyReadConstraints, propertyBag);
                if (propertyValidationError3 != null)
                {
                    list.Add(propertyValidationError3);
                }
            }
            return(list);
        }
コード例 #6
0
        private PropertyValidationError ValidateCollection(IEnumerable collection, bool useOnlyReadConstraints, IPropertyBag propertyBag)
        {
            ReadOnlyCollection <CollectionPropertyDefinitionConstraint> readOnlyCollection = useOnlyReadConstraints ? this.readOnlyReadCollectionConstraints : this.readOnlyAllCollectionConstraints;
            int count = readOnlyCollection.Count;

            for (int i = 0; i < count; i++)
            {
                PropertyValidationError propertyValidationError = readOnlyCollection[i].Validate(collection, this, propertyBag);
                if (propertyValidationError != null)
                {
                    return(propertyValidationError);
                }
            }
            return(null);
        }
コード例 #7
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);
        }
コード例 #8
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);
            });
        }
コード例 #9
0
ファイル: CsvRow.cs プロジェクト: YHZX2013/exchange_diff
 internal void SetError(string columnName, PropertyValidationError error)
 {
     this.errors[columnName] = error;
 }
コード例 #10
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");
                }
            }
        }
コード例 #11
0
 public bool Equals(PropertyValidationError other)
 {
     return(other != null && object.Equals(this.PropertyDefinition, other.PropertyDefinition) && object.Equals(this.InvalidData, other.InvalidData) && base.Equals(other));
 }