public void TriggerInRuleMatch(TriggerDefinition trigger, RuleDefinition rule, List<Link> _links)
        {
            List<string> matches = new List<string>();

            //Build up list of stirng pattern matches based on trigger access code
            matches = TriggerCodeConversion(trigger, matches);

            foreach (string s in matches)
            {
            if (rule.Body.StartsWith(s))
            {
                string triggerName = trigger.TableName.ToString() + ", " + trigger.RuleName.ToString() + ", " + trigger.Access.ToString();
                Link record = new Link(rule.Name, triggerName);
                bool exists = CheckLinkExists(_links, record);

                if (!exists)
                {
                    _links.Add(record);
                }
            }
            }
        }
        private bool ExtractRules()
        {
            string line;
            string ruleSeparator = GetRuleSeparator();

            bool newRule = false; // indicates the start of processing new rule
            int posRule = 0; // position of the extracted rule
            string ruleName = String.Empty; // extracted rule name
            int lineNo = 0;
            int ruleCount = 0;
            string ruleFile = config.RuleFile;
            string unit = "";
            int unitpos = 0;
            int lineCount = 0;

            log.Log("Extract Rule Definitions to local variables - start");

            if (File.Exists(ruleFile))
            {
                StreamReader rulesFile = new StreamReader(ruleFile);
                try
                {
                    while ((line = rulesFile.ReadLine()) != null) // loop through all rules extract lines
                    {
                        lineNo++;
                        if (lineNo > Common.Constants.rulesLinesToSkip)
                        {
                            line = line.Substring(Common.Constants.charsToSkip);

                            if (newRule)
                            {
                                if (line.Contains("("))
                                {
                                    posRule = line.IndexOf("(");
                                    int x = line.LastIndexOf(';');
                                    unitpos = x + 2;
                                }
                                else if (line.Contains(";"))
                                {
                                    posRule = line.LastIndexOf(';');
                                    unitpos = posRule + 2;
                                    //unit = line.Substring(unitpos,Common.Constants.lenRuleUnit).Trim();
                                }
                                ruleName = line.Substring(0, posRule);
                                //write processing output to same line
                                log.Log(string.Format("Reading rule {0}             \r", ruleName));
                                ruleNames.Add(ruleName, ruleCount);
                                ruleCount++;
                                newRule = false;
                                //unit = line.Substring(unitpos,Common.Constants.lenRuleUnit).Trim();
                            }

                            if (line.Substring(0, Common.Constants.lenRuleSeperator).Trim().Equals(ruleSeparator))
                            {
                                newRule = true;
                                unit = line.Substring(Common.Constants.posRuleUnit).Trim();
                            }
                            else
                            {
                                lineCount++;
                                RuleDefinition ruleDefinition = new RuleDefinition();
                                ruleDefinition.Name = ruleName;
                                ruleDefinition.CodeLine = lineNo;
                                ruleDefinition.Body = line;
                                ruleDefinition.Unit = unit;
                                ruleDefinition.Id = lineCount;
                                _rules.Add(ruleDefinition);
                            }
                        }

                    }

                    rulesFile.Close();
                    log.Log("Extract Rule Definitions to local variables - complete");
                }
                catch (Exception e)
                {
                    rulesFile.Close();
                    log.Log(string.Format("Incorrect format of the Rule file. Error:{0}", e.Message));
                    return false;
                }
            }
            else
            {
                log.Log("Rule file is missing");
                return false;
            }
            return true;
        }
        public bool TableInRuleMatch(string calledTable, RuleDefinition rule, List<Link> _links)
        {
            string match1 = " " + calledTable + ";";
            string match2 = " " + calledTable + "(";
            string match3 = " " + calledTable + " ";
            string match4 = calledTable + ".";
            string match5 = "'" + calledTable + "'";

            if (rule.Body.Contains(match1) || rule.Body.Contains(match2) || rule.Body.Contains(match3) || rule.Body.Contains(match4) || rule.Body.Contains(match5))
            {
            Link record = new Link(rule.Name.ToString(), calledTable);

            bool exists = CheckLinkExists(_links, record);
            if (!exists)
            {
                _links.Add(record);
                return true; // no need to loop any more
            }
            else
            {
                return false;
            }
            }
            else
            {
            return false;
            }
        }
