internal void AddConstraint(string prefix, string tag) { if (string.IsNullOrEmpty(tag)) { throw new ArgumentNullException("tag"); } if (string.IsNullOrEmpty(prefix)) { prefix = ""; } Pair <string, string> pair = new Pair <string, string>(prefix, tag); if (_constraints == null) { _constraints = new AutoKeyedCollection <Pair <string, string> >(); } if (!_constraints.Contains(pair)) { _constraints.Add(pair); } }
/// <summary> /// Fills the specified items. /// </summary> /// <param name="items">The items.</param> /// <param name="constraintValues">The constraint values.</param> internal protected void Fill(AutoKeyedCollection <string, TagItemCollection> items, string[] constraintValues) { ClearValues(); _items = items; _cValues = constraintValues; }
/// <summary> /// Creates a batch instance over a single item /// </summary> /// <typeparam name="TKey">The type of the key.</typeparam> /// <param name="definition">The definition.</param> /// <param name="checkConditions">if set to <c>true</c> [check conditions].</param> /// <returns></returns> private IEnumerable <TagBatchInstance <TKey> > RunBatchInternal <TKey>(TagBatchDefinition <TKey> definition, bool checkConditions) where TKey : class { AutoKeyedCollection <string, TagItemCollection> restLists = new AutoKeyedCollection <string, TagItemCollection>(StringComparer.OrdinalIgnoreCase); AutoKeyedCollection <string, TagItemCollection> currentLists = new AutoKeyedCollection <string, TagItemCollection>(StringComparer.OrdinalIgnoreCase); int nLeft = 0; foreach (string itemName in definition.ItemsUsed) { TagItemCollection tt = Items.GetAllByName(itemName); restLists.Add(tt); currentLists.Add(tt.Clone(false)); nLeft += tt.Count; } // Create a list of valid items IList <Pair <string, string> > constraints = definition.Constraints; TagBatchInstance <TKey> instance = new TagBatchInstance <TKey>(this, definition); do { string[] constraintValues = new string[constraints.Count]; for (int iList = 0; iList < restLists.Count; iList++) { TagItemCollection rest = restLists[iList]; TagItemCollection current = currentLists[iList]; string listName = restLists[iList].Name; for (int iItem = 0; iItem < rest.Count; iItem++) { TagItem ti = rest[iItem]; int n = 0; bool next = false; foreach (Pair <string, string> p in constraints) { if (!string.IsNullOrEmpty(p.First) && !StringComparer.OrdinalIgnoreCase.Equals(p.First, listName)) { continue; } string v = ti.ExpandedKey(p.Second); if ((object)constraintValues[n] == null) { constraintValues[n++] = v; } else if (!StringComparer.OrdinalIgnoreCase.Equals(v, constraintValues[n++])) { next = true; break; } } if (next) { continue; } else { rest.RemoveAt(iItem--); current.Add(ti); nLeft--; } } } // At least one item was added to current instance.Fill(currentLists, constraintValues); if (!checkConditions || instance.ConditionResult()) { yield return(instance); } foreach (TagItemCollection current in currentLists) { current.Clear(); } }while (nLeft > 0); }