Files
ersatztv/ErsatzTV.Infrastructure/Locking/EntityLocker.cs
T
Jason DoveandGitHub aa938baec8 enable plex for movies (#72)
* re-enable plex, temp force secure connections

* add plex fanart

* synchronize genre from plex

* fix plex library sync

* improve stream error handling

* synchronize plex artwork

* use switch instead of button

* prioritize local connections for insecure plex sources

* sign out of plex

* better plex sign in/out

* code cleanup

* fix plex movie aspect ratio and scan type
2021-03-13 21:04:54 +00:00

70 lines
1.8 KiB
C#

using System;
using System.Collections.Concurrent;
using ErsatzTV.Core.Interfaces.Locking;
namespace ErsatzTV.Infrastructure.Locking
{
public class EntityLocker : IEntityLocker
{
private readonly ConcurrentDictionary<int, byte> _lockedMediaSources;
private bool _plex;
public EntityLocker() => _lockedMediaSources = new ConcurrentDictionary<int, byte>();
public event EventHandler OnLibraryChanged;
public event EventHandler OnPlexChanged;
public bool LockLibrary(int mediaSourceId)
{
if (!_lockedMediaSources.ContainsKey(mediaSourceId) && _lockedMediaSources.TryAdd(mediaSourceId, 0))
{
OnLibraryChanged?.Invoke(this, EventArgs.Empty);
return true;
}
return false;
}
public bool UnlockLibrary(int mediaSourceId)
{
if (_lockedMediaSources.TryRemove(mediaSourceId, out byte _))
{
OnLibraryChanged?.Invoke(this, EventArgs.Empty);
return true;
}
return false;
}
public bool IsLibraryLocked(int mediaSourceId) =>
_lockedMediaSources.ContainsKey(mediaSourceId);
public bool LockPlex()
{
if (!_plex)
{
_plex = true;
OnPlexChanged?.Invoke(this, EventArgs.Empty);
return true;
}
return false;
}
public bool UnlockPlex()
{
if (_plex)
{
_plex = false;
OnPlexChanged?.Invoke(this, EventArgs.Empty);
return true;
}
return false;
}
public bool IsPlexLocked() => _plex;
}
}