Example #1
0
        internal static BuildResultCompiledGlobalAsaxType GetGlobalAsaxBuildResult(bool isPrecompiledApp)
        {
            string cacheKey = "App_global.asax";
            BuildResultCompiledGlobalAsaxType buildResultFromCache = BuildManager.GetBuildResultFromCache(cacheKey) as BuildResultCompiledGlobalAsaxType;

            if (buildResultFromCache == null)
            {
                if (isPrecompiledApp)
                {
                    return(null);
                }
                VirtualPath globalAsaxVirtualPath = BuildManager.GlobalAsaxVirtualPath;
                if (!globalAsaxVirtualPath.FileExists())
                {
                    return(null);
                }
                ApplicationBuildProvider o = new ApplicationBuildProvider();
                o.SetVirtualPath(globalAsaxVirtualPath);
                DateTime utcNow = DateTime.UtcNow;
                BuildProvidersCompiler compiler = new BuildProvidersCompiler(globalAsaxVirtualPath, BuildManager.GenerateRandomAssemblyName("App_global.asax"));
                compiler.SetBuildProviders(new SingleObjectCollection(o));
                CompilerResults results = compiler.PerformBuild();
                buildResultFromCache = (BuildResultCompiledGlobalAsaxType)o.GetBuildResult(results);
                buildResultFromCache.CacheToMemory = false;
                BuildManager.CacheBuildResult(cacheKey, buildResultFromCache, utcNow);
            }
            return(buildResultFromCache);
        }
 internal override BuildResultCompiledType CreateBuildResult(Type t)
 {
     BuildResultCompiledGlobalAsaxType type = new BuildResultCompiledGlobalAsaxType(t);
     if ((base.Parser.ApplicationObjects != null) || (base.Parser.SessionObjects != null))
     {
         type.HasAppOrSessionObjects = true;
     }
     return type;
 }
    internal override BuildResultCompiledType CreateBuildResult(Type t) {
        BuildResultCompiledGlobalAsaxType result = new BuildResultCompiledGlobalAsaxType(t);

        // If global.asax contains <object> tags, set a flag to avoid doing useless work
        // later on in HttpApplicationFactory (VSWhidbey 453101)
        if (Parser.ApplicationObjects != null || Parser.SessionObjects != null)
            result.HasAppOrSessionObjects = true;

        return result;
    }
