/// <summary> /// Adds the rules in another order constraint to this one /// </summary> /// <param name="other">The other order constraint from which to take rules</param> public void AddAnd(OrderConstraint other) { foreach (var kvp in other.itemItemsBefore) { AddBefores(kvp.Key, kvp.Value); } foreach (var kvp in other.itemItemsAfter) { AddAfters(kvp.Key, kvp.Value); } }
/// <summary> /// Register a function to process event data on raising of an event elsewhere ensuring specified processes on which it /// is dependent are performed first /// </summary> /// <param name="eventName">The name of the event being raised</param> /// <param name="processor">A delegate which takes the current event data and the sender and returns the processed event data</param> /// <param name="moduleId">The name of the module. This can be moduletype.module</param> /// <param name="constraint">An order constraint specifying restrictions on the relative position of this processor in any chain of processors</param> public void RegisterEventProcessor( string eventName, Func <EventHubData, object> processor, string moduleId, OrderConstraint constraint) { var newProcessor = new ProcessorInfo { EventName = eventName, ModuleId = moduleId, Processor = processor }; // register processor on all processor queues where event is or covers a subset of this event var subEvents = Processors.Keys.Where(k => k.StartsWith(eventName)).ToList(); bool matched = false; foreach (string subEvent in subEvents) { if (Processors[subEvent].Any(p => p.ModuleId == newProcessor.ModuleId)) { throw new Exception("Trying to add more than 1 processor for module " + newProcessor.ModuleId + " to event queue " + subEvent); } Processors[subEvent].Add(newProcessor, constraint); matched = (subEvent == eventName); } // if not regstered anywhere, create a new processor queue containing the processes from the least super event of this one if (!matched) { var leastSuperEvent = LeastSuperEvent(eventName); var pList = new ConstraintOrderedCollection <ProcessorInfo>(pi => pi.ModuleId); if (leastSuperEvent != null) { pList = Processors[leastSuperEvent].Copy(); } pList.Add(newProcessor, constraint); Processors.Add(eventName, pList); } }
/// <summary> /// Add a new item with a constraint rule /// </summary> /// <param name="item">The item to add</param> /// <param name="constraint">The constraint rule</param> public void Add(T item, OrderConstraint constraint) { Add(item); orderConstraint.AddAnd(constraint); }
/// <summary> /// Construct a new ConstraintOrderedCollection with a selector for the string used to identify /// items in constraint rules /// </summary> /// <param name="nameSelector">Function which creates the name string from an item</param> public ConstraintOrderedCollection(Func <T, string> nameSelector) { orderConstraint = new OrderConstraint(); this.nameSelector = nameSelector; innerList = new List <T>(); }