12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #region --------------- Copyright Dresser Wayne Pignone -------------
- /*
- * $Log: /Wrk/WayneLibraries/Wrk/Log/EventLogStorage/VolatileStorage.cs $
- *
- * 2 08-02-18 7:58 Mattias.larsson
- * Optimized use of Dictionaries.
- */
- #endregion
- using System.Collections.Generic;
- namespace Wayne.Lib.Log
- {
- /// <summary>
- /// The VolatileStorage event storage class keeps events only in memory which means that
- /// the unhandled events will vanish when the application is restarted.
- /// </summary>
- 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
- }
- }
|