private SingleRepositoryResult GenerateSingleRepo(IEnumerable <RepositoryMemberInfo> atoms) { var namespaceGenerator = new NamespaceGenerator(); var result = new SingleRepositoryResult { Header = namespaceGenerator.Header(), Namespaces = namespaceGenerator.GetNamespaces(_config).Concat(new[] { "PF.Common.SqlClient", _config.Entities.Namespace, "PF.Contrib.Dapper.Extensions" }).ToList(), Classes = GenerateSprocs(atoms).ToList(), RepositoryNamespace = _config.Repository.Namespace }; return(result); }
public RepositoryResult Generate(KeyValuePair<string, List<RepositoryMemberInfo>> arg) { string ExtraNamespaces = new NamespaceGenerator().ByConfig(Config); string groupName = arg.Key; var classesToGenerate = arg.Value.DistinctBy(i => i.Info.BaseAtom.Name); var accessors = string.Join(Environment.NewLine + Environment.NewLine, classesToGenerate.Select(CreateAccessor)) .Trim(); string optionalStrongTypes = GenerateStrongTypeInitializers(arg.Key, arg.Value.First()).IndentAllLines(byTabs: 1, ignoreFirst: true); var template = $@" {ExtraNamespaces} using PF.Contrib.Dapper.Extensions; using Dapper; using System.Configuration; using {Config.Entities.Namespace}; namespace {Config.Repository.Namespace} {{ public partial class {groupName} : Database<{groupName}> {{ {accessors.IndentAllLines(byTabs: 2, ignoreFirst: true)} public static {groupName} Create(string connectionString){{ return {groupName}.Init(ConfigurationManager.ConnectionStrings[connectionString].ConnectionString); }} }} {optionalStrongTypes} }}".Trim(); return new RepositoryResult { Name = arg.Key + ".cs", CodeString = template }; }
public RepositoryResult Generate(KeyValuePair <string, List <RepositoryMemberInfo> > arg) { string ExtraNamespaces = new NamespaceGenerator().ByConfig(Config); string groupName = arg.Key; var classesToGenerate = arg.Value.DistinctBy(i => i.Info.BaseAtom.Name); var accessors = string.Join(Environment.NewLine + Environment.NewLine, classesToGenerate.Select(CreateAccessor)) .Trim(); string optionalStrongTypes = GenerateStrongTypeInitializers(arg.Key, arg.Value.First()).IndentAllLines(byTabs: 1, ignoreFirst: true); var template = $@" {ExtraNamespaces} using PF.Contrib.Dapper.Extensions; using Dapper; using System.Configuration; using {Config.Entities.Namespace}; namespace {Config.Repository.Namespace} {{ public partial class {groupName} : Database<{groupName}> {{ {accessors.IndentAllLines(byTabs: 2, ignoreFirst: true)} public static {groupName} Create(string connectionString){{ return {groupName}.Init(ConfigurationManager.ConnectionStrings[connectionString].ConnectionString); }} }} {optionalStrongTypes} }}".Trim(); return(new RepositoryResult { Name = arg.Key + ".cs", CodeString = template }); }
internal RepositoryResult Generate(List <RepositoryMemberInfo> atoms) { SingleRepositoryResult singleRepositoryResult = GenerateSingleRepo(atoms); var namespaces = new NamespaceGenerator(); string usings = string.Join(Environment.NewLine, namespaces.Usings(singleRepositoryResult.Namespaces)); string repos = string.Join(Environment.NewLine + Environment.NewLine, singleRepositoryResult.Classes .Select(c => c.ClassCode.IndentAllLines(byTabs: 1))); string singleRepoTemplate = $@" {singleRepositoryResult.Header} {usings} namespace {singleRepositoryResult.RepositoryNamespace} {{ {repos} public abstract partial class BaseRepository<TRepo> : SqlClientRepositoryBase {{ protected BaseRepository(string connectionString) : base(connectionString) {{ }} protected Database GetDb() {{ return Database.Init(OpenConnection(), TimeSpan.FromSeconds(30)); }} public static TRepo FromConfig(string connectionString) {{ return (TRepo) Activator.CreateInstance(typeof (TRepo), GetConnectionStringFromConfig(connectionString)); }} }} public partial interface IReadableRepository<TRecord, TKey> {{ Task<TRecord> GetOne(TKey key); Task<IEnumerable<TRecord>> GetAll(); }} public partial interface IWritableRepository<TRecord, TKey> {{ Task<TKey> Insert(TRecord record); Task Update(TRecord record); }} public partial interface IRepository<TRecord, TKey> : IReadableRepository<TRecord, TKey>, IWritableRepository<TRecord, TKey> {{ }} }} ".Trim(); return(new RepositoryResult { Name = "Repositories.cs", CodeString = singleRepoTemplate }); }
internal RepositoryResult Generate(List<RepositoryMemberInfo> atoms) { SingleRepositoryResult singleRepositoryResult = GenerateSingleRepo(atoms); var namespaces = new NamespaceGenerator(); string usings = string.Join(Environment.NewLine, namespaces.Usings(singleRepositoryResult.Namespaces)); string repos = string.Join(Environment.NewLine + Environment.NewLine, singleRepositoryResult.Classes .Select(c => c.ClassCode.IndentAllLines(byTabs: 1))); string singleRepoTemplate = $@" {singleRepositoryResult.Header} {usings} namespace {singleRepositoryResult.RepositoryNamespace} {{ {repos} public abstract partial class BaseRepository<TRepo> : SqlClientRepositoryBase {{ protected BaseRepository(string connectionString) : base(connectionString) {{ }} protected Database GetDb() {{ return Database.Init(OpenConnection(), TimeSpan.FromSeconds(30)); }} public static TRepo FromConfig(string connectionString) {{ return (TRepo) Activator.CreateInstance(typeof (TRepo), GetConnectionStringFromConfig(connectionString)); }} }} public partial interface IReadableRepository<TRecord, TKey> {{ Task<TRecord> GetOne(TKey key); Task<IEnumerable<TRecord>> GetAll(); }} public partial interface IWritableRepository<TRecord, TKey> {{ Task<TKey> Insert(TRecord record); Task Update(TRecord record); }} public partial interface IRepository<TRecord, TKey> : IReadableRepository<TRecord, TKey>, IWritableRepository<TRecord, TKey> {{ }} }} ".Trim(); return new RepositoryResult { Name = "Repositories.cs", CodeString = singleRepoTemplate }; }
private SingleRepositoryResult GenerateSingleRepo(IEnumerable<RepositoryMemberInfo> atoms) { var namespaceGenerator = new NamespaceGenerator(); var result = new SingleRepositoryResult { Header = namespaceGenerator.Header(), Namespaces = namespaceGenerator.GetNamespaces(_config).Concat(new[] { "PF.Common.SqlClient", _config.Entities.Namespace, "PF.Contrib.Dapper.Extensions" }).ToList(), Classes = GenerateSprocs(atoms).ToList(), RepositoryNamespace = _config.Repository.Namespace }; return result; }