EventLogStorage.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections.Generic;
  2. namespace Wayne.Lib.Log
  3. {
  4. internal class EventLogStorage
  5. {
  6. #region Fields
  7. private Dictionary<LogConfigEventLogStorageType, ISubscriptionStorage> storageDict = new Dictionary<LogConfigEventLogStorageType, ISubscriptionStorage>();
  8. #endregion
  9. #region Construction
  10. public EventLogStorage()
  11. {
  12. storageDict[LogConfigEventLogStorageType.Volatile] = new VolatileStorage();
  13. storageDict[LogConfigEventLogStorageType.NoStorage] = new NoStorage();
  14. storageDict[LogConfigEventLogStorageType.RestartSafe] = new FileSystemStorage();
  15. }
  16. #endregion
  17. #region Methods
  18. internal void Add(string subscriberId, EventLogEntry logEntry, LogConfigEventLogStorageType storageType)
  19. {
  20. storageDict[storageType].Add(subscriberId, logEntry);
  21. }
  22. internal EventLogEntry[] GetPendingEvents(string eventSubscriberId)
  23. {
  24. List<EventLogEntry> entries = new List<EventLogEntry>();
  25. foreach (ISubscriptionStorage storage in storageDict.Values)
  26. entries.AddRange(storage.GetStoredEvents(eventSubscriberId));
  27. return entries.ToArray();
  28. }
  29. internal void Remove(IEventSubscriber eventSubscriber, EventLogEntry eventLogEntry)
  30. {
  31. foreach (ISubscriptionStorage storage in storageDict.Values)
  32. storage.Remove(eventSubscriber.SubscriberId, eventLogEntry);
  33. }
  34. #endregion
  35. }
  36. }