Пример #1
0
        /// <summary>
        /// Creates and Caches the ConstructorInfo for the specified provider. 
        /// </summary>
        public static ConstructorInfo CreateConstructorInfo(Provider dataProvider)
        {
            // The assembly should be in \bin or GAC, so we simply need
            // to get an instance of the type
            //
            CSConfiguration config = CSConfiguration.GetConfig();
            ConstructorInfo providerCnstr = null;
            try
            {
                //string providerTypeName = ((Provider) config.Providers[providerName]).Type;
                Type type  = Type.GetType( dataProvider.Type );

                // Insert the type into the cache
                //
                Type[] paramTypes = new Type[2];
                paramTypes[0] = typeof(string);
                paramTypes[1] = typeof(string);

                providerCnstr = type.GetConstructor(paramTypes);

            }
            catch
            {
                ProviderException(dataProvider.Name);
            }

               if(providerCnstr == null)
               ProviderException(dataProvider.Name);

            return providerCnstr;
        }
Пример #2
0
 public static CommonDataProvider Instance(Provider dataProvider)
 {
     CommonDataProvider fdp = CSCache.Get(dataProvider.Name) as CommonDataProvider;
     if(fdp == null)
     {
         fdp = DataProviders.Invoke(dataProvider) as CommonDataProvider;
         CSCache.Max(dataProvider.Name,fdp);
     }
     return fdp;
 }
Пример #3
0
        /// <summary>
        /// Creates an instance of the provider using Activator. This instance should be
        /// cached since it is an expesivie operation
        /// </summary>
        public static object CreateInstance(Provider dataProvider, params object[] args )
        {
            //Get the type
            Type type  = Type.GetType(dataProvider.Type);

            object newObject = null;
            if(type != null)
            {
                if(args != null)
                    newObject = Activator.CreateInstance(type, args);
                else
                    newObject = Activator.CreateInstance(type);
            }

            if(newObject == null) //If we can not create an instance, throw an exception
                ProviderException(dataProvider.Name);

            return newObject;
        }
Пример #4
0
        public static ExtensionModule Instance(Provider provider)
        {
            try
            {
                if(provider == null)
                    return null;

                // Use the cache because the reflection used later is expensive
                //
                string cacheKey = "Module-" + provider.Name;
                ConstructorInfo constructor = CSCache.Get(cacheKey) as ConstructorInfo;
                ExtensionModule module = null;

                // Is the module already cached?
                //
                if(constructor == null)
                {
                    Type type = Type.GetType( provider.Type );

                    if(type == null)
                        return null;

                    constructor = type.GetConstructor(Type.EmptyTypes);

                    // Insert the type into the cache
                    //
                    CSCache.Max(cacheKey, constructor); //Did not have a cache time specified
                }

                module = (ExtensionModule)constructor.Invoke(null);

                // Initialize the module for the request
                //
                module.Init(provider);

                return module;
            }
            catch
            {
                return null;
            }
        }
Пример #5
0
        /// <summary>
        /// Creates an instance of the provider using Activator. This instance should be
        /// cached since it is an expesivie operation
        /// </summary>
        public static object CreateInstance(Provider dataProvider)
        {
            //Find the current attributes
            string connectionString = null; //dataProvider.Attributes["connectionString"];
            string databaseOwner = null;// dataProvider.Attributes["databaseOwner"];

            GetDataStoreParameters(dataProvider, out connectionString, out databaseOwner);

            //Get the type
            Type type  = Type.GetType(dataProvider.Type);

            object newObject = null;
            if(type != null)
            {
                newObject =  Activator.CreateInstance(type,new object[]{databaseOwner,connectionString});
            }

            if(newObject == null) //If we can not create an instance, throw an exception
                ProviderException(dataProvider.Name);

            return newObject;
        }
Пример #6
0
 /// <summary>
 /// Creates an instance of the provider using Activator. This instance should be
 /// cached since it is an expesivie operation
 /// </summary>
 public static object CreateInstance(Provider dataProvider)
 {
     return CreateInstance(dataProvider, null);
 }
Пример #7
0
 public abstract void Init(Provider provider);
Пример #8
0
        private static void GetDataStoreParameters(Provider dataProvider, out string connectionString, out string databaseOwner)
        {
            databaseOwner = dataProvider.Attributes["databaseOwner"];
            if(databaseOwner == null || databaseOwner.Trim().Length == 0)
                databaseOwner = ConfigurationSettings.AppSettings[dataProvider.Attributes["databaseOwnerStringName"]];

            connectionString = dataProvider.Attributes["connectionString"];
            if(connectionString == null || connectionString.Trim().Length == 0)
                connectionString = ConfigurationSettings.AppSettings[dataProvider.Attributes["connectionStringName"]];
        }
Пример #9
0
        /// <summary>
        /// Creates an instance of the specified provider using the Cached
        /// ConstructorInfo from CreateConstructorInfo
        /// </summary>
        public static object Invoke(Provider dataProvider)
        {
            object[] paramArray = new object[2];

            string dbOwner = null;
            string connstring = null;

            GetDataStoreParameters(dataProvider, out connstring, out dbOwner);

            paramArray[0] = dbOwner;
            paramArray[1] = connstring;

            return CreateConstructorInfo(dataProvider).Invoke(paramArray);
        }