Files
ersatztv/ErsatzTV.Core/SystemStartup.cs
T
Jason DoveandGitHub 7e30444857 dependencies and code cleanup (#2117)
* fix validation in new form layout

* pin mediatr to last oss version

* update dependencies

* cleanup code in core

* cleanup code in ffmpeg

* cleanup code in infra

* cleanup code in scanner

* cleanup code in application

* cleanup main code

* cleanup test code

* solution-wide code cleanup
2025-07-06 15:56:17 +00:00

70 lines
2.0 KiB
C#

namespace ErsatzTV.Core;
public class SystemStartup : IDisposable
{
private readonly SemaphoreSlim _databaseCleaned = new(0, 100);
private readonly SemaphoreSlim _databaseStartup = new(0, 100);
private readonly SemaphoreSlim _searchIndexStartup = new(0, 100);
private bool _disposedValue;
public bool IsDatabaseReady { get; private set; }
public bool IsDatabaseCleaned { get; private set; }
public bool IsSearchIndexReady { get; private set; }
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public event EventHandler OnDatabaseReady;
public event EventHandler OnDatabaseCleaned;
public event EventHandler OnSearchIndexReady;
public async Task WaitForDatabase(CancellationToken cancellationToken) =>
await _databaseStartup.WaitAsync(cancellationToken);
public async Task WaitForDatabaseCleaned(CancellationToken cancellationToken) =>
await _databaseCleaned.WaitAsync(cancellationToken);
public async Task WaitForSearchIndex(CancellationToken cancellationToken) =>
await _searchIndexStartup.WaitAsync(cancellationToken);
public void DatabaseIsReady()
{
_databaseStartup.Release(100);
IsDatabaseReady = true;
OnDatabaseReady?.Invoke(this, EventArgs.Empty);
}
public void DatabaseIsCleaned()
{
_databaseCleaned.Release(100);
IsDatabaseCleaned = true;
OnDatabaseCleaned?.Invoke(this, EventArgs.Empty);
}
public void SearchIndexIsReady()
{
_searchIndexStartup.Release(100);
IsSearchIndexReady = true;
OnSearchIndexReady?.Invoke(this, EventArgs.Empty);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
_databaseStartup.Dispose();
_databaseCleaned.Dispose();
_searchIndexStartup.Dispose();
}
_disposedValue = true;
}
}
}