Example #4
0
        internal override BuildResultCompiledType CreateBuildResult(Type t)
        {
            BuildResultCompiledGlobalAsaxType type = new BuildResultCompiledGlobalAsaxType(t);

            if ((base.Parser.ApplicationObjects != null) || (base.Parser.SessionObjects != null))
            {
                type.HasAppOrSessionObjects = true;
            }
            return(type);
        }
        internal static BuildResultCompiledGlobalAsaxType GetGlobalAsaxBuildResult(bool isPrecompiledApp)
        {
            string cacheKey = BuildManager.GlobalAsaxAssemblyName;

            // Try the cache first, and if it's not there, compile it
            BuildResultCompiledGlobalAsaxType result = BuildManager.GetBuildResultFromCache(cacheKey) as
                                                       BuildResultCompiledGlobalAsaxType;

            if (result != null)
            {
                return(result);
            }

            // If this is a precompiled app don't attempt to compile it
            if (isPrecompiledApp)
            {
                return(null);
            }

            VirtualPath virtualPath = BuildManager.GlobalAsaxVirtualPath;

            // If global.asax doesn't exist, just ignore it
            if (!virtualPath.FileExists())
            {
                return(null);
            }

            // Compile global.asax
            ApplicationBuildProvider buildProvider = new ApplicationBuildProvider();

            buildProvider.SetVirtualPath(virtualPath);

            DateTime utcStart = DateTime.UtcNow;

            BuildProvidersCompiler bpc = new BuildProvidersCompiler(virtualPath /*configPath*/,
                                                                    BuildManager.GenerateRandomAssemblyName(BuildManager.GlobalAsaxAssemblyName));

            // Set the BuildProvider using a single item collection
            bpc.SetBuildProviders(new SingleObjectCollection(buildProvider));

            CompilerResults results = bpc.PerformBuild();

            result = (BuildResultCompiledGlobalAsaxType)buildProvider.GetBuildResult(results);

            // Top level assembliy should not be cached to memory.
            result.CacheToMemory = false;

            // Cache it for next time
            BuildManager.CacheBuildResult(cacheKey, result, utcStart);

            // Return the compiled type
            return(result);
        }
        internal override BuildResultCompiledType CreateBuildResult(Type t)
        {
            BuildResultCompiledGlobalAsaxType result = new BuildResultCompiledGlobalAsaxType(t);

            // If global.asax contains <object> tags, set a flag to avoid doing useless work
            // later on in HttpApplicationFactory (VSWhidbey 453101)
            if (Parser.ApplicationObjects != null || Parser.SessionObjects != null)
            {
                result.HasAppOrSessionObjects = true;
            }

            return(result);
        }
        internal static BuildResult CreateBuildResultFromCode(BuildResultTypeCode code, System.Web.VirtualPath virtualPath)
        {
            BuildResult result = null;

            switch (code)
            {
            case BuildResultTypeCode.BuildResultCompiledAssembly:
                result = new BuildResultCompiledAssembly();
                break;

            case BuildResultTypeCode.BuildResultCompiledType:
                result = new BuildResultCompiledType();
                break;

            case BuildResultTypeCode.BuildResultCompiledTemplateType:
                result = new BuildResultCompiledTemplateType();
                break;

            case BuildResultTypeCode.BuildResultCustomString:
                result = new BuildResultCustomString();
                break;

            case BuildResultTypeCode.BuildResultMainCodeAssembly:
                result = new BuildResultMainCodeAssembly();
                break;

            case BuildResultTypeCode.BuildResultCodeCompileUnit:
                result = new BuildResultCodeCompileUnit();
                break;

            case BuildResultTypeCode.BuildResultCompiledGlobalAsaxType:
                result = new BuildResultCompiledGlobalAsaxType();
                break;

            case BuildResultTypeCode.BuildResultResourceAssembly:
                result = new BuildResultResourceAssembly();
                break;

            default:
                return(null);
            }
            result.VirtualPath        = virtualPath;
            result._nextUpToDateCheck = DateTime.MinValue;
            return(result);
        }
        private void CompileGlobalAsax() {
            _globalAsaxBuildResult = ApplicationBuildProvider.GetGlobalAsaxBuildResult(IsPrecompiledApp);

            // Make sure that global.asax notifications are set up (VSWhidbey 267245)
            HttpApplicationFactory.SetupFileChangeNotifications();

            if (_globalAsaxBuildResult != null) {

                // We need to add not only the global.asax type, but also its parent types to
                // the top level assembly list.  This can happen when global.asax has a 'src'
                // attribute pointing to a source file containing its base type.
                Type type = _globalAsaxBuildResult.ResultType;
                while (type.Assembly != typeof(HttpRuntime).Assembly) {
                    _topLevelReferencedAssemblies.Add(type.Assembly);
                    type = type.BaseType;
                }
            }
        }
    #pragma warning restore 0649

    internal static BuildResult CreateBuildResultFromCode(BuildResultTypeCode code,
        VirtualPath virtualPath) {

        BuildResult ret = null;

        switch (code) {
            case BuildResultTypeCode.BuildResultCompiledAssembly:
                ret = new BuildResultCompiledAssembly();
                break;

            case BuildResultTypeCode.BuildResultCompiledType:
                ret = new BuildResultCompiledType();
                break;

            case BuildResultTypeCode.BuildResultCompiledTemplateType:
                ret = new BuildResultCompiledTemplateType();
                break;

            case BuildResultTypeCode.BuildResultCompiledGlobalAsaxType:
                ret = new BuildResultCompiledGlobalAsaxType();
                break;

            case BuildResultTypeCode.BuildResultCustomString:
                ret = new BuildResultCustomString();
                break;

            case BuildResultTypeCode.BuildResultMainCodeAssembly:
                ret = new BuildResultMainCodeAssembly();
                break;

            case BuildResultTypeCode.BuildResultResourceAssembly:
                ret = new BuildResultResourceAssembly();
                break;

            case BuildResultTypeCode.BuildResultCodeCompileUnit:
                ret = new BuildResultCodeCompileUnit();
                break;

            default:
                Debug.Assert(false, "code=" + code);
                return null;
        }

        ret.VirtualPath = virtualPath;

        // Set _nextUpToDateCheck to MinValue, to make sure the next call to IsUpToDate()
        // actually makes the check
        ret._nextUpToDateCheck = DateTime.MinValue;

        return ret;
    }