EPG: IsCurrent prueft auch Cache-Datei-Timestamp
This commit is contained in:
parent
4bf42b96b5
commit
e2aeeb4332
1 changed files with 19 additions and 3 deletions
|
|
@ -27,10 +27,25 @@ public class EpgService
|
||||||
/// <summary>In-Memory-Index: Sendername (normalisiert) → Liste der Events, sortiert nach Startzeit</summary>
|
/// <summary>In-Memory-Index: Sendername (normalisiert) → Liste der Events, sortiert nach Startzeit</summary>
|
||||||
private Dictionary<string, List<EpgEvent>> _eventsByChannel = new();
|
private Dictionary<string, List<EpgEvent>> _eventsByChannel = new();
|
||||||
private DateTime _loadedAt = DateTime.MinValue;
|
private DateTime _loadedAt = DateTime.MinValue;
|
||||||
|
private string _loadedFile = "";
|
||||||
|
|
||||||
/// <summary>True wenn Daten geladen sind und nicht älter als 12h</summary>
|
/// <summary>True wenn Daten geladen sind, nicht älter als 12h, und die Cache-Datei nicht geändert wurde</summary>
|
||||||
public bool IsCurrent => _eventsByChannel.Count > 0
|
public bool IsCurrent
|
||||||
&& (DateTime.Now - _loadedAt).TotalHours < 12;
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_eventsByChannel.Count == 0) return false;
|
||||||
|
if ((DateTime.Now - _loadedAt).TotalHours >= 12) return false;
|
||||||
|
// Cache-Datei neuer als letzter Parse? → neu laden
|
||||||
|
var todayFile = Path.Combine(CacheDir, $"epg_{DateTime.Today:yyyyMMdd}.xml");
|
||||||
|
if (File.Exists(todayFile))
|
||||||
|
{
|
||||||
|
var fileTime = new FileInfo(todayFile).LastWriteTime;
|
||||||
|
if (fileTime > _loadedAt) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Lädt EPG-Daten (Cache-Hit oder Web), parst und indiziert sie</summary>
|
/// <summary>Lädt EPG-Daten (Cache-Hit oder Web), parst und indiziert sie</summary>
|
||||||
public async Task LoadAsync(IProgress<string>? progress = null)
|
public async Task LoadAsync(IProgress<string>? progress = null)
|
||||||
|
|
@ -53,6 +68,7 @@ public class EpgService
|
||||||
progress?.Report("Parse EPG…");
|
progress?.Report("Parse EPG…");
|
||||||
ParseXmlTv(todayFile);
|
ParseXmlTv(todayFile);
|
||||||
_loadedAt = DateTime.Now;
|
_loadedAt = DateTime.Now;
|
||||||
|
_loadedFile = todayFile;
|
||||||
progress?.Report($"EPG: {_eventsByChannel.Count} Sender, {_eventsByChannel.Values.Sum(l => l.Count)} Events");
|
progress?.Report($"EPG: {_eventsByChannel.Count} Sender, {_eventsByChannel.Values.Sum(l => l.Count)} Events");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue