Ejemplo n.º 1
0
        /// <summary>
        /// Provide an instance of the configured provider
        /// </summary>
        /// <returns></returns>
        public static void GetInstance(IFileSystemProvidee provi)
        {
            String assemblyPath = ConfigurationSettings.AppSettings["FileSystemProviderAssemblyPath"];
            String classStr     = ConfigurationSettings.AppSettings["FileSystemProviderClassName"];

            string[] tokens = classStr.Split(";".ToCharArray());
            string   cparam;
            string   className = tokens[0];

            if (tokens.Length > 1)
            {
                cparam = tokens[1];
            }
            else
            {
                cparam = null;
            }

            //use the cache because the reflection used later is expensive
            if (Globals.Context == null)
            {
                if (m_instance == null)
                {
                    provi.Acquire((m_instance = LoadFromAssembly(assemblyPath, className, cparam)));
                }
                else
                {
                    provi.Acquire(m_instance);
                }
            }
            else
            {
                //use the cache because the reflection used later is expensive
                Cache cache = Globals.Context.Cache;

                if (null == cache["IFileSystemProvider"])
                {
                    // 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 {
                        IFileSystemProvider fs = LoadFromAssembly(assemblyPath, className, cparam);
                        cache.Insert("IFileSystemProvider", fs, 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((IFileSystemProvider)(cache["IFileSystemProvider"]));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Provide an instance of the configured provider
        /// </summary>
        /// <returns></returns>
        public static void GetInstance(IFileSystemProvidee provi)
        {
            String assemblyPath = ConfigurationSettings.AppSettings["FileSystemProviderAssemblyPath"];
            String classStr = ConfigurationSettings.AppSettings["FileSystemProviderClassName"];

            string[] tokens = classStr.Split(";".ToCharArray());
            string cparam;
            string className = tokens[0];
            if (tokens.Length > 1)
                cparam = tokens[1];
            else
                cparam = null;

            //use the cache because the reflection used later is expensive
            if (Globals.Context == null) {
                if (m_instance == null)
                    provi.Acquire((m_instance = LoadFromAssembly(assemblyPath, className, cparam)));
                else
                    provi.Acquire(m_instance);
            }
            else {
                //use the cache because the reflection used later is expensive
                Cache cache = Globals.Context.Cache;

                if (null == cache["IFileSystemProvider"]) {

                    // 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 {
                        IFileSystemProvider fs = LoadFromAssembly(assemblyPath, className, cparam);
                        cache.Insert("IFileSystemProvider", fs, 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((IFileSystemProvider)(cache["IFileSystemProvider"]));
            }
        }