Beispiel #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);
        }
Beispiel #2
0
 internal static void CheckVirtualFileExists(VirtualPath virtualPath)
 {
     if (!virtualPath.FileExists())
     {
         throw new HttpException(0x194, System.Web.SR.GetString("FileName_does_not_exist", new object[] { virtualPath.VirtualPathString }));
     }
 }
Beispiel #3
0
        internal static bool VirtualFileExistsWithAssert(VirtualPath virtualPath)
        {
            string path = virtualPath.MapPathInternal();

            if (path != null)
            {
                InternalSecurityPermissions.PathDiscovery(path).Assert();
            }
            return(virtualPath.FileExists());
        }
        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 static bool VirtualFileExistsWithAssert(VirtualPath virtualPath) {
        string physicalDir = virtualPath.MapPathInternal();

        if (physicalDir != null) {
            (InternalSecurityPermissions.PathDiscovery(physicalDir)).Assert();
        }

        return virtualPath.FileExists();
    }
 internal static void CheckVirtualFileExists(VirtualPath virtualPath) {
     if (!virtualPath.FileExists()) {
         throw new HttpException(
             HttpStatus.NotFound,
             SR.GetString(SR.FileName_does_not_exist,
                 virtualPath.VirtualPathString));
     }
 }
        private BuildResult GetVPathBuildResultInternal(VirtualPath virtualPath, bool noBuild, bool allowCrossApp, bool allowBuildInPrecompile, bool throwIfNotFound, bool ensureIsUpToDate = true) {

            Debug.Trace("BuildManager", "GetBuildResult(" + virtualPath + ")");

            // This should never be called while building top level files (VSWhidbey 480256)
            if (_compilationStage == CompilationStage.TopLevelFiles) {
                throw new HttpException(SR.GetString(SR.Too_early_for_webfile, virtualPath));
            }

            // Make sure the path is not relative
            Debug.Assert(!virtualPath.IsRelative);

            // Try the cache first before getting the mutex
            BuildResult result = GetVPathBuildResultFromCacheInternal(virtualPath, ensureIsUpToDate);
            if (result != null)
                return result;

            // If we were only checking the cache and it wasn't there, return null.
            if (noBuild)
                return null;

            // Check if it's trying to go cross app, or points to a special directory.
            // It's important to do this before checkin existence, to avoid revealing information
            // about other apps (VSWhidbey 442632)
            ValidateVirtualPathInternal(virtualPath, allowCrossApp, false /*codeFile*/);

            if (throwIfNotFound) {
                // Before grabbing the lock, make sure the file at least exists (ASURT 46465)
                Util.CheckVirtualFileExists(virtualPath);
            }
            else if (!virtualPath.FileExists()) {
                return null;
            }

            // If this is a precompiled app, complain if we couldn't find it in the cache
            if (IsNonUpdatablePrecompiledApp && !allowBuildInPrecompile) {
                throw new HttpException(
                    SR.GetString(SR.Cant_update_precompiled_app, virtualPath));
            }

            bool gotLock = false;

            try {
                // Grab the compilation mutex
                CompilationLock.GetLock(ref gotLock);

                // Check the cache a second time after getting the mutex
                result = GetVPathBuildResultFromCacheInternal(virtualPath, ensureIsUpToDate);
                if (result != null)
                    return result;

                // Get the circular reference checker (create it if needed)
                VirtualPathSet circularReferenceChecker;
                circularReferenceChecker = CallContext.GetData(CircularReferenceCheckerSlotName)
                    as VirtualPathSet;
                if (circularReferenceChecker == null) {
                    circularReferenceChecker = new VirtualPathSet();

                    // Create it and save it in the CallContext
                    CallContext.SetData(CircularReferenceCheckerSlotName, circularReferenceChecker);
                }

                // If a circular reference is detected, throw an error
                if (circularReferenceChecker.Contains(virtualPath)) {
                    throw new HttpException(
                        SR.GetString(SR.Circular_include));
                }

                // Add the current virtualPath to the circular reference checker
                circularReferenceChecker.Add(virtualPath);

                try {
                    // 
                    EnsureTopLevelFilesCompiled();
                    result = CompileWebFile(virtualPath);
                }
                finally {
                    // Remove the current virtualPath from the circular reference checker
                    Debug.Assert(circularReferenceChecker.Contains(virtualPath));
                    circularReferenceChecker.Remove(virtualPath);
                }
            }
            finally {
                // Always release the mutex if we had taken it
                if (gotLock) {
                    CompilationLock.ReleaseLock();
                }
            }

            return result;
        }