private PostgreSQLTransactionalExecutor GetPostgreSQLTransactionalExecutor() { var npgsqlConnection = new NpgsqlConnection(PostgreSQLConnectionFactory.GetConnectionString(GetConnectionSettings(GetTestDBName()))); var transactionalExecutor = new PostgreSQLTransactionalExecutor(npgsqlConnection); return(transactionalExecutor); }
public (PostgreSQLTypeLookup, EntityUtils, ConnectionSettings, PostgreSQLExecutor) Generate() { var connectionSettings = new ConnectionSettings(); connectionSettings.DbName = ConfigurationManager.AppSettings["DbName"]; connectionSettings.DbHost = ConfigurationManager.AppSettings["DbHost"]; connectionSettings.DbUser = ConfigurationManager.AppSettings["DbUser"]; connectionSettings.DbPassword = ConfigurationManager.AppSettings["DbPass"]; connectionSettings.DbPort = ConfigurationManager.AppSettings["DbPort"]; var typeLookup = new PostgreSQLTypeLookup(); var entityUtils = new EntityUtils(typeLookup, Assembly.GetExecutingAssembly()); var masterConnectionString = PostgreSQLConnectionFactory.GetConnectionString(connectionSettings.DbHost, connectionSettings.DbNameMaster, connectionSettings.DbUser, connectionSettings.DbPassword, connectionSettings.DbPort); var masterConnectionFactory = new PostgreSQLConnectionFactory(masterConnectionString); var sqlExecutorMaster = new PostgreSQLExecutor(masterConnectionFactory, entityUtils); var connectionString = PostgreSQLConnectionFactory.GetConnectionString(connectionSettings); var connectionFactory = new PostgreSQLConnectionFactory(connectionString); var sqlExecutor = new PostgreSQLExecutor(connectionFactory, entityUtils); var dbGenerator = new PostgreSQLDbGenerator(typeLookup, entityUtils, sqlExecutorMaster, sqlExecutor); if (!dbGenerator.IsDbExistsDb(connectionSettings.DbName)) { dbGenerator.CreateDb(connectionSettings.DbName); dbGenerator.Generate().Wait(); } return(typeLookup, entityUtils, connectionSettings, sqlExecutor); }
public void PostgreSQLDbGenerator_Generate() { var connectionSettings = GetConnectionSettings(); connectionSettings.DbName += "_" + Guid.NewGuid().ToString("N"); var typeLookup = new PostgreSQLTypeLookup(); var entityUtils = new EntityUtils(typeLookup, typeof(Project).Assembly); var masterConnectionString = PostgreSQLConnectionFactory.GetConnectionString(connectionSettings.DbHost, connectionSettings.DbNameMaster, connectionSettings.DbUser, connectionSettings.DbPassword, connectionSettings.DbPort); var masterConnectionFactory = new PostgreSQLConnectionFactory(masterConnectionString); var sqlExecutorMaster = new PostgreSQLExecutor(masterConnectionFactory, entityUtils); var connectionString = PostgreSQLConnectionFactory.GetConnectionString(connectionSettings); var connectionFactory = new PostgreSQLConnectionFactory(connectionString); var sqlExecutor = new PostgreSQLExecutor(connectionFactory, entityUtils); var dbGenerator = new PostgreSQLDbGenerator(typeLookup, entityUtils, sqlExecutorMaster, sqlExecutor); dbGenerator.CreateDb(connectionSettings.DbName); dbGenerator.Generate().Wait(); Assert.True(dbGenerator.IsDbExistsDb(connectionSettings.DbName)); sqlExecutorMaster.ExecuteSql($@"SELECT Pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '{connectionSettings.DbName}' AND pid <> Pg_backend_pid(); DROP DATABASE {connectionSettings.DbName};").Wait(); }
private async Task <PostgreSQLTransactionalExecutor> GetPostgreSQLTransactionalExecutor() { var connectionSettings = await GetConnectionSettings(GetTestDBName()); var npgsqlConnection = new NpgsqlConnection(PostgreSQLConnectionFactory.GetConnectionString(connectionSettings)); var transactionalExecutor = new PostgreSQLTransactionalExecutor(npgsqlConnection); return(await Task.FromResult(transactionalExecutor)); }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register(Component.For <CryptoHelper>()); var connectionSettings = new ConnectionSettings(); connectionSettings.DbName = ConfigurationManager.AppSettings[ConstantHelper.KEY_DB_NAME]; connectionSettings.DbHost = ConfigurationManager.AppSettings[ConstantHelper.KEY_DB_HOST]; connectionSettings.DbUser = ConfigurationManager.AppSettings[ConstantHelper.KEY_DB_USER]; connectionSettings.DbPassword = ConfigurationManager.AppSettings[ConstantHelper.KEY_DB_PASS]; connectionSettings.DbPort = ConfigurationManager.AppSettings[ConstantHelper.KEY_DB_PORT]; container.Register(Component.For <ConnectionSettings>().Instance(connectionSettings)); var adminSettings = new AdminSettings(); adminSettings.AdminEmail = ConfigurationManager.AppSettings[ConstantHelper.KEY_SUPER_ADMIN_EMAIL]; adminSettings.AdminFirstName = ConfigurationManager.AppSettings[ConstantHelper.KEY_SUPER_ADMIN_FIRST_NAME]; adminSettings.AdminLastName = ConfigurationManager.AppSettings[ConstantHelper.KEY_SUPER_ADMIN_LAST_NAME]; adminSettings.AdminPassword = ConfigurationManager.AppSettings[ConstantHelper.KEY_SUPER_ADMIN_PASS]; container.Register(Component.For <AdminSettings>().Instance(adminSettings)); container.Register(Component.For(typeof(PostgreSQLConstants <>))); var expressionUtils = new PostgreSQLExpressionUtils(); container.Register(Component.For <ExpressionUtils>().Instance(expressionUtils)); var typeLookup = new PostgreSQLTypeLookup(); container.Register(Component.For <PostgreSQLTypeLookup>().Instance(typeLookup)); var entityAssemblies = new[] { typeof(Organization).Assembly }; var entityUtils = new EntityUtils(typeLookup, entityAssemblies); container.Register(Component.For <EntityUtils>().Instance(entityUtils)); container.Register(Component.For <PostgreSQLConnectionFactory>()); container.Register(Component.For <NpgsqlConnection>() .DependsOn(Dependency.OnValue("connectionString", PostgreSQLConnectionFactory.GetConnectionString(connectionSettings))) .LifestyleTransient()); container.Register(Component.For <PostgreSQLExecutor>().LifestyleTransient()); container.Register(Component.For <PostgreSQLTransactionalExecutor>().LifestyleTransient()); }
public static void Generate(WindsorContainer container, string webRootPath) { var connectionSettings = container.Resolve <ConnectionSettings>(); var adminSettings = container.Resolve <AdminSettings>(); var typeLookup = container.Resolve <PostgreSQLTypeLookup>(); var entityUtils = container.Resolve <EntityUtils>(); var masterConnectionString = PostgreSQLConnectionFactory.GetConnectionString(connectionSettings.DbHost, connectionSettings.DbNameMaster, connectionSettings.DbUser, connectionSettings.DbPassword, connectionSettings.DbPort); var masterConnectionFactory = new PostgreSQLConnectionFactory(masterConnectionString); var sqlExecutorMaster = new PostgreSQLExecutor(masterConnectionFactory, entityUtils); var connectionString = PostgreSQLConnectionFactory.GetConnectionString(connectionSettings); var connectionFactory = new PostgreSQLConnectionFactory(connectionString); var sqlExecutor = new PostgreSQLExecutor(connectionFactory, entityUtils); var organizationService = container.Resolve <IOrganizationService>(); var dbGenerator = new PostgreSQLDbGenerator(typeLookup, entityUtils, sqlExecutorMaster, sqlExecutor); if (!dbGenerator.IsDbExistsDb(connectionSettings.DbName)) { dbGenerator.CreateDb(connectionSettings.DbName); dbGenerator.Generate().Wait(); var languageRepository = container.Resolve <ILanguageRepository>(); var languageFactory = container.Resolve <LanguageFactory>(); var(turkish, english) = InsertLanguages(languageRepository, languageFactory); var organizationRepository = container.Resolve <IOrganizationRepository>(); var userRepository = container.Resolve <IUserRepository>(); var projectRepository = container.Resolve <IProjectRepository>(); var organizationId = InsertAdmin(adminSettings, organizationService, organizationRepository, userRepository, projectRepository); var project = projectRepository.Select(x => x.OrganizationId == organizationId).Result; var labelService = container.Resolve <ILabelService>(); InsertLabels(labelService, project, webRootPath); } organizationService.LoadOrganizationsToCache(); organizationService.LoadUsersToCache(); }
static void Main() { var dbGenerator = new DbGenerator(); var(typeLookup, entityUtils, connectionSettings, sqlExecutor) = dbGenerator.Generate(); Console.WriteLine("Db Generated!"); var organizationRepository = new OrganizationRepository(typeLookup, new PostgreSQLConstants <Organization>(entityUtils), entityUtils, new PostgreSQLExpressionUtils(), sqlExecutor, new List <string>()); var projectRepository = new ProjectRepository(typeLookup, new PostgreSQLConstants <Project>(entityUtils), entityUtils, new PostgreSQLExpressionUtils(), sqlExecutor, new List <string>()); #region initial example var organization = new Organization { Name = "test", Email = "*****@*****.**" }; var orgId = organizationRepository.Insert(1, organization).Result; Console.WriteLine("Organization inserted, " + orgId); var project = new Project { Name = "test", Description = "test description", Cost = 1, IsActive = false }; var projectId = projectRepository.Insert(1, project).Result; Console.WriteLine("Project inserted, " + projectId); project.Name = "other test"; projectRepository.Update(1, project).Wait(); project.Name = "more other test"; projectRepository.Update(1, project).Wait(); var updatedProject = projectRepository.Select(x => x.Id == projectId).Result; Console.WriteLine("Project name updated to " + updatedProject.Name); Console.WriteLine("Project revisions;"); var projectRevisions = projectRepository.SelectRevisions(projectId).Result; for (var i = 0; i < projectRevisions.Count; i++) { var projectRevision = projectRevisions[i]; Console.WriteLine(projectRevision.Revision + " - " + projectRevision.Entity.Name); } try { var transactionalExecutor = new PostgreSQLTransactionalExecutor(new NpgsqlConnection(PostgreSQLConnectionFactory.GetConnectionString(connectionSettings))); var result = transactionalExecutor.ExecuteAsync <bool>(async cnn => { organizationRepository.SetSqlExecutorForTransaction(cnn); projectRepository.SetSqlExecutorForTransaction(cnn); var orgIdOther = organizationRepository.Insert(1, organization).Result; project.OrganizationId = orgIdOther; project.OrganizationUid = organization.Uid; project.OrganizationName = organization.Name; var projectIdOther = await projectRepository.Insert(1, project); return(true); }).Result; } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("project count " + projectRepository.Count().Result); Console.WriteLine("organization count " + organizationRepository.Count().Result); #endregion #region order by example for (var i = 0; i < 10; i++) { var organizationForOrderBy = new Organization { Name = "test " + i + 1, Email = "*****@*****.**" + (i - 10), Description = "order by test" }; organizationRepository.Insert(1, organizationForOrderBy).Wait(); } var orderedItems = organizationRepository.SelectAll(x => x.Description == "order by test", false, new List <OrderByInfo <Organization> > { new OrderByInfo <Organization>(y => y.Email, false) }).Result; Console.WriteLine("email desc ordered, first item > " + orderedItems.First().Email); orderedItems = organizationRepository.SelectAll(x => x.Description == "order by test", false, new List <OrderByInfo <Organization> > { new OrderByInfo <Organization>(y => y.Name), new OrderByInfo <Organization>(y => y.Id, false), }).Result; Console.WriteLine("name asc ordered, first item > " + orderedItems.First().Name + " - " + orderedItems.First().Id); #endregion Console.Read(); }
static void Main() { var dbGenerator = new DbGenerator(); var(typeLookup, entityUtils, connectionSettings, sqlExecutor) = dbGenerator.Generate(); Console.WriteLine("Db Generated!"); var organizationRepository = new OrganizationRepository(typeLookup, new PostgreSQLConstants <Organization>(entityUtils), entityUtils, new PostgreSQLExpressionUtils(), sqlExecutor, new List <string>()); var organization = new Organization { Name = "test", Email = "*****@*****.**" }; var orgId = organizationRepository.Insert(1, organization).Result; Console.WriteLine("Organization inserted, " + orgId); var projectRepository = new ProjectRepository(typeLookup, new PostgreSQLConstants <Project>(entityUtils), entityUtils, new PostgreSQLExpressionUtils(), sqlExecutor, new List <string>()); var project = new Project { Name = "test", Description = "test description", Cost = 1, IsActive = false }; var projectId = projectRepository.Insert(1, project).Result; project.Id = projectId; Console.WriteLine("Project inserted, " + projectId); project.Name = "other test"; projectRepository.Update(1, project).Wait(); project.Name = "more other test"; projectRepository.Update(1, project).Wait(); var updatedProject = projectRepository.Select(x => x.Id == projectId).Result; Console.WriteLine("Project name updated to " + updatedProject.Name); Console.WriteLine("Project revisions;"); var projectRevisions = projectRepository.SelectRevisions(projectId).Result; for (var i = 0; i < projectRevisions.Count; i++) { var projectRevision = projectRevisions[i]; Console.WriteLine(projectRevision.Revision + " - " + projectRevision.Entity.Name); } try { var transactionalExecutor = new PostgreSQLTransactionalExecutor(new NpgsqlConnection(PostgreSQLConnectionFactory.GetConnectionString(connectionSettings))); var result = transactionalExecutor.ExecuteAsync <bool>(async cnn => { organizationRepository.SetSqlExecutorForTransaction(cnn); projectRepository.SetSqlExecutorForTransaction(cnn); var orgIdOther = organizationRepository.Insert(1, organization).Result; project.OrganizationId = orgIdOther; project.OrganizationUid = organization.Uid; project.OrganizationName = organization.Name; var projectIdOther = projectRepository.Insert(1, project).Result; return(true); }).Result; } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("project count " + projectRepository.Count().Result); Console.WriteLine("organization count " + organizationRepository.Count().Result); }
public PostgreSQLExecutor(PostgreSQLConnectionFactory connectionFactory, EntityUtils entityUtils) : base(connectionFactory, entityUtils) { }