/// <summary> /// Gets the entity framework context. /// </summary> /// <param name="connectionName">Name of the connection.</param> /// <param name="provider">The provider.</param> /// <returns></returns> public static ImageOptimizationEFDbContext GetContext(string connectionName, IImageOptimizationEFDataProvider provider) { ImageOptimizationEFDataConnection connection; if (!connections.TryGetValue(connectionName, out connection)) connection = InitializeConnection(connectionName, provider); return new ImageOptimizationEFDbContext(connection.connectionString); }
/// <summary> /// Gets the entity framework context. /// </summary> /// <param name="provider">The provider.</param> /// <returns></returns> private ImageOptimizationEFDbContext GetContext(IImageOptimizationEFDataProvider provider) { if (provider.ProviderContext == null) { throw new Exception(String.Format("Provider {0} is not initialized.", provider.Name)); } return(ImageOptimizationEFDataConnection.GetContext(this.connectionName, provider)); }
/// <summary> /// Gets the entity framework context. /// </summary> /// <param name="connectionName">Name of the connection.</param> /// <param name="provider">The provider.</param> /// <returns></returns> public static ImageOptimizationEFDbContext GetContext(string connectionName, IImageOptimizationEFDataProvider provider) { ImageOptimizationEFDataConnection connection; if (!connections.TryGetValue(connectionName, out connection)) { connection = InitializeConnection(connectionName, provider); } return(new ImageOptimizationEFDbContext(connection.connectionString)); }
/// <summary> /// Initializes the connection. /// </summary> /// <param name="connectionName">Name of the connection.</param> /// <param name="dataProvider">The data provider.</param> /// <returns></returns> public static ImageOptimizationEFDataConnection InitializeConnection(string connectionName, IImageOptimizationEFDataProvider dataProvider) { IConnectionStringSettings connectionSettings = ImageOptimizationEFDataConnection.GetConnectionStringSettings(connectionName); ImageOptimizationEFDataConnection connection; if (!ImageOptimizationEFDataConnection.connections.TryGetValue(connectionSettings.Name, out connection)) { lock (ImageOptimizationEFDataConnection.connectionsLock) { if (!ImageOptimizationEFDataConnection.connections.TryGetValue(connectionSettings.Name, out connection)) { connection = new ImageOptimizationEFDataConnection(connectionSettings.Name, connectionSettings.ConnectionString, dataProvider); ImageOptimizationEFDataConnection.connections.Add(connectionSettings.Name, connection); } } } return connection; }
/// <summary> /// Initializes the connection. /// </summary> /// <param name="connectionName">Name of the connection.</param> /// <param name="dataProvider">The data provider.</param> /// <returns></returns> public static ImageOptimizationEFDataConnection InitializeConnection(string connectionName, IImageOptimizationEFDataProvider dataProvider) { IConnectionStringSettings connectionSettings = ImageOptimizationEFDataConnection.GetConnectionStringSettings(connectionName); ImageOptimizationEFDataConnection connection; if (!ImageOptimizationEFDataConnection.connections.TryGetValue(connectionSettings.Name, out connection)) { lock (ImageOptimizationEFDataConnection.connectionsLock) { if (!ImageOptimizationEFDataConnection.connections.TryGetValue(connectionSettings.Name, out connection)) { connection = new ImageOptimizationEFDataConnection(connectionSettings.Name, connectionSettings.ConnectionString, dataProvider); ImageOptimizationEFDataConnection.connections.Add(connectionSettings.Name, connection); } } } return(connection); }
/// <summary> /// Initializes a new instance of the <see cref="ImageOptimizationEFDataConnection" /> class. /// </summary> /// <param name="connectionName">Name of the connection.</param> /// <param name="connectionString">The connection string.</param> /// <param name="dataProvider">The data provider.</param> private ImageOptimizationEFDataConnection(string connectionName, string connectionString, IImageOptimizationEFDataProvider dataProvider) { this.connectionName = connectionName; this.connectionString = connectionString; this.dataProvider = dataProvider; }
/// <summary> /// Gets the scope id. /// </summary> /// <param name="provider">The data provider.</param> /// <returns></returns> private string GetScopeId(IImageOptimizationEFDataProvider provider) { return(provider.ProviderContext.ProviderKey); }