Beispiel #1
0
        protected virtual void FlushTempStorage()
        {
            List <EntityContext> nextFlushEntities = new List <EntityContext>();

            do
            {
                foreach (EntityContext entityContext in nextFlushEntities)
                {
                    List <IPersistentStorage> storage      = _setup.GetPersistentStorages(entityContext.Description);
                    IFlushStrategy            flushTrigger = _setup.GetFlushTrigger(entityContext.Description);

                    flushTrigger.SetNextFlushCount(entityContext);
                    flushTrigger.SetNextReleaseCount(entityContext);

                    if (entityContext.Description.InsertToPersistentStorageBeforeUse)
                    {
                        _setup.TemporaryStorage.GenerateStorageIds(entityContext, storage);
                    }

                    _setup.TemporaryStorage.FlushToPersistent(entityContext, storage);
                }

                _setup.TemporaryStorage.WaitAllTasks();

                nextFlushEntities = _entityContexts.Values
                                    .Where(x => x.EntityProgress.ReleasedCount < x.EntityProgress.CurrentCount)
                                    .ToList();
            } while (nextFlushEntities.Count > 0);

            _setup.TemporaryStorage.WaitAllTasks();
        }
        //Flush required checks
        public virtual bool CheckIsFlushRequired(EntityContext entityContext)
        {
            EntityProgress progress          = entityContext.EntityProgress;
            bool           isFlushInProgress = progress.IsFlushInProgress();

            if (isFlushInProgress)
            {
                return(false);
            }

            //NextReleaseCount will be used by child entities to check if they still can generate from this parent
            IFlushStrategy flushTrigger = _generatorSetup.GetFlushTrigger(entityContext.Description);

            flushTrigger.SetNextReleaseCount(entityContext);

            //when all entities are generated also should flush
            bool isFlushRequired = flushTrigger.IsFlushRequired(entityContext);
            bool isCompleted     = progress.CurrentCount >= progress.TargetCount;

            if (isCompleted)
            {
                isFlushRequired = true;
            }
            if (!isFlushRequired)
            {
                //if flush is not required NextFlushCount should not be updated
                //isFlushInProgress is using NextFlushCount
                return(isFlushRequired);
            }

            //update next flush count
            flushTrigger.SetNextFlushCount(entityContext);

            //add to flush candidates if will be used by dependent children
            bool hasDependentChild = FindChildThatCanGenerate(entityContext, true) != null;

            if (hasDependentChild)
            {
                _flushCandidates.Add(entityContext);
            }

            return(isFlushRequired);
        }