public SeedingEventArgs(int seedingStep, SeedInfo seed) { Assert(seedingStep >= 0); Assert((seedingStep > 0 && seed != null) || (seedingStep == 0 && seed == null)); SeedingStep = seedingStep; Seed = seed; }
/// <summary> /// Gets <see cref="SeedInfo"/> that describes the <paramref name="seedType"/>. /// If such seed info does not exist it will be created and added to the tree. /// </summary> internal SeedInfo GetOrCreateSeedInfoFor(Type seedType) { Assert(seedType != null); Assert(seedType.IsSeedType()); if (!allSeedInfos.ContainsKey(seedType)) { allSeedInfos.Add(seedType, SeedInfo.CreateFor(seedType, this)); } return(allSeedInfos[seedType]); }
private async Task Seed(SeedingPlan seedingPlan) { SeedInfo currentSeedInfo = null; int seedingStep = 0; try { var serviceCollection = new ServiceCollection(); var seedingSetup = seedingPlan.SeedingSetup; if (seedingSetup == null && seedingPlan.SeedingSetupType != null) { seedingSetup = (ISeedingSetup)Activator.CreateInstance(seedingPlan.SeedingSetupType); } if (seedingSetup != null) { RaiseMessageEvent($"Configuring services by using the seeding setup '{seedingPlan.SeedingSetupType}'."); seedingSetup.ConfigureServices(serviceCollection, seedingSetup.BuildConfiguration(new string[0])); RaiseMessageEvent("Services configured."); } else { RaiseMessageEvent($"No seeding setup found."); } var serviceProvider = serviceCollection.BuildServiceProvider(); for (int i = 0; i < seedingPlan.Seeds.Count; i++) { currentSeedInfo = seedingPlan.Seeds[i]; seedingStep = i + 1; await SeedSingleSeed(seedingStep, serviceProvider, currentSeedInfo); } } catch (SeedContractViolationException exception) { SeedContractViolation?.Invoke(this, new SeedContractViolationEventArgs(seedingStep, currentSeedInfo, exception.Message)); SeedingAborted?.Invoke(this, new SeedingEventArgs(seedingStep, currentSeedInfo)); } catch (Exception exception) { RaiseMessageEvent($"Exception: {exception}"); SeedingAborted?.Invoke(this, new SeedingEventArgs(seedingStep, currentSeedInfo)); } }
internal SeedingMessageEventArgs(string message, int seedingStep, SeedInfo seed) : base(seedingStep, seed) { Assert(message != null); Message = message; }
public SingleSeedSeedingReport(SingleSeedSeedingStatus status, SeedInfo seedInfo) { Status = status; SeedInfo = seedInfo; }
private async Task SeedSingleSeed(int seedingStep, ServiceProvider serviceProvider, SeedInfo seedInfo) { Assert(seedingStep > 0); Assert(serviceProvider != null); Assert(seedInfo != null); Preparing?.Invoke(this, new SeedingEventArgs(seedingStep, seedInfo)); var seed = (ISeed)ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, seedInfo.SeedType); foreach (var seedOutputProperty in seedInfo.SeedOutputProperties) { // We always want to create a new instance of a seed output class. // Why? Because in a general case seed output classes will have dependency constructors // that can potentially have transient dependencies. var propertyValue = ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, seedOutputProperty.PropertyType); seedOutputProperty.SetValue(seed, propertyValue); } if (await seed.OutputAlreadyExists()) { Skipping?.Invoke(this, new SeedingEventArgs(seedingStep, seedInfo)); return; } Seeding?.Invoke(this, new SeedingEventArgs(seedingStep, seedInfo)); await seed.Seed(); SeedingEnded?.Invoke(this, new SeedingEventArgs(seedingStep, seedInfo)); }