Exemplo n.º 1
0
        protected virtual Dictionary <Type, object> GetRequiredEntities()
        {
            var result = new Dictionary <Type, object>();

            foreach (RequiredEntity requiredEntity in EntityContext.Description.Required)
            {
                Type          parent = requiredEntity.Type;
                EntityContext parentEntityContext = _entityContexts[parent];

                ISpreadStrategy spreadStrategy    = _setup.GetSpreadStrategy(EntityContext.Description, requiredEntity);
                long            parentEntityIndex = spreadStrategy.GetParentIndex(parentEntityContext, EntityContext);

                object parentEntity = _setup.TemporaryStorage.Select(parentEntityContext, parentEntityIndex);
                result.Add(parent, parentEntity);
            }

            return(result);
        }
        protected virtual bool CheckChildCanGenerate(EntityContext child,
                                                     EntityContext parent, bool onlyCheckCanGenerate)
        {
            Type            typeToFlush    = parent.Type;
            RequiredEntity  requiredParent = child.Description.Required.First(x => x.Type == typeToFlush);
            ISpreadStrategy spreadStrategy = _generatorSetup.GetSpreadStrategy(child.Description, requiredParent);

            //check if child can still use parent entities from temporary storage to generate
            bool canGenerateMore = spreadStrategy.CanGenerateFromParentNextReleaseCount(parent, child);

            if (onlyCheckCanGenerate)
            {
                return(canGenerateMore);
            }

            //check if child is not a flush candidate itself
            bool childIsFlushCandidate = _flushCandidates.Contains(child);

            return(!childIsFlushCandidate && canGenerateMore);
        }
        protected virtual void AddRequiredParentsRecursive(EntityContext child, Stack <OrderIterationType> generationOrder)
        {
            if (child.Description.Required == null)
            {
                return;
            }

            foreach (RequiredEntity requiredEntity in child.Description.Required)
            {
                EntityContext   parent         = _entityContexts[requiredEntity.Type];
                ISpreadStrategy spreadStrategy = _generatorSetup.GetSpreadStrategy(child.Description, requiredEntity);

                long parentRequiredCount = spreadStrategy.GetNextIterationParentCount(parent, child);
                long parentNewItemsCount = parentRequiredCount - parent.EntityProgress.CurrentCount;

                bool added = PushQueueItem(generationOrder, requiredEntity.Type, parentNewItemsCount);
                if (added)
                {
                    AddRequiredParentsRecursive(parent, generationOrder);
                }
            }
        }