Ejemplo n.º 1
0
        public static List <Element> GetTargetedElements(string documentGuid, string ruleGuid)
        {
            RegexRule regexRule = RegularApp.RegexRuleCacheService.GetRegexRule(documentGuid, ruleGuid);

            if (regexRule == null)
            {
                return(null);
            }

            Document document = RegularApp.DocumentCacheService.GetDocument(documentGuid);

            ElementMulticategoryFilter elementMulticategoryFilter = new ElementMulticategoryFilter(
                regexRule.TargetCategoryObjects
                .Where(x => x.IsChecked)
                .Select(x => Category.GetCategory(document, new ElementId(x.CategoryObjectId)))
                .Select(CategoryUtils.GetBuiltInCategoryFromCategory)
                .ToList());

            List <Element> targetedElements = new FilteredElementCollector(document)
                                              .WhereElementIsNotElementType()
                                              .WherePasses(elementMulticategoryFilter)
                                              .Where(x => x.GroupId == ElementId.InvalidElementId)
                                              .ToList();

            return(targetedElements);
        }
        private static void AssertSingleExcludeAllTypesRule(IRegexFilter regexFilter)
        {
            RegexRule regexRule = regexFilter.TypeRules.Single();

            Assert.False(regexRule.Include);
            Assert.Matches(regexRule.Type, Guid.NewGuid().ToString());
        }
Ejemplo n.º 3
0
        public void Execute(object parameter)
        {
            switch (ruleEditorViewModel.RuleEditorInfo.RuleEditorType)
            {
            case RuleEditorType.CreateNewRule:
                RegexRule.Save
                (
                    ruleEditorViewModel.RuleEditorInfo.DocumentGuid,
                    ruleEditorViewModel.StagingRule
                );
                break;

            case RuleEditorType.EditingExistingRule:
                RegexRule.Update
                (
                    ruleEditorViewModel.RuleEditorInfo.DocumentGuid,
                    ruleEditorViewModel.StagingRule
                );
                break;

            case RuleEditorType.DuplicateExistingRule:
                RegexRule.Save
                (
                    ruleEditorViewModel.RuleEditorInfo.DocumentGuid,
                    ruleEditorViewModel.StagingRule
                );
                break;
            }
        }
Ejemplo n.º 4
0
        public static RuleResult ApplyTo(this RegexRule regexRule, string url)
        {
            // Break the URL in chunks based on the rule configuration
            var chunks = GetChunks(url, regexRule);

            // Apply the rule to each chunk
            bool anyChunkUpdated;
            var  updatedChunks = ApplyRuleToChunks(regexRule, chunks, out anyChunkUpdated);

            // If the rule didn't apply to any chunk then return a NoMatch result
            if (!anyChunkUpdated)
            {
                return(RuleResult.NoMatch);
            }

            // If the rule applied to at least one chunk and the ignore flag is true then return an Ignore result
            if (regexRule.Ignore)
            {
                return(RuleResult.Ignore);
            }

            // Otherwise return a successful result with the updated URL
            var path = string.Join(MetricNames.PathSeparator, updatedChunks.ToArray());

            return(new RuleResult(true, path));
        }
Ejemplo n.º 5
0
        public void CustomAttributesMatchingPatternMustSucceedTest()
        {
            EntityMetadata entity = new EntityMetadata()
            {
                SchemaName = "Account",
            };

            entity.SetSealedPropertyValue("IsManaged", true);
            entity.SetSealedPropertyValue("IsCustomEntity", false);

            var field1Metadata = new StringAttributeMetadata("foo_CustomField");

            field1Metadata.SetSealedPropertyValue("IsManaged", false);
            field1Metadata.SetSealedPropertyValue("IsCustomAttribute", true);

            var attributes = new List <AttributeMetadata> {
                field1Metadata
            };

            var isOwnedBySolution = false;

            var validSolutionEntity = new SolutionEntity(entity,
                                                         attributes,
                                                         isOwnedBySolution);

            var regexPattern = @"^[A-Za-z]+_[A-Z]{1}[a-z]{1}[A-Za-z]*$";
            var scope        = RuleScope.Attribute;

            var ruleToTest = new RegexRule(regexPattern, scope);

            var results = ruleToTest.Validate(validSolutionEntity);

            Assert.True(results.Passed);
        }
