示例#1
0
        // Passing in ICommerceDatabase instead of CommerceDatabase is because,
        // in IoC container the service type is ICommerceDatabase.
        // If we ask for CommerceDatabase here, the IoC container will not be able to provide the CommerceDatabase instance.
        public CommerceRepository(ICommerceDatabase database)
        {
            Require.NotNull(database, "database");
            Require.That(database is CommerceDatabase, "Requires type " + typeof(CommerceDatabase) + ".");

            _database = (CommerceDatabase)database;
        }
示例#2
0
        public CommerceDbTransaction(DbContextTransaction underlyingTransaction, CommerceDatabase database)
        {
            Require.NotNull(underlyingTransaction, "underlyingTransaction");
            Require.NotNull(database, "database");

            UnderlyingTransaction = underlyingTransaction;
            Database = database;
        }
        public void CreateInstance(CommerceInstanceSettings settings)
        {
            Require.NotNull(settings, "settings");

            var current = _settingsManager.Get(settings.Name);

            if (current != null)
            {
                throw new InvalidOperationException("Commerce instance \"" + settings.Name + "\" already exists.");
            }

            var dbProvider       = _dbProviders.Find(settings.DbProviderInvariantName, settings.DbProviderManifestToken);
            var connectionString = dbProvider.GetConnectionString(settings);

            try
            {
                CreatePhysicalDatabaseIfNotExists(connectionString, dbProvider);

                using (var database = new CommerceDatabase(settings))
                {
                    dbProvider.DatabaseOperations.CreateDatabase(database);
                }
            }
            catch (Exception ex)
            {
                throw new CommerceDbException("Commerce instance creation failed: " + ex.Message, ex);
            }

            _settingsManager.Create(settings.Name, settings);

            if (_initializers != null)
            {
                var instance = GetInstance(settings.Name);
                foreach (var initializer in _initializers)
                {
                    initializer.Initialize(instance);
                }
            }

            Event.Raise(new CommerceInstanceCreated(settings.Name, settings), GetInstance(settings.Name));
        }
        public void DeleteInstance(string name)
        {
            var settings = _settingsManager.Get(name);

            if (settings == null)
            {
                throw new InvalidOperationException("Cannot find metadata for commerce instance: " + name + ".");
            }

            var instance = GetInstance(name);

            try
            {
                var dbProvider = _dbProviders.Find(settings.DbProviderInvariantName, settings.DbProviderManifestToken);
                using (var database = new CommerceDatabase(settings))
                {
                    if (database.DbContext.Database.Exists())
                    {
                        dbProvider.DatabaseOperations.DeleteDatabase(database);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new CommerceDbException("Commerce instance deletion failed: " + ex.Message, ex);
            }

            _settingsManager.Delete(name);

            // Delete instance folder
            var folder = DataFolders.Instances.GetFolder(settings.Name);

            folder.Delete();

            Event.Raise(new CommerceInstanceDeleted(settings.Name, settings), instance);
        }
示例#5
0
 public CommerceRepository(CommerceDatabase database, Type entityType)
 {
     _database  = database;
     EntityType = entityType;
 }