public int StoreAsRule() { if (RuleIndex == -1) { RuleIndex = MemoryCoordinator.GetBoolRuleIndex(); } return(RuleIndex); }
public int StoreAsRule() { if (RuleIndex != -1) { return(RuleIndex); } //get a new bool rule index //get the fields referenced in the parents switch statements, store them, and then set //their relevant filter(s) to the rule index generagted above //get a lis of parent protocols -> those protocols that have a switch statement connecting them to this protocol var parents = ProtocolLibrary.Protocols.Values.Where(p => p.Switch != null && p.Switch.Cases.Exists(s => s.Protocol == Name)).ToList(); //var test = new List<int>(); ////check parents to ensure a rule id doesnt already exit (by accidentally or intentionally referencing the full path to the protocol ////from a field filter of the previous protocol (unlikely, but possible); ////if single alternative exists, use that value. otherwise write new value if 0 or many defined. //foreach (var parent in parents) //{ // var cases = parent.Switch.Cases.Where(f => f.Protocol == Name).ToList(); // foreach (var c in cases) // { // var filters = parent.Switch.Target.Filters.FindAll(f => f.ID == c.Filter).Select(i => i.RuleIndex); // test.AddRange(filters); // } //} // //.Select(f => f.RuleIndex); //test.Remove(-1); RuleIndex = MemoryCoordinator.GetBoolRuleIndex(); //for each of these parent protocols, set the field targeted by the switch statement to a rule field foreach (var tmp in parents.Select(parent => parent.Switch)) { RuleFields.Add(tmp.Target); //get the name(s) of the relevant filter(s) var filterIds = new HashSet <string>(tmp.Cases.FindAll(f => f.Protocol == Name).Select(s => s.Filter)); //get a list of the relevant filters from their string ids var filters = tmp.Target.Filters.FindAll(f => filterIds.Contains(f.ID)); //for each of these filters, set their result index to the result index of the protocol filters.ForEach(f => f.StoreAsProtocolResult(RuleIndex)); } return(RuleIndex); }
public PredicateTransactionSet(Predicate predicate) { this.Transactions = new List <PredicateTransaction>(); if (predicate.Layer > 0) { predicate.Subpredicates.Sort(); foreach (var s in predicate.Subpredicates) { s.WriteIndex = MemoryCoordinator.GetBoolRuleIndex(); Transactions.Add(s.WriteTransaction(PredOutLoc.BoolRuleMemory)); } } predicate.WriteIndex = MemoryCoordinator.GetBoolResultIndex(); Transactions.Add(predicate.WriteTransaction(PredOutLoc.BoolResultMemory)); }