Beispiel #1
0
        public static string GetConnectionString(this ICommerceDbProvider dbProvider, CommerceInstanceSettings metadata)
        {
            if (String.IsNullOrEmpty(metadata.ConnectionString))
            {
                return(dbProvider.ConnectionStringBuilder.BuildConnectionString(metadata.ConnectionStringParameters));
            }

            return(metadata.ConnectionString);
        }
        static void CreatePhysicalDatabaseIfNotExists(string connectionString, ICommerceDbProvider provider)
        {
            var conn = DbProviderFactories.GetFactory(provider.InvariantName).CreateConnection();

            conn.ConnectionString = connectionString;

            // TODO: Do not generate __MigrateHistory table or ...?
            using (var dbContext = new EmptyDbContext(conn))
            {
                dbContext.Database.CreateIfNotExists();
            }
        }
Beispiel #3
0
        public void AddDbProvider(ICommerceDbProvider provider)
        {
            DbProviders.Add(new SelectListItem
            {
                Text  = provider.DisplayName,
                Value = provider.InvariantName + "|" + provider.ManifestToken
            });

            ConnectionStringParameterNames.Add(new ConnectionStringParameterNames
            {
                DbProviderKey  = provider.InvariantName + "|" + provider.ManifestToken,
                ParameterNames = provider.ConnectionStringBuilder.ParameterNames.ToList()
            });
        }
Beispiel #4
0
        internal static CommerceDbContext Create(CommerceInstanceSettings metadata, ICommerceDbProvider dbProvider)
        {
            var dbProviderInfo = new DbProviderInfo(metadata.DbProviderInvariantName, metadata.DbProviderManifestToken);

            var model = _modelCache.GetOrAdd(new ModelCacheKey(metadata.DbSchema, dbProviderInfo), key =>
            {
                return CreateModel(key.Schema, key.DbProviderInfo);
            });

            var dbProviderFactory = DbConfiguration.DependencyResolver.GetService(typeof(DbProviderFactory), dbProvider.InvariantName) as DbProviderFactory;
            var conn = dbProviderFactory.CreateConnection();
            conn.ConnectionString = dbProvider.GetConnectionString(metadata);

            return new CommerceDbContext(metadata, conn, model);
        }
        internal static CommerceDbContext Create(CommerceInstanceSettings metadata, ICommerceDbProvider dbProvider)
        {
            var dbProviderInfo = new DbProviderInfo(metadata.DbProviderInvariantName, metadata.DbProviderManifestToken);

            var model = _modelCache.GetOrAdd(new ModelCacheKey(metadata.DbSchema, dbProviderInfo), key =>
            {
                return(CreateModel(key.Schema, key.DbProviderInfo));
            });

            var dbProviderFactory = DbConfiguration.DependencyResolver.GetService(typeof(DbProviderFactory), dbProvider.InvariantName) as DbProviderFactory;
            var conn = dbProviderFactory.CreateConnection();

            conn.ConnectionString = dbProvider.GetConnectionString(metadata);

            return(new CommerceDbContext(metadata, conn, model));
        }
Beispiel #6
0
        public CommerceDatabase(CommerceInstanceSettings instanceSettings, ICommerceDbProvider dbProvider)
        {
            Require.NotNull(instanceSettings, "instanceSettings");

            if (dbProvider == null)
            {
                dbProvider = CommerceDbProviders.Providers.Find(instanceSettings.DbProviderInvariantName, instanceSettings.DbProviderManifestToken);
                if (dbProvider == null)
                {
                    throw new InvalidOperationException("Cannot find db provider from the provided manifest. Invariant name: " + instanceSettings.DbProviderInvariantName + ", manifest token: " + instanceSettings.DbProviderManifestToken + ".");
                }
            }

            InstanceSettings = instanceSettings;
            DbContext        = CommerceDbContext.Create(instanceSettings, dbProvider);
        }
        static void CreatePhysicalDatabaseIfNotExists(string connectionString, ICommerceDbProvider provider)
        {
            var conn = DbProviderFactories.GetFactory(provider.InvariantName).CreateConnection();
            conn.ConnectionString = connectionString;

            // TODO: Do not generate __MigrateHistory table or ...?
            using (var dbContext = new EmptyDbContext(conn))
            {
                dbContext.Database.CreateIfNotExists();
            }
        }
        public void AddDbProvider(ICommerceDbProvider provider)
        {
            DbProviders.Add(new SelectListItem
            {
                Text = provider.DisplayName,
                Value = provider.InvariantName + "|" + provider.ManifestToken
            });

            ConnectionStringParameterNames.Add(new ConnectionStringParameterNames
            {
                DbProviderKey = provider.InvariantName + "|" + provider.ManifestToken,
                ParameterNames = provider.ConnectionStringBuilder.ParameterNames.ToList()
            });
        }