private void m_dailyTimer_Elapsed(object sender, ElapsedEventArgs e)
{
try
{
ClientDatabaseBase<HistorianKey, HistorianValue> database = GetClientDatabase();
// Get list of files that have both a start time and an end time that are greater than the maximum archive days. We check both start and end times
// since PMUs can provide bad time (not currently being filtered) and you don't want to accidentally delete a file with otherwise in-range data.
ArchiveDetails[] filesToDelete = database.GetAllAttachedFiles().Where(file => (DateTime.UtcNow - file.StartTime).TotalDays > MaximumArchiveDays && (DateTime.UtcNow - file.EndTime).TotalDays > MaximumArchiveDays).ToArray();
database.DeleteFiles(filesToDelete.Select(file => file.Id).ToList());
OnStatusMessage("Deleted the following old archive files:\r\n {0}", filesToDelete.Select(file => FilePath.TrimFileName(file.FileName, 75)).ToDelimitedString(Environment.NewLine + " "));
}
catch (Exception ex)
{
OnProcessException(new InvalidOperationException($"Failed to limit maximum archive size: {ex.Message}", ex));
}
}