コード例 #1
0
 public BrokenRule(string name, string desc, string propName, ValidationSeverity sev)
 {
     Description = desc + "";
     Reason      = Description;
     RuleName    = name + "";
     Severity    = sev;
 }
コード例 #2
0
 public ValidationIssue(object subject, ValidationSeverity severity, string message, object viewdata = null)
 {
     Severity = severity;
     Message  = message;
     Subject  = subject;
     ViewData = viewdata;
 }
コード例 #3
0
 public static ValidationOptions WithValidationSeverity(
     this ValidationOptions options,
     ValidationSeverity validationSeverity)
 {
     options.ValidationSeverity = validationSeverity;
     return(options);
 }
コード例 #4
0
 private IValidationContext CreateValidationContext(ValidationSeverity validationSeverity)
 {
     return(new ServiceCollection()
            .AddValidation(o => o.ValidationSeverity = validationSeverity)
            .BuildServiceProvider()
            .GetRequiredService <IValidationContext>());
 }
コード例 #5
0
ファイル: ValidationIssue.cs プロジェクト: lishxi/_SharpMap
 public ValidationIssue(object subject, ValidationSeverity severity, string message, object viewdata=null)
 {
     Severity = severity;
     Message = message;
     Subject = subject;
     ViewData = viewdata;
 }
コード例 #6
0
 public IEnumerable <IBrokenRule> BrokenValidationsForSeverity(ValidationSeverity severity)
 {
     CheckValidations();
     return(from itm in BrokenValidations
            where itm.Severity == severity
            select itm);
 }
コード例 #7
0
 public ValidationResult(ValidationSeverity severity,
                         string propertyName, string text)
 {
     Severity     = severity;
     PropertyName = propertyName;
     Text         = text;
 }
コード例 #8
0
        /// <summary>
        ///   Adds <see cref="ValidationDetail" /> to <see cref="IValidationContext" /> with specified
        ///   <see cref="ValidationSeverity" />
        /// </summary>
        /// <exception cref="ValidationConditionException">
        ///   Throws when ValidationDetail.ValidationSeverity greater ValidationContext.ValidationSeverity.
        ///   Example: Add fatal detail, when validation context severity is error
        /// </exception>
        public static ValidationDetail?AddValidationDetail(
            this IValidationCondition condition,
            string validationMessage,
            ValidationSeverity validationSeverity = ValidationSeverity.Error)
        {
            var validationContext = condition.ValidationContext;

            var validationDetail = new ValidationDetail(
                validationContext,
                condition.ValidationKey,
                validationMessage,
                validationSeverity,
                condition.IsValid ?? false);

            // Not null or false
            // Null by default, so validationContext.When(...).AddValidationDetail(...) works without additional conditions
            if (validationDetail.IsValid)
            {
                return(validationDetail);
            }

            validationContext.ValidationDetails.Add(validationDetail);

            if (validationDetail.ValidationSeverity > validationContext.ValidationSeverity)
            {
                throw new ValidationConditionException(validationDetail);
            }

            return(validationDetail);
        }
コード例 #9
0
 public ValidationMessage(string message,
                          ValidationSeverity severity,
                          params string[] members)
 {
     Message  = message;
     Severity = severity;
     Members  = members;
 }
コード例 #10
0
 public RepositoryCheckoutValidation(Pipeline pipeline)
 {
     _resources = pipeline.Resources?.FlattenDefinitions() ?? Array.Empty <Resources>();
     _steps     = pipeline.Stages
                  .SelectMany(stage => stage.FlattenDefinitions())
                  .SelectMany(stage => stage.Jobs.GetSteps());
     _severity = SharplinerConfiguration.Current.Validations.RepositoryCheckouts;
 }
コード例 #11
0
 public ValidationMessage(
     ValidationSeverity severity,
     string message
     )
 {
     Severity = severity;
     Message  = message;
 }
コード例 #12
0
 public BrokenRule(string name, string desc, string propName, ValidationSeverity sev, object objectBroke)
 {
     Description = desc + "";
     RuleName    = name + "";
     ObjectBroke = objectBroke.GetType().Name;;
     Severity    = sev;
     Reason      = Description;
 }
