/// <summary> /// Reconstructs the rules from the api object. /// </summary> /// <param name="inputSchema">The input schema.</param> /// <returns></returns> private static List<PledgeRule> ReconstructRules(Schema inputSchema, List<RuleSet> rules) { List<PledgeRule> configRules = new List<PledgeRule>(); foreach (var row in inputSchema.Rows) { var apiRule = rules.First(arg => arg.TargetIndex == row.InputIndex); var rule = new PledgeRule { ColumnIndex = apiRule.TargetIndex, ColumnName = apiRule.TargetName, Operands = GetOperandsFromText(apiRule.Operands), DataType = apiRule.DataType, RuleType = apiRule.RuleType, Description = apiRule.Name }; configRules.Add(rule); } return configRules; }
private static List<RuleSet> DeconstructRules(PledgeRule rule, IConfiguration pledgeConfig) { var groupedRules = new List<RuleSet>(); foreach (var pledgeRule in rule.Children) { var apiRule = new RuleSet { Name = pledgeRule.Description, Operands = pledgeRule.Operands, DataType = pledgeRule.DataType, RuleType = pledgeRule.RuleType, RuleId = pledgeRule.RuleId, LogicType = pledgeRule.LogicType, IsConditional = pledgeRule.Mode == EvaluationMode.Passive, FailureCode = pledgeRule.FailureCode, Children = DeconstructRules(pledgeRule, pledgeConfig), Columns = pledgeRule.Columns.GroupJoin( pledgeConfig.Model.OutputSchema, operand => operand.Index, row => row.InputColumnIndex, (operand, rows) => { var columns = rows as IList<OutputDefinition> ?? rows.ToList(); return new ColumnOperand { Index = columns.FirstOrDefault() != null ? columns.First().InputColumnIndex : -1, Name = columns.FirstOrDefault() != null ? columns.First().ColumnNameAlias : string.Empty, }; }).ToList() }; groupedRules.Add(apiRule); } return groupedRules; }