15 private static readonly Random rnd =
new Random();
16 private static Scheduler? scheduler =
null;
17 private static string? appDataFolder =
null;
18 private static string? brotliFolder =
null;
19 private static bool compressDynamic =
false;
20 private static bool compressStatic =
true;
44 compressDynamic = Dynamic;
45 compressStatic = Static;
64 string? CompressedFileName;
66 if (!
string.IsNullOrEmpty(brotliFolder))
67 CompressedFileName = Path.Combine(brotliFolder, ETag +
".br");
69 CompressedFileName =
null;
83 if (
string.IsNullOrEmpty(ETag) ||
string.IsNullOrEmpty(brotliFolder))
86 string CompressedFileName = Path.Combine(brotliFolder, ETag +
".br");
88 return new FileInfo(CompressedFileName);
96 public static void Init(
string AppDataFolder)
100 appDataFolder = AppDataFolder;
101 brotliFolder = Path.Combine(appDataFolder,
"Brotli");
103 if (!Directory.Exists(brotliFolder))
104 Directory.CreateDirectory(brotliFolder);
106 if (scheduler is
null)
114 Log.Terminating += (Sender, e) =>
122 DeleteOldFiles(TimeSpan.FromDays(7));
130 private static void DeleteOldFiles(
object P)
132 if (P is TimeSpan MaxAge)
133 DeleteOldFiles(MaxAge,
true);
143 DateTime Limit = DateTime.Now - MaxAge;
146 DirectoryInfo BrotliFolder =
new DirectoryInfo(brotliFolder);
147 FileInfo[] Files = BrotliFolder.GetFiles(
"*.*");
149 foreach (FileInfo FileInfo
in Files)
151 if (FileInfo.LastAccessTime < Limit)
155 File.Delete(FileInfo.FullName);
160 Log.
Error(
"Unable to delete old file: " + ex.Message, FileInfo.FullName);
166 Log.
Informational(Count.ToString() +
" old file(s) deleted.", brotliFolder);
172 scheduler?.
Add(DateTime.Now.AddDays(rnd.NextDouble() * 2), DeleteOldFiles, MaxAge);
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
static void Error(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an error event.
static void Informational(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an informational event.
Grade Supports(string Label)
How well the Content-Encoding handles the encoding specified by Label .
void ConfigureSupport(bool Dynamic, bool Static)
Configures support for the algorithm.
static void DeleteOldFiles(TimeSpan MaxAge, bool Reschedule)
Deletes generated files older than MaxAge .
bool SupportsStaticEncoding
If encoding can be used for static encoding.
static void Init(string AppDataFolder)
Initializes the Brotli-compression integration.
bool SupportsDynamicEncoding
If encoding can be used for dynamic encoding.
string Label
Label identifying the Content-Encoding
FileInfo? TryGetPrecompressedFile(string ETag)
Tries to get a reference to the precompressed file, if available.
TransferEncoding GetEncoder(TransferEncoding Output, long? ExpectedContentLength, string ETag)
Gets an encoder.
Class performing br encoding and decoding.
void PrepareForCompression()
Prepares the encoder for compression
Base class for all transfer encodings.
Static class that dynamically manages types and interfaces available in the runtime environment.
static bool TryGetModuleParameter(string Name, out object Value)
Tries to get a module parameter value.
Class that can be used to schedule events in time. It uses a timer to execute tasks at the appointed ...
void Dispose()
IDisposable.Dispose
DateTime Add(DateTime When, ScheduledEventCallback Callback, object State)
Adds an event.
Interface for content encodings in HTTP transfers.