public static IRepository <Company, ICompanyQueryBuilder> CreateRepo(RepositoryConfiguration config = null) { var provider = new StandardRepositoryProvider(); return(provider.CreateRepository <Company, ICompanyQueryBuilder>( config ?? new RepositoryConfiguration { CollectionName = "companies", DatabaseName = "testdata", ConnectionString = "mongodb://localhost", SafeModeSetting = SafeMode.True }, typeof(ICompanyQueryBuilder), typeof(ByConvention), typeof(ContainsConvention))); }
public async Task Run() { Console.WriteLine("EXPORT APPARATUS INTO TEI FILES\n"); Console.ResetColor(); Console.WriteLine( $"Database: {_database}\n" + $"Output dir: {_outputDir}\n" + $"Comments: {_comments}\n" + $"Dry: {_dry}\n" + $"Group IDs: {string.Join(", ", _groupIds)}"); ILoggerFactory loggerFactory = new LoggerFactory(); loggerFactory.AddSerilog(Log.Logger); Log.Logger.Information("EXPORT APPARATUS INTO TEI FILES"); ICadmusRepository repository = _repositoryProvider.CreateRepository(_database); ApparatusExporter exporter = new ApparatusExporter(repository) { Logger = loggerFactory.CreateLogger("export"), IncludeComments = _comments, IsDryModeEnabled = _dry }; foreach (string id in _groupIds) { exporter.SelectedGroupIds.Add(id); } if (!Directory.Exists(_outputDir)) { Directory.CreateDirectory(_outputDir); } using (var bar = new ProgressBar(100, "Exporting...", new ProgressBarOptions { ProgressCharacter = '.', ProgressBarOnBottom = true, DisplayTimeInRealTime = false })) { await exporter.ExportAsync(_outputDir, new Progress <ProgressReport>( r => bar.Tick(r.Percent, r.Message))); } }
public void ItDoesNotThrowWhenConventionsDontMatchAnything() { Assert.DoesNotThrow(() => { var provider = new StandardRepositoryProvider(); var repo = provider.CreateRepository<Company, IBadCompanyQueryBuilder>( new RepositoryConfiguration { CollectionName = "companies", DatabaseName = "testdata", ConnectionString = "mongodb://localhost", SafeModeSetting = SafeMode.True }, typeof(ByConvention)); }); }
public void ItThrowsWhenNoConventionsMatchYourQueryBuilderMethod() { Assert.Throws<NoMatchingMethodConventionException>(() => { var provider = new StandardRepositoryProvider(); var repo = provider.CreateRepository<Company, IBadCompanyQueryBuilder>( new RepositoryConfiguration { CollectionName = "companies", DatabaseName = "testdata", ConnectionString = "mongodb://localhost", SafeModeSetting = SafeMode.True }, typeof(IBadCompanyQueryBuilder)); }); }
public Task Run() { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("IMPORT JSON TEXT AND APPARATUS\n"); Console.ResetColor(); Console.WriteLine( $"Text dir: {_txtFileDir}\n" + $"Text mask: {_txtFileMask}\n" + $"Apparatus dir: {_appFileDir}\n" + $"Profile file: {_profilePath}\n" + $"Database: {_database}\n" + $"Dry run: {_dry}\n"); ILoggerFactory loggerFactory = new LoggerFactory(); loggerFactory.AddSerilog(Log.Logger); Log.Logger.Information("IMPORT JSON TEXT AND APPARATUS"); if (!_dry) { // create database if not exists string connection = string.Format(CultureInfo.InvariantCulture, _config.GetConnectionString("Default"), _database); IDatabaseManager manager = new MongoDatabaseManager(); string profileContent = LoadProfile(_profilePath); IDataProfileSerializer serializer = new JsonDataProfileSerializer(); DataProfile profile = serializer.Read(profileContent); if (!manager.DatabaseExists(connection)) { Console.WriteLine("Creating database..."); Log.Information($"Creating database {_database}..."); manager.CreateDatabase(connection, profile); Console.WriteLine("Database created."); Log.Information("Database created."); } } else { if (!File.Exists(_profilePath)) { string error = "Profile path not found: " + _profilePath; Console.WriteLine(error); Log.Error(error); return(Task.CompletedTask); } } ICadmusRepository repository = _repositoryProvider.CreateRepository(_database); JsonImporter importer = new JsonImporter(repository) { Logger = loggerFactory.CreateLogger("json-importer"), IsDry = _dry }; int inputFileCount = 0; // 1) import text string[] files = FileEnumerator.Enumerate( _txtFileDir, _txtFileMask, _regexMask).ToArray(); HashSet <string> fileNames = new HashSet <string>(); Console.WriteLine($"Importing text from {files.Length} file(s)..."); foreach (string txtFilePath in files) { fileNames.Add( StripFileNameNr( Path.GetFileNameWithoutExtension(txtFilePath))); Console.WriteLine(txtFilePath); inputFileCount++; using (Stream stream = new FileStream(txtFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { importer.ImportText(stream); } } // 2) import apparatus Console.WriteLine("Importing apparatus..."); foreach (string fileName in fileNames) { Console.WriteLine(fileName); foreach (string appFilePath in Directory.EnumerateFiles( _appFileDir, fileName + "-app_*.json")) { Console.WriteLine(" " + appFilePath); using (Stream stream = new FileStream(appFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { importer.ImportApparatus(stream); } } } return(Task.CompletedTask); }
public Task Run() { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("REPLACE APPARATUS THESAURI\n"); Console.ResetColor(); Console.WriteLine( $"Input file: {_inputPath}" + $"Database: {_dbName}\n"); ILoggerFactory loggerFactory = new LoggerFactory(); loggerFactory.AddSerilog(Log.Logger); Log.Logger.Information("REPLACE APPARATUS THESAURI"); using Stream input = new FileStream(_inputPath, FileMode.Open, FileAccess.Read, FileShare.Read); JsonDocument doc = JsonDocument.Parse(input, new JsonDocumentOptions { AllowTrailingCommas = true }); ICadmusRepository repository = _repositoryProvider.CreateRepository(_dbName); string msg; // 1) remove all the apparatus- thesauri int delCount = 0; foreach (string id in repository.GetThesaurusIds(new ThesaurusFilter { PageSize = 0, Id = "apparatus-" })) { if (!id.StartsWith("apparatus-")) { continue; } delCount++; msg = "Deleting " + id; Console.WriteLine(msg); Log.Logger.Information(msg); if (!_isDry) { repository.DeleteThesaurus(id); } } // 2) insert new apparatus- thesauri // this is the thesauri JSON file generated by import thesauri, // having a root array with each thesaurus as an item int addCount = 0; foreach (JsonElement el in doc.RootElement.EnumerateArray()) { addCount++; Thesaurus thesaurus = ReadThesaurus(el); msg = "Adding thesaurus " + thesaurus.Id; Console.WriteLine(msg); Log.Logger.Information(msg); if (!_isDry) { repository.AddThesaurus(thesaurus); } } Console.WriteLine($"Completed: deleted {delCount}, added {addCount}"); return(Task.CompletedTask); }