/// <summary>
        /// Performs validation and then throws an exception if validation fails.
        /// </summary>
        /// <param name="validator">The validator this method is extending.</param>
        /// <param name="instance">The instance of the type we are validating.</param>
        /// <param name="applyTo">The ruleset to validate against.</param>
        public static void ValidateAndThrow <T>(this IValidator <T> validator, T instance, ApplyTo applyTo)
        {
            var ruleSet = applyTo.ToString().ToUpper();

            validator.Validate(instance, options => {
                options.IncludeRuleSets(RulesetValidatorSelector.LegacyRulesetSplit(ruleSet));
                options.ThrowOnFailures();
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Defines a RuleSet that can be used to provide specific validation rules for specific HTTP methods (GET, POST...)
        /// </summary>
        /// <param name="appliesTo">The HTTP methods where this rule set should be used.</param>
        /// <param name="action">Action that encapsulates the rules in the ruleset.</param>
        public void RuleSet(ApplyTo appliesTo, Action action)
        {
            var httpMethods = appliesTo.ToString().Split(',')
                              .Map(x => x.Trim().ToUpper());

            foreach (var httpMethod in httpMethods)
            {
                RuleSet(httpMethod, action);
            }
        }
Esempio n. 3
0
        public void ApplyTransformation(ApplyTo scope)
        {
            if (addIn.theRibbon.dropDown1.SelectedItem == null)
            {
                addIn.Log("ApplyTransformation tried with empty dropdown");
                return;
            }

            addIn.bbColorSmells.decolorCells(transformationCells);

            addIn.Log("Apply in " + scope.ToString() + " transformation " + addIn.theRibbon.dropDown1.SelectedItem.Label);

            FSharpTransformationRule T = AllTransformations.FirstOrDefault(x => x.Name == addIn.theRibbon.dropDown1.SelectedItem.Label);

            switch (scope)
            {
            case ApplyTo.Range:
                applyInRange(T, addIn.Application.Selection);
                break;

            case ApplyTo.Worksheet:
                applyInRange(T, addIn.Application.ActiveSheet.UsedRange);
                break;

            case ApplyTo.Workbook:
                foreach (ExcelRaw.Worksheet worksheet in addIn.Application.Worksheets)
                {
                    applyInRange(T, worksheet.UsedRange);
                }
                break;
            }

            //after applying, we want to empty the preview box, find new rewrites and show them (in dropdown and preview)
            FindApplicableTransformations();
            addIn.bbTransformations.MakePreview(addIn);
        }
 /// <summary>
 /// Performs validation asynchronously and then throws an exception if validation fails.
 /// </summary>
 /// <param name="validator">The validator this method is extending.</param>
 /// <param name="instance">The instance of the type we are validating.</param>
 /// <param name="ruleSet">Optional: a ruleset when need to validate against.</param>
 public static Task ValidateAndThrowAsync <T>(this IValidator <T> validator, T instance, ApplyTo ruleSet)
 {
     return(validator.ValidateAndThrowAsync(instance, ruleSet.ToString().ToUpper()));
 }
 /// <summary>
 /// Performs validation and then throws an exception if validation fails.
 /// </summary>
 /// <param name="validator">The validator this method is extending.</param>
 /// <param name="instance">The instance of the type we are validating.</param>
 /// <param name="ruleSet">The ruleset to validate against.</param>
 public static void ValidateAndThrow <T>(this IValidator <T> validator, T instance, ApplyTo ruleSet)
 {
     validator.ValidateAndThrow(instance, ruleSet.ToString().ToUpper());
 }