示例#1
0
        private void RemoveAssemblyAndCleanupDependencies(string assemblyName)
        {
            bool gotLock = false;

            try
            {
                CompilationLock.GetLock(ref gotLock);
                lock (this._dependentAssemblies)
                {
                    this.RemoveAssemblyAndCleanupDependenciesNoLock(assemblyName);
                }
            }
            finally
            {
                if (gotLock)
                {
                    CompilationLock.ReleaseLock();
                }
                DiskBuildResultCache.ShutDownAppDomainIfRequired();
            }
        }
示例#2
0
        private void RemoveAssemblyAndCleanupDependencies(string assemblyName)
        {
            bool gotLock = false;

            try {
                // Grab the compilation mutex, since we will remove cached build result
                CompilationLock.GetLock(ref gotLock);

                // Protect the dependent assemblies table, as it's accessed/modified in the recursion
                lock (_dependentAssemblies) {
                    RemoveAssemblyAndCleanupDependenciesNoLock(assemblyName);
                }
            }
            finally {
                // Always release the mutex if we had taken it
                if (gotLock)
                {
                    CompilationLock.ReleaseLock();
                }
                DiskBuildResultCache.ShutDownAppDomainIfRequired();
            }
        }
示例#3
0
 internal virtual void RemoveAssemblyAndRelatedFiles(string assemblyName)
 {
     if (assemblyName.StartsWith("App_Web_", StringComparison.Ordinal))
     {
         string str     = assemblyName.Substring("App_Web_".Length);
         bool   gotLock = false;
         try
         {
             CompilationLock.GetLock(ref gotLock);
             DirectoryInfo info = new DirectoryInfo(this._cacheDir);
             foreach (FileInfo info2 in info.GetFiles("*" + str + ".*"))
             {
                 if (info2.Extension == ".dll")
                 {
                     string assemblyCacheKey = BuildResultCache.GetAssemblyCacheKey(info2.FullName);
                     HttpRuntime.CacheInternal.Remove(assemblyCacheKey);
                     RemoveAssembly(info2);
                     StandardDiskBuildResultCache.RemoveSatelliteAssemblies(assemblyName);
                 }
                 else if (info2.Extension == ".delete")
                 {
                     CheckAndRemoveDotDeleteFile(info2);
                 }
                 else
                 {
                     TryDeleteFile(info2);
                 }
             }
         }
         finally
         {
             if (gotLock)
             {
                 CompilationLock.ReleaseLock();
             }
             ShutDownAppDomainIfRequired();
         }
     }
 }
