DisplayChannelList.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections.Concurrent;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace fis.Vid
  5. {
  6. public class DisplayChannelList
  7. {
  8. private readonly ConcurrentDictionary<string, DisplayChannel> _channels = new ConcurrentDictionary<string, DisplayChannel>();
  9. /// <summary>
  10. /// Add a channel into list
  11. /// </summary>
  12. /// <param name="channel">The channel to be added</param>
  13. public void Add(DisplayChannel channel)
  14. {
  15. _channels.AddOrUpdate(channel.ChannelId, channel, (channelId, displayChannel) => channel);
  16. }
  17. /// <summary>
  18. /// Remove a channel from the list.
  19. /// </summary>
  20. /// <param name="channel"></param>
  21. public bool Remove(DisplayChannel channel)
  22. {
  23. return _channels.TryRemove(channel.ChannelId, out _);
  24. }
  25. /// <summary>
  26. /// Get all channels.
  27. /// </summary>
  28. /// <returns></returns>
  29. public IList<DisplayChannel> GetChannels()
  30. {
  31. return _channels.Values.ToList();
  32. }
  33. /// <summary>
  34. /// Get one channel by channel Id.
  35. /// </summary>
  36. /// <returns></returns>
  37. public DisplayChannel GetChannel(string channelId)
  38. {
  39. if (_channels.TryGetValue(channelId, out DisplayChannel channel))
  40. {
  41. return channel;
  42. }
  43. return null;
  44. }
  45. }
  46. }