Stream custom live channels using your own media
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

96 lines
2.4 KiB

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 _jellyfin;
private bool _plex;
public EntityLocker() => _lockedMediaSources = new ConcurrentDictionary<int, byte>();
public event EventHandler OnLibraryChanged;
public event EventHandler OnPlexChanged;
public event EventHandler OnJellyfinChanged;
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;
public bool LockJellyfin()
{
if (!_jellyfin)
{
_jellyfin = true;
OnJellyfinChanged?.Invoke(this, EventArgs.Empty);
return true;
}
return false;
}
public bool UnlockJellyfin()
{
if (_jellyfin)
{
_jellyfin = false;
OnJellyfinChanged?.Invoke(this, EventArgs.Empty);
return true;
}
return false;
}
}
}