public TRepository GetRepository <TRepository>() where TRepository : IDataRepository { foreach (Assembly assembly in Assemblies.Where(a => !a.FullName.Contains("Reflection"))) { foreach (Type type in assembly.GetTypes()) { if (typeof(TRepository).IsAssignableFrom(type) && type.GetTypeInfo().IsClass) { TRepository repository = (TRepository)Activator.CreateInstance(type); repository.SetStorageContext(StorageContext); return(repository); } } } throw new ArgumentException("Implementation of " + typeof(TRepository) + " not found"); }
public static TRepository CreateRepository <TRepository>() where TRepository : IRepository { TRepository result = theFactory.CreateRepository <TRepository>(); return(result); }
static async Task MainAsync(string[] args) { TChrono chrono = new TChrono(); chrono.Start(); SplitArgs Args = new SplitArgs(args); string SourceRepository = Args.GetValue <string>("source", ""); string RepositoryName = Args.GetValue <string>("name", SourceRepository.AfterLast(Path.DirectorySeparatorChar)); string OutputFilename = Args.GetValue <string>("output", "bdindex"); string OutputFormat = Args.GetValue <string>("outputformat", "txt").ToLower(); List <string> AllowedFormats = new List <string>() { "txt", "json", "xml" }; if (!AllowedFormats.Contains(OutputFormat)) { OutputFormat = "txt"; } Console.WriteLine(TextBox.BuildDynamic($"Index folder {SourceRepository}...")); Console.WriteLine($" Name = {RepositoryName}"); Console.WriteLine($" Output to {OutputFilename}.{OutputFormat}"); Console.WriteLine(); if (!Directory.Exists(SourceRepository)) { Usage("Missing source directory"); } TRepository CurrentRepository = new TRepository(SourceRepository, RepositoryName); await CurrentRepository.BuildIndex(); Console.WriteLine($"Total folders : {CurrentRepository.Books.EnumerateCollections().Count()}"); Console.WriteLine($"Found (...) folders : {CurrentRepository.Books.EnumerateCollections().Count(x => x.HasArticle)}"); Console.WriteLine("------------------ Display name -----------------"); foreach (IEnumerable <TBookCollection> BookCollectionItems in CurrentRepository.Books.EnumerateCollections().OrderBy(x => x.DisplayName).GroupBy(x => x.DisplayName.First())) { Console.Write($"{BookCollectionItems.First().DisplayName.First()} : "); Console.WriteLine(new string('#', BookCollectionItems.Count())); } Console.WriteLine("------------------ Name -----------------"); foreach (IEnumerable <TBookCollection> BookCollectionItems in CurrentRepository.Books.EnumerateCollections().OrderBy(x => x.Name).GroupBy(x => x.Name.First())) { Console.Write($"{BookCollectionItems.First().Name.First()} : "); Console.WriteLine(new string('#', BookCollectionItems.Count())); } OutputFilename += $".{OutputFormat}"; if (File.Exists(OutputFilename)) { File.Delete(OutputFilename); } switch (OutputFormat) { case "txt": foreach (TBookCollection BookCollectionItem in CurrentRepository.Books.EnumerateCollections()) { File.AppendAllText(OutputFilename, BookCollectionItem.ToString()); File.AppendAllText(OutputFilename, Environment.NewLine); } break; case "json": JsonValue.Save(OutputFilename, CurrentRepository.ToJson()); break; case "xml": File.AppendAllText(OutputFilename, CurrentRepository.ToXml().ToString()); break; } //TBookCollection MissingInBrilly = new TBookCollection(BdBrilly.Books.GetMissingFrom(BdLuc.Books)); //TBookCollection MissingInLuc = new TBookCollection(BdLuc.Books.GetMissingFrom(BdBrilly.Books)); //Console.WriteLine("=== Missing in Luc ================================================="); //string OutputMissingLuc = @"i:\# BDS\MissingInLuc.txt"; //File.Delete(OutputMissingLuc); //File.AppendAllText(OutputMissingLuc, $"{MissingInLuc.Count()} books{Environment.NewLine}"); //foreach ( TBookCollection BookCollectionItem in MissingInLuc.EnumerateCollections() ) { // File.AppendAllText(OutputMissingLuc, BookCollectionItem.ToString()); // File.AppendAllText(OutputMissingLuc, Environment.NewLine); //} //Console.WriteLine("=== Missing in Brilly =============================================="); //foreach ( TBookCollection BookCollectionItem in MissingInBrilly.EnumerateCollections() ) { // Console.WriteLine(BookCollectionItem.ToString()); //} Console.WriteLine($"Indexing process completed in {chrono.ElapsedTime.TotalSeconds} secs"); //ConsoleExtension.Pause(); //Environment.Exit(0); }
/// <summary> /// Prepares pagination dto according to pagination parameters. /// </summary> /// <typeparam name="TRepository"></typeparam> /// <typeparam name="TEntity"></typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="repository"></param> /// <param name="pageIndex"></param> /// <param name="requestedItemCount"></param> /// <param name="orderByProperty"></param> /// <param name="orderByAscending"></param> /// <param name="condition"></param> /// <param name="includes"></param> /// <returns></returns> public static async Task <(IEnumerable <TEntity> entities, int pageCount, int totalDataCount)> PreparePaginationDTO <TRepository, TEntity, TKey>(this TRepository repository, int pageIndex, int requestedItemCount, string orderByProperty = null, bool orderByAscending = false, Expression <Func <TEntity, bool> > condition = null, Func <IIncludable <TEntity>, IIncludable> includes = null)
this Dictionary <Type, object> repositories, TRepository setter)