Beispiel #1
0
        public Task <SeedingReport> SeedSeedBucket(Type seedBucketType, ISeedableFilter?filter = null) // TODO: Design the API properly, see where to have the filter in public methods etc.
        {
            System.Diagnostics.Debug.Assert(seedBucketType.IsSeedBucketType());

            // We know that the seed bucket info builder always returns
            // a seed bucket info and never null; threfore "!".
            var seedBucketInfo = seedBucketInfoBuilder.BuildFrom(seedBucketType) !;

            // TODO: Return proper seeding report if there is more then one seeding startup available.
            if (seedBucketInfo.Startups.Count() > 1)
            {
                throw new Exception("TODO: Return proper seeding report if there is more then one seeding startup available.");
            }

            var seedBucketStartupType = seedBucketInfo.Startups.FirstOrDefault().Type;

            return(Seed(seedBucketInfo, CreateSeedBucketStartup(seedBucketStartupType), filter ?? AcceptAllSeedableFilter.Instance));
        }
Beispiel #2
0
        SeedBucketInfo?IExtractor <Type, SeedBucketInfo?> .ExtractFrom(Type seedableImplementation)
        {
            System.Diagnostics.Debug.Assert(seedableImplementation.IsSeedableType());

            var discoverdSeedBucketTypes = seedBucketOfSeedableDiscoverer.DiscoverIn(seedableImplementation).DiscoveredItems;

            return(discoverdSeedBucketTypes.Count == 1
                ? seedBucketInfoBuilder.BuildFrom(discoverdSeedBucketTypes.First())
                : null);
        }
Beispiel #3
0
 /// <summary>
 /// Gets <see cref="SeedBucketInfo"/> for this seed bucket.
 /// </summary>
 /// <returns><see cref="SeedBucketInfo"/> that describes this seed bucket.</returns>
 public SeedBucketInfo GetMetaInfo()
 {
     // We know that the seed bucket info builder always returns
     // a seed bucket info and never null; threfore "!".
     return(seedBucketInfoBuilder.BuildFrom(GetType()) !);
 }
Beispiel #4
0
        public async Task <SeedingReport> Seed(Type seedBucketType)
        {
            System.Diagnostics.Debug.Assert(typeof(SeedBucket).IsAssignableFrom(seedBucketType));

            // We know that the seed bucket info builder always returns
            // a seed bucket info and never null; threfore "!".
            var seedBucketInfo = seedBucketInfoBuilder.BuildFrom(seedBucketType) !;

            if (seedBucketInfo.HasAnyErrors)
            {
                return(SeedingReport.CreateForSeedBucketHasErrors(seedBucketInfo));
            }

            var seedingPlan = SeedingPlan.CreateFor(seedBucketInfo);

            return(await SeedSeedingPlan());

            async Task <SeedingReport> SeedSeedingPlan()
            {
                SeedInfo?       currentSeedInfo;
                int             seedingStepNumber;
                var             serviceCollection = new ServiceCollection();
                ServiceProvider?serviceProvider;
                var             singleSeedSeedingResults = new List <SingleSeedSeedingReport>();

                try
                {
                    // TODO: Add creation of SeedingStartup and registration of services.

                    // TODO: Add finer granulation of errors and seeding result - CreatingSeedingStartupFailed.

                    serviceProvider = serviceCollection.BuildServiceProvider();
                }
                catch
                {
                    // TODO: Output sink.
                    return(SeedingReport.CreateForBuildingServiceProviderFailed(seedBucketInfo, seedingPlan));
                }

                for (int i = 0; i < seedingPlan.SeedingSteps.Count; i++)
                {
                    currentSeedInfo   = seedingPlan.SeedingSteps[i];
                    seedingStepNumber = i + 1;
                    try
                    {
                        var hasSeeded = await SeedSingleSeed(seedingStepNumber, serviceProvider, currentSeedInfo);

                        singleSeedSeedingResults.Add(new SingleSeedSeedingReport(hasSeeded ? SingleSeedSeedingStatus.Seeded : SingleSeedSeedingStatus.Skipped, currentSeedInfo));
                    }
                    catch
                    {
                        // TODO: Output sink.
                        // TODO: Add finer granulation of errors and seeding result - CreatingSeedFailed.
                        // TODO: Add seed contract violation.
                        singleSeedSeedingResults.Add(new SingleSeedSeedingReport(SingleSeedSeedingStatus.Failed, currentSeedInfo));
                        return(SeedingReport.CreateForSeedingSingleSeedFailed(seedBucketInfo, seedingPlan, singleSeedSeedingResults));
                    }
                }

                return(SeedingReport.CreateForSucceeded(seedBucketInfo, seedingPlan, singleSeedSeedingResults));

                // Returns true if Seed() is called or false if the seed HasAlreadyYielded().
                async Task <bool> SeedSingleSeed(int seedingStep, ServiceProvider serviceProvider, SeedInfo seedInfo)
                {
                    System.Diagnostics.Debug.Assert(seedingStep > 0);

                    // TODO: Output sink.

                    // TODO: Check if seedInfo.Type exists. Where to check that? Seeding should work only if Type exists. Where to add those checks?
                    var seed = (ISeed)ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, seedInfo.Type);

                    // TODO: Create YieldOf objects and assign them to YieldOf properties.

                    if (await seed.HasAlreadyYielded())
                    {
                        // TODO: Output sink.
                        return(false);
                    }

                    // TODO: Output sink.

                    await seed.Seed();

                    // TODO: Output sink.

                    return(true);
                }
            }
        }