private long GetDependenciesCombinedHash() { DateTimeCombiner dateTimeCombiner = new DateTimeCombiner(); // Sort the source dependencies to make the hash code predictable ArrayList sortedSourceDependencies = new ArrayList(SourceDependencies.Keys); sortedSourceDependencies.Sort(InvariantComparer.Default); foreach (string sourceDependency in sortedSourceDependencies) { dateTimeCombiner.AddFile(sourceDependency); } return(dateTimeCombiner.CombinedHash); }
/* * Perform initialization work that should only be done once (per app domain). */ private static void DoFirstTimeInit(HttpContext context) { // Find out how many recompilations we allow before restarting the appdomain s_maxRecompilations = CompilationConfiguration.GetRecompilationsBeforeAppRestarts(context); // Create the temp files directory if it's not already there string tempFilePath = HttpRuntime.CodegenDirInternal; if (!FileUtil.DirectoryExists(tempFilePath)) { try { Directory.CreateDirectory(tempFilePath); } catch (IOException e) { throw new HttpException(HttpRuntime.FormatResourceString(SR.Failed_to_create_temp_dir, HttpRuntime.GetSafePath(tempFilePath)), e); } } long specialFilesCombinedHash = ReadPreservedSpecialFilesCombinedHash(); Debug.Trace("PreservedAssemblyEntry", "specialFilesCombinedHash=" + specialFilesCombinedHash); // Delete all the non essential files left over in the codegen dir, unless // specialFilesCombinedHash is 0, in which case we delete *everything* further down if (specialFilesCombinedHash != 0) { RemoveOldTempFiles(); } // Use a DateTimeCombiner object to handle the time stamps of all the 'special' // files that all compilations depend on: // - The config files (excluding the ones from subdirectories) // - global.asax // - System.Web.dll (in case there is a newer version of ASP.NET) DateTimeCombiner specialFilesDateTimeCombiner = new DateTimeCombiner(); // Add a check for the app's physical path, in case it changes (ASURT 12975) specialFilesDateTimeCombiner.AddObject(context.Request.PhysicalApplicationPath); // Process the config files. Note that this only includes the top level ones, // namely the machine one, and the one in the root of the app. The others are // handled as regular dependencies. string appPath = context.Request.ApplicationPath; string[] configFiles = context.GetConfigurationDependencies(appPath); _numTopLevelConfigFiles = configFiles.Length; for (int i = 0; i < _numTopLevelConfigFiles; i++) { specialFilesDateTimeCombiner.AddFile(configFiles[i]); } // Process global.asax string appFileName = HttpApplicationFactory.GetApplicationFile(context); specialFilesDateTimeCombiner.AddFile(appFileName); // Process System.Web.dll string aspBinaryFileName = typeof(HttpRuntime).Module.FullyQualifiedName; specialFilesDateTimeCombiner.AddFile(aspBinaryFileName); // If they don't match, cleanup everything and write the new hash file if (specialFilesDateTimeCombiner.CombinedHash != specialFilesCombinedHash) { Debug.Trace("PreservedAssemblyEntry", "EnsureFirstTimeInit: hash codes don't match. Old=" + specialFilesCombinedHash + " New=" + specialFilesDateTimeCombiner.CombinedHash); RemoveAllCodeGenFiles(); WritePreservedSpecialFilesCombinedHash(specialFilesDateTimeCombiner.CombinedHash); } else { Debug.Trace("PreservedAssemblyEntry", "PreservedAssemblyEntry: the special files are up to date"); } }