Ejemplo n.º 6
0
        public void FindAll_CmpRegex()
        {
            KeywordRule acsRule = new KeywordRule
            {
                Keywords = "abstract,as,base,bool,break,byte,case,catch,char,checked,class,const,continue,decimal,default,delegate,do,double,else,enum,event,explicit,extern,false,finally,fixed,float,for,foreach,goto,if,implicit,in,int,interface,internal,is,lock,long,namespace,new,null,object,operator,out,override,params,private,protected,public,readonly,ref,return,sbyte,sealed,short,sizeof,stackalloc,static,string,struct,switch,this,throw,true,try,typeof,uint,ulong,unchecked,unsafe,ushort,using,using,static,virtual,void,volatile,while,get,set,yield,var"
            };
            RegexRule regexRule = new RegexRule
            {
                Pattern = @"\babstract\b|\bas\b|\bbase\b|\bbool\b|\bbreak\b|\bbyte\b|\bcase\b|\bcatch\b|\bchar\b|\bchecked\b|\bclass\b|\bconst\b|\bcontinue\b|\bdecimal\b|\bdefault\b|\bdelegate\b|\bdo\b|\bdouble\b|\belse\b|\benum\b|\bevent\b|\bexplicit\b|\bextern\b|\bfalse\b|\bfinally\b|\bfixed\b|\bfloat\b|\bfor\b|\bforeach\b|\bgoto\b|\bif\b|\bimplicit\b|\bin\b|\bint\b|\binterface\b|\binternal\b|\bis\b|\block\b|\blong\b|\bnamespace\b|\bnew\b|\bnull\b|\bobject\b|\boperator\b|\bout\b|\boverride\b|\bparams\b|\bprivate\b|\bprotected\b|\bpublic\b|\breadonly\b|\bref\b|\breturn\b|\bsbyte\b|\bsealed\b|\bshort\b|\bsizeof\b|\bstackalloc\b|\bstatic\b|\bstring\b|\bstruct\b|\bswitch\b|\bthis\b|\bthrow\b|\btrue\b|\btry\b|\btypeof\b|\buint\b|\bulong\b|\bunchecked\b|\bunsafe\b|\bushort\b|\busing\b|\busing\b|\bstatic\b|\bvirtual\b|\bvoid\b|\bvolatile\b|\bwhile\b|\bget\b|\bset\b|\byield\b|\bvar\b"
            };

            string file  = Path.Combine(Environment.CurrentDirectory, @"..\..\..\UI.SyntaxBox\SyntaxRenderer.cs");
            var    input = File.ReadAllLines(file);

            var regex = input
                        .SelectMany((x) => regexRule.Match(x))
                        .OrderBy((x) => x.FromChar)
                        .ThenBy((x) => x.Length)
                        .ToList();
            var acs = input
                      .SelectMany((x) => acsRule.Match(x))
                      .OrderBy((x) => x.FromChar)
                      .ThenBy((x) => x.Length)
                      .ToList();

            Assert.AreEqual(regex.Count, acs.Count, "Not the same number of matches");
            Assert.IsTrue(Enumerable.SequenceEqual(regex, acs, new FormatInstructionCmp()), "Different matches");
        }
