using SharpChat.Events; using System; using System.Collections.Generic; using System.Linq; namespace SharpChat.EventStorage { public class VirtualEventStorage : IEventStorage { private readonly Dictionary Events = new(); public void AddEvent(IChatEvent evt) { if(evt == null) throw new ArgumentNullException(nameof(evt)); Events.Add(evt.SequenceId, evt); } public IChatEvent GetEvent(long seqId) { return Events.TryGetValue(seqId, out IChatEvent evt) ? evt : null; } public void RemoveEvent(IChatEvent evt) { if(evt == null) throw new ArgumentNullException(nameof(evt)); Events.Remove(evt.SequenceId); } public IEnumerable GetChannelEventLog(string channelName, int amount = 20, int offset = 0) { IEnumerable subset = Events.Values.Where(ev => ev.ChannelName == channelName); int start = subset.Count() - offset - amount; if(start < 0) { amount += start; start = 0; } return subset.Skip(start).Take(amount).ToArray(); } } }