123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Linq;
- namespace fis.Vid
- {
- public class DisplayChannelList
- {
- private readonly ConcurrentDictionary<string, DisplayChannel> _channels = new ConcurrentDictionary<string, DisplayChannel>();
- /// <summary>
- /// Add a channel into list
- /// </summary>
- /// <param name="channel">The channel to be added</param>
- public void Add(DisplayChannel channel)
- {
- _channels.AddOrUpdate(channel.ChannelId, channel, (channelId, displayChannel) => channel);
- }
- /// <summary>
- /// Remove a channel from the list.
- /// </summary>
- /// <param name="channel"></param>
- public bool Remove(DisplayChannel channel)
- {
- return _channels.TryRemove(channel.ChannelId, out _);
- }
- /// <summary>
- /// Get all channels.
- /// </summary>
- /// <returns></returns>
- public IList<DisplayChannel> GetChannels()
- {
- return _channels.Values.ToList();
- }
- /// <summary>
- /// Get one channel by channel Id.
- /// </summary>
- /// <returns></returns>
- public DisplayChannel GetChannel(string channelId)
- {
- if (_channels.TryGetValue(channelId, out DisplayChannel channel))
- {
- return channel;
- }
- return null;
- }
- }
- }
|