void ParseRecursively(XmlNode root) { _assembly = GetNonEmptyRequiredAttribute(root, "assembly"); // The rest of the values is optional for us and since we don't use them // at all (at least for now) we also ignore all the integer parsing errors try { _virtualPath = GetNonEmptyOptionalAttribute(root, "virtualPath"); _fileHash = GetNonEmptyOptionalAttributeInt32(root, "filehash"); _hash = GetNonEmptyOptionalAttributeInt32(root, "hash"); _flags = GetNonEmptyOptionalAttributeInt32(root, "flags"); _resultType = (BuildResultTypeCode)GetNonEmptyOptionalAttributeInt32(root, "resultType"); foreach (XmlNode child in root.ChildNodes) { if (child.NodeType != XmlNodeType.Element) { continue; } if (child.Name != "filedeps") { continue; } ReadFileDeps(child); } } catch (Exception) { } }
#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; }
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 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); }
void ParseRecursively (XmlNode root) { _assembly = GetNonEmptyRequiredAttribute (root, "assembly"); // The rest of the values is optional for us and since we don't use them // at all (at least for now) we also ignore all the integer parsing errors try { _virtualPath = GetNonEmptyOptionalAttribute (root, "virtualPath"); _fileHash = GetNonEmptyOptionalAttributeInt32 (root, "filehash"); _hash = GetNonEmptyOptionalAttributeInt32 (root, "hash"); _flags = GetNonEmptyOptionalAttributeInt32 (root, "flags"); _resultType = (BuildResultTypeCode) GetNonEmptyOptionalAttributeInt32 (root, "resultType"); foreach (XmlNode child in root.ChildNodes) { if (child.NodeType != XmlNodeType.Element) continue; if (child.Name != "filedeps") continue; ReadFileDeps (child); } } catch (Exception) { } }