public void ImportBooks(EntityApp app, int count = 250) { _app = app; _session = _app.OpenSystemSession(); //Preload caches _bookCache = _session.GetEntities<IBook>(take: 1000).ToDictionary(b => b.Title, StringComparer.InvariantCultureIgnoreCase); _publishersCache = _session.GetEntities<IPublisher>(take: 200).ToDictionary(p => p.Name, StringComparer.InvariantCultureIgnoreCase); _authorsCache = _session.GetEntities<IAuthor>(take: 1000).ToDictionary(a => a.FirstName + a.LastName, StringComparer.InvariantCultureIgnoreCase); _client = new GoogleBooksApiClient(); var batchSize = count / 5; ImportBooksInCategory(BookCategory.Programming, "c#", batchSize); ImportBooksInCategory(BookCategory.Programming, "Linux", batchSize); ImportBooksInCategory(BookCategory.Fiction, "Comics", batchSize); ImportBooksInCategory(BookCategory.Fiction, "Science fiction", batchSize); ImportBooksInCategory(BookCategory.Kids, "Fairy tales", batchSize); }
public void ImportBooks(EntityApp app, int count = 250) { _app = app; _session = _app.OpenSystemSession(); //Preload caches _bookCache = _session.GetEntities <IBook>(take: 1000).ToDictionary(b => b.Title, StringComparer.OrdinalIgnoreCase); _publishersCache = _session.GetEntities <IPublisher>(take: 200).ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase); _authorsCache = _session.GetEntities <IAuthor>(take: 1000).ToDictionary(a => a.FirstName + a.LastName, StringComparer.OrdinalIgnoreCase); _client = new GoogleBooksApiClient(_session.Context); var batchSize = count / 5; ImportBooksInCategory(BookCategory.Programming, "c#", batchSize); ImportBooksInCategory(BookCategory.Programming, "Linux", batchSize); ImportBooksInCategory(BookCategory.Fiction, "Comics", batchSize); ImportBooksInCategory(BookCategory.Fiction, "Science fiction", batchSize); ImportBooksInCategory(BookCategory.Kids, "Fairy tales", batchSize); }//method
// Use it to import from resource - look at ImportDefaultSecretQuestions public static int ImportSecretQuestions(IEntitySession session, Stream stream) { var reader = new StreamReader(stream); var text = reader.ReadToEnd(); // File.ReadAllLines(filePath); var lines = text.Split(new [] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries); var oldList = session.GetEntities<ISecretQuestion>(); var count = 0; foreach(var line in lines) { if(string.IsNullOrWhiteSpace(line) || line.StartsWith("//")) continue; //check if there's existing var trimLine = line.Trim(); var oldLine = oldList.FirstOrDefault(l => l.Question == trimLine); if(oldLine != null) continue; var q = session.NewEntity<ISecretQuestion>(); q.Question = trimLine; q.Number = count++; q.Flags = SecretQuestionFlags.None; } return count; }
private void SaveModulesInfo(IEntitySession session, DbVersionInfo dbVersion) { var moduleRecs = session.GetEntities<IDbModuleInfo>(take: 1000); foreach (var mi in dbVersion.Modules) { var mrec = moduleRecs.FirstOrDefault(r => r.ModuleName == mi.ModuleName && r.Schema == mi.Schema); if (mrec == null) { mrec = session.NewEntity<IDbModuleInfo>(); mrec.ModuleName = mi.ModuleName; mrec.Schema = mi.Schema; } mrec.Version = mi.Version.ToString(); } }