Ejemplo n.º 7
0
        private static IEnumerable <string> ApplyRuleToChunks(RegexRule regexRule, IEnumerable <string> chunks, out bool anyChunkUpdated)
        {
            if (chunks == null)
            {
                anyChunkUpdated = false;

                return(new List <string>());
            }

            var wasChunkUpdated = false;

            var updatedChunks = chunks
                                .Where(chunk => chunk != null)
                                .Select(chunk =>
            {
                var result = ApplyRuleToChunk(chunk, regexRule);
                if (!result.IsMatch)
                {
                    return(chunk);
                }

                wasChunkUpdated = true;
                return(result.Replacement);
            })
                                .ToList();

            anyChunkUpdated = wasChunkUpdated;
            return(updatedChunks);
        }
Ejemplo n.º 8
0
        public static void DeleteRegexRuleFromExtensibleStorage(string documentGuid, string regexRuleGuid)
        {
            Document document = RegularApp.DocumentCacheService.GetDocument(documentGuid);
            KeyValuePair <DataStorage, Entity> ruleInExtensibleStorage = GetRegexRuleInExtensibleStorage(documentGuid, regexRuleGuid);
            Entity regexRuleEntity = ruleInExtensibleStorage.Value;

            if (regexRuleEntity == null)
            {
                return;
            }
            DataStorage dataStorage = ruleInExtensibleStorage.Key;

            string    serializedRegexRule = regexRuleEntity.Get <string>("SerializedRegexRule");
            RegexRule regexRule           = SerializationUtils.DeserializeRegexRule(serializedRegexRule);
            string    ruleName            = regexRule.RuleName;

            using (Transaction transaction = new Transaction(document, $"Regular - Deleting Rule {ruleName}"))
            {
                transaction.Start();
                List <ElementId> dataStorageToDelete = new List <ElementId> {
                    dataStorage.Id
                };
                document.Delete(dataStorageToDelete);
                transaction.Commit();
            }
        }
Ejemplo n.º 9
0
        public void CustomLookupOnCustomUnmanagedEntityConformingRuleResultStringIsCorrect()
        {
            var entity = new EntityMetadata()
            {
                SchemaName  = "foo_MyEntity",
                DisplayName = new Label()
                {
                    UserLocalizedLabel = new LocalizedLabel("My Entity", 1033)
                }
            };

            entity.SetSealedPropertyValue("IsManaged", false);
            entity.SetSealedPropertyValue("IsCustomEntity", true);

            var scope = RuleScope.Lookup;

            var lookupAttr = new LookupAttributeMetadata(LookupFormat.None)
            {
                SchemaName = "foo_MyCustomLookupId"
            };

            lookupAttr.SetSealedPropertyValue("IsCustomAttribute", true);
            lookupAttr.SetSealedPropertyValue("IsManaged", false);

            var attributes = new List <AttributeMetadata> {
                lookupAttr
            };
            var solutionEntity = new SolutionEntity(entity, attributes, true);

            var rule    = new RegexRule(_REGEX_PATTERN, scope);
            var results = rule.Validate(solutionEntity);

            Assert.Equal($"Rule: {rule.Description} Succeeded for entity \"My Entity\" (foo_MyEntity).",
                         results.FormatValidationResult());
        }