Exemplo n.º 4
0
 private XElement RuleToXml(RuleDefinition rule, int index) =>
 new XElement("Rule", new XAttribute("Ordinal", index),
              new XElement("Head", this.SymbolsToXml(rule.Head)),
              new XElement("Body", this.SymbolsToXml(rule.Body)));
Exemplo n.º 5
0
 public static string ToString(RuleDefinition rule) =>
 $"{rule.Head} -> {ToString(rule.Body, string.Empty, " ", string.Empty)}";
Exemplo n.º 6
0
        /// <summary>
        /// Creates rule definition using current state of the builder.
        /// </summary>
        /// <returns>Rule definition.</returns>
        public IRuleDefinition Build()
        {
            Validate();

            IBuilder<DependencyGroupElement> dependencyBuilder = _dependencyBuilder;
            DependencyGroupElement dependencies = dependencyBuilder.Build();

            IBuilder<GroupElement> groupBuilder = _groupBuilder;
            GroupElement conditions = groupBuilder.Build();

            IBuilder<ActionGroupElement> actionBuilder = _actionGroupBuilder;
            ActionGroupElement actions = actionBuilder.Build();

            var ruleDefinition = new RuleDefinition(_name, _description, _priority, _repeatability, _tags, dependencies, conditions, actions);
            return ruleDefinition;
        }
Exemplo n.º 7
0
        public void Serialize()
        {
            var sequenceNumberFieldDefinition = CreateFieldDefinition("SequenceNumber", "Sequence Number", "IntegerDecoder", "(?!0{4})[0-9]{4}", ValidationResultType.Error);

            var minNumberFieldRule = new RuleDefinition
            {
                Name                 = "SequenceNumber-MinNumberFieldRule",
                Description          = "Sequence number should be greater or equal to 10",
                Rule                 = "MinNumberFieldRule",
                FailValidationResult = ValidationResultType.Error
            };

            var maxNumberFieldRule = new RuleDefinition
            {
                Name        = "SequenceNumber-MaxNumberFieldRule",
                Description = "Sequence number should be equal or less than 100",
                Rule        = "MinNumberFieldRule",
                Args        = new ArgDefinition[] { new ArgDefinition {
                                                        Name = "ruleValue", Value = "100"
                                                    } },
                FailValidationResult = ValidationResultType.Error
            };

            sequenceNumberFieldDefinition.Rules = new RuleDefinition[] { minNumberFieldRule, maxNumberFieldRule };

            var originatorName = CreateFieldDefinition("OriginatorName", "Originator Name", "TextDecoder", @"[a-zA-Z\s-']{2,35}", ValidationResultType.Error);

            originatorName.Aggregators = new AggregatorDefinition[]
            {
                new AggregatorDefinition("BalanceAggregator", "Balance aggregator", "SumAggregator")
            };

            var target = new InputDefinitionFile10
            {
                Name             = "FXWDCSV",
                Description      = "Demo defining part of FXWDCSV",
                Version          = "1.0",
                FrameworkVersion = "1.0"
            };

            target.Header = new RowDefinition
            {
                Fields = new FieldDefinition[]
                {
                    CreateFieldDefinition("FileType", "File Type", "TextDecoder", "PAYMENT", ValidationResultType.Error),
                    CreateFieldDefinition("RecordType", "Record Type", "TextDecoder", "HEADER", ValidationResultType.Error),
                    CreateFieldDefinition("CreationDate", "Creation Date", "DateDecoder", "MMddyyyy", ValidationResultType.Error),
                    CreateFieldDefinition("LocationID", "Location ID", "TextDecoder", "[a-zA-Z]{12}", ValidationResultType.Warning),
                    sequenceNumberFieldDefinition
                }
            };

            target.Data = new RowDefinition
            {
                Fields = new FieldDefinition[]
                {
                    CreateFieldDefinition("RecordType", "Record Type", "TextDecoder", "PAYMENT", ValidationResultType.Error),
                    CreateFieldDefinition("PaymentType", "Payment Type", "TextDecoder", "(FXW|MBW)", ValidationResultType.Error),
                    CreateFieldDefinition("SendersReferenceNumber", "Senders Reference Number", "TextDecoder", "[a-zA-Z0-9]{1,16}", ValidationResultType.Error),
                    CreateFieldDefinition("RelatedReferenceNumber", "Related Reference Number", "TextDecoder", "[a-zA-Z0-9]{1,16}", ValidationResultType.Error),
                    CreateFieldDefinition("ValueDate", "Value Date", "DateDecoder", "MMddyyyy", ValidationResultType.Error),
                    CreateFieldDefinition("PaymentType", "Payment Type", "TextDecoder", "(DEBIT|CREDIT)", ValidationResultType.Error),
                    CreateFieldDefinition("Amount", "Amount", "DecimalDecoder", @"(?!0+)([0-9]{1,2},)?([0-9]{1,3},)?([0-9]{1,3},)?[0-9]{1,3}\.[0-9]{2}", ValidationResultType.Error),
                    CreateFieldDefinition("CreditCurrency", "Credit Currency", "TextDecoder", "[A-Z]{3}", ValidationResultType.Error),
                    originatorName
                }
            };

            target.Trailer = new RowDefinition
            {
                Fields = new FieldDefinition[]
                {
                    CreateFieldDefinition("FileType", "File Type", "TextDecoder", "PAYMENT", ValidationResultType.Error),
                    CreateFieldDefinition("RecordType", "Record Type", "TextDecoder", "TRAILER", ValidationResultType.Error),
                    CreateFieldDefinition("HashTotal", "Hash Total", "DecimalDecoder", @"(?!0+)([0-9]{1,2},)?([0-9]{1,3},)?([0-9]{1,3},)?[0-9]{1,3}\.[0-9]{2}", ValidationResultType.Error),
                    CreateFieldDefinition("RecordCount", "Record Count", "IntegerDecoder", @"\d{1,5}", ValidationResultType.Error)
                }
            };

            var xml = HelperXmlSerializer.Serialize(target);

            TestContext.WriteLine(xml);
        }
