示例#1
0
        /// <summary>
        /// Provide an instance of the configured provider
        /// </summary>
        public static void GetInstance(IProvidee provi)
        {
            String assemblyPath = ConfigurationSettings.AppSettings["DataProviderAssemblyPath"];
            String className    = ConfigurationSettings.AppSettings["DataProviderClassName"];

            //use the cache because the reflection used later is expensive
            if (Globals.Context == null)
            {
                if (m_instance == null)
                {
                    provi.Acquire((m_instance = (IDataProvider)Assembly.LoadFrom(
                                       assemblyPath).GetType(className).GetConstructor(new Type[0]).Invoke(null)));
                }
                else
                {
                    provi.Acquire(m_instance);
                }
            }
            else
            {
                Cache cache = Globals.Context.Cache;
                if (null == cache["IDataProvider"])
                {
                    // assemblyPath presented in virtual form, must convert to physical path
                    assemblyPath = Globals.Context.Server.MapPath(Globals.Context.Request.ApplicationPath + "/bin/" + assemblyPath);

                    // Uuse reflection to store the constructor of the class that implements IWebForumDataProvider
                    try {
                        IDataProvider dp = (IDataProvider)Assembly.LoadFrom(assemblyPath).GetType(
                            className).GetConstructor(new Type[0]).Invoke(null);
                        cache.Insert("IDataProvider", dp, new CacheDependency(assemblyPath));
                    }
                    catch (Exception) {
                        // could not locate DLL file
                        HttpContext.Current.Response.Write("<b>ERROR:</b> Could not locate file: <code>" + assemblyPath + "</code> or could not locate class <code>" + className + "</code> in file.");
                        HttpContext.Current.Response.End();
                    }
                }
                provi.Acquire((IDataProvider)cache["IDataProvider"]);
            }
        }
示例#2
0
        /// <summary>
        /// Provide an instance of the configured provider
        /// </summary>
        public static void GetInstance(IProvidee provi)
        {
            String assemblyPath = ConfigurationSettings.AppSettings["DataProviderAssemblyPath"];
            String className = ConfigurationSettings.AppSettings["DataProviderClassName"];

            //use the cache because the reflection used later is expensive
            if (Globals.Context == null) {
                if (m_instance == null)
                    provi.Acquire((m_instance = (IDataProvider) Assembly.LoadFrom(
                        assemblyPath).GetType(className).GetConstructor(new Type[0]).Invoke(null)));
                else
                    provi.Acquire(m_instance);
            }
            else {
                Cache cache = Globals.Context.Cache;
                if (null == cache["IDataProvider"]) {

                    // assemblyPath presented in virtual form, must convert to physical path
                    assemblyPath = Globals.Context.Server.MapPath(Globals.Context.Request.ApplicationPath + "/bin/" + assemblyPath);

                    // Uuse reflection to store the constructor of the class that implements IWebForumDataProvider
                    try {
                        IDataProvider dp = (IDataProvider) Assembly.LoadFrom(assemblyPath).GetType(
                            className).GetConstructor(new Type[0]).Invoke(null);
                        cache.Insert("IDataProvider", dp, new CacheDependency(assemblyPath));
                    }
                    catch (Exception) {
                        // could not locate DLL file
                        HttpContext.Current.Response.Write("<b>ERROR:</b> Could not locate file: <code>" + assemblyPath + "</code> or could not locate class <code>" + className + "</code> in file.");
                        HttpContext.Current.Response.End();
                    }
                }
                provi.Acquire((IDataProvider)cache["IDataProvider"]);
            }
        }