示例#4
0
        /*
         * Delete an assembly and all its related files.  The assembly is typically named
         * something like ASPNET.jnw_y10n.dll, while related files are simply jnw_y10n.*.
         */
        internal virtual void RemoveAssemblyAndRelatedFiles(string assemblyName)
        {
            Debug.Trace("DiskBuildResultCache", "RemoveAssemblyAndRelatedFiles(" + assemblyName + ")");

            // If the name doesn't start with the prefix, the cleanup code doesn't apply
            if (!assemblyName.StartsWith(BuildManager.WebAssemblyNamePrefix, StringComparison.Ordinal))
            {
                return;
            }

            // Get rid of the prefix, since related files don't have it
            string baseName = assemblyName.Substring(BuildManager.WebAssemblyNamePrefix.Length);

            bool gotLock = false;

            try {
                // Grab the compilation mutex, since we will remove generated assembly
                CompilationLock.GetLock(ref gotLock);

                DirectoryInfo directory = new DirectoryInfo(_cacheDir);

                // Find all the files that contain the base name
                FileInfo[] files = directory.GetFiles("*" + baseName + ".*");
                foreach (FileInfo f in files)
                {
                    if (f.Extension == ".dll")
                    {
                        // Notify existing buildresults that result assembly will be removed.
                        // This is required otherwise new components can be compiled
                        // with obsolete build results whose assembly has been removed.
                        string assemblyKey = GetAssemblyCacheKey(f.FullName);
                        HttpRuntime.CacheInternal.Remove(assemblyKey);

                        // Remove the assembly
                        RemoveAssembly(f);

                        // Also, remove satellite assemblies that may be associated with it
                        StandardDiskBuildResultCache.RemoveSatelliteAssemblies(assemblyName);
                    }
                    else if (f.Extension == dotDelete)
                    {
                        CheckAndRemoveDotDeleteFile(f);
                    }
                    else
                    {
                        // Remove the file, or if not possible, rename it, so it'll get
                        // cleaned up next time by RemoveOldTempFiles()

                        TryDeleteFile(f);
                    }
                }
            }
            finally {
                // Always release the mutex if we had taken it
                if (gotLock)
                {
                    CompilationLock.ReleaseLock();
                }
                DiskBuildResultCache.ShutDownAppDomainIfRequired();
            }
        }
        private BuildResult ReadFileInternal(VirtualPath virtualPath, string preservationFile, long hashCode, bool ensureIsUpToDate)
        {
            XmlDocument document = new XmlDocument();

            document.Load(preservationFile);
            this._root = document.DocumentElement;
            if ((this._root == null) || (this._root.Name != "preserve"))
            {
                return(null);
            }
            BuildResultTypeCode code = (BuildResultTypeCode)int.Parse(this.GetAttribute("resultType"), CultureInfo.InvariantCulture);

            if (virtualPath == null)
            {
                virtualPath = VirtualPath.Create(this.GetAttribute("virtualPath"));
            }
            long   num  = 0L;
            string str2 = null;

            if (!this._precompilationMode)
            {
                string attribute = this.GetAttribute("hash");
                if (attribute == null)
                {
                    return(null);
                }
                num  = long.Parse(attribute, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
                str2 = this.GetAttribute("filehash");
            }
            BuildResult result = BuildResult.CreateBuildResultFromCode(code, virtualPath);

            if (!this._precompilationMode)
            {
                this.ReadDependencies();
                if (this._sourceDependencies != null)
                {
                    result.SetVirtualPathDependencies(this._sourceDependencies);
                }
                result.VirtualPathDependenciesHash = str2;
                bool flag = false;
                if (!result.IsUpToDate(virtualPath, ensureIsUpToDate))
                {
                    flag = true;
                }
                else
                {
                    long num2 = result.ComputeHashCode(hashCode);
                    if ((num2 == 0L) || (num2 != num))
                    {
                        flag = true;
                    }
                }
                if (flag)
                {
                    bool gotLock = false;
                    try
                    {
                        CompilationLock.GetLock(ref gotLock);
                        result.RemoveOutOfDateResources(this);
                        File.Delete(preservationFile);
                    }
                    finally
                    {
                        if (gotLock)
                        {
                            CompilationLock.ReleaseLock();
                        }
                    }
                    return(null);
                }
            }
            result.GetPreservedAttributes(this);
            return(result);
        }
        private BuildResult ReadFileInternal(VirtualPath virtualPath, string preservationFile, long hashCode, bool ensureIsUpToDate)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(preservationFile);

            // Get the root element, and make sure it's what we expect
            _root = doc.DocumentElement;
            Debug.Assert(_root != null && _root.Name == "preserve", "_root != null && _root.Name == \"preserve\"");
            if (_root == null || _root.Name != "preserve")
            {
                return(null);
            }

            // Get the type of the BuildResult preserved in this file
            string resultTypeCodeString        = GetAttribute("resultType");
            BuildResultTypeCode resultTypeCode = (BuildResultTypeCode)Int32.Parse(
                resultTypeCodeString, CultureInfo.InvariantCulture);

            // Get the config path that affects this BuildResult if one wasn't passed in.
            // Note that the passed in path may be different with Sharepoint-like ghosting (VSWhidbey 343230)
            if (virtualPath == null)
            {
                virtualPath = VirtualPath.Create(GetAttribute("virtualPath"));
            }

            long   savedHash     = 0;
            string savedFileHash = null;

            // Ignore dependencies in precompilation mode
            if (!_precompilationMode)
            {
                // Read the saved hash from the preservation file
                string hashString = GetAttribute("hash");
                Debug.Assert(hashString != null, "hashString != null");
                if (hashString == null)
                {
                    return(null);
                }

                // Parse the saved hash string as an hex int
                savedHash = Int64.Parse(hashString, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);

                // Read the saved file hash from the preservation file.  This is the hash the represents
                // the state of all the virtual files that the build result depends on.
                savedFileHash = GetAttribute("filehash");
            }

            // Create the BuildResult accordingly
            BuildResult result = BuildResult.CreateBuildResultFromCode(resultTypeCode, virtualPath);

            // Ignore dependencies in precompilation mode
            if (!_precompilationMode)
            {
                ReadDependencies();
                if (_sourceDependencies != null)
                {
                    result.SetVirtualPathDependencies(_sourceDependencies);
                }

                result.VirtualPathDependenciesHash = savedFileHash;

                // Check if the build result is up to date
                bool outOfDate = false;
                if (!result.IsUpToDate(virtualPath, ensureIsUpToDate))
                {
                    Debug.Trace("PreservationFileReader", Path.GetFileName(preservationFile) +
                                " is out of date (IsUpToDate==false)");

                    outOfDate = true;
                }
                else
                {
                    // The virtual paths hash code was up to date, so check the
                    // other hash code.

                    // Get the current hash code
                    long currentHash = result.ComputeHashCode(hashCode);

                    // If the hash doesn't match, the preserved data is out of date
                    if (currentHash == 0 || currentHash != savedHash)
                    {
                        outOfDate = true;
                        Debug.Trace("PreservationFileReader", Path.GetFileName(preservationFile) +
                                    " is out of date (ComputeHashCode)");
                    }
                }

                if (outOfDate)
                {
                    bool gotLock = false;
                    try {
                        // We need to delete the preservation file together with the assemblies/pdbs
                        // under the same lock so to avoid bad interleaving where one process
                        // deletes the .compiled file that another process just created, orphaning
                        // the files generated by the other process.
                        // (Dev10 bug 791299)
                        CompilationLock.GetLock(ref gotLock);

                        // Give the BuildResult a chance to do some cleanup
                        result.RemoveOutOfDateResources(this);

                        // The preservation file is not useable, so delete it
                        File.Delete(preservationFile);
                    }
                    finally {
                        // Always release the mutex if we had taken it
                        if (gotLock)
                        {
                            CompilationLock.ReleaseLock();
                        }
                    }
                    return(null);
                }
            }

            // Ask the BuildResult to read the data it needs
            result.GetPreservedAttributes(this);

            return(result);
        }
        private static BuildResultCompiledType GetThemeBuildResultType(string themeName)
        {
            string appThemeCacheKey, globalThemeCacheKey = null;

            // First, check if the application theme is cached
            appThemeCacheKey = "Theme_" + Util.MakeValidTypeNameFromString(themeName);
            BuildResultCompiledType result = (BuildResultCompiledType)
                                             BuildManager.GetBuildResultFromCache(appThemeCacheKey);

            if (result == null)
            {
                // Then, check if the global theme is cached
                globalThemeCacheKey = "GlobalTheme_" + themeName;
                result = (BuildResultCompiledType)BuildManager.GetBuildResultFromCache(
                    globalThemeCacheKey);
            }

            // If we found a theme buildresulttype, return it
            if (result != null)
            {
                return(result);
            }

            bool gotLock = false;

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

                // Check the cache again now that we have the mutex
                result = (BuildResultCompiledType)BuildManager.GetBuildResultFromCache(appThemeCacheKey);
                if (result == null)
                {
                    result = (BuildResultCompiledType)BuildManager.GetBuildResultFromCache(
                        globalThemeCacheKey);
                }

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

                // Theme was not found in the caches; check if the directory exists.
                VirtualPath appVirtualDir, globalVirtualDir = null;

                appVirtualDir = GetAppThemeVirtualDir(themeName);
                PageThemeBuildProvider themeBuildProvider = null;

                VirtualPath virtualDir = appVirtualDir;

                string cacheKey = appThemeCacheKey;
                // If the theme directories do not exist, simply throw
                if (appVirtualDir.DirectoryExists())
                {
                    themeBuildProvider = new PageThemeBuildProvider(appVirtualDir);
                }
                else
                {
                    globalVirtualDir = GetGlobalThemeVirtualDir(themeName);

                    if (!globalVirtualDir.DirectoryExists())
                    {
                        throw new HttpException(SR.GetString(SR.Page_theme_not_found, themeName));
                    }

                    virtualDir         = globalVirtualDir;
                    cacheKey           = globalThemeCacheKey;
                    themeBuildProvider = new GlobalPageThemeBuildProvider(globalVirtualDir);
                }

                // The directory exists (either app or global), so compile it
                DateTime utcStart = DateTime.UtcNow;

                VirtualDirectory vdir = virtualDir.GetDirectory();

                // Add all the .skin files to it
                AddThemeFilesToBuildProvider(vdir, themeBuildProvider, true);

                // Use predictable fixed names for theme assemblies.
                BuildProvidersCompiler bpc = new BuildProvidersCompiler(virtualDir,
                                                                        themeBuildProvider.AssemblyNamePrefix + BuildManager.GenerateRandomAssemblyName(themeName));

                // Add the single build provider to the BuildProvidersCompiler
                bpc.SetBuildProviders(new SingleObjectCollection(themeBuildProvider));

                // Compile it
                CompilerResults results = bpc.PerformBuild();

                // Get the Type we care about from the BuildProvider
                result = (BuildResultCompiledType)themeBuildProvider.GetBuildResult(results);

                // Cache it for next time
                BuildManager.CacheBuildResult(cacheKey, result, utcStart);
            }
            finally {
                // Always release the mutex if we had taken it
                if (gotLock)
                {
                    CompilationLock.ReleaseLock();
                }
            }
            return(result);
        }
