コード例 #1
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            this.PrivateProcessRecord();
            int num = 102400;

            if (InternalExchangeSettingsSchema.ConfigurationXMLRaw.AllConstraints != null)
            {
                foreach (PropertyDefinitionConstraint propertyDefinitionConstraint in InternalExchangeSettingsSchema.ConfigurationXMLRaw.AllConstraints)
                {
                    StringLengthConstraint stringLengthConstraint = propertyDefinitionConstraint as StringLengthConstraint;
                    if (stringLengthConstraint != null)
                    {
                        num = stringLengthConstraint.MaxLength;
                        break;
                    }
                }
            }
            int length = this.DataObject.Xml.Serialize(false).Length;
            int num2   = num * 9 / 10;

            if (length >= num2)
            {
                this.WriteWarning(Strings.ExchangeSettingsWarningMaximumSize(length, num));
            }
            base.InternalProcessRecord();
            TaskLogger.LogExit();
        }
コード例 #2
0
 internal static PropertyConstraintViolationError ValidateUserSamAccountNameLength(object value, PropertyDefinition propertyDefinition, IPropertyBag propertyBag, PropertyDefinitionConstraint owner)
 {
     if (propertyBag != null)
     {
         MultiValuedProperty <string> multiValuedProperty = (MultiValuedProperty <string>)propertyBag[ADObjectSchema.ObjectClass];
         if (multiValuedProperty.Count > 0 && multiValuedProperty.Contains("user"))
         {
             StringLengthConstraint stringLengthConstraint = new StringLengthConstraint(1, 20);
             return(stringLengthConstraint.Validate(value, propertyDefinition, propertyBag));
         }
     }
     return(null);
 }
コード例 #3
0
        internal static int GetMaxLengthFromDefinition(ProviderPropertyDefinition propDefinition)
        {
            int num = int.MaxValue;

            foreach (PropertyDefinitionConstraint propertyDefinitionConstraint in propDefinition.AllConstraints)
            {
                StringLengthConstraint stringLengthConstraint = propertyDefinitionConstraint as StringLengthConstraint;
                if (stringLengthConstraint != null && stringLengthConstraint.MaxLength < num)
                {
                    num = stringLengthConstraint.MaxLength;
                }
            }
            return(num);
        }
コード例 #4
0
        public void StringWithCorrectLengthShouldNeverViolateConstraint()
        {
            // Fixture setup
            const uint length = 10;

            var generator = from s in Arb.Generate <string>()
                            where s != null && s.Length == length
                            select s;

            var constraint = new StringLengthConstraint(length);

            // Exercise system and verify outcome
            Prop.ForAll(
                generator.ToArbitrary(),
                s => constraint.Check(s).Violated.Should().BeFalse())
            .QuickCheckThrowOnFailure();
        }
コード例 #5
0
        public void StringWithIncorrectLengthShouldAlwaysViolateConstraint()
        {
            // Fixture setup
            const uint length = 10;

            var generator = from s in Arb.Generate <string>()
                            where s != null && s.Length != length
                            select s;

            var constraint = new StringLengthConstraint(length);

            // Exercise system and verify outcome
            Prop.ForAll(generator.ToArbitrary(), s =>
            {
                var result = constraint.Check(s);
                result.Violated.Should().BeTrue();
                result.Message.Should().Be($"String length must be '{length}' but '{s.Length}'.");
            }).QuickCheckThrowOnFailure();
        }
コード例 #6
0
        internal static int GetStringConstraintLength(ADObjectSchema schema, ADPropertyDefinition propertyDefinition)
        {
            if (propertyDefinition == null)
            {
                throw new ArgumentNullException("propertyDefinition");
            }
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }
            schema.InitializeAutogeneratedConstraints();
            int num = int.MaxValue;

            foreach (PropertyDefinitionConstraint propertyDefinitionConstraint in propertyDefinition.AllConstraints)
            {
                StringLengthConstraint stringLengthConstraint = propertyDefinitionConstraint as StringLengthConstraint;
                if (stringLengthConstraint != null && stringLengthConstraint.MaxLength < num)
                {
                    num = stringLengthConstraint.MaxLength;
                }
            }
            return(num);
        }
