Пример #1
0
        protected DbDataProvider(string connectionString, string providerName)
        {
            if (String.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException("connectionString");
            }

            ConnectionString = connectionString;

            if (String.IsNullOrEmpty(providerName))
            {
                throw new ArgumentNullException("providerName");
            }

            DbDataProviderName = providerName;

            // TODO: Schema is specific to SQL Server?
            Schema = new DatabaseSchema();

            InterceptionStrategy = new DynamicProxyInterceptionStrategy(this);
        }
        private static void EnsureControlCollectionIntercepted(IApplicationContext defaultApplicationContext, Control control)
        {
            // check the collection
            ControlAccessor   ctlAccessor   = new ControlAccessor(control);
            ControlCollection childControls = ctlAccessor.Controls;

            if (IsDependencyInjectionAware(defaultApplicationContext, childControls))
            {
                return; // nothing more to do
            }

            // check, if the collection's owner has already been intercepted
            ControlCollectionAccessor ctlColAccessor = new ControlCollectionAccessor(childControls);

            if (IsDependencyInjectionAware(defaultApplicationContext, ctlColAccessor.Owner))
            {
                return; // nothing more to do
            }

            // lookup strategy in cache
            IInterceptionStrategy strategy = null;

            lock (s_cachedInterceptionStrategies)
            {
                strategy = (IInterceptionStrategy)s_cachedInterceptionStrategies[control.GetType()];
            }

            if (strategy != null)
            {
                strategy.Intercept(defaultApplicationContext, ctlAccessor, ctlColAccessor);
            }
            else
            {
                // nothing in cache - try well-known strategies for owner resp. child collection type
                strategy = (IInterceptionStrategy)s_knownInterceptionStrategies[control.GetType()];
                if (strategy == null)
                {
                    strategy = (IInterceptionStrategy)s_knownInterceptionStrategies[childControls.GetType()];
                }

                // try intercept using well-known strategy
                if (strategy != null)
                {
                    bool bOk = strategy.Intercept(defaultApplicationContext, ctlAccessor, ctlColAccessor);
                    if (!bOk)
                    {
                        strategy = null;
                    }
                }

                // not well-known or didn't work out
                if (strategy == null)
                {
                    // probe for a strategy
                    bool bOk = false;
                    for (int i = 0; i < s_availableInterceptionStrategies.Length; i++)
                    {
                        strategy = s_availableInterceptionStrategies[i];
                        bOk      = strategy.Intercept(defaultApplicationContext, ctlAccessor, ctlColAccessor);
                        if (bOk)
                        {
                            break;
                        }
                    }
                    if (!bOk)
                    {
                        LogManager.GetLogger(typeof(ControlInterceptor)).Warn(string.Format("dependency injection not supported for control type {0}", ctlAccessor.GetTarget().GetType()));
                        strategy = s_noopInterceptionStrategy;
                    }
                }

                lock (s_cachedInterceptionStrategies)
                {
                    s_cachedInterceptionStrategies[control.GetType()] = strategy;
                }
            }
        }