private static void AddRule(CheckPoint_Layer layer, CheckPoint_Rule newRule) { bool match = false; int pos = GetFirstRuleWithSameAction(layer, newRule.Action); if (pos >= 0) { for (int i = pos; i < layer.Rules.Count(); i++) { if (IsRuleSimilarToRule(layer.Rules[i], newRule)) { layer.Rules[i] = MergeRules(layer.Rules[i], newRule); match = true; break; } } } if (!match) { CheckPoint_Rule rule = newRule.Clone(); rule.Layer = layer.Name; rule.Comments = ""; rule.ConversionComments = newRule.ConversionComments; layer.Rules.Add(rule); } }
public static CheckPoint_Layer Optimize(CheckPoint_Layer originalLayer, string newName) { CheckPoint_Layer curLayer = originalLayer; CheckPoint_Layer newLayer; while (true) { var nextLayer = new CheckPoint_Layer { Name = newName }; foreach (CheckPoint_Rule rule in curLayer.Rules) { AddRule(nextLayer, rule); } if (nextLayer.Rules.Count == curLayer.Rules.Count) { newLayer = nextLayer; break; } curLayer = nextLayer; } for (int i = 0; i < newLayer.Rules.Count; ++i) { newLayer.Rules[i].ConversionComments = OptimizeConverstionComments(newLayer.Rules[i].ConversionComments); } return(newLayer); }
public static CheckPoint_Layer Optimize(CheckPoint_Layer originalLayer, string newName) { CheckPoint_Layer curLayer = originalLayer; CheckPoint_Layer newLayer; while (true) { var nextLayer = new CheckPoint_Layer { Name = newName }; foreach (CheckPoint_Rule rule in curLayer.Rules) { AddRule(nextLayer, rule); } if (nextLayer.Rules.Count == curLayer.Rules.Count) { newLayer = nextLayer; break; } curLayer = nextLayer; } return(newLayer); }
private static int GetFirstRuleWithSameAction(CheckPoint_Layer layer, CheckPoint_Rule.ActionType action) { int matchedRules = 0; int pos = layer.Rules.Count - 1; while (pos >= 0 && layer.Rules[pos].Action == action) { matchedRules++; pos--; } return((matchedRules == 0) ? -1 : (pos + 1)); }