Beispiel #1
0
 internal abstract ExValue Evaluate <TKey>(TagBatchInstance <TKey> instance)
     where TKey : class;
Beispiel #2
0
        /// <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);
        }