public ActionResult Create(CommerceInstanceEditorModel model, string @return) { var metadata = new CommerceInstanceSettings { Name = model.Name, DisplayName = model.DisplayName, DbSchema = model.DbSchema }; var dbProviderKeyParts = model.DbProviderKey.Split('|'); metadata.DbProviderInvariantName = dbProviderKeyParts[0]; metadata.DbProviderManifestToken = dbProviderKeyParts[1]; if (model.AdvancedMode) { metadata.ConnectionString = model.ConnectionString; } else { foreach (var param in model.ConnectionStringParameters) { metadata.ConnectionStringParameters.Add(param.Text, param.Value); } } _instanceManager.CreateInstance(metadata); return AjaxForm().RedirectTo(@return); }
public void Create(string instanceName, CommerceInstanceSettings settings) { var folder = DataFolders.Instances.GetFolder(instanceName); var file = folder.GetFile(SettingsFileName); if (file.Exists) throw new InvalidOperationException("Instance settings file already exists. Instance name: " + instanceName + "."); file.Write(settings); }
public void Create(string instanceName, CommerceInstanceSettings settings) { var folder = DataFolders.Instances.GetFolder(instanceName); var file = folder.GetFile(SettingsFileName); if (file.Exists) { throw new InvalidOperationException("Instance settings file already exists. Instance name: " + instanceName + "."); } file.Write(settings); }
public void Update(string instanceName, CommerceInstanceSettings settings) { var folder = DataFolders.Instances.GetFolder(instanceName); var file = folder.GetFile(SettingsFileName); if (!file.Exists) throw new InvalidOperationException("Failed to update instance metadata because instance was not found. Instance name: " + instanceName + "."); if (settings.Name != instanceName) { settings.Name = instanceName; } file.Write(settings); }
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)); }
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); }
public void Update(string instanceName, CommerceInstanceSettings settings) { var folder = DataFolders.Instances.GetFolder(instanceName); var file = folder.GetFile(SettingsFileName); if (!file.Exists) { throw new InvalidOperationException("Failed to update instance metadata because instance was not found. Instance name: " + instanceName + "."); } if (settings.Name != instanceName) { settings.Name = instanceName; } file.Write(settings); }
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 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 CommerceInstance(CommerceInstanceSettings settings) { Require.NotNull(settings, "settings"); Settings = settings; }
private CommerceDbContext(CommerceInstanceSettings commerceInstanceMetadata, DbConnection connection, DbCompiledModel model) : base(connection, model, true) { CommerceInstanceMetadata = commerceInstanceMetadata; }
public CommerceDatabase(CommerceInstanceSettings instanceSettings) : this(instanceSettings, null) { }