Commits

wasp committed c49548e

Extracting PersistorBase from InMemoryPersistor

  • Participants
  • Parent commits 5d1b73d

Comments (0)

Files changed (3)

src/ElmahR/Core/Persistors/InMemoryPersistor.cs

+using System.ComponentModel.DataAnnotations;
 namespace ElmahR.Core.Persistors
 {
     #region Imports
 
-    using System.Collections;
     using System.Collections.Generic;
-    using System.Web;
     using System.Linq;
     using Extensions;
 
     #endregion
 
-    public class InMemoryPersistor : IApplicationsPersistor
+    public class InMemoryPersistor : PersistorBase
     {
-        private readonly Dictionary<string, Application> _sources = new Dictionary<string, Application>();
-
         private readonly List<Error> _errors = new List<Error>();
         private readonly Dictionary<string, Error> _errorsById = new Dictionary<string, Error>();
 
-        public void Add(string key, Application application)
-        {
-            _sources.Add(key, application);
-        }
-
-        public Application this[string key]
-        {
-            get { return _sources.ContainsKey(key) ? _sources[key] : null; }
-        }
-
-        public void AddError(Error error, string errorId)
+        public override void AddError(Error error, string errorId)
         {
             lock (_errors)
             {
             }
         }
 
-        public Error GetError(string id)
+        public override Error GetError(string id)
         {
             return _errorsById.ContainsKey(id) ? _errorsById[id] : null;
         }
 
-        public IEnumerable<Error> GetErrors()
+        public override IEnumerable<Error> GetErrors()
         {
             return _errors;
         }
 
-        public IEnumerable<Error> GetErrors(int count)
+        public override IEnumerable<Error> GetErrors(int count)
         {
             return _errors.Take(count);
         }
 
-        public IEnumerable<Error> GetErrors(int count, int beforeId)
+        public override IEnumerable<Error> GetErrors(int count, int beforeId)
         {
             return (from e in
                         from ue in _errors.Index()
                     where e.Key < beforeId
                     select e.Value).Take(count);
         }
-
-        public IEnumerator<Application> GetEnumerator()
-        {
-            return _sources.Values.GetEnumerator();
-        }
-
-        IEnumerator IEnumerable.GetEnumerator()
-        {
-            return GetEnumerator();
-        }
     }
 }

src/ElmahR/Core/Persistors/PersistorBase.cs

+namespace ElmahR.Core.Persistors
+{
+    #region Imports
+
+    using System.Collections;
+    using System.Collections.Generic;
+
+    #endregion
+
+    public abstract class PersistorBase : IApplicationsPersistor
+    {
+        private readonly Dictionary<string, Application> _sources = new Dictionary<string, Application>();
+
+        public void Add(string key, Application application)
+        {
+            _sources.Add(key, application);
+        }
+
+        public Application this[string key]
+        {
+            get { return _sources.ContainsKey(key) ? _sources[key] : null; }
+        }
+
+        public abstract void AddError(Error error, string errorId);
+
+        public abstract Error GetError(string id);
+
+        public abstract IEnumerable<Error> GetErrors();
+
+        public abstract IEnumerable<Error> GetErrors(int count);
+
+        public abstract IEnumerable<Error> GetErrors(int count, int beforeId);
+
+        public IEnumerator<Application> GetEnumerator()
+        {
+            return _sources.Values.GetEnumerator();
+        }
+
+        IEnumerator IEnumerable.GetEnumerator()
+        {
+            return GetEnumerator();
+        }
+    }
+}

src/ElmahR/ElmahR.csproj

     <Compile Include="Core\Error.cs" />
     <Compile Include="Core\Applications.cs" />
     <Compile Include="Core\Persistors\IApplicationsPersistor.cs" />
+    <Compile Include="Core\Persistors\PersistorBase.cs" />
     <Compile Include="Global.asax.cs">
       <DependentUpon>Global.asax</DependentUpon>
     </Compile>