Ejemplo n.º 10
0
        public void ManagedCustomEntityMustBeSkippedTest()
        {
            EntityMetadata entity = new EntityMetadata()
            {
                SchemaName = "new_notconforming",
            };

            entity.SetSealedPropertyValue("IsManaged", true);
            entity.SetSealedPropertyValue("IsCustomEntity", true);

            List <AttributeMetadata> attributes = null;

            var isOwnedBySolution = true;

            var validSolutionEntity = new SolutionEntity(entity,
                                                         attributes,
                                                         isOwnedBySolution);

            var regexPattern = @"^[A-Za-z]+_[A-Z]{1}[a-z]{1}[A-Za-z]*$";
            var scope        = RuleScope.Entity;

            var ruleToTest = new RegexRule(regexPattern, scope);

            var results = ruleToTest.Validate(validSolutionEntity);

            Assert.True(results.Passed);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Validate that the property value match the given regex.  Null or empty values are allowed.
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="fieldValue"></param>
        /// <returns><c>true</c> if the field is OK</returns>
        public override bool IsValid(object instance, object fieldValue)
        {
            if (fieldValue != null && fieldValue.ToString() != "")
            {
                var value = fieldValue.ToString();

                if (value.Length > 0)
                {
                    if (value.Length != 36)
                    {
                        return(false);
                    }
                    if (RegexRule.IsMatch(value))
                    {
                        if (acceptEmptyGuid)
                        {
                            return(true);
                        }
                        return(value != Guid.Empty.ToString());
                    }
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 12
0
        public void EntityFirstLetterIsCapitalLetterFailureDescriptionIsCorrectTest()
        {
            EntityMetadata entity = new EntityMetadata()
            {
                SchemaName  = "foobar_myMagnificientEntity",
                DisplayName = new Label()
                {
                    UserLocalizedLabel = new LocalizedLabel("Suurenmoinen entiteetti",
                                                            1035)
                }
            };

            entity.SetSealedPropertyValue("IsManaged", false);
            entity.SetSealedPropertyValue("IsCustomEntity", true);

            List <AttributeMetadata> attributes = null;

            var isOwnedBySolution = true;

            var validSolutionEntity = new SolutionEntity(entity,
                                                         attributes,
                                                         isOwnedBySolution);

            var regexPattern = @"^[A-Za-z]+_[A-Z]{1}[a-z]{1}[A-Za-z]*$";
            var scope        = RuleScope.Entity;

            var ruleToTest = new RegexRule(regexPattern, scope);

            var results = ruleToTest.Validate(validSolutionEntity);

            Assert.Equal($"Rule failed: {ruleToTest.Description} Entity schema name {entity.SchemaName} doesn't match given pattern \"{regexPattern}\".",
                         results.FormatValidationResult());
        }
Ejemplo n.º 13
0
        public void ExcludeEntityFromCheck()
        {
            EntityMetadata entity = new EntityMetadata()
            {
                SchemaName = "foobar_myNotSoMagnificientEntity",
            };

            entity.SetSealedPropertyValue("IsManaged", false);
            entity.SetSealedPropertyValue("IsCustomEntity", true);

            List <AttributeMetadata> attributes = null;

            var isOwnedBySolution = true;

            var validSolutionEntity = new SolutionEntity(entity,
                                                         attributes,
                                                         isOwnedBySolution);

            var regexPattern     = @"^[A-Za-z]+_[A-Z]{1}[a-z]{1}[A-Za-z]*$";
            var scope            = RuleScope.Entity;
            var excludedEntities = new List <string> {
                "foobar_123",
                "foobar_myNotSoMagnificientEntity",
                "foobar_mySecondNotSoGreatAgainEntity"
            };

            var ruleToTest = new RegexRule(regexPattern, scope,
                                           excludedEntities);

            var results = ruleToTest.Validate(validSolutionEntity);

            Assert.True(results.Passed);
        }
Ejemplo n.º 14
0
        public void CustomLookupOnCustomUnmanagedEntityConformingRule()
        {
            var entity = new EntityMetadata()
            {
                SchemaName = "foo_MyEntity",
            };

            entity.SetSealedPropertyValue("IsManaged", false);
            entity.SetSealedPropertyValue("IsCustomEntity", true);

            var scope = RuleScope.Lookup;

            var lookupAttr = new LookupAttributeMetadata(LookupFormat.None)
            {
                SchemaName = "foo_MyCustomLookupId"
            };

            lookupAttr.SetSealedPropertyValue("IsCustomAttribute", true);
            lookupAttr.SetSealedPropertyValue("IsManaged", false);

            var attributes = new List <AttributeMetadata> {
                lookupAttr
            };
            var solutionEntity = new SolutionEntity(entity, attributes, true);

            var rule    = new RegexRule(_REGEX_PATTERN, scope);
            var results = rule.Validate(solutionEntity);

            Assert.True(results.Passed);
        }
Ejemplo n.º 15
0
        public void EnsureEntityFirstLetterIsCapitalLetterFailsTest()
        {
            EntityMetadata entity = new EntityMetadata()
            {
                SchemaName = "foobar_myMagnificientEntity",
            };

            entity.SetSealedPropertyValue("IsManaged", false);
            entity.SetSealedPropertyValue("IsCustomEntity", true);

            List <AttributeMetadata> attributes = null;

            var isOwnedBySolution = true;

            var validSolutionEntity = new SolutionEntity(entity,
                                                         attributes,
                                                         isOwnedBySolution);

            var regexPattern = @"^[A-Za-z]+_[A-Z]{1}[a-z]{1}[A-Za-z]*$";
            var scope        = RuleScope.Entity;

            var ruleToTest = new RegexRule(regexPattern, scope);

            var results = ruleToTest.Validate(validSolutionEntity);

            Assert.False(results.Passed);
        }
Ejemplo n.º 16
0
        public void CustomLookupOnCustomUnmanagedEntityNotConformingRuleValidationMessage()
        {
            var entity = new EntityMetadata()
            {
                SchemaName  = "foo_MyEntity",
                DisplayName = new Label()
                {
                    UserLocalizedLabel = new LocalizedLabel("My Entity", 1033)
                }
            };

            entity.SetSealedPropertyValue("IsManaged", false);
            entity.SetSealedPropertyValue("IsCustomEntity", true);

            var scope = RuleScope.Lookup;

            var lookupAttr = new LookupAttributeMetadata(LookupFormat.None)
            {
                SchemaName = "foo_MyCustomLookup"
            };

            lookupAttr.SetSealedPropertyValue("IsCustomAttribute", true);
            lookupAttr.SetSealedPropertyValue("IsManaged", false);

            var attributes = new List <AttributeMetadata> {
                lookupAttr
            };
            var solutionEntity = new SolutionEntity(entity, attributes, true);

            var rule    = new RegexRule(_REGEX_PATTERN, scope);
            var results = rule.Validate(solutionEntity);

            Assert.Equal($"Rule failed: {rule.Description} Following lookups do not match given pattern: foo_MyCustomLookup.",
                         results.FormatValidationResult());
        }
Ejemplo n.º 17
0
        private static KeyValuePair <DataStorage, Entity> GetRegexRuleInExtensibleStorage(string documentGuid, string regexRuleGuid)
        {
            Document document      = RegularApp.DocumentCacheService.GetDocument(documentGuid);
            Schema   regularSchema = GetRegularSchema();

            // Retrieving and testing all DataStorage objects in the document against our Regular schema.
            List <DataStorage> allDataStorage = new FilteredElementCollector(document).OfClass(typeof(DataStorage)).OfType <DataStorage>().ToList();

            if (allDataStorage.Count < 1)
            {
                return(new KeyValuePair <DataStorage, Entity>(null, null));
            }

            // Returning any Entities which employ the RegularSchema
            List <DataStorage> regexRuleDataStorage = allDataStorage.Where(x => x.GetEntity(regularSchema).IsValid()).ToList();

            foreach (DataStorage dataStorage in regexRuleDataStorage)
            {
                Entity    regexRuleEntity     = dataStorage.GetEntity(regularSchema);
                string    serializedRegexRule = regexRuleEntity.Get <string>("SerializedRegexRule");
                RegexRule regexRule           = SerializationUtils.DeserializeRegexRule(serializedRegexRule);
                // If the rule has the right GUID, we return the DataStorage and Entity objects to be worked with
                if (regexRule.RuleGuid == regexRuleGuid)
                {
                    return(new KeyValuePair <DataStorage, Entity>(dataStorage, regexRuleEntity));
                }
            }
            MessageBox.Show($"Unable to find rule with GUID: {regexRuleGuid}");
            // If the rule wasn't found, we return nothing
            return(new KeyValuePair <DataStorage, Entity>(null, null));
        }
Ejemplo n.º 18
0
        public void Execute(object parameter)
        {
            if (!(parameter is RegexRule regexRule))
            {
                return;
            }

            ConfirmationDialogView confirmationDialogView = new ConfirmationDialogView
                                                            (
                new ConfirmationDialog.Model.ConfirmationDialogInfo
            {
                Title  = $"Delete { regexRule.RuleName }?",
                Header = $"Warning: Deleted Rules Cannot Be Retrieved",
                Body   = "Please confirm that you would like to delete this rule."
            }
                                                            );

            confirmationDialogView.ShowDialog();
            if (confirmationDialogView.DialogResult != true)
            {
                return;
            }

            RegexRule.Delete(ruleManagerViewModel.DocumentGuid, regexRule);
        }
        public void ApplyTo_ReturnsNonMatch_IfRuleDoesNotMatch()
        {
            var rule   = new RegexRule("apple", "banana", false, 1, true, true, true);
            var result = rule.ApplyTo("cthulu");

            Assert.IsFalse(result.IsMatch);
        }
        public void ApplyTo_ReturnsCorrectResult_ForComplicatedRule(string input, string expectedOutput)
        {
            var rule   = new RegexRule("(.*)/social/rest/([^/]*)/.*", "$1/social/rest/$2/*", false, 0, false, false, false);
            var output = rule.ApplyTo(input).Replacement;

            Assert.AreEqual(expectedOutput, output);
        }
Ejemplo n.º 21
0
        public void TestRegexRule()
        {
            var wordRule = new RegexRule("\\d");

            Assert.IsTrue(wordRule.Match("1"));
            Assert.IsTrue(wordRule.Match("123"));
            Assert.IsFalse(wordRule.Match("test"));
        }
Ejemplo n.º 22
0
 public void Execute(object parameter)
 {
     RegexRule.SaveRenamedRegexRule
     (
         ImportRuleViewModel.ImportRuleInfo.DocumentGuid,
         ImportRuleViewModel.ImportRuleInfo.NewRegexRule
     );
 }
Ejemplo n.º 23
0
 public void Execute(object parameter)
 {
     RegexRule.ReplaceRegexRule
     (
         ImportRuleViewModel.ImportRuleInfo.DocumentGuid,
         ImportRuleViewModel.ImportRuleInfo.ExistingRegexRule,
         ImportRuleViewModel.ImportRuleInfo.NewRegexRule
     );
 }
        public void ApplyTo_ReturnsCorrectResult_ForIgnoreRule()
        {
            var rule = new RegexRule("/test/.*", null, true, 0, false, false, false);

            var result = rule.ApplyTo("WebTransaction/NormalizedUri/test/ignore");

            Assert.IsTrue(result.IsMatch);
            Assert.IsNull(result.Replacement);
        }
Ejemplo n.º 25
0
        public void LookupRuleDescriptionIsCorrect()
        {
            var scope = RuleScope.Lookup;

            var rule = new RegexRule(_REGEX_PATTERN, scope);

            Assert.Equal($"Schema name of a Lookup must match to regular expression pattern {_REGEX_PATTERN}.",
                         rule.Description);
        }
        private static void AssertSingleExcludeAllParametersRule(IRegexFilter regexFilter)
        {
            RegexRule regexRule = regexFilter.ParameterRules.Single();

            Assert.False(regexRule.Include);
            Assert.Null(regexRule.Type);
            Assert.Null(regexRule.Method);
            Assert.Matches(regexRule.Parameter, Guid.NewGuid().ToString());
        }
        public void GivenValidatingRegex_WhenPatternIsNull_ValidationFails()
        {
            var    value   = "SomeValue";
            string pattern = null;

            var result = new RegexRule(pattern).Validate(0, 0, string.Empty, string.Empty, value);

            result.IsSuccess.Should().BeFalse();
        }
Ejemplo n.º 28
0
        public void Execute(object parameter)
        {
            RegexRule selectedRegexRule = ruleManagerViewModel.SelectedRegexRule;

            int index = ruleManagerViewModel.RegexRules.IndexOf(selectedRegexRule);

            ruleManagerViewModel.RegexRules.RemoveAt(index);
            ruleManagerViewModel.RegexRules.Insert(index - 1, selectedRegexRule);
            ruleManagerViewModel.SelectedRegexRule = selectedRegexRule;
        }
        public void GivenValidatingRegex_WhenEmptyValueIsAllowed_NoValueIsValid()
        {
            string value   = null;
            var    pattern = @"^$|^[^@\s]+@[^@\s]+$`";

            var result = new RegexRule(pattern).Validate(0, 0, "email", "email", value);

            result.IsSuccess.Should().BeTrue();
            result.Value.Should().Be(string.Empty);
        }
Ejemplo n.º 30
0
        public void RuleDescriptionMustShowScopeAndPatternTest()
        {
            var regexPattern = @"^[A-Za-z]+_[A-Z]{1}[a-z]{1}[A-Za-z]*$";
            var scope        = RuleScope.Entity;

            var ruleToTest = new RegexRule(regexPattern, scope);

            Assert.Equal($"Schema name of an Entity must match to regular expression pattern {regexPattern}.",
                         ruleToTest.Description);
        }
Ejemplo n.º 31
0
 public static Rule CreateRule(RuleTypeEnum ruleType)
 {
     Rule rule = null;
     switch (ruleType)
     {
         case RuleTypeEnum.MAX_LENGTH_RULE:
             rule = new MaxLengthRule();
             break;
         case RuleTypeEnum.MIN_LENGTH_RULE:
             rule = new MinLengthRule();
             break;
         case RuleTypeEnum.MAX_VALUE_RULE:
             rule = new MaxValueRule();
             break;
         case RuleTypeEnum.MIN_VALUE_RULE:
             rule = new MinValueRule();
             break;
         case RuleTypeEnum.MAX_INPUT_NUM_RULE:
             rule = new MaxInputNumRule();
             break;
         case RuleTypeEnum.MIN_INPUT_NUM_RULE:
             rule = new MinInputNumRule();
             break;
         case RuleTypeEnum.VALUE_TYPE_RULE:
             rule = new ValueTypeRule();
             break;
         case RuleTypeEnum.REQUIRED_RULE:
             rule = new RequiredRule();
             break;
         case RuleTypeEnum.DISABLE_RULE:
             rule = new DisableRule();
             break;
         case RuleTypeEnum.MAX_DECIMAL_DIGITS_RULE:
             rule = new MaxDecimalDigitsRule();
             break;
         case RuleTypeEnum.MIN_DECIMAL_DIGITS_RULE:
             rule = new MinDecimalDigitsRule();
             break;
         case RuleTypeEnum.REGEX_RULE:
             rule = new RegexRule();
             break;
         case RuleTypeEnum.SET_RULE:
             rule = new SetRule();
             break;
         case RuleTypeEnum.TIP_RULE:
             rule = new TipRule();
             break;
         case RuleTypeEnum.DEV_TIP_RULE:
             rule = new DevTipRule();
             break;
         case RuleTypeEnum.READ_ONLY_RULE:
             rule = new ReadOnlyRule();
             break;
         case RuleTypeEnum.MAX_TARGET_SIZE_RULE:
             rule = new MaxTargetSizeRule();
             break;
         case RuleTypeEnum.MIN_TARGET_SIZE_RULE:
             rule = new MinTargetSizeRule();
             break;
         case RuleTypeEnum.MAX_IMAGE_SIZE_RULE:
             rule = new MaxImageSizeRule();
             break;
         case RuleTypeEnum.MIN_IMAGE_SIZE_RULE:
             rule = new MinImageSizeRule();
             break;
     }
     return rule;
 }