public void Seed(IBiblioRepository repository, int count) { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } foreach (WorkType type in new[] { new WorkType { Id = "book", Name = "Book" }, new WorkType { Id = "journal", Name = "Journal" }, new WorkType { Id = "procs", Name = "Proceedings" }, new WorkType { Id = "article", Name = "Article" } }) { repository.AddWorkType(type); } }
public void Seed(IBiblioRepository repository, int count) { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } Faker faker = new Faker(); HashSet <Tuple <string, string> > names = new HashSet <Tuple <string, string> >(); int repeat = 0; for (int n = 1; n <= count; n++) { string first = faker.Name.FirstName(); string last = faker.Name.LastName(); var t = Tuple.Create(first, last); if (names.Contains(t)) { if (++repeat > 100) { break; } continue; } Author author = new Faker <Author>() .RuleFor(a => a.Id, Guid.NewGuid()) .RuleFor(a => a.First, first) .RuleFor(a => a.Last, last) .RuleFor(a => a.Suffix, (string)null) .Generate(); repository.AddAuthor(author); repeat = 0; } }
public void Seed(IBiblioRepository repository, int count) { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } DataPage <Author> authorsPage = repository.GetAuthors(new AuthorFilter { PageNumber = 1, PageSize = 20 }); DataPage <Keyword> keywordsPage = repository.GetKeywords(new KeywordFilter { PageNumber = 1, PageSize = 20 }); Faker faker = new Faker(); for (int n = 1; n <= count; n++) { Container container = new Faker <Container>() .RuleFor(c => c.Id, Guid.NewGuid()) .RuleFor(c => c.Type, f => f.PickRandom(WorkTypeSeeder.TypeIds)) .RuleFor(c => c.Title, f => f.Random.Words(3)) .RuleFor(c => c.Language, "eng") .RuleFor(c => c.Edition, f => f.Random.Short(0, 3)) .RuleFor(c => c.Publisher, f => f.Company.CompanyName()) .RuleFor(c => c.YearPub, f => (short)f.Random.Number(1900, DateTime.Now.Year)) .RuleFor(c => c.PlacePub, f => f.Address.City()) .RuleFor(c => c.Location, f => f.Random.Bool()? f.Internet.Url() : null) .RuleFor(c => c.AccessDate, f => f.Random.Bool(0.2f) ? (DateTime?)f.Date.Recent() : null) .RuleFor(c => c.Number, f => $"{f.Random.Number(0, 100)}") .RuleFor(c => c.Note, f => f.Random.Bool(0.2f) ? f.Lorem.Sentence() : null) .Generate(); container.Key = WorkKeyBuilder.Build(container); // authors container.Authors.Add(new WorkAuthor { Id = faker.PickRandom(authorsPage.Items).Id, Role = "editor" }); // keywords for (int k = 1; k <= faker.Random.Number(1, 2); k++) { container.Keywords.Add(faker.PickRandom(keywordsPage.Items)); } repository.AddContainer(container); } }
public void Seed(IBiblioRepository repository, int count) { if (repository == null) { throw new ArgumentNullException(nameof(repository)); } foreach (string word in new Faker().Random.WordsArray(count)) { int i = word.IndexOf(' '); string value = i > -1? word.Substring(0, i) : word; repository.AddKeyword(new Keyword { Language = "eng", Value = value }); } }
private static Task SeedBiblioAsync(IServiceProvider serviceProvider) { return(Policy.Handle <DbException>() .WaitAndRetry(new[] { TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(60) }, (exception, timeSpan, _) => { ILogger logger = serviceProvider .GetService <ILoggerFactory>() .CreateLogger(typeof(BiblioHostSeedExtensions)); string message = "Unable to connect to DB" + $" (sleep {timeSpan}): {exception.Message}"; Console.WriteLine(message); logger.LogError(exception, message); }).Execute(() => { IConfiguration config = serviceProvider.GetService <IConfiguration>(); ILogger logger = serviceProvider .GetService <ILoggerFactory>() .CreateLogger(typeof(BiblioHostSeedExtensions)); Console.WriteLine("Seeding database..."); IBiblioRepository repository = serviceProvider.GetService <IBiblioRepository>(); BiblioSeeder seeder = new BiblioSeeder(repository) { Logger = logger }; seeder.Seed(config.GetValue <int>("Seed:EntityCount")); Console.WriteLine("Seeding completed"); return Task.CompletedTask; })); }
/// <summary> /// Initializes a new instance of the <see cref="ContainerController"/> /// class. /// </summary> /// <param name="repository">The repository.</param> public ContainerController(IBiblioRepository repository) { _repository = repository; }
public KeywordController(IBiblioRepository repository) { _repository = repository; }
/// <summary> /// Initializes a new instance of the <see cref="WorkController"/> /// class. /// </summary> /// <param name="repository">The repository.</param> public WorkController(IBiblioRepository repository) { _repository = repository; }
/// <summary> /// Initializes a new instance of the <see cref="AuthorController"/> /// class. /// </summary> /// <param name="repository">The repository.</param> public AuthorController(IBiblioRepository repository) { _repository = repository; }
/// <summary> /// Initializes a new instance of the <see cref="BiblioSeeder"/> class. /// </summary> /// <param name="repository">The repository.</param> /// <exception cref="ArgumentNullException">repository</exception> public BiblioSeeder(IBiblioRepository repository) { _repository = repository ?? throw new ArgumentNullException(nameof(repository)); }