/// <summary> /// Get the content statistics for a source file and returns true if found. /// </summary> public bool TryGetStats(string sourceFile, out ContentStats stats) { lock (_locker) { if (!_statsBySource.TryGetValue(sourceFile, out stats)) { return(false); } return(true); } }
/// <summary> /// Load the content statistics from a folder. /// </summary> /// <param name="outputPath">The folder where the .mgstats file can be found.</param> /// <returns>Returns the content statistics or an empty collection.</returns> public static ContentStatsCollection Read(string outputPath) { var collection = new ContentStatsCollection(); var filePath = Path.Combine(outputPath, Extension); try { int lineIndex = 0; foreach (string line in File.ReadLines(filePath)) { // The first line is the CSV header... if it doesn't match // then assume the data is invalid or changed formats. if (lineIndex++ == 0 && line != Header) { return(collection); } var columns = SplitRegex.Split(line); if (columns.Length != 7) { continue; } var stats = new ContentStats( sourceFile: columns[0].Trim('"'), destFile: columns[1].Trim('"'), processorType: columns[2].Trim('"'), contentType: columns[3].Trim('"'), sourceFileSize: long.Parse(columns[4]), destFileSize: long.Parse(columns[5]), buildSeconds: float.Parse(columns[6])); if (!collection._statsBySource.ContainsKey(stats.SourceFile)) { collection._statsBySource.Add(stats.SourceFile, stats); } } } catch // (Exception ex) { // Assume the file didn't exist or was incorrectly // formatted... either way we start from fresh data. collection.Reset(); } return(collection); }
/// <summary> /// Store content building stats for a source file. /// </summary> /// <param name="sourceFile">The absolute path to the source asset file.</param> /// <param name="destFile">The absolute path to the destination content file.</param> /// <param name="processorType">The type name of the content processor.</param> /// <param name="contentType">The content type object.</param> /// <param name="buildSeconds">The build time in seconds.</param> public void RecordStats( string sourceFile, string destFile, string processorType, Type contentType, float buildSeconds) { var sourceSize = new FileInfo(sourceFile).Length; var destSize = new FileInfo(destFile).Length; var stats = new ContentStats( sourceFile, destFile, processorType, GetFriendlyTypeName(contentType), sourceSize, destSize, buildSeconds); lock (_locker) _statsBySource[sourceFile] = stats; }