/// <summary> /// Extracts a list of csproje files included in each project. /// </summary> public override void ExtractCandidateFiles() { CandidateFiles.Clear(); foreach (String solutionFile in SourceFiles) { String baseDir = Path.GetDirectoryName(solutionFile) + "\\"; Uri baseUri = new Uri(baseDir); String solutionFileContents = File.ReadAllText(solutionFile); MatchCollection matches = projectRegex.Matches(solutionFileContents); foreach (Match match in matches) { String[] parts = match.Value.Replace("\r\n", " ").Split(','); if (parts != null && parts.Length > 1 && parts[1].Contains(FileExtension)) { Uri csprojUri = new Uri(baseUri, parts[1].Replace("\"", "")); if (!CandidateFiles.Contains(csprojUri.LocalPath)) { CandidateFiles.Add(csprojUri.LocalPath); } } } } }
//list files that are almost expired => antique - threshold public void RebuildCandidateList() { lock (locker) { try { if (Service.Break) { return; } EventLogger.Info("rebuilding list of old temp files"); long total_length = 0, candidate_length = 0; CandidateFiles.Clear(); CandidateDirectories.Clear(); DateTime now = DateTime.UtcNow; for (int i = 0; i < Profiles.Count; ++i) { if (Service.Break) { return; } DirectoryInfo di = new DirectoryInfo(Profiles[i]); if (!di.Exists) { continue; } try { foreach (var item in di.EnumerateFileSystemInfos("*", SearchOption.AllDirectories)) { if (Service.Break) { return; } try { long item_length = 0; string name = item.FullName; FileSystemInfo temp = null; bool isDir = item.IsDirectory(); if (isDir) { try { temp = new DirectoryInfo(name); } catch (PathTooLongException) { name = item.FullName.PrefixForLongNames(); } } else { try { item_length = new FileInfo(name).Length; } catch (PathTooLongException) { name = item.FullName.PrefixForLongNames(); try { item_length = new FileInfo(name).Length; } catch { } } } if (temp != null && !temp.Exists) { //use it just to avoid compiler optimizations on that code EventLogger.Warning("item does not exist: " + temp.FullName); } total_length += item_length; var span0 = now - item.CreationTimeUtc; var span1 = now - item.LastAccessTimeUtc; var span2 = now - item.LastWriteTimeUtc; if (span0 >= antique && span1 >= antique && span2 >= antique) { if (isDir) { CandidateDirectories.Add(name); } else { candidate_length += item_length; CandidateFiles.Add(name); } } } catch (Exception e) { EventLogger.Warning("exception when enumerating temporary files (item will be ignored)", e); } } } catch (Exception e) { EventLogger.Warning("exception when enumerating temporary folder (profile will be ignored)", e); } } CandidateDirectories.Sort((x, y) => { return(y.Length.CompareTo(x.Length)); }); EventLogger.Info( string.Format( "can potentially save {0} of a total of {1} in temporary files", ByteSuffixes.GetString(candidate_length), ByteSuffixes.GetString(total_length) )); } catch (Exception e) { EventLogger.Error("unexpected exception (enumerating)", e); } } }