Exemplo n.º 1
0
            /// <summary>
            /// Moves the enumerator to the next item.
            /// </summary>
            /// <returns>True if there is a next item, false otherwise.</returns>
            public bool MoveNext()
            {
                if (this.collectionStack == null)
                {
                    if (this.collection.Count == 0)
                    {
                        return(false);
                    }

                    this.collectionStack = new Stack();
                    this.collectionStack.Push(new CollectionSymbol(this.collection));
                }

                CollectionSymbol symbol = (CollectionSymbol)this.collectionStack.Peek();

                if (this.FindNext(symbol))
                {
                    return(true);
                }

                this.collectionStack.Pop();
                if (this.collectionStack.Count == 0)
                {
                    return(false);
                }

                return(this.MoveNext());
            }
Exemplo n.º 2
0
            /// <summary>
            /// Finds the next item from a given symbol.
            /// </summary>
            /// <param name="symbol">The symbol to start looking from.</param>
            /// <returns>True if a next element is found, false otherwise.</returns>
            private bool FindNext(CollectionSymbol symbol)
            {
                object container = symbol.Collection.items[symbol.ContainerIndex];

                CollectionItem collectionItem = container as CollectionItem;

                if (collectionItem != null)
                {
                    if (symbol.ItemIndex + 1 < collectionItem.Elements.Count)
                    {
                        symbol.ItemIndex++;
                        return(true);
                    }
                }

                ElementCollection elementCollection = container as ElementCollection;

                if (elementCollection != null && elementCollection.Count > 0 && symbol.ItemIndex == -1)
                {
                    symbol.ItemIndex++;
                    this.PushCollection(elementCollection);
                    return(true);
                }

                symbol.ItemIndex = 0;

                for (int i = symbol.ContainerIndex + 1; i < symbol.Collection.items.Count; ++i)
                {
                    object nestedContainer = symbol.Collection.items[i];

                    CollectionItem nestedCollectionItem = nestedContainer as CollectionItem;
                    if (nestedCollectionItem != null)
                    {
                        if (nestedCollectionItem.Elements.Count > 0)
                        {
                            symbol.ContainerIndex = i;
                            return(true);
                        }
                    }

                    ElementCollection nestedElementCollection = nestedContainer as ElementCollection;
                    if (nestedElementCollection != null && nestedElementCollection.Count > 0)
                    {
                        symbol.ContainerIndex = i;
                        this.PushCollection(nestedElementCollection);
                        return(true);
                    }
                }

                return(false);
            }
Exemplo n.º 3
0
            /// <summary>
            /// Pushes a collection onto the stack.
            /// </summary>
            /// <param name="collection">The collection to push.</param>
            private void PushCollection(ElementCollection collection)
            {
                if (collection.Count <= 0)
                {
                    throw new ArgumentException(String.Format(
                                                    CultureInfo.InvariantCulture,
                                                    "Collection has {0} elements. Must have at least one.",
                                                    collection.Count));
                }

                CollectionSymbol symbol = new CollectionSymbol(collection);

                this.collectionStack.Push(symbol);
                this.FindNext(symbol);
            }
Exemplo n.º 4
0
            /// <summary>
            /// Pushes a collection onto the stack.
            /// </summary>
            /// <param name="elementCollection">The collection to push.</param>
            private void PushCollection(ElementCollection elementCollection)
            {
                if (elementCollection.Count <= 0)
                {
                    throw new ArgumentException(String.Format(
                                                    CultureInfo.InvariantCulture,
                                                    WixHarvesterStrings.EXP_CollectionMustHaveAtLeastOneElement,
                                                    elementCollection.Count));
                }

                CollectionSymbol symbol = new CollectionSymbol(elementCollection);

                this.collectionStack.Push(symbol);
                this.FindNext(symbol);
            }