Ejemplo n.º 1
0
        internal virtual Dictionary <Type, EntityContext> SetupEntityContexts(
            Dictionary <Type, IEntityDescription> entityDescriptions)
        {
            var entityContexts = new Dictionary <Type, EntityContext>();

            foreach (IEntityDescription description in entityDescriptions.Values)
            {
                List <IEntityDescription> children = entityDescriptions.Values
                                                     .Where(x => x.Required != null &&
                                                            x.Required.Select(req => req.Type).Contains(description.Type))
                                                     .ToList();

                List <IEntityDescription> parents = new List <IEntityDescription>();
                if (description.Required != null)
                {
                    IEnumerable <Type> parentTypes = description.Required.Select(x => x.Type);
                    parents = entityDescriptions.Values
                              .Where(x => parentTypes.Contains(x.Type))
                              .ToList();
                }

                IQuantityProvider quantityProvider = GetQuantityProvider(description);
                long targetTotalCount = quantityProvider.GetTargetQuantity();

                entityContexts.Add(description.Type, new EntityContext
                {
                    Type           = description.Type,
                    Description    = description,
                    ChildEntities  = children,
                    ParentEntities = parents,
                    EntityProgress = new EntityProgress
                    {
                        TargetCount = targetTotalCount
                    }
                });
            }

            return(entityContexts);
        }
Ejemplo n.º 2
0
        //Generation prestart checks
        /// <summary>
        /// Validate that all required parameters were set for each entity or among default parameters.
        /// </summary>
        /// <param name="entityDescriptions"></param>
        public virtual void CheckGeneratorSetupComplete(Dictionary <Type, IEntityDescription> entityDescriptions)
        {
            ISupervisor supervisor = _generatorSetup.Supervisor;

            if (supervisor == null)
            {
                throw new ArgumentNullException(nameof(_generatorSetup.Supervisor));
            }

            foreach (IEntityDescription description in entityDescriptions.Values)
            {
                string msgFormat = $"Entity description [{description.Type}] did not have {{0}} configured and {nameof(GeneratorSetup)} {{1}} was not provided";

                IQuantityProvider quantityProvider = description.QuantityProvider
                                                     ?? _generatorSetup.DefaultQuantityProvider;
                if (quantityProvider == null)
                {
                    string defName = nameof(_generatorSetup.DefaultFlushStrategy);
                    string msg     = string.Format(msgFormat
                                                   , nameof(description.QuantityProvider), defName);
                    throw new ArgumentNullException(defName, msg);
                }

                IGenerator generator = description.Generator
                                       ?? _generatorSetup.DefaultGenerator;
                if (generator == null)
                {
                    string defName = nameof(_generatorSetup.DefaultFlushStrategy);
                    string msg     = string.Format(msgFormat
                                                   , nameof(description.QuantityProvider), defName);
                    throw new ArgumentNullException(defName, msg);
                }

                List <IPersistentStorage> persistentStorages = description.PersistentStorages
                                                               ?? _generatorSetup.DefaultPersistentStorages;
                if (persistentStorages == null || persistentStorages.Count == 0)
                {
                    string defName = nameof(_generatorSetup.DefaultPersistentStorages);
                    string msg     = string.Format(msgFormat
                                                   , nameof(description.PersistentStorages), defName);
                    throw new ArgumentNullException(defName, msg);
                }

                IFlushStrategy insertTrigger = description.FlushTrigger
                                               ?? _generatorSetup.DefaultFlushStrategy;
                if (insertTrigger == null)
                {
                    string defName = nameof(_generatorSetup.DefaultFlushStrategy);
                    string msg     = string.Format(msgFormat
                                                   , nameof(description.FlushTrigger), defName);
                    throw new ArgumentNullException(defName, msg);
                }

                if (description.Required != null)
                {
                    foreach (RequiredEntity required in description.Required)
                    {
                        ISpreadStrategy spreadStrategy = required.SpreadStrategy
                                                         ?? _generatorSetup.DefaultSpreadStrategy;
                        if (spreadStrategy == null)
                        {
                            string defName = nameof(_generatorSetup.DefaultSpreadStrategy);
                            string msg     = $"Entity description [{description.Type}] with required type [{required.Type}] did not have {nameof(RequiredEntity.SpreadStrategy)} configured and {nameof(GeneratorSetup)} {defName} was not provided";
                            throw new ArgumentNullException(defName, msg);
                        }
                    }
                }
            }
        }