private void ConstructFileTable() { string tLogRootingMarker = null; bool flag2; bool flag3; try { tLogRootingMarker = DependencyTableCache.FormatNormalizedTlogRootingMarker(this.tlogFiles); } catch (ArgumentException exception) { FileTracker.LogWarningWithCodeFromResources(this.Log, "Tracking_RebuildingDueToInvalidTLog", new object[] { exception.Message }); return; } if (this.tlogsAvailable) { DependencyTableCacheEntry cachedEntry = null; lock (DependencyTableCache.DependencyTable) { cachedEntry = DependencyTableCache.GetCachedEntry(tLogRootingMarker); } if (cachedEntry != null) { this.dependencyTable = (IDictionary <string, DateTime>)cachedEntry.DependencyTable; this.UpdateFileEntryDetails(); FileTracker.LogMessageFromResources(this.Log, MessageImportance.Low, "Tracking_TrackingCached", new object[0]); foreach (ITaskItem item in cachedEntry.TlogFiles) { FileTracker.LogMessage(this.Log, MessageImportance.Low, "\t{0}", new object[] { item.ItemSpec }); } return; } FileTracker.LogMessageFromResources(this.Log, MessageImportance.Low, "Tracking_TrackingLogs", new object[0]); flag2 = false; flag3 = false; string itemSpec = null; foreach (ITaskItem item2 in this.tlogFiles) { try { FileTracker.LogMessage(this.Log, MessageImportance.Low, "\t{0}", new object[] { item2.ItemSpec }); DateTime lastWriteTimeUtc = NativeMethods.GetLastWriteTimeUtc(item2.ItemSpec); if (lastWriteTimeUtc > this.newestTLogTimeUtc) { this.newestTLogTimeUtc = lastWriteTimeUtc; this.newestTLogFileName = item2.ItemSpec; } using (StreamReader reader = File.OpenText(item2.ItemSpec)) { string key = reader.ReadLine(); while (key != null) { if (key.Length == 0) { flag2 = true; itemSpec = item2.ItemSpec; goto Label_02B7; } if (key[0] == '#') { key = reader.ReadLine(); continue; } if ((key[0] == '^') && this.TreatRootMarkersAsEntries) { key = key.Substring(1); if (key.Length != 0) { goto Label_0242; } flag2 = true; itemSpec = item2.ItemSpec; goto Label_02B7; } if (key[0] == '^') { key = reader.ReadLine(); continue; } Label_0242: if (!this.dependencyTable.ContainsKey(key) && !FileTracker.FileIsExcludedFromDependencies(key)) { this.RecordEntryDetails(key, true); } key = reader.ReadLine(); } } } catch (Exception exception2) { if (ExceptionHandling.NotExpectedException(exception2)) { throw; } FileTracker.LogWarningWithCodeFromResources(this.Log, "Tracking_RebuildingDueToInvalidTLog", new object[] { exception2.Message }); break; } Label_02B7: if (flag2) { FileTracker.LogWarningWithCodeFromResources(this.Log, "Tracking_RebuildingDueToInvalidTLogContents", new object[] { itemSpec }); break; } } } else { lock (DependencyTableCache.DependencyTable) { if (DependencyTableCache.DependencyTable.ContainsKey(tLogRootingMarker)) { DependencyTableCache.DependencyTable.Remove(tLogRootingMarker); } } return; } lock (DependencyTableCache.DependencyTable) { if (flag2 || flag3) { if (DependencyTableCache.DependencyTable.ContainsKey(tLogRootingMarker)) { DependencyTableCache.DependencyTable.Remove(tLogRootingMarker); } this.dependencyTable = new Dictionary <string, DateTime>(StringComparer.OrdinalIgnoreCase); } else { DependencyTableCache.DependencyTable[tLogRootingMarker] = new DependencyTableCacheEntry(this.tlogFiles, (IDictionary)this.dependencyTable); } } }
/// <summary> /// Construct our dependency table for our source files /// </summary> private void ConstructOutputTable() { string tLogRootingMarker = null; try { // construct a rooting marker from the tlog files tLogRootingMarker = DependencyTableCache.FormatNormalizedTlogRootingMarker(_tlogFiles); } catch (ArgumentException e) { FileTracker.LogWarningWithCodeFromResources(_log, "Tracking_RebuildingDueToInvalidTLog", e.Message); return; } // Record the current directory (which under normal circumstances will be the project directory) // so that we can compare tracked paths against it for inclusion in the dependency graph string currentProjectDirectory = FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()); if (!_tlogAvailable) { FileTracker.LogMessageFromResources(_log, MessageImportance.Low, "Tracking_TrackingLogNotAvailable"); lock (DependencyTableCache.DependencyTable) { // The tracking logs are not available, they may have been deleted at some point. // Be safe and remove any references from the cache. if (DependencyTableCache.DependencyTable.ContainsKey(tLogRootingMarker)) { DependencyTableCache.DependencyTable.Remove(tLogRootingMarker); } } return; } DependencyTableCacheEntry cachedEntry = null; lock (DependencyTableCache.DependencyTable) { // Look in the dependency table cache to see if its available and up to date cachedEntry = DependencyTableCache.GetCachedEntry(tLogRootingMarker); } // We have an up to date cached entry if (cachedEntry != null) { _dependencyTable = (Dictionary <string, System.Collections.Generic.Dictionary <string, System.DateTime> >)cachedEntry.DependencyTable; // Log information about what we're using FileTracker.LogMessageFromResources(_log, MessageImportance.Low, "Tracking_WriteTrackingCached"); foreach (ITaskItem tlogItem in cachedEntry.TlogFiles) { FileTracker.LogMessage(_log, MessageImportance.Low, "\t{0}", tlogItem.ItemSpec); } return; } FileTracker.LogMessageFromResources(_log, MessageImportance.Low, "Tracking_WriteTrackingLogs"); // Now we need to construct the rest of the table from the TLOG files // If there are any errors in the tlogs, we want to warn, stop parsing tlogs, and empty // out the dependency table, essentially forcing a rebuild. bool encounteredInvalidTLogContents = false; bool exceptionCaught = false; string invalidTLogName = null; foreach (ITaskItem tlogFileName in _tlogFiles) { FileTracker.LogMessage(_log, MessageImportance.Low, "\t{0}", tlogFileName.ItemSpec); try { using (StreamReader tlog = File.OpenText(tlogFileName.ItemSpec)) { string tlogEntry = tlog.ReadLine(); while (tlogEntry != null) { if (tlogEntry.Length == 0) { encounteredInvalidTLogContents = true; invalidTLogName = tlogFileName.ItemSpec; break; } if (tlogEntry[0] == '^') // This is a rooting record, follow the outputs for it { Dictionary <string, DateTime> dependencies; tlogEntry = tlogEntry.Substring(1); if (tlogEntry.Length == 0) { encounteredInvalidTLogContents = true; invalidTLogName = tlogFileName.ItemSpec; break; } if (!_dependencyTable.TryGetValue(tlogEntry, out dependencies)) { dependencies = new Dictionary <string, DateTime>(StringComparer.OrdinalIgnoreCase); _dependencyTable.Add(tlogEntry, dependencies); } // Process each file encountered until we hit a rooting marker do { tlogEntry = tlog.ReadLine(); if (tlogEntry != null) { if (tlogEntry.Length == 0) { encounteredInvalidTLogContents = true; invalidTLogName = tlogFileName.ItemSpec; break; } else if ((tlogEntry[0] != '^') && (tlogEntry[0] != '#') && (!dependencies.ContainsKey(tlogEntry))) { // Allows incremental build of projects existing under temp, only for those reads / writes that // either are not under temp, or are recursively beneath the current project directory. if (FileTracker.FileIsUnderPath(tlogEntry, currentProjectDirectory) || !FileTracker.FileIsExcludedFromDependencies(tlogEntry)) { DateTime fileModifiedTime = NativeMethods.GetLastWriteTimeUtc(tlogEntry); dependencies.Add(tlogEntry, fileModifiedTime); } } } } while ((tlogEntry != null) && (tlogEntry[0] != '^')); if (encounteredInvalidTLogContents) { break; } } else // don't know what this entry is, so skip it { tlogEntry = tlog.ReadLine(); } } } } catch (Exception e) { if (ExceptionHandling.NotExpectedException(e)) { throw; } FileTracker.LogWarningWithCodeFromResources(_log, "Tracking_RebuildingDueToInvalidTLog", e.Message); break; } if (encounteredInvalidTLogContents) { FileTracker.LogWarningWithCodeFromResources(_log, "Tracking_RebuildingDueToInvalidTLogContents", invalidTLogName); break; } } lock (DependencyTableCache.DependencyTable) { // There were problems with the tracking logs -- we've already warned or errored; now we want to make // sure that we essentially force a rebuild of this particular root. if (encounteredInvalidTLogContents || exceptionCaught) { if (DependencyTableCache.DependencyTable.ContainsKey(tLogRootingMarker)) { DependencyTableCache.DependencyTable.Remove(tLogRootingMarker); } _dependencyTable = new Dictionary <string, Dictionary <string, DateTime> >(StringComparer.OrdinalIgnoreCase); } else { // Record the newly built valid dependency table in the cache DependencyTableCache.DependencyTable[tLogRootingMarker] = new DependencyTableCacheEntry(_tlogFiles, _dependencyTable); } } }
private void ConstructOutputTable() { string tLogRootingMarker = null; bool flag2; bool flag3; try { tLogRootingMarker = DependencyTableCache.FormatNormalizedTlogRootingMarker(this.tlogFiles); } catch (ArgumentException exception) { FileTracker.LogWarningWithCodeFromResources(this.Log, "Tracking_RebuildingDueToInvalidTLog", new object[] { exception.Message }); return; } string path = FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()); if (this.tlogAvailable) { DependencyTableCacheEntry cachedEntry = null; lock (DependencyTableCache.DependencyTable) { cachedEntry = DependencyTableCache.GetCachedEntry(tLogRootingMarker); } if (cachedEntry != null) { this.dependencyTable = (Dictionary <string, Dictionary <string, DateTime> >)cachedEntry.DependencyTable; FileTracker.LogMessageFromResources(this.Log, MessageImportance.Low, "Tracking_WriteTrackingCached", new object[0]); foreach (ITaskItem item in cachedEntry.TlogFiles) { FileTracker.LogMessage(this.Log, MessageImportance.Low, "\t{0}", new object[] { item.ItemSpec }); } return; } FileTracker.LogMessageFromResources(this.Log, MessageImportance.Low, "Tracking_WriteTrackingLogs", new object[0]); flag2 = false; flag3 = false; string itemSpec = null; foreach (ITaskItem item2 in this.tlogFiles) { FileTracker.LogMessage(this.Log, MessageImportance.Low, "\t{0}", new object[] { item2.ItemSpec }); try { using (StreamReader reader = File.OpenText(item2.ItemSpec)) { string key = reader.ReadLine(); while (key != null) { if (key.Length == 0) { flag2 = true; itemSpec = item2.ItemSpec; goto Label_0305; } if (key[0] == '^') { key = key.Substring(1); if (key.Length == 0) { flag2 = true; itemSpec = item2.ItemSpec; } else { Dictionary <string, DateTime> dictionary; if (!this.dependencyTable.TryGetValue(key, out dictionary)) { dictionary = new Dictionary <string, DateTime>(StringComparer.OrdinalIgnoreCase); this.dependencyTable.Add(key, dictionary); } do { key = reader.ReadLine(); if (key != null) { if (key.Length == 0) { flag2 = true; itemSpec = item2.ItemSpec; break; } if ((((key[0] != '^') && (key[0] != '#')) && !dictionary.ContainsKey(key)) && (FileTracker.FileIsUnderPath(key, path) || !FileTracker.FileIsExcludedFromDependencies(key))) { DateTime lastWriteTimeUtc = NativeMethods.GetLastWriteTimeUtc(key); dictionary.Add(key, lastWriteTimeUtc); } } }while ((key != null) && (key[0] != '^')); if (!flag2) { continue; } } goto Label_0305; } key = reader.ReadLine(); } } } catch (Exception exception2) { if (ExceptionHandling.NotExpectedException(exception2)) { throw; } FileTracker.LogWarningWithCodeFromResources(this.Log, "Tracking_RebuildingDueToInvalidTLog", new object[] { exception2.Message }); break; } Label_0305: if (flag2) { FileTracker.LogWarningWithCodeFromResources(this.Log, "Tracking_RebuildingDueToInvalidTLogContents", new object[] { itemSpec }); break; } } } else { FileTracker.LogMessageFromResources(this.Log, MessageImportance.Low, "Tracking_TrackingLogNotAvailable", new object[0]); lock (DependencyTableCache.DependencyTable) { if (DependencyTableCache.DependencyTable.ContainsKey(tLogRootingMarker)) { DependencyTableCache.DependencyTable.Remove(tLogRootingMarker); } } return; } lock (DependencyTableCache.DependencyTable) { if (flag2 || flag3) { if (DependencyTableCache.DependencyTable.ContainsKey(tLogRootingMarker)) { DependencyTableCache.DependencyTable.Remove(tLogRootingMarker); } this.dependencyTable = new Dictionary <string, Dictionary <string, DateTime> >(StringComparer.OrdinalIgnoreCase); } else { DependencyTableCache.DependencyTable[tLogRootingMarker] = new DependencyTableCacheEntry(this.tlogFiles, this.dependencyTable); } } }
private void ConstructDependencyTable() { string tLogRootingMarker = null; bool flag2; bool flag3; try { tLogRootingMarker = DependencyTableCache.FormatNormalizedTlogRootingMarker(this.tlogFiles); } catch (ArgumentException exception) { FileTracker.LogWarningWithCodeFromResources(this.Log, "Tracking_RebuildingDueToInvalidTLog", new object[] { exception.Message }); return; } string path = FileUtilities.EnsureTrailingSlash(Directory.GetCurrentDirectory()); if (this.tlogAvailable) { DependencyTableCacheEntry cachedEntry = null; lock (DependencyTableCache.DependencyTable) { cachedEntry = DependencyTableCache.GetCachedEntry(tLogRootingMarker); } if (cachedEntry != null) { this.dependencyTable = (Dictionary <string, Dictionary <string, string> >)cachedEntry.DependencyTable; FileTracker.LogMessageFromResources(this.Log, MessageImportance.Low, "Tracking_ReadTrackingCached", new object[0]); foreach (ITaskItem item2 in cachedEntry.TlogFiles) { FileTracker.LogMessage(this.Log, MessageImportance.Low, "\t{0}", new object[] { item2.ItemSpec }); } return; } flag2 = false; flag3 = false; string itemSpec = null; FileTracker.LogMessageFromResources(this.Log, MessageImportance.Low, "Tracking_ReadTrackingLogs", new object[0]); foreach (ITaskItem item3 in this.tlogFiles) { try { FileTracker.LogMessage(this.Log, MessageImportance.Low, "\t{0}", new object[] { item3.ItemSpec }); using (StreamReader reader = File.OpenText(item3.ItemSpec)) { string key = reader.ReadLine(); while (key != null) { Dictionary <string, string> dictionary; Dictionary <string, string> dictionary2; if (key.Length == 0) { flag2 = true; itemSpec = item3.ItemSpec; goto Label_04A1; } if (key[0] == '#') { goto Label_044D; } bool flag4 = false; if (key[0] == '^') { key = key.Substring(1); if (key.Length == 0) { flag2 = true; itemSpec = item3.ItemSpec; goto Label_04A1; } flag4 = true; } if (!flag4) { goto Label_0442; } if (!this.maintainCompositeRootingMarkers) { dictionary2 = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); if (key.Contains("|")) { foreach (ITaskItem item4 in this.sourceFiles) { dictionary2.Add(FileUtilities.NormalizePath(item4.ItemSpec), null); } } else { dictionary2.Add(key, null); } } else { dictionary2 = null; } if (!this.dependencyTable.TryGetValue(key, out dictionary)) { dictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); if (!this.maintainCompositeRootingMarkers) { dictionary.Add(key, null); } this.dependencyTable.Add(key, dictionary); } key = reader.ReadLine(); if (!this.maintainCompositeRootingMarkers) { goto Label_0439; } while (key != null) { if (key.Length == 0) { flag2 = true; itemSpec = item3.ItemSpec; break; } if ((key[0] == '#') || (key[0] == '^')) { break; } if (!dictionary.ContainsKey(key) && (FileTracker.FileIsUnderPath(key, path) || !FileTracker.FileIsExcludedFromDependencies(key))) { dictionary.Add(key, null); } key = reader.ReadLine(); } continue; Label_038D: if (key.Length == 0) { flag2 = true; itemSpec = item3.ItemSpec; continue; } if ((key[0] == '#') || (key[0] == '^')) { continue; } if (dictionary2.ContainsKey(key)) { if (!this.dependencyTable.TryGetValue(key, out dictionary)) { dictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); dictionary.Add(key, null); this.dependencyTable.Add(key, dictionary); } } else if (!dictionary.ContainsKey(key) && (FileTracker.FileIsUnderPath(key, path) || !FileTracker.FileIsExcludedFromDependencies(key))) { dictionary.Add(key, null); } key = reader.ReadLine(); Label_0439: if (key != null) { goto Label_038D; } continue; Label_0442: key = reader.ReadLine(); continue; Label_044D: key = reader.ReadLine(); } } } catch (Exception exception2) { if (ExceptionHandling.NotExpectedException(exception2)) { throw; } FileTracker.LogWarningWithCodeFromResources(this.Log, "Tracking_RebuildingDueToInvalidTLog", new object[] { exception2.Message }); break; } Label_04A1: if (flag2) { FileTracker.LogWarningWithCodeFromResources(this.Log, "Tracking_RebuildingDueToInvalidTLogContents", new object[] { itemSpec }); break; } } } else { foreach (ITaskItem item in this.tlogFiles) { if (!FileUtilities.FileExistsNoThrow(item.ItemSpec)) { FileTracker.LogMessageFromResources(this.Log, MessageImportance.Low, "Tracking_SingleLogFileNotAvailable", new object[] { item.ItemSpec }); } } lock (DependencyTableCache.DependencyTable) { if (DependencyTableCache.DependencyTable.ContainsKey(tLogRootingMarker)) { DependencyTableCache.DependencyTable.Remove(tLogRootingMarker); } } return; } lock (DependencyTableCache.DependencyTable) { if (flag2 || flag3) { if (DependencyTableCache.DependencyTable.ContainsKey(tLogRootingMarker)) { DependencyTableCache.DependencyTable.Remove(tLogRootingMarker); } this.dependencyTable = new Dictionary <string, Dictionary <string, string> >(StringComparer.OrdinalIgnoreCase); } else { DependencyTableCache.DependencyTable[tLogRootingMarker] = new DependencyTableCacheEntry(this.tlogFiles, this.dependencyTable); } } }
/// <summary> /// Construct our dependency table for our source files /// </summary> private void ConstructFileTable() { string tLogRootingMarker = null; try { // construct a rooting marker from the tlog files tLogRootingMarker = DependencyTableCache.FormatNormalizedTlogRootingMarker(_tlogFiles); } catch (ArgumentException e) { FileTracker.LogWarningWithCodeFromResources(_log, "Tracking_RebuildingDueToInvalidTLog", e.Message); return; } if (!_tlogsAvailable) { lock (DependencyTableCache.DependencyTable) { // The tracking logs are not available, they may have been deleted at some point. // Be safe and remove any references from the cache. if (DependencyTableCache.DependencyTable.ContainsKey(tLogRootingMarker)) { DependencyTableCache.DependencyTable.Remove(tLogRootingMarker); } } return; } DependencyTableCacheEntry cachedEntry = null; lock (DependencyTableCache.DependencyTable) { // Look in the dependency table cache to see if its available and up to date cachedEntry = DependencyTableCache.GetCachedEntry(tLogRootingMarker); } // We have an up to date cached entry if (cachedEntry != null) { _dependencyTable = (IDictionary <string, DateTime>)cachedEntry.DependencyTable; // We may have stored the dependency table in the cache, but all the other information // (newest file time, number of missing files, etc.) has been reset to default. Refresh // the data. this.UpdateFileEntryDetails(); // Log information about what we're using FileTracker.LogMessageFromResources(_log, MessageImportance.Low, "Tracking_TrackingCached"); foreach (ITaskItem tlogItem in cachedEntry.TlogFiles) { FileTracker.LogMessage(_log, MessageImportance.Low, "\t{0}", tlogItem.ItemSpec); } return; } FileTracker.LogMessageFromResources(_log, MessageImportance.Low, "Tracking_TrackingLogs"); // Now we need to construct the rest of the table from the TLOG files // If there are any errors in the tlogs, we want to warn, stop parsing tlogs, and empty // out the dependency table, essentially forcing a rebuild. bool encounteredInvalidTLogContents = false; bool exceptionCaught = false; string invalidTLogName = null; foreach (ITaskItem tlogFileName in _tlogFiles) { try { FileTracker.LogMessage(_log, MessageImportance.Low, "\t{0}", tlogFileName.ItemSpec); DateTime tlogLastWriteTimeUtc = NativeMethods.GetLastWriteTimeUtc(tlogFileName.ItemSpec); if (tlogLastWriteTimeUtc > _newestTLogTimeUtc) { _newestTLogTimeUtc = tlogLastWriteTimeUtc; _newestTLogFileName = tlogFileName.ItemSpec; } using (StreamReader tlog = File.OpenText(tlogFileName.ItemSpec)) { string tlogEntry = tlog.ReadLine(); while (tlogEntry != null) { if (tlogEntry.Length == 0) // empty lines are a sign that something has gone wrong { encounteredInvalidTLogContents = true; invalidTLogName = tlogFileName.ItemSpec; break; } // Preprocessing for the line entry else if (tlogEntry[0] == '#') // a comment marker should be skipped { tlogEntry = tlog.ReadLine(); continue; } else if (tlogEntry[0] == '^' && TreatRootMarkersAsEntries) // This is a rooting record, and we should keep it { tlogEntry = tlogEntry.Substring(1); if (tlogEntry.Length == 0) { encounteredInvalidTLogContents = true; invalidTLogName = tlogFileName.ItemSpec; break; } } else if (tlogEntry[0] == '^') // root marker is not being treated as an entry, skip it { tlogEntry = tlog.ReadLine(); continue; } // If we haven't seen this file before, then record it if (!_dependencyTable.ContainsKey(tlogEntry)) { // It may be that this is one of the locations that we should ignore if (!FileTracker.FileIsExcludedFromDependencies(tlogEntry)) { RecordEntryDetails(tlogEntry, true); } } tlogEntry = tlog.ReadLine(); } } } catch (Exception e) when(ExceptionHandling.IsIoRelatedException(e)) { FileTracker.LogWarningWithCodeFromResources(_log, "Tracking_RebuildingDueToInvalidTLog", e.Message); break; } if (encounteredInvalidTLogContents) { FileTracker.LogWarningWithCodeFromResources(_log, "Tracking_RebuildingDueToInvalidTLogContents", invalidTLogName); break; } } lock (DependencyTableCache.DependencyTable) { // There were problems with the tracking logs -- we've already warned or errored; now we want to make // sure that we essentially force a rebuild of this particular root. if (encounteredInvalidTLogContents || exceptionCaught) { if (DependencyTableCache.DependencyTable.ContainsKey(tLogRootingMarker)) { DependencyTableCache.DependencyTable.Remove(tLogRootingMarker); } _dependencyTable = new Dictionary <string, DateTime>(StringComparer.OrdinalIgnoreCase); } else { // Record the newly built dependency table in the cache DependencyTableCache.DependencyTable[tLogRootingMarker] = new DependencyTableCacheEntry(_tlogFiles, (IDictionary)_dependencyTable); } } }