コード例 #7
0
 internal StringLengthValidatorInfo(StringLengthConstraint constraint) : this(constraint.MinLength, constraint.MaxLength)
 {
 }
コード例 #8
0
 private void SetConstraintsFromType(Type propertyType, PropertyDefinitionConstraint[] constraints)
 {
     if (propertyType.IsGenericType)
     {
         if (propertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
         {
             propertyType = propertyType.GetGenericArguments()[0];
         }
         Type[] genericArguments = propertyType.GetGenericArguments();
         if (genericArguments.Length == 1 && !genericArguments[0].IsGenericParameter)
         {
             propertyType = genericArguments[0];
         }
     }
     if (this.IsMaskExpressionEnable())
     {
         if (typeof(short) == propertyType || typeof(int) == propertyType || typeof(long) == propertyType)
         {
             this.SetMaskExpression(this.CreateMaskExpressionForSignedNumericField(constraints));
         }
         else if (typeof(ushort) == propertyType || typeof(uint) == propertyType || typeof(ulong) == propertyType || typeof(ByteQuantifiedSize) == propertyType || typeof(EnhancedTimeSpan) == propertyType)
         {
             this.SetMaskExpression("[0-9]");
         }
         FieldInfo field = propertyType.GetField("AllowedCharacters");
         if (null != field && field.FieldType == typeof(string))
         {
             this.SetMaskExpression((string)field.GetValue(null));
         }
         if (string.IsNullOrEmpty(this.GetMaskExpression()))
         {
             StringBuilder stringBuilder = new StringBuilder("[^");
             foreach (PropertyDefinitionConstraint propertyDefinitionConstraint in constraints)
             {
                 CharacterConstraint characterConstraint = propertyDefinitionConstraint as CharacterConstraint;
                 if (characterConstraint != null)
                 {
                     if (characterConstraint.ShowAsValid)
                     {
                         this.SetMaskExpression(characterConstraint.Pattern);
                         break;
                     }
                     stringBuilder.Append(characterConstraint.Pattern.Substring(2, characterConstraint.Pattern.Length - 3));
                 }
             }
             if (string.IsNullOrEmpty(this.GetMaskExpression()) && stringBuilder.Length > 2)
             {
                 this.SetMaskExpression(stringBuilder.Append(']').ToString());
             }
         }
     }
     if (this.IsMaxLengthEnable())
     {
         int num = this.IsInvalidChar('-') ? -1 : 0;
         if (typeof(short) == propertyType || typeof(ushort) == propertyType)
         {
             this.SetMaxLength(short.MinValue.ToString().Length + num);
         }
         else if (typeof(int) == propertyType || typeof(uint) == propertyType)
         {
             this.SetMaxLength(int.MinValue.ToString().Length + num);
         }
         else if (typeof(long) == propertyType || typeof(ulong) == propertyType || typeof(ByteQuantifiedSize) == propertyType || typeof(EnhancedTimeSpan) == propertyType)
         {
             this.SetMaxLength(long.MinValue.ToString().Length + num);
         }
         FieldInfo fieldInfo = null;
         Type      type      = propertyType;
         while (null != type && null == fieldInfo)
         {
             fieldInfo = type.GetField("MaxLength");
             type      = type.BaseType;
         }
         if (null != fieldInfo && fieldInfo.FieldType == typeof(int))
         {
             this.SetMaxLength((int)fieldInfo.GetValue(null));
         }
         foreach (PropertyDefinitionConstraint propertyDefinitionConstraint2 in constraints)
         {
             UIImpactStringLengthConstraint uiimpactStringLengthConstraint = propertyDefinitionConstraint2 as UIImpactStringLengthConstraint;
             if (uiimpactStringLengthConstraint != null)
             {
                 this.SetMaxLength(uiimpactStringLengthConstraint.MaxLength);
                 return;
             }
             StringLengthConstraint stringLengthConstraint = propertyDefinitionConstraint2 as StringLengthConstraint;
             if (stringLengthConstraint != null)
             {
                 this.SetMaxLength(stringLengthConstraint.MaxLength);
                 return;
             }
         }
     }
 }