コード例 #13
0
 public Validation(string key, ValidationSeverity severity, string validationmessage, string overRideInstructions, Dictionary <string, string> options) :
     this(key, severity, validationmessage, overRideInstructions)
 {
     if (options == null)
     {
         options = new Dictionary <string, string>();
     }
     this.Options = options;
 }
コード例 #14
0
 public static Result CreateResultForFailure(ValidationSeverity validationSeverity,
                                             string parameterName, string message, int rowKey = int.MinValue)
 {
     return(validationSeverity switch
     {
         ValidationSeverity.Error => ResultFactory.Error(parameterName, message, rowKey),
         ValidationSeverity.Warning => ResultFactory.Warning(parameterName, message, rowKey),
         _ => throw new System.NotImplementedException()
     });
コード例 #15
0
        public static IRule GuidEmpty(string propname, ValidationSeverity severity = ValidationSeverity.Critical)
        {
            ClientSideValidationRule <Guid, Guid> newValidation = new ClientSideValidationRule <Guid, Guid>("GUID Empty",
                                                                                                            "Item must be empty.",
                                                                                                            propname,
                                                                                                            CommonPropRuleHandlers.EmptyGuidHandler);

            newValidation.Severity = severity;
            return(newValidation);
        }
コード例 #16
0
        public static IRule NotEmptyStringValidation(string PropName = null, ValidationSeverity severity = ValidationSeverity.Critical)
        {
            ClientSideValidationRule <string, string> newValidation = new ClientSideValidationRule <string, string>("Not Empty",
                                                                                                                    "Value cannot be empty.",
                                                                                                                    PropName,
                                                                                                                    CommonPropRuleHandlers.NonBlankStringHandler);

            newValidation.Severity = severity;
            return(newValidation);
        }
コード例 #17
0
        public static IRule DateNotMaxValidation(string propname, ValidationSeverity severity = ValidationSeverity.Critical)
        {
            ClientSideValidationRule <DateTime, object> newValidation = new ClientSideValidationRule <DateTime, object>("Date Not Max",
                                                                                                                        "Date must be less than " + DateTime.MaxValue.ToString() + ".",
                                                                                                                        propname,
                                                                                                                        CommonPropRuleHandlers.DateNotMinHandler);

            newValidation.Severity = severity;
            return(newValidation);
        }
コード例 #18
0
        public static IRule MustBeNullOrNumeric(string propname, ValidationSeverity severity = ValidationSeverity.Critical)
        {
            ClientSideValidationRule <object, object> newValidation = new ClientSideValidationRule <object, object>("Must Be Null Or Numeric",
                                                                                                                    "Value {0} is not a valid number.".FormatStr(propname),
                                                                                                                    propname,
                                                                                                                    CommonPropRuleHandlers.IsNumberBroke);

            newValidation.Severity = severity;
            return(newValidation);
        }
コード例 #19
0
        public static IRule DateNotMinValidation(string propname, ValidationSeverity severity = ValidationSeverity.Critical)
        {
            ClientSideValidationRule <DateTime, object> newValidation = new ClientSideValidationRule <DateTime, object>("Date Not Min",
                                                                                                                        "Date must be set.",
                                                                                                                        propname,
                                                                                                                        CommonPropRuleHandlers.DateNotMinHandler);

            newValidation.Severity = severity;
            return(newValidation);
        }
コード例 #20
0
        public static IRule NotNothingValidation(string propName, ValidationSeverity severity = ValidationSeverity.Critical)
        {
            ClientSideValidationRule <object, object> newValidation = new ClientSideValidationRule <object, object>("Not Nothing",
                                                                                                                    "Value must be set.",
                                                                                                                    propName,
                                                                                                                    CommonPropRuleHandlers.NotNullHandler);

            newValidation.Severity = severity;
            return(newValidation);
        }
コード例 #21
0
        public static IRule BetweenValidation(string propname, IDateRange range, ValidationSeverity severity = ValidationSeverity.Critical)
        {
            ClientSideValidationRule <DateTime, IDateRange> newValidation = new ClientSideValidationRule <DateTime, IDateRange>("Date Between",
                                                                                                                                "Date must be between " + range.FirstValidDate.ToString() + " and " + range.LastValidDate.ToString() + ".",
                                                                                                                                propname,
                                                                                                                                CommonPropRuleHandlers.DateRangeHandler);

            newValidation.AllowedValue = range;
            newValidation.Severity     = severity;
            return(newValidation);
        }
コード例 #22
0
 public ValidationResult(bool pIsOk, string pMessage, ValidationSeverity pSeverity, string pPropertyName)
 {
     this._isOk         = pIsOk;
     this._message      = pMessage;
     this._severity     = pSeverity;
     this._propertyName = pPropertyName;
     if (!this._isOk && (this._severity == ValidationSeverity.NA))
     {
         this._severity = ValidationSeverity.Error;
     }
 }
コード例 #23
0
        public static IRule LessThanValidation(string propname, IComparable value, ValidationSeverity severity = ValidationSeverity.Critical)
        {
            ClientSideValidationRule <IComparable, IComparable> newValidation = new ClientSideValidationRule <IComparable, IComparable>("Less Than",
                                                                                                                                        "Value must be less than " + value?.ToString() + ".",
                                                                                                                                        propname,
                                                                                                                                        CommonPropRuleHandlers.LessThanHandler);

            newValidation.AllowedValue = value;
            newValidation.Severity     = severity;
            return(newValidation);
        }
コード例 #24
0
        public static IRule NotEqualToValidation(string propname, IComparable value, ValidationSeverity severity = ValidationSeverity.Critical)
        {
            ClientSideValidationRule <IComparable, IComparable> newValidation = new ClientSideValidationRule <IComparable, IComparable>("Not Equal To",
                                                                                                                                        "Value must not be equal to " + value.ToString() + ".",
                                                                                                                                        propname,
                                                                                                                                        CommonPropRuleHandlers.NotEqualToHandler);

            newValidation.AllowedValue = value;
            newValidation.Severity     = severity;
            return(newValidation);
        }
コード例 #25
0
 public static void Deconstruct(
     this ValidationDetail validationDetail,
     out string validationKey,
     out string validationMessage,
     out bool isValid,
     out ValidationSeverity validationSeverity)
 {
     validationKey      = validationDetail.ValidationKey;
     validationMessage  = validationDetail.ValidationMessage;
     isValid            = validationDetail.IsValid;
     validationSeverity = validationDetail.ValidationSeverity;
 }
コード例 #26
0
 public ValidationDetail(
     IValidationContext validationContext,
     string validationKey,
     string validationMessage,
     ValidationSeverity validationSeverity,
     bool isValid)
 {
     ValidationContext  = validationContext;
     ValidationKey      = validationKey ?? throw new ArgumentNullException(nameof(validationKey));
     ValidationMessage  = validationMessage ?? throw new ArgumentNullException(nameof(validationMessage));
     ValidationSeverity = validationSeverity;
     IsValid            = isValid;
 }
コード例 #27
0
ファイル: ValidationHelper.cs プロジェクト: lishxi/_SharpMap
        public static IList<ValidationIssue> ValidateDuplicateNames(IEnumerable<INameable> nameables, string typeNamePlural, object viewData, ValidationSeverity severity = ValidationSeverity.Error)
        {
            var issues = new List<ValidationIssue>();
            var nonUniqueNames = GetNonUniqueNames(nameables);

            foreach (var nonUniqueName in nonUniqueNames)
            {
                var first = nameables.First(n => n.Name == nonUniqueName);
                
                issues.Add(
                    new ValidationIssue(first, severity,
                                        String.Format("Several {0} with the same id exist", typeNamePlural),
                                        viewData));
            }
            return issues;
        }
コード例 #28
0
        public Validation(string key, ValidationSeverity severity, string validationMessage) : this()
        {
            this.Key = !string.IsNullOrEmpty(key) ? key : throw new ArgumentNullException("Key");
            this.ValidationMessage    = !string.IsNullOrEmpty(validationMessage) ? validationMessage : throw new ArgumentNullException("ValidationMessage");
            this.Severity             = severity;
            this.Options              = new Dictionary <string, string>();
            this.OverRideInstructions = string.Empty;
            switch (severity)
            {
            case ValidationSeverity.Escalate:
                this.OverRideInstructions = "Override?"; break;

            case ValidationSeverity.Confirm:
                this.OverRideInstructions = "Confirm?"; break;
            }
        }
コード例 #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidationResult"/> class.
 /// </summary>
 /// <param name="propertyName">Name of the property to which this <see cref="ValidationResult"/> belongs.</param>
 /// <param name="message">The message of this <see cref="ValidationResult"/>.</param>
 /// <param name="severity">The severity of the <see cref="ValidationResult"/>. This parameter is optional.
 /// <br/>Default value: <see cref="ValidationSeverity.Error"/>.</param>
 public ValidationResult(string propertyName, string message, ValidationSeverity severity = ValidationSeverity.Error)
 {
     if (propertyName == null)
     {
         Throw.ArgumentNullException(Argument.propertyName);
     }
     if (message == null)
     {
         Throw.ArgumentNullException(Argument.message);
     }
     PropertyName = propertyName;
     Message      = message;
     if (!Enum <ValidationSeverity> .IsDefined(severity))
     {
         Throw.EnumArgumentOutOfRangeWithValues(Argument.severity, severity);
     }
     Severity = severity;
 }
コード例 #30
0
        /// <summary>
        /// Adds a message for given key.
        /// </summary>
        public void Add(ValidationSeverity severity, string key, string text)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            Add(new ValidationMessage()
            {
                Severity = severity,
                Key      = key,
                Text     = text,
            });
        }
