/// <summary> /// Ermittelt alle Protokolleinträge für einen bestimmten Zeitraum. /// </summary> /// <param name="firstDate">Erster zu berücksichtigender Tag.</param> /// <param name="lastDate">Letzter zu berücksichtigender Tag.</param> /// <param name="profile">Profile, dessen Protokolle ausgelesen werden sollen.</param> /// <returns>Liste aller Protokolleinträge für den gewünschten Zeitraum.</returns> internal List <VCRRecordingInfo> FindLogEntries(DateTime firstDate, DateTime lastDate, ProfileState profile) { // Create list var logs = new List <VCRRecordingInfo>(); // Create search patterns var last = lastDate.AddDays(1).ToString(LogEntryDateFormat); var first = firstDate.ToString(LogEntryDateFormat); // Load all jobs foreach (var file in LogDirectory.GetFiles("*" + VCRRecordingInfo.FileSuffix)) { // Skip if (file.Name.CompareTo(first) < 0) { continue; } if (file.Name.CompareTo(last) >= 0) { continue; } // Load item var logEntry = SerializationTools.Load <VCRRecordingInfo>(file); if (logEntry == null) { continue; } // Check if (profile != null) { if (!profile.IsResponsibleFor(logEntry.Source)) { continue; } } // Attach the name logEntry.LogIdentifier = file.Name.ToLower(); // Remember logs.Add(logEntry); } // Sort by start time logs.Sort(VCRRecordingInfo.ComparerByStarted); // Report return(logs); }
// Removes the oldest log files if the total number of files is greater than intended public void CleanDirectory() { FileInfo[] files = LogDirectory.GetFiles(); if (files.Length > BackLogDays) { int difference = files.Length - BackLogDays; int extLength = FileExt.Length; Array.Sort(files, (x, y) => DateTime.Parse(x.Name.Substring(0, x.Name.Length - extLength)) .CompareTo(DateTime.Parse(y.Name.Substring(0, y.Name.Length - extLength)))); for (int i = 0; i < difference; i++) { files[i].Delete(); } } }