Exemplo n.º 8
0
 private static bool HasRepoPrefix(RuleDefinition ruleDefinition, string prefix) =>
 ruleDefinition.RuleKey.StartsWith(prefix) && ruleDefinition.RuleKey.Length > prefix.Length;
Exemplo n.º 9
0
 private static bool EslintKeyIsValid(RuleDefinition ruleDefinition) =>
 !string.IsNullOrEmpty(ruleDefinition.EslintKey) ||
 // Special case - "JavaScript parser failure"
 ruleDefinition.RuleKey.EndsWith(":S2260");
Exemplo n.º 10
0
 private static bool RuleHasParameters(RuleDefinition ruleDefinition) =>
 ruleDefinition.Params.Length > 0;
Exemplo n.º 11
0
 private static bool RuleKeyIsValid(RuleDefinition ruleDefinition) =>
 ruleDefinition.RuleKey != null &&
 (HasRepoPrefix(ruleDefinition, "javascript:") || HasRepoPrefix(ruleDefinition, "typescript:"));
Exemplo n.º 12
0
 private IEnumerable <Request> FindMatchingRequests(IEnumerable <Request> requests, RuleDefinition rule)
 {
     return(requests.Where(r => r.TypeOfThisRequest == rule.ConcerningRequestType));
 }
Exemplo n.º 13
0
 private ImmutableList <RuleDefinition> Rules(ImmutableList <RuleDefinition> rules, RuleDefinition next) => rules.Add(next);
Exemplo n.º 14
0
 private ImmutableList <RuleDefinition> Rules(string rulesKeyword, string colon, RuleDefinition initialRule) => ImmutableList <RuleDefinition> .Empty.Add(initialRule);
