public void InitialDB() { ContainerBuilder builder = new ContainerBuilder(); builder.Register <DbContext>(c => new PosDBContext("PosTest")); //builder.RegisterType<EfRepository<BaseEntity>>().As<IRepository<BaseEntity>>().InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope(); IContainer container = builder.Build(); SqlServerDataProvider provider = new SqlServerDataProvider(); provider.InitDatabase(); //PosDBContext context = new PosDBContext("PosTest"); //var product = new EfRepository<Product>(context); //product.Insert(new Product()); using (var scope = container.BeginLifetimeScope()) { var writer = scope.Resolve <IRepository <Product> >(); writer.Insert(new Product()); } }
private static IDataProvider GetSqlServerDataProvider() { var db = new SqlServerDataProvider($@"Server=localhost\SQLEXPRESS;Database=workitems_test;Trusted_Connection=True;"); db.InitAsync().Wait(); return(db); }
/// <summary> /// Saves the changes made to an entity /// list /// </summary> /// <typeparam name="T">Entity type</typeparam> /// <param name="entities">Entity list reference</param> /// <returns>ComplexResponse list of Primary key inserted/updated</returns> public static async Task <BasicResponse> Save <T>(this List <T> entities, SqlTransaction transaction = null) where T : class, IEntity, new() { //Verify entity state if (entities.IsNotValid()) { return(new ModelResponse <List <long> >(false, @"The specified entity list is not valid for save operation.")); } string configUrl = $@"{AppDomain.CurrentDomain.BaseDirectory}Storage\SqlServer\DataProvider.json"; //Verify configuration file if (!configUrl.IsFilePath(out _)) { return(new ModelResponse <List <long> >(false, @"The configuration file is not present, the task could not be completed as requested.")); } JsonLoader <Configuration> jsonLoader = new JsonLoader <Configuration>(configUrl); await jsonLoader.Load(); Configuration configuration = jsonLoader.Instance; string connectionString = configuration.Values .GetFirst <string>(@"ConnectionString"); //Verify connection string value if (connectionString.IsNotValid()) { return(new ModelResponse <List <long> >(false, @"The specified connection string in the configuration file is not valid for its use, the task could not be completed as requested.")); } //Save entity list SqlServerDataProvider <T> provider = new SqlServerDataProvider <T>(connectionString); return(await provider.Save(entities, transaction)); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration of the application</param> /// <param name="hostingEnvironment">Hosting environment</param> /// <returns>Configured service provider</returns> public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration, IHostingEnvironment hostingEnvironment) { //add HttpContext accessor services.AddHttpContextAccessor(); //add CORS services.AddCors(); //add MVC services.AddMvc(); //add dbcontext var connectionString = configuration["ConnectionStrings:Registry"].ToString(); services.AddDbContext <RegistryDbContext>(t => t.UseSqlServer(connectionString, x => x.UseNetTopologySuite())); //create engine var engine = EngineContext.Create(); var serviceProvider = engine.ConfigureServices(services); var sqlProvider = new SqlServerDataProvider(); sqlProvider.InitializeDatabase(); return(serviceProvider); }
public void CanCreateAConnection() { var provider = new SqlServerDataProvider(connectionString); using (var connection = provider.CreateConnection()) { connection.Open(); } }
/// <summary> /// Creates a new sql data provider test instance /// </summary> public SqlDataProviderTests() { JsonLoader <Configuration> config = new JsonLoader <Configuration>($@"{AppDomain.CurrentDomain.BaseDirectory}Storage\SqlServer\DataProvider.json"); config.Load() .Wait(); ConnectionString = config.Instance.Values .GetFirst <string>(@"ConnectionString"); DataProvider = new SqlServerDataProvider <TestingEntity>(ConnectionString); }
public PosEngine() { sqlProvider = new SqlServerDataProvider(); var depency = new DependencyRegistrar(); ContainerBuilder builder = new ContainerBuilder(); depency.Register(builder); container = builder.Build(); }
public (IList <Book> records, int total, int totalDisplay) GetBooks(int pageIndex, int pageSize, string searchText, string sortText) { using var dbProvider = new SqlServerDataProvider <Book>(_connectionString); var books = dbProvider.GetData("GetBooks", new List <(string, object, bool)> { ("PageIndex", pageIndex, false), ("PageSize", pageSize, false), ("SearchText", searchText, false), ("OrderBy", sortText, false), ("Total", 0, true), ("TotalDisplay", 0, true) });
public (IList <Product> records, int total, int totalDisplay) GetProducts(int pageIndex, int pageSize, string searchText, string sortText) { using var dbProvider = new SqlServerDataProvider <Product>(_connectionString); var products = dbProvider.GetData("SpGetAllProducts", new List <(string, object, bool)>() { ("PageIndex", pageIndex, false), ("PageSize", pageSize, false), ("SearchText", searchText, false), ("OrderBy", sortText, false), ("Total", 0, true), ("TotalDisplay", 0, true) }); return(products.result, products.total, products.totalDisplay); }
/// <summary> /// Creates an entity instance with the given connection string /// </summary> /// <returns></returns> public ICartRepository Create() { var name = "ApplicationDBConnectionString"; var config = System.Configuration.ConfigurationManager.ConnectionStrings[name]; if (config == null || string.IsNullOrWhiteSpace(config.ConnectionString)) { throw new Exception($"{name} has not been configured"); } var connectionString = config.ConnectionString; var prov = new SqlServerDataProvider("", SqlServerVersion.v2012); var conn = new SqlConnection(connectionString); this.CreateMappings(prov, conn); var result = new Linq2DbRepository(prov, conn); return(result); }
public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment hostingEnvironment) { //add Config configuration parameters CepresConfig config = services.ConfigureStartupConfig <CepresConfig>(configuration.GetSection("Cepres")); //add accessor to HttpContext services.AddHttpContextAccessor(); CommonHelper.DefaultFileProvider = new FileManagerProvider(hostingEnvironment); IMvcCoreBuilder mvcCoreBuilder = services.AddMvcCore(); //create, initialize and configure the engine IEngine engine = EngineContext.Create(); IServiceProvider serviceProvider = engine.ConfigureServices(services, configuration); SqlServerDataProvider.InitializeDatabase(config.DataConnectionString); return(serviceProvider); }
public void InstallSampleData() { ContainerBuilder builder = new ContainerBuilder(); builder.Register <IDbContext>(c => new PosDBContext("PosTest")); builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope(); IContainer container = builder.Build(); SqlServerDataProvider provider = new SqlServerDataProvider(); provider.InitDatabase(); using (var scope = container.BeginLifetimeScope()) { var context = scope.Resolve <IDbContext>(); var sqlFile = new SqlFileInstallation(context); sqlFile.InstallData(); } }
/// <summary> /// Get connection string of EA database /// </summary> /// <param name="rep"></param> /// <param name="provider"></param> /// <returns></returns> /// string dsnName = "DSN=MySqlEa;Trusted_Connection=Yes;"; // dsnName = "DSN=MySqlEa;"; public static string GetConnectionString(EA.Repository rep, out IDataProvider provider) { provider = null; var(connectionString, dbType) = GetConnectionStringFromRepository(rep); string dsnConnectionString; // EAP file // Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\hoData\Work.eap;" switch (dbType) { case "JET": provider = new AccessDataProvider(); dsnConnectionString = GetConnectionStringForDsn(connectionString); if (dsnConnectionString != "") { return(dsnConnectionString); } if (connectionString.ToLower().EndsWith(".eap") || connectionString.ToLower().EndsWith(".eapx")) { return($"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={connectionString};"); } break; case @"SQLSVR": provider = new SqlServerDataProvider("", SqlServerVersion.v2012); dsnConnectionString = GetConnectionStringForDsn(connectionString); if (dsnConnectionString != "") { return(dsnConnectionString); } return(FilterConnectionString(connectionString)); case "MYSQL": provider = new MySqlDataProvider(); dsnConnectionString = GetConnectionStringForDsn(connectionString); if (dsnConnectionString != "") { return(dsnConnectionString); } return(FilterConnectionString(connectionString)); case "ACCESS2007": provider = new AccessDataProvider(); dsnConnectionString = GetConnectionStringForDsn(connectionString); if (dsnConnectionString != "") { return(dsnConnectionString); } return(FilterConnectionString(connectionString)); case "ASA": provider = new SybaseDataProvider(); dsnConnectionString = GetConnectionStringForDsn(connectionString); if (dsnConnectionString != "") { return(dsnConnectionString); } return(FilterConnectionString(connectionString)); case "ORACLE": provider = new OracleDataProvider(); dsnConnectionString = GetConnectionStringForDsn(connectionString); if (dsnConnectionString != "") { return(dsnConnectionString); } return(FilterConnectionString(connectionString)); case "POSTGRES": provider = new PostgreSQLDataProvider(); dsnConnectionString = GetConnectionStringForDsn(connectionString); if (dsnConnectionString != "") { return(dsnConnectionString); } return(FilterConnectionString(connectionString)); } MessageBox.Show($"Database: {rep.RepositoryType()}\r\nConnectionString:{connectionString} ", "DataBase not supported, only Access (*.eap/*.eapx), SqlServer and MySQL"); return(""); }
/// <summary> /// Default constructor that uses the connection string name OneWorkspaceSqlConnection /// </summary> public CSIProductConfigurationRepositoryFactory() { ISqlServerDataProvider dataProvider = new SqlServerDataProvider("CSIProductConfigurationSqlConnection"); InitialiseRepositories(dataProvider); }
public void Register(ContainerBuilder builder, ITypeFinder typeFinder) { builder.Register(x => new HttpContextWrapper(HttpContext.Current) as HttpContextBase) .InstancePerLifetimeScope(); builder.Register(c => c.Resolve <HttpContextBase>().Request) .As <HttpRequestBase>() .InstancePerLifetimeScope(); builder.Register(c => c.Resolve <HttpContextBase>().Response) .As <HttpResponseBase>() .InstancePerLifetimeScope(); builder.Register(c => c.Resolve <HttpContextBase>().Server) .As <HttpServerUtilityBase>() .InstancePerLifetimeScope(); builder.Register(c => c.Resolve <HttpContextBase>().Session) .As <HttpSessionStateBase>() .InstancePerLifetimeScope(); builder.RegisterType <WebHelper>().As <IWebHelper>() .InstancePerLifetimeScope(); builder.RegisterType <UserService>().As <IUserService>() .InstancePerLifetimeScope(); builder.RegisterType <FormsAuthenticationService>() .As <IAuthenticationService>() .InstancePerLifetimeScope(); //web helper builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope(); //controllers builder.RegisterControllers(typeFinder.GetAssemblies().ToArray()); //data layer IDataProvider dataProvider = new SqlServerDataProvider(); dataProvider.InitConnectionFactory(); builder.Register <IDbContext>( c => new LxsObjectContext( "Data Source=.;Initial Catalog=lxsOa;Integrated Security=False;Persist Security Info=False;User ID=sa;Password=123456")) .InstancePerLifetimeScope(); //var sqlbuilder = new SqlConnectionStringBuilder("Data Source=.;Initial Catalog=lxsOa;Integrated Security=False;Persist Security Info=False;User ID=sa;Password=123456"); //var databaseName = sqlbuilder.InitialCatalog; ////now create connection string to 'master' dabatase. It always exists. //sqlbuilder.InitialCatalog = "master"; //var masterCatalogConnectionString = sqlbuilder.ToString(); //string query = string.Format("CREATE DATABASE [{0}]", databaseName); // var collation = ""; //if (!String.IsNullOrWhiteSpace(collation)) // query = string.Format("{0} COLLATE {1}", query, collation); //using (var conn = new SqlConnection(masterCatalogConnectionString)) //{ // conn.Open(); // using (var command = new SqlCommand(query, conn)) // { // command.ExecuteNonQuery(); // } //} dataProvider.InitDatabase(); //builder.Register<IDbContext>( // x => // new LxsObjectContext( // "Data Source=.;Initial Catalog=lxsOa;Integrated Security=False;Persist Security Info=False;User ID=sa;Password=123456")) // .InstancePerLifetimeScope(); builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope(); //plugins // builder.RegisterType<PluginFinder>().As<IPluginFinder>().InstancePerLifetimeScope(); //work context builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope(); builder.RegisterType <CodeFirstInstallationService>().As <IInstallationService>().InstancePerLifetimeScope(); Debug.WriteLine("hello world!"); }