Ejemplo n.º 1
0
        private static SeedingPlan GetSeedingPlanFor(SeedAssembly seedAssembly, ISeedingSetup seedingSetup)
        {
            Assert(seedAssembly != null);

            var seedInfoTree = SeedInfoTree.Create(seedAssembly.SeedTypes);

            var seedingSteps = new List <SeedInfo>();

            foreach (var seedInfo in seedInfoTree.AllSeeds)
            {
                RecursivelyBuildSeedingSteps(seedInfo);
            }

            return(new SeedingPlan(seedingSetup, seedAssembly.SeedingSetupType, seedingSteps));

            void RecursivelyBuildSeedingSteps(SeedInfo seedInfo)
            {
                if (seedingSteps.Contains(seedInfo))
                {
                    return;
                }

                foreach (var dependency in seedInfo.DependsOn)
                {
                    RecursivelyBuildSeedingSteps(dependency);
                }

                seedingSteps.Add(seedInfo);
            }
        }
Ejemplo n.º 2
0
        public SeedingPlan GetSeedingPlanFor(Assembly assembly, IEnumerable <string> seedFilters, ISeedingSetup seedingSetup = null)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            return(GetSeedingPlanImpl());

            SeedingPlan GetSeedingPlanImpl()
            {
                return(GetSeedingPlanFor(SeedAssembly.Create(assembly, seedFilters), seedingSetup));
            }
        }
Ejemplo n.º 3
0
        public SeedInfoTree GetSeedInfoTree(Assembly assembly, IEnumerable <string> seedFilters)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            return(GetSeedInfoTreeImpl());

            SeedInfoTree GetSeedInfoTreeImpl()
            {
                var seedAssembly = SeedAssembly.Create(assembly, seedFilters);

                return(SeedInfoTree.Create(seedAssembly.SeedTypes));
            }
        }
Ejemplo n.º 4
0
        public IEnumerable <SeedInfo> GetSeedsFor(Assembly assembly, IEnumerable <string> seedFilters)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            return(GetSeedInfosImpl());

            IEnumerable <SeedInfo> GetSeedInfosImpl()
            {
                var seedAssembly = SeedAssembly.Create(assembly, seedFilters);

                return(SeedInfoTree.Create(seedAssembly.SeedTypes)
                       .AllSeeds
                       .Where(seedInfo => seedAssembly.SeedTypes.Contains(seedInfo.SeedType)));
            }
        }
Ejemplo n.º 5
0
        public async Task Seed(Assembly assembly, IEnumerable <string> seedFilters, Type seedingSetupType = null, ISeedingSetup seedingSetup = null)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            await SeedImpl();

            async Task SeedImpl()
            {
                var filters = seedFilters.ToArray();

                RaiseMessageEvent(string.Format("Seed assembly: {1}{0}" +
                                                "Seed filter:{0}{2}",
                                                Environment.NewLine,
                                                assembly.Location,
                                                string.Join(Environment.NewLine, filters.Select(filter => "\t" + filter))));

                var seedAssembly = SeedAssembly.Create(assembly, filters, seedingSetupType);

                var seedingPlan = GetSeedingPlanFor(seedAssembly, seedingSetup);

                RaiseMessageEvent(string.Format("Seeding plan:{0}{1}",
                                                Environment.NewLine,
                                                string.Join(Environment.NewLine, seedingPlan.Seeds.Select((seedInfo, index) => (index + 1) + ". " + seedInfo.DisplayName))));

                RaiseMessageEvent("Seeding started.");

                try
                {
                    await Seed(seedingPlan);
                }
                catch (Exception e)
                {
                    RaiseMessageEvent(e.ToString());
                }


                RaiseMessageEvent("Seeding finished.");
            }
        }