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
        internal SeedingPlan(ISeedingSetup seedingSetup, Type seedingSetupType, List <SeedInfo> seeds)
        {
            if (seedingSetupType != null)
            {
                Assert(seedingSetupType.IsSeedingSetupType());
            }
            Assert(seeds != null);

            SeedingSetup     = seedingSetup;
            SeedingSetupType = seedingSetupType;
            Seeds            = seeds;
        }
Ejemplo n.º 3
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.º 4
0
 public async Task Seed <TSeed>(ISeedingSetup seedingSetup) where TSeed : ISeed
 {
     await Seed(typeof(TSeed).Assembly, new[] { typeof(TSeed).FullName }, null, seedingSetup);
 }
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.");
            }
        }