Example #1
0
        //    1 word:
        //        Bits 15 - 3: Unknown(Seems to have random content)
        //        Bits 2 - 1: Container type. In Dungeon Master and Chaos Strikes Back, the only valid value is 00 for the Chests.
        //        Bit 0: Unknown(Seems to have random content)
        //     1 word: 00 00 : Unused


        public IEnumerable <ItemData> GetEnumerator(DungeonData dungeon)
        {
            var it = new ItemEnumerator(dungeon, NextContainedObjectID);

            while (it.MoveNext())
            {
                yield return(it.Current);
            }
        }
Example #2
0
        /// <summary>
        /// An enumerator which contains all items/indices in this mask;
        /// </summary>
        public IEnumerator <int> GetItemEnumerator()
        {
            var r = new ItemEnumerator()
            {
                ChunkEnum = this.GetEnumerator()
            };

            return(r);
        }
Example #3
0
        public void Dispose()
        {
            lock (LockObject)
            {
                if (!IsDisposing)
                {
                    IsDisposing = true;

                    if (ItemEnumerator != null &&
                        SplitOnEnumerator != null)
                    {
                        ItemEnumerator.Dispose();
                        ItemEnumerator = null;
                        SplitOnEnumerator.Dispose();
                        SplitOnEnumerator = null;
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Begins mapping objects from Dapper.
        /// </summary>
        /// <typeparam name="TEntityType">The entity type to be mapped.</typeparam>
        /// <returns>The mapped entity.</returns>
        public TEntityType Start <TEntityType>()
            where TEntityType : class
        {
            lock (LockObject)
            {
                ItemEnumerator      = Items.GetEnumerator();
                SplitOnEnumerator   = SplitOn.GetEnumerator();
                CurrentSelectionSet = SelectionSet.GetSelectedFields();
                MappedCount         = 0;

                if (ItemEnumerator.MoveNext() &&
                    SplitOnEnumerator.MoveNext())
                {
                    var entity = ItemEnumerator.Current as TEntityType;
                    MappedCount++;
                    return(entity);
                }
                return(default(TEntityType));
            }
        }
Example #5
0
        protected static void UpdateItems <TItem>(ItemList <TItem> items,
                                                  TCollection collection, ItemEnumerator <TItem> enumerator, bool continueFromLastUpdate, int stopCount)
        {
            if (collection == null)
            {
                items.Clear();
                return;
            }

            if (!continueFromLastUpdate || enumerator == null)
            {
                enumerator.Reset(collection);
                items.Clear();
            }

            while (items.Count < stopCount && enumerator.MoveNext())
            {
                items.Add(new ItemInfo <TItem>(enumerator.CurrentItem, enumerator.CurrentGetResult));
            }
        }
Example #6
0
        /// <summary>
        /// Maps the next object from Dapper.
        /// </summary>
        /// <typeparam name="TItemType">The item type to be mapped.</typeparam>
        /// <param name="context">The context used to map object from Dapper.</param>
        /// <param name="fieldNames">The names of one or more GraphQL fields associated with the item.</param>
        /// <param name="entityMapper">An optional entity mapper.  This is used to map complex objects from Dapper mapping results.</param>
        /// <returns>The mapped item.</returns>
        public TItemType Next <TItemType>(
            IEnumerable <string> fieldNames,
            Func <IDictionary <string, Field>, IHaveSelectionSet, IHaveSelectionSet> getSelectionSet,
            IEntityMapper <TItemType> entityMapper = null)
            where TItemType : class
        {
            if (fieldNames == null)
            {
                throw new ArgumentNullException(nameof(fieldNames));
            }

            if (ItemEnumerator == null ||
                SplitOnEnumerator == null)
            {
                throw new NotSupportedException("Cannot call Next() before calling Start()");
            }

            lock (LockObject)
            {
                var keys = fieldNames.Intersect(CurrentSelectionSet.Keys);
                if (keys.Any())
                {
                    TItemType item = default(TItemType);
                    while (
                        ItemEnumerator.MoveNext() &&
                        SplitOnEnumerator.MoveNext())
                    {
                        // Whether a non-null object exists at this position or not,
                        // the SplitOn is expecting this type here, so we will yield it.
                        if (SplitOnEnumerator.Current == typeof(TItemType))
                        {
                            item = ItemEnumerator.Current as TItemType;
                            break;
                        }
                    }

                    if (entityMapper != null)
                    {
                        // Determine where the next entity mapper will get its selection set from
                        IHaveSelectionSet selectionSet = getSelectionSet(CurrentSelectionSet, SelectionSet);

                        var nextContext = new EntityMapContext
                        {
                            Items        = Items.Skip(MappedCount),
                            SelectionSet = selectionSet,
                            SplitOn      = SplitOn.Skip(MappedCount),
                        };
                        using (nextContext)
                        {
                            item = entityMapper.Map(nextContext);

                            // Update enumerators to skip past items already mapped
                            var mappedCount = nextContext.MappedCount;
                            MappedCount += nextContext.MappedCount;
                            int i = 0;
                            while (
                                // Less 1, the next time we iterate we
                                // will advance by 1 as part of the iteration.
                                i < mappedCount - 1 &&
                                ItemEnumerator.MoveNext() &&
                                SplitOnEnumerator.MoveNext())
                            {
                                i++;
                            }
                        }
                    }
                    else
                    {
                        MappedCount++;
                    }
                    return(item);
                }
            }
            return(default(TItemType));
        }