Ejemplo n.º 1
0
        /*=========================*/
        #endregion

        #region Provider registration
        /*=========================*/

        /// <summary>
        ///
        /// </summary>
        /// <param name="providerName"></param>
        /// <param name="provider"></param>
        public static void RegisterProvider(PersistenceProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            string providerName = provider.Name;

            if (String.IsNullOrWhiteSpace(providerName) || providerName.IndexOf(PersistenceConnection.ConnectionNameSeparator) >= 0)
            {
                throw new ArgumentException("Provider name cannot be empty and cannot contain the '" + PersistenceConnection.ConnectionNameSeparator + "' character.", "provider");
            }

            // EXCEPTION:
            if (_registeredProviders.ContainsKey(providerName))
            {
                throw new Exception(String.Format("A provider is already registered with the name '{0}'.", providerName));
            }

            lock (_registeredProviders)
            {
                _registeredProviders.Add(providerName, provider);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="providerName"></param>
        /// <param name="threadLocal"></param>
        /// <returns>A new connection object if one was created, otherwise null if the specified connection was already open.</returns>
        public static PersistenceConnection Connect(string providerName, string connectionName = null, bool threadLocal = true)
        {
            PersistenceProvider provider = GetOrThrow(providerName);

            // Get the requested connection lists
            PersistenceConnectionManager connections;

            if (!threadLocal)
            {
                connections = _globalConnections;
            }
            else
            {
                if (_localConnections == null)
                {
                    _localConnections = new PersistenceConnectionManager(true);
                }

                connections = _localConnections;
            }

            PersistenceConnection conn = connections.SwitchTo(provider, connectionName);

            // If it's not open, open it and return it, otherwise return null
            if (!conn.IsOpen)
            {
                conn.Open();
                return(conn);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="providerName"></param>
        public static void ForceClose(string providerName, string connectionName = null)
        {
            PersistenceProvider provider = GetOrThrow(providerName);

            PersistenceConnection conn = null;

            if (_localConnections != null)
            {
                conn = _localConnections[providerName, connectionName];
            }
            if (conn == null)
            {
                conn = _globalConnections[providerName, connectionName];
            }

            // Close and remove connection
            if (conn != null)
            {
                if (conn.IsOpen)
                {
                    Close(conn);
                }

                _localConnections.Remove(conn);
            }
        }
 void IDisposable.Dispose()
 {
     if (IsOpen)
     {
         PersistenceProvider.Close(this);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="provider"></param>
 public static void UnregisterProvider(PersistenceProvider provider)
 {
     lock (_registeredProviders)
     {
         _registeredProviders.Remove(provider.Name);
     }
 }
        public static void Register(string providerName, PersistenceProvider provider)
        {
            // EXCEPTION:
            if (_registeredProviders.ContainsKey(providerName))
            {
                throw new Exception("A provider is already registered under this name.");
            }

            _registeredProviders.Add(providerName, provider);
        }
        public PersistenceProvider(PersistenceProvider provider, PersistenceProviderConfiguration configuration)
        {
            // Check required attribute
            object[] attr = this.GetType().GetCustomAttributes(typeof(RequiresCustomSettingsAttribute), true);
            if (attr.Length > 0)
            {
                RequiresCustomSettingsAttribute attribute = (RequiresCustomSettingsAttribute)attr[0];
                foreach (string setting in attribute.RequiredSettings)
                {
                    // EXCEPTION:
                    if (!configuration.CustomSettings.ContainsKey(setting))
                    {
                        throw new ConfigurationErrorsException(String.Format("The custom configuration setting {0} is required.", setting));
                    }
                }
            }

            Configuration = configuration;
        }
Ejemplo n.º 8
0
        public PersistenceConnection SwitchTo(PersistenceProvider provider, string connectionName)
        {
            int index = IndexOf(provider.Name, connectionName);

            // Connection is already at top of stack
            //if (index == 0)
            //	return;

            // Either reuse an existing or create a new connection
            PersistenceConnection connection = index < 0 ?
                                               connection = provider.NewConnection(connectionName, _threadLocal) :
                                                            connection = _connections[index];

            if (index != 0)
            {
                SwitchTo(connection);
            }

            return(connection);
        }
Ejemplo n.º 9
0
 protected override void OnExecute(PersistenceProvider provider)
 {
     //if (!(provider is SqlServerPersistenceProvider))
     //	throw new NotSupportedException("This command can only be executed using a SqlServerPersistenceProvider.");
 }
Ejemplo n.º 10
0
 protected virtual void OnExecute(PersistenceProvider provider)
 {
 }
        /*=========================*/
        #endregion

        #region Constructors
        /*=========================*/

        internal protected PersistenceConnection(PersistenceProvider provider)
        {
            Provider = provider;
        }