#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
{
///
/// The VolatileStorage event storage class keeps events only in memory which means that
/// the unhandled events will vanish when the application is restarted.
///
internal class VolatileStorage : ISubscriptionStorage
{
#region Fields
private Dictionary> db = new Dictionary>();
private object dbLock = new object();
#endregion
#region Methods
public void Remove(string eventSubscriberId, EventLogEntry logEntry)
{
lock (dbLock)
{
List pendingEventLogs;
if (db.TryGetValue(eventSubscriberId, out pendingEventLogs))
pendingEventLogs.Remove(logEntry);
}
}
public EventLogEntry[] GetStoredEvents(string eventSubscriberId)
{
lock (dbLock)
{
List 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 pendingEventLogs;
if (!db.TryGetValue(eventSubscriberId, out pendingEventLogs))
{
pendingEventLogs = new List();
db.Add(eventSubscriberId, pendingEventLogs);
}
pendingEventLogs.Add(logEntry);
}
}
#endregion
}
}