Exemplo n.º 15
0
        public bool RuleInRuleMatch(string calledRule, RuleDefinition rule, List<Link> _links, bool addNotApplicable)
        {
            //line contains
            string match1 = " " + calledRule + ";";
            string match2 = " " + calledRule + "(";
            string match3 = "(" + calledRule + ";";
            string match4 = "(" + calledRule + "(";
            string match7 = "(" + calledRule + ")";
            string match10 = "= " + calledRule + "(";
            string match24 = "= " + calledRule + ";";
            string match11 = "^= " + calledRule + "(";
            string match25 = "^= " + calledRule + ";";
            string match15 = "> " + calledRule + "(";
            string match27 = "> " + calledRule + ";";
            string match16 = "=> " + calledRule + "(";
            string match28 = "=> " + calledRule + ";";
            string match19 = "< " + calledRule + "(";
            string match29 = "< " + calledRule + ";";
            string match20 = "<= " + calledRule + "(";
            string match30 = "<= " + calledRule + ";";
            string match21 = "(" + calledRule + ",";
            string match22 = ", " + calledRule + ", ";
            string match23 = ", " + calledRule + ")";

            //line starts with
            string match5 = calledRule + "(";
            string match6 = calledRule + ";";
            string match8 = calledRule + " =";
            string match9 = calledRule + " ^=";
            string match13 = calledRule + " >";
            string match14 = calledRule + " =>";
            string match17 = calledRule + " <";
            string match18 = calledRule + " <=";
            string match12 = "^" + calledRule + "(";
            string match26 = "^" + calledRule + ";";

            //donot add a rule if it matches the following string patterns, as they are signals.
            string signal1 = "SIGNAL " + calledRule + ";";
            string signal2 = "ON " + calledRule + ";";
            string signal3 = "UNTIL " + calledRule + ";";

            string line = rule.Body;

            if (!line.Contains(signal1) && !line.Contains(signal2) && !line.Contains(signal3))
            {
                if (line.Contains(match1) || line.Contains(match2) || line.Contains(match3) || line.Contains(match4) || line.Contains(match7) || line.Contains(match10) || line.Contains(match11) || line.Contains(match15) || line.Contains(match16) || line.Contains(match19) || line.Contains(match20) || line.Contains(match21) || line.Contains(match22) || line.Contains(match23) || line.Contains(match24) || line.Contains(match25) || line.Contains(match27) || line.Contains(match28) || line.Contains(match29) || line.Contains(match30) || line.StartsWith(match13) || line.StartsWith(match14) || line.StartsWith(match5) || line.StartsWith(match6) || line.StartsWith(match8) || line.StartsWith(match9) || line.StartsWith(match12) || line.StartsWith(match17) || line.StartsWith(match18) || line.StartsWith(match26))
                {
                    Link record = new Link(rule.Name.ToString(), calledRule);

                    bool exists = CheckLinkExists(_links, record);

                    if (!exists)
                    {
                        _links.Add(record);
                        addNotApplicable = false;
                    }

                }
            }
            return addNotApplicable;
        }
Exemplo n.º 16
0
 private static bool HasDefaultParameters(RuleDefinition ruleDefinition) =>
 ruleDefinition.DefaultParams.Length > 0;
Exemplo n.º 17
0
        private CategoryDefinition LoadCategoryDefinition(XElement categoryElement)
        {
            CategoryDefinition categoryDefinition = new CategoryDefinition();
              categoryDefinition.Id = int.Parse(categoryElement.Attribute(XName.Get(ID)).Value);
              categoryDefinition.Enabled = bool.Parse(categoryElement.Attribute(XName.Get(ENABLED)).Value); // XSD should have validated input...
              categoryDefinition.CategoryDeclarationReferenceId = int.Parse(categoryElement.Attribute(XName.Get(REF_ID)).Value);
              categoryDefinition.CategoryDeclarationReferenceName = categoryElement.Attribute(XName.Get(REF_NAME)).Value;

              foreach (XElement rule in categoryElement.Descendants(PROJECT_RULE))
              {
            RuleDefinition ruleDefinition = new RuleDefinition();
            ruleDefinition.ParentDefinition = categoryDefinition;
            ruleDefinition.Id = int.Parse(rule.Attribute(XName.Get(ID)).Value);
            ruleDefinition.Enabled = bool.Parse(rule.Attribute(XName.Get(ENABLED)).Value); // XSD should have validated input...
            ruleDefinition.RuleDeclarationReferenceId = int.Parse(rule.Attribute(XName.Get(REF_ID)).Value);
            ruleDefinition.RuleDeclarationReferenceName = rule.Attribute(XName.Get(REF_NAME)).Value;

            categoryDefinition.Rules.Add(ruleDefinition.RuleDeclarationReferenceId, ruleDefinition);

            // Update 'Rule Definition' statistics counters...
            ProxyHome.Instance.RetrieveStatisticsProxy(ConfigKeyKeeper.Instance.AccessKey).IncrementCounter(CounterIds.TotalRuleDefinitions);
            if (ruleDefinition.Enabled)
              ProxyHome.Instance.RetrieveStatisticsProxy(ConfigKeyKeeper.Instance.AccessKey).IncrementCounter(CounterIds.ActiveRuleDefinitions);
              }
              return categoryDefinition;
        }
Exemplo n.º 18
0
 public RuleExecutor(RuleDefinition definition)
 {
     _definition = definition;
 }