コード例 #31
0
 /// <summary>
 /// Creates a new validation using the specified field, message and severity.
 /// </summary>
 /// <param name="field">The field.</param>
 /// <param name="message">The message.</param>
 /// <param name="severity">The severity.</param>
 /// <returns>A new validation</returns>
 public static BaseValidation Create(string field, string message, ValidationSeverity severity)
 {
     return Create(field, message, Guid.Empty, severity);
 }
コード例 #32
0
 /// <summary>
 /// Creates a new validation using the specified field and severity.
 /// </summary>
 /// <param name="field">The field.</param>
 /// <param name="entityID">The entity ID.</param>
 /// <param name="severity">The severity.</param>
 /// <returns>
 /// A new validation
 /// </returns>
 public static BaseValidation Create(string field, Guid entityID, ValidationSeverity severity)
 {
     return Create(field, null, entityID, severity);
 }
コード例 #33
0
        public static IList <ValidationIssue> ValidateDuplicateNames(IEnumerable <INameable> nameables, string typeNamePlural, object viewData, ValidationSeverity severity = ValidationSeverity.Error)
        {
            var issues         = new List <ValidationIssue>();
            var nonUniqueNames = GetNonUniqueNames(nameables);

            foreach (var nonUniqueName in nonUniqueNames)
            {
                var first = nameables.First(n => n.Name == nonUniqueName);

                issues.Add(
                    new ValidationIssue(first, severity,
                                        String.Format("Several {0} with the same id exist", typeNamePlural),
                                        viewData));
            }
            return(issues);
        }
コード例 #34
0
 /// <summary>
 /// Creates a new validation using the specified field, message and severity.
 /// </summary>
 /// <param name="field">The field.</param>
 /// <param name="message">The message.</param>
 /// <param name="entityID">The entity ID.</param>
 /// <param name="severity">The severity.</param>
 /// <returns>
 /// A new validation
 /// </returns>
 public static BaseValidation Create(string field, string message, Guid entityID, ValidationSeverity severity)
 {
     switch (severity)
     {
         case ValidationSeverity.Suggestion:
             return new ValidationSuggestion(field, message, entityID);
         case ValidationSeverity.Warning:
             return new ValidationWarning(field, message, entityID);
         case ValidationSeverity.Error:
             return new ValidationError(field, message, entityID);
         default:
             throw new ArgumentOutOfRangeException("severity");
     }
 }
コード例 #35
0
 public Validation(string key, ValidationSeverity severity, string validationMessage, string overRideInstructions) : this()
 {
     this.OverRideInstructions = string.IsNullOrEmpty(overRideInstructions) ? this.OverRideInstructions : overRideInstructions;
 }