using BomLocalService.Models; using Microsoft.Extensions.Configuration; namespace BomLocalService.Utilities; /// /// Utility methods for cache folder validation and operations. /// public static class CacheHelper { /// /// Gets the configured frame count for a data type from configuration. /// public static int GetFrameCountForDataType(IConfiguration configuration, CachedDataType dataType) { var dataTypeName = dataType.ToString(); var frameCount = configuration.GetValue($"CachedDataTypes:{dataTypeName}:FrameCount", 7); return frameCount; } /// /// Checks if a cache folder has complete data for a specific data type. /// public static bool IsCacheFolderCompleteForDataType(string cacheFolderPath, CachedDataType dataType, IConfiguration configuration) { if (string.IsNullOrEmpty(cacheFolderPath) || !Directory.Exists(cacheFolderPath)) { return false; } var dataTypeFolder = FilePathHelper.GetDataTypeFolderPath(cacheFolderPath, dataType); if (!Directory.Exists(dataTypeFolder)) { return false; } var expectedFrameCount = GetFrameCountForDataType(configuration, dataType); for (int i = 0; i < expectedFrameCount; i++) { var framePath = FilePathHelper.GetFrameFilePath(cacheFolderPath, dataType, i); if (!File.Exists(framePath)) { return false; } } // Check for frames.json in data type folder var framesMetadataPath = FilePathHelper.GetFramesMetadataFilePath(cacheFolderPath, dataType); if (!File.Exists(framesMetadataPath)) { return false; } return true; } /// /// Checks if a cache folder is complete (has radar data - for backward compatibility). /// public static bool IsCacheFolderComplete(string cacheFolderPath, IConfiguration configuration) { return IsCacheFolderCompleteForDataType(cacheFolderPath, CachedDataType.Radar, configuration); } }