Example #1
0
        internal static Type GetBrowserCapabilitiesType()
        {
            InternalSecurityPermissions.Unrestricted.Assert();
            BuildResult buildResultFromCache = null;

            try
            {
                buildResultFromCache = BuildManager.GetBuildResultFromCache("__browserCapabilitiesCompiler");
                if (buildResultFromCache == null)
                {
                    DateTime         utcNow    = DateTime.UtcNow;
                    VirtualDirectory directory = AppBrowsersVirtualDir.GetDirectory();
                    string           path      = HostingEnvironment.MapPathInternal(AppBrowsersVirtualDir);
                    if ((directory != null) && Directory.Exists(path))
                    {
                        ArrayList list  = new ArrayList();
                        ArrayList list2 = new ArrayList();
                        if (AddBrowserFilesToList(directory, list, false))
                        {
                            AddBrowserFilesToList(directory, list2, true);
                        }
                        else
                        {
                            list2 = list;
                        }
                        if (list2.Count > 0)
                        {
                            ApplicationBrowserCapabilitiesBuildProvider o = new ApplicationBrowserCapabilitiesBuildProvider();
                            foreach (string str2 in list)
                            {
                                o.AddFile(str2);
                            }
                            BuildProvidersCompiler compiler = new BuildProvidersCompiler(null, BuildManager.GenerateRandomAssemblyName("App_Browsers"));
                            compiler.SetBuildProviders(new SingleObjectCollection(o));
                            buildResultFromCache = new BuildResultCompiledType(compiler.PerformBuild().CompiledAssembly.GetType("ASP.ApplicationBrowserCapabilitiesFactory"))
                            {
                                VirtualPath = AppBrowsersVirtualDir
                            };
                            buildResultFromCache.AddVirtualPathDependencies(list2);
                            BuildManager.CacheBuildResult("__browserCapabilitiesCompiler", buildResultFromCache, utcNow);
                        }
                    }
                }
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
            if (buildResultFromCache == null)
            {
                return(_browserCapabilitiesFactoryBaseType);
            }
            return(((BuildResultCompiledType)buildResultFromCache).ResultType);
        }
        internal static Type GetBrowserCapabilitiesType() {

            //Need to assert here to check directories and files
            InternalSecurityPermissions.Unrestricted.Assert();

            BuildResult result = null;

            try {
                // Try the cache first, and if it's not there, compile it
                result = BuildManager.GetBuildResultFromCache(browerCapabilitiesCacheKey);
                if (result == null) {
                    DateTime utcStart = DateTime.UtcNow;

                    VirtualDirectory directory = AppBrowsersVirtualDir.GetDirectory();

                    // first try if app browser dir exists
                    string physicalDir = HostingEnvironment.MapPathInternal(AppBrowsersVirtualDir);

                    /* DevDivBugs 173531
                     * For the App_Browsers scenario, we need to cache the generated browser caps processing 
                     * code. We need to add path dependency on all files so that changes to them will 
                     * invalidate the cache entry and cause recompilation. */
                    if (directory != null && Directory.Exists(physicalDir)) {
                        ArrayList browserFileList = new ArrayList();
                        ArrayList browserFileDependenciesList = new ArrayList();
                        bool hasCustomCaps = AddBrowserFilesToList(directory, browserFileList, false);
                        if (hasCustomCaps) {
                            AddBrowserFilesToList(directory, browserFileDependenciesList, true);
                        }
                        else {
                            browserFileDependenciesList = browserFileList;
                        }

                        if (browserFileDependenciesList.Count > 0) {
                            ApplicationBrowserCapabilitiesBuildProvider buildProvider = new ApplicationBrowserCapabilitiesBuildProvider();
                            foreach (string virtualPath in browserFileList) {
                                buildProvider.AddFile(virtualPath);
                            }
                            
                            BuildProvidersCompiler bpc = new BuildProvidersCompiler(null /*configPath*/,
                                BuildManager.GenerateRandomAssemblyName(BuildManager.AppBrowserCapAssemblyNamePrefix));
                            
                            bpc.SetBuildProviders(new SingleObjectCollection(buildProvider));
                            CompilerResults results = bpc.PerformBuild();
                            Assembly assembly = results.CompiledAssembly;
                            // Get the type we want from the assembly
                            Type t = assembly.GetType(
                                BaseCodeDomTreeGenerator.defaultNamespace + "." + ApplicationBrowserCapabilitiesCodeGenerator.FactoryTypeName);
                            // Cache it for next time
                            result = new BuildResultCompiledType(t);
                            result.VirtualPath = AppBrowsersVirtualDir;
                            result.AddVirtualPathDependencies(browserFileDependenciesList);

                            BuildManager.CacheBuildResult(browerCapabilitiesCacheKey, result, utcStart);
                        }
                    }
                }
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }

            // Simply return the global factory type.
            if (result == null)
                return _browserCapabilitiesFactoryBaseType;

            // Return the compiled type
            return ((BuildResultCompiledType)result).ResultType;
        }
        internal static Type GetBrowserCapabilitiesType()
        {
            //Need to assert here to check directories and files
            InternalSecurityPermissions.Unrestricted.Assert();

            BuildResult result = null;

            try {
                // Try the cache first, and if it's not there, compile it
                result = BuildManager.GetBuildResultFromCache(browerCapabilitiesCacheKey);
                if (result == null)
                {
                    DateTime utcStart = DateTime.UtcNow;

                    VirtualDirectory directory = AppBrowsersVirtualDir.GetDirectory();

                    // first try if app browser dir exists
                    string physicalDir = HostingEnvironment.MapPathInternal(AppBrowsersVirtualDir);

                    /* DevDivBugs 173531
                     * For the App_Browsers scenario, we need to cache the generated browser caps processing
                     * code. We need to add path dependency on all files so that changes to them will
                     * invalidate the cache entry and cause recompilation. */
                    if (directory != null && Directory.Exists(physicalDir))
                    {
                        ArrayList browserFileList             = new ArrayList();
                        ArrayList browserFileDependenciesList = new ArrayList();
                        bool      hasCustomCaps = AddBrowserFilesToList(directory, browserFileList, false);
                        if (hasCustomCaps)
                        {
                            AddBrowserFilesToList(directory, browserFileDependenciesList, true);
                        }
                        else
                        {
                            browserFileDependenciesList = browserFileList;
                        }

                        if (browserFileDependenciesList.Count > 0)
                        {
                            ApplicationBrowserCapabilitiesBuildProvider buildProvider = new ApplicationBrowserCapabilitiesBuildProvider();
                            foreach (string virtualPath in browserFileList)
                            {
                                buildProvider.AddFile(virtualPath);
                            }

                            BuildProvidersCompiler bpc = new BuildProvidersCompiler(null /*configPath*/,
                                                                                    BuildManager.GenerateRandomAssemblyName(BuildManager.AppBrowserCapAssemblyNamePrefix));

                            bpc.SetBuildProviders(new SingleObjectCollection(buildProvider));
                            CompilerResults results  = bpc.PerformBuild();
                            Assembly        assembly = results.CompiledAssembly;
                            // Get the type we want from the assembly
                            Type t = assembly.GetType(
                                BaseCodeDomTreeGenerator.defaultNamespace + "." + ApplicationBrowserCapabilitiesCodeGenerator.FactoryTypeName);
                            // Cache it for next time
                            result             = new BuildResultCompiledType(t);
                            result.VirtualPath = AppBrowsersVirtualDir;
                            result.AddVirtualPathDependencies(browserFileDependenciesList);

                            BuildManager.CacheBuildResult(browerCapabilitiesCacheKey, result, utcStart);
                        }
                    }
                }
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }

            // Simply return the global factory type.
            if (result == null)
            {
                return(_browserCapabilitiesFactoryBaseType);
            }

            // Return the compiled type
            return(((BuildResultCompiledType)result).ResultType);
        }
 internal static Type GetBrowserCapabilitiesType()
 {
     InternalSecurityPermissions.Unrestricted.Assert();
     BuildResult buildResultFromCache = null;
     try
     {
         buildResultFromCache = BuildManager.GetBuildResultFromCache("__browserCapabilitiesCompiler");
         if (buildResultFromCache == null)
         {
             DateTime utcNow = DateTime.UtcNow;
             VirtualDirectory directory = AppBrowsersVirtualDir.GetDirectory();
             string path = HostingEnvironment.MapPathInternal(AppBrowsersVirtualDir);
             if ((directory != null) && Directory.Exists(path))
             {
                 ArrayList list = new ArrayList();
                 ArrayList list2 = new ArrayList();
                 if (AddBrowserFilesToList(directory, list, false))
                 {
                     AddBrowserFilesToList(directory, list2, true);
                 }
                 else
                 {
                     list2 = list;
                 }
                 if (list2.Count > 0)
                 {
                     ApplicationBrowserCapabilitiesBuildProvider o = new ApplicationBrowserCapabilitiesBuildProvider();
                     foreach (string str2 in list)
                     {
                         o.AddFile(str2);
                     }
                     BuildProvidersCompiler compiler = new BuildProvidersCompiler(null, BuildManager.GenerateRandomAssemblyName("App_Browsers"));
                     compiler.SetBuildProviders(new SingleObjectCollection(o));
                     buildResultFromCache = new BuildResultCompiledType(compiler.PerformBuild().CompiledAssembly.GetType("ASP.ApplicationBrowserCapabilitiesFactory")) {
                         VirtualPath = AppBrowsersVirtualDir
                     };
                     buildResultFromCache.AddVirtualPathDependencies(list2);
                     BuildManager.CacheBuildResult("__browserCapabilitiesCompiler", buildResultFromCache, utcNow);
                 }
             }
         }
     }
     finally
     {
         CodeAccessPermission.RevertAssert();
     }
     if (buildResultFromCache == null)
     {
         return _browserCapabilitiesFactoryBaseType;
     }
     return ((BuildResultCompiledType) buildResultFromCache).ResultType;
 }