示例#8
0
        private static BuildResultCompiledType GetThemeBuildResultType(string themeName)
        {
            string cacheKey = null;
            string str      = "Theme_" + Util.MakeValidTypeNameFromString(themeName);
            BuildResultCompiledType buildResultFromCache = (BuildResultCompiledType)BuildManager.GetBuildResultFromCache(str);

            if (buildResultFromCache == null)
            {
                cacheKey             = "GlobalTheme_" + themeName;
                buildResultFromCache = (BuildResultCompiledType)BuildManager.GetBuildResultFromCache(cacheKey);
            }
            if (buildResultFromCache == null)
            {
                bool gotLock = false;
                try
                {
                    CompilationLock.GetLock(ref gotLock);
                    buildResultFromCache = (BuildResultCompiledType)BuildManager.GetBuildResultFromCache(str);
                    if (buildResultFromCache == null)
                    {
                        buildResultFromCache = (BuildResultCompiledType)BuildManager.GetBuildResultFromCache(cacheKey);
                    }
                    if (buildResultFromCache != null)
                    {
                        return(buildResultFromCache);
                    }
                    VirtualPath            virtualDirPath     = null;
                    VirtualPath            appThemeVirtualDir = GetAppThemeVirtualDir(themeName);
                    PageThemeBuildProvider themeBuildProvider = null;
                    VirtualPath            configPath         = appThemeVirtualDir;
                    string str3 = str;
                    if (appThemeVirtualDir.DirectoryExists())
                    {
                        themeBuildProvider = new PageThemeBuildProvider(appThemeVirtualDir);
                    }
                    else
                    {
                        virtualDirPath = GetGlobalThemeVirtualDir(themeName);
                        if (!virtualDirPath.DirectoryExists())
                        {
                            throw new HttpException(System.Web.SR.GetString("Page_theme_not_found", new object[] { themeName }));
                        }
                        configPath         = virtualDirPath;
                        str3               = cacheKey;
                        themeBuildProvider = new GlobalPageThemeBuildProvider(virtualDirPath);
                    }
                    DateTime utcNow = DateTime.UtcNow;
                    AddThemeFilesToBuildProvider(configPath.GetDirectory(), themeBuildProvider, true);
                    BuildProvidersCompiler compiler = new BuildProvidersCompiler(configPath, themeBuildProvider.AssemblyNamePrefix + BuildManager.GenerateRandomAssemblyName(themeName));
                    compiler.SetBuildProviders(new SingleObjectCollection(themeBuildProvider));
                    CompilerResults results = compiler.PerformBuild();
                    buildResultFromCache = (BuildResultCompiledType)themeBuildProvider.GetBuildResult(results);
                    BuildManager.CacheBuildResult(str3, buildResultFromCache, utcNow);
                }
                finally
                {
                    if (gotLock)
                    {
                        CompilationLock.ReleaseLock();
                    }
                }
            }
            return(buildResultFromCache);
        }