12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #region --------------- Copyright Dresser Wayne Pignone -------------
- #endregion
- using System.Collections.Generic;
- namespace Wayne.Lib.Log
- {
-
-
-
-
- internal class VolatileStorage : ISubscriptionStorage
- {
- #region Fields
- private Dictionary<string, List<EventLogEntry>> db = new Dictionary<string, List<EventLogEntry>>();
- private object dbLock = new object();
- #endregion
- #region Methods
- public void Remove(string eventSubscriberId, EventLogEntry logEntry)
- {
- lock (dbLock)
- {
- List<EventLogEntry> pendingEventLogs;
- if (db.TryGetValue(eventSubscriberId, out pendingEventLogs))
- pendingEventLogs.Remove(logEntry);
- }
- }
- public EventLogEntry[] GetStoredEvents(string eventSubscriberId)
- {
- lock (dbLock)
- {
- List<EventLogEntry> pendingEventLogs;
- if (db.TryGetValue(eventSubscriberId, out pendingEventLogs))
- return pendingEventLogs.ToArray();
- else
- return new EventLogEntry[0];
- }
- }
- public void Add(string eventSubscriberId, EventLogEntry logEntry)
- {
- lock (dbLock)
- {
- List<EventLogEntry> pendingEventLogs;
- if (!db.TryGetValue(eventSubscriberId, out pendingEventLogs))
- {
- pendingEventLogs = new List<EventLogEntry>();
- db.Add(eventSubscriberId, pendingEventLogs);
- }
- pendingEventLogs.Add(logEntry);
- }
- }
- #endregion
- }
- }
|