public DataTable GetDataTable(string _query)
        {
            DataSettingsManager _dataSettingsManager = new DataSettingsManager();
            DataSettings        _dataSettings        = _dataSettingsManager.LoadSettings();
            SqlConnection       _sqlConnection       = new SqlConnection(_dataSettings.DataConnectionString + ";Connection Timeout=0");
            DataTable           dt = new DataTable();

            if (_sqlConnection.State == ConnectionState.Closed)
            {
                _sqlConnection.Open();
            }
            SqlDataAdapter _da = new SqlDataAdapter(_query, _sqlConnection);

            _da.Fill(dt);
            return(dt);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add and configure any of the middleware
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration of the application</param>
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            var mAssemblies = new AppDomainTypeFinder().FindClassesOfType <AutoReversingMigration>()
                              .Select(t => t.Assembly)
                              .Distinct()
                              .ToArray();

            services
            // add common FluentMigrator services
            .AddFluentMigratorCore()
            .AddScoped <IProcessorAccessor, NopProcessorAccessor>()
            // set accessor for the connection string
            .AddScoped <IConnectionStringAccessor>(x => DataSettingsManager.LoadSettings())
            .AddScoped <IMigrationManager, MigrationManager>()
            .AddSingleton <IConventionSet, NopConventionSet>()
            .ConfigureRunner(rb =>
                             rb.WithVersionTable(new MigrationVersionInfo()).AddSqlServer().AddMySql5()
                             // define the assembly containing the migrations
                             .ScanIn(mAssemblies).For.Migrations());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the db context.
        /// </summary>
        /// <returns>The db context.</returns>
        public NopObjectContext CreateDbContext(string[] args)
        {
            //power shell -> Add-Migration migration-name
            //consule -> dotnet ef migrations add migration-name

            //consule -> dotnet ef database update

            var    nopFileProvider = EngineContext.Current.Resolve <INopFileProvider>();
            string connection      = DataSettingsManager.LoadSettings(nopFileProvider.MapPath("~/App_Data/dataSettings.json"), true).DataConnectionString;

            if (string.IsNullOrEmpty(connection))
            {
                //this connection string used when programmer need forec start migration as design time
                connection = "Data Source=10.1.11.102,1433;Initial Catalog=NopFramework;Integrated Security=False;Persist Security Info=False;User ID=sa;Password=123qweRt";
            }

            var optionsBuilder = new DbContextOptionsBuilder <NopObjectContext>();

            try
            {
                //test connection string
                //var _ = new SqlConnectionStringBuilder(connection);

                optionsBuilder
                .UseSqlServer(connection
                              , sqlOptions =>
                {
                    sqlOptions.EnableRetryOnFailure(
                        maxRetryCount: 10,
                        maxRetryDelay: TimeSpan.FromSeconds(30),
                        errorNumbersToAdd: null);
                });
            }
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
            catch
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
            {
                // do noting
            }
            return(new NopObjectContext(optionsBuilder.Options));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add and configure any of the middleware
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration of the application</param>
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            var mAssemblies = new AppDomainTypeFinder().FindClassesOfType <MigrationBase>()
                              .Select(t => t.Assembly)
                              .Where(assembly => !assembly.FullName.Contains("FluentMigrator.Runner"))
                              .Distinct()
                              .ToArray();

            services
            // add common FluentMigrator services
            .AddFluentMigratorCore()
            .AddScoped <IProcessorAccessor, NopProcessorAccessor>()
            // set accessor for the connection string
            .AddScoped <IConnectionStringAccessor>(x => DataSettingsManager.LoadSettings())
            .AddSingleton <IMigrationManager, MigrationManager>()
            .AddSingleton <IConventionSet, NopConventionSet>()
            .AddTransient <IMappingEntityAccessor>(x => x.GetRequiredService <IDataProviderManager>().DataProvider)
            .ConfigureRunner(rb =>
                             rb.WithVersionTable(new MigrationVersionInfo()).AddSqlServer().AddMySql5().AddPostgres()
                             // define the assembly containing the migrations
                             .ScanIn(mAssemblies).For.Migrations());
        }
        public bool ExecuteNonQuery(string _query)
        {
            DataSettingsManager _dataSettingsManager = new DataSettingsManager();
            DataSettings        _dataSettings        = _dataSettingsManager.LoadSettings();
            SqlConnection       _sqlConnection       = new SqlConnection(_dataSettings.DataConnectionString + ";Connection Timeout=0");
            DataTable           dt = new DataTable();

            if (_sqlConnection.State == ConnectionState.Closed)
            {
                _sqlConnection.Open();
            }
            SqlCommand _command = new SqlCommand(_query, _sqlConnection);

            try
            {
                _command.ExecuteNonQuery();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        protected virtual SqlConnectionStringBuilder GetConnectionStringBuilder()
        {
            var connectionString = DataSettingsManager.LoadSettings().ConnectionString;

            return(new SqlConnectionStringBuilder(connectionString));
        }