private static void Init() { var serviceCollection = new ServiceCollection(); serviceCollection.AddLogging(builder => builder.AddSerilog()); var serviceProvider = serviceCollection.BuildServiceProvider(); Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var loggerFactory = serviceProvider.GetService <ILoggerFactory>(); FactoryApplication.SetLoggerFactory(loggerFactory); FactoryBusinessOperation.ClearRegisteredItems(); FactoryBusinessOperation.RegisterBusinessOperations(BusinessErpOperations.GetInstance().ExportedServicesList()); string host = Environment.GetEnvironmentVariable("ONIX_ERP_DB_HOST"); string dbname = Environment.GetEnvironmentVariable("ONIX_ERP_DB_NAME"); string user = Environment.GetEnvironmentVariable("ONIX_ERP_DB_USER"); string password = Environment.GetEnvironmentVariable("ONIX_ERP_DB_PASSWORD"); DbCredential crd = new DbCredential(host, 5432, dbname, user, password, "pgsql"); OnixErpDbContext ctx = new OnixErpDbContext(crd); ctx.SetLoggerFactory(loggerFactory); FactoryBusinessOperation.SetDatabaseContext(ctx); FactoryBusinessOperation.SetLoggerFactory(loggerFactory); Assembly asm = Assembly.GetExecutingAssembly(); FactoryDbContext.RegisterDbContext(asm, "OnixErpDbContextPgSql", "OnixBusinessErpApp.OnixErpDbContextPgSql"); }
protected override int Execute() { ILogger logger = GetLogger(); Hashtable args = GetArguments(); string defaultHost = Environment.GetEnvironmentVariable("ONIX_ERP_DB_HOST"); string defaultPassword = Environment.GetEnvironmentVariable("ONIX_ERP_DB_PASSWORD"); string user = Environment.GetEnvironmentVariable("ONIX_ERP_DB_USER"); string dbname = Environment.GetEnvironmentVariable("ONIX_ERP_DB_NAME"); string host = GetOptionValue(args, "host", defaultHost); int port = Int32.Parse(GetOptionValue(args, "port", "5432")); string db = GetOptionValue(args, "database", dbname);; string uname = GetOptionValue(args, "user", user); string passwd = GetOptionValue(args, "password", defaultPassword); string provider = GetOptionValue(args, "provider", "pgsql"); string msg = "Migrating data : host=[{0}] port=[{1}] db=[{2}] provider=[{3}]..."; LogUtils.LogInformation(logger, msg, host, port, db, provider); DbCredential crd = new DbCredential(host, port, db, uname, passwd); var ctx = (OnixErpDbContextPgSql)FactoryDbContext.CreateDbContextObject("OnixErpDbContextPgSql", crd); ctx.Database.Migrate(); LogUtils.LogInformation(logger, "Migrating done"); return(0); }
protected OnixErpDbContext CreateOnixDbContext() { DbCredential crd = new DbCredential("", 9999, "", "", "", "sqlite_inmem"); ctx = new OnixErpDbContext(crd); ctx.Database.EnsureCreated(); FactoryBusinessOperation.SetDatabaseContext(ctx); return(ctx); }
public static BaseDbContext CreateDbContextObject(string name, DbCredential credential) { if (!classMaps.ContainsKey(name)) { throw new ArgumentNullException(String.Format("DbContext not found [{0}]", name)); } PluginEntry entry = classMaps[name]; Assembly asm = Assembly.Load(entry.Asm.GetName()); Type t = asm.GetType(entry.Fqdn); BaseDbContext obj = (BaseDbContext)Activator.CreateInstance(t, credential); obj.SetLoggerFactory(loggerFactory); return(obj); }
public Startup(IConfiguration configuration) { var loggerFactory = LoggerFactory.Create(builder => { builder .AddFilter("Its", LogLevel.Warning) .AddConsole(); }); string host = Environment.GetEnvironmentVariable("ONIX_ERP_DB_HOST"); string dbname = Environment.GetEnvironmentVariable("ONIX_ERP_DB_NAME"); string user = Environment.GetEnvironmentVariable("ONIX_ERP_DB_USER"); string password = Environment.GetEnvironmentVariable("ONIX_ERP_DB_PASSWORD"); crd = new DbCredential(host, 5432, dbname, user, password, "pgsql"); Configuration = configuration; FactoryBusinessOperation.RegisterBusinessOperations(BusinessErpOperations.GetInstance().ExportedServicesList()); FactoryBusinessOperation.SetLoggerFactory(loggerFactory); }
public void UnknownDbContextNameTest(string ctxName, string host, int port, string db, string uname, string pw, string provider) { try { DbCredential credential = null; if (string.IsNullOrEmpty(provider)) { credential = new DbCredential(host, port, db, uname, pw); } else { credential = new DbCredential(host, port, db, uname, pw, provider); } BaseDbContext opt = FactoryDbContext.CreateDbContextObject(ctxName, credential); Assert.True(false, "Exception shoud be throw for unknow application name!!!"); } catch (Exception e) { Assert.True(true, e.Message); } }
public void knownDbContextNameTest(string ctxName, string host, int port, string db, string uname, string pw, string provider) { try { DbCredential credential = null; if (string.IsNullOrEmpty(provider)) { credential = new DbCredential(host, port, db, uname, pw); } else { credential = new DbCredential(host, port, db, uname, pw, provider); } BaseDbContext opt = FactoryDbContext.CreateDbContextObject(ctxName, credential); Assert.IsNotNull(opt, "Object created from factory must be null!!!"); } catch (Exception e) { Assert.True(false, e.Message); } }
protected OnixErpDbContext CreateOnixDbContext(string db, string provider) { OnixErpDbContext ctx = null; if (provider.Equals("pgsql")) { string host = Environment.GetEnvironmentVariable("ONIX_ERP_DB_HOST"); string dbname = Environment.GetEnvironmentVariable("ONIX_ERP_DB_NAME"); string user = Environment.GetEnvironmentVariable("ONIX_ERP_DB_USER"); string password = Environment.GetEnvironmentVariable("ONIX_ERP_DB_PASSWORD"); DbCredential crd = new DbCredential(host, 5432, dbname, user, password, provider); ctx = new OnixErpDbContext(crd); } else if (provider.Equals("sqlite_inmem")) { DbCredential crd = new DbCredential("", 9999, "", "", "", provider); ctx = new OnixErpDbContext(crd); ctx.Database.EnsureCreated(); } FactoryBusinessOperation.SetDatabaseContext(ctx); return(ctx); }
public OnixErpDbContext(DbCredential credential) : base(credential) { }
/// <inheritdoc /> public IDbSourceEntity CreateSource(string name, DbCredential credential) { return(new DbSourceEntity(name, credential, new SqlServerDatabaseEntityProvider())); }
public void OnixErpDbContextConnectTest(string host, int port, string db, string user, string passwd, string provider) { var credential = new DbCredential(host, port, db, user, passwd, provider); OnixErpDbContext ctx = new OnixErpDbContext(credential); }
public OnixErpDbContextPgSql(DbCredential crd) : base(crd) { }