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