[banshee] [Hyena.Metrics] Clean up, make Sample subclassable



commit c3ba9b0b193f7d51eefe89ed00b5accdf0054de5
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Thu Feb 18 17:55:24 2010 -0800

    [Hyena.Metrics] Clean up, make Sample subclassable

 .../Hyena/Hyena.Metrics/MetricsCollection.cs       |    6 +++---
 src/Libraries/Hyena/Hyena.Metrics/Sample.cs        |    6 +++++-
 src/Libraries/Hyena/Makefile.am                    |    2 +-
 3 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/src/Libraries/Hyena/Hyena.Metrics/MetricsCollection.cs b/src/Libraries/Hyena/Hyena.Metrics/MetricsCollection.cs
index 5b649cd..a421ece 100644
--- a/src/Libraries/Hyena/Hyena.Metrics/MetricsCollection.cs
+++ b/src/Libraries/Hyena/Hyena.Metrics/MetricsCollection.cs
@@ -37,6 +37,8 @@ namespace Hyena.Metrics
 {
     public sealed class MetricsCollection : List<Metric>, IDisposable
     {
+        public static readonly int FormatVersion = 1;
+
         public string AnonymousUserId { get; private set; }
         public ISampleStore Store { get; private set; }
 
@@ -75,15 +77,13 @@ namespace Hyena.Metrics
             Clear ();
         }
 
-        const int CUR_FMT_VERSION = 1;
-
         public string ToJsonString ()
         {
             var report = new Dictionary<string, object> ();
 
             report["ID"] = AnonymousUserId;
             report["Now"] = DateTimeUtil.ToInvariantString (DateTime.Now);
-            report["FormatVersion"] = CUR_FMT_VERSION;
+            report["FormatVersion"] = FormatVersion;
 
             var metrics = new Dictionary<string, object> ();
             foreach (var metric in this.OrderBy (m => m.Name)) {
diff --git a/src/Libraries/Hyena/Hyena.Metrics/Sample.cs b/src/Libraries/Hyena/Hyena.Metrics/Sample.cs
index fca35df..ceb6e27 100644
--- a/src/Libraries/Hyena/Hyena.Metrics/Sample.cs
+++ b/src/Libraries/Hyena/Hyena.Metrics/Sample.cs
@@ -32,7 +32,7 @@ namespace Hyena.Metrics
     public class Sample
     {
         [DatabaseColumn (Constraints = DatabaseColumnConstraints.PrimaryKey)]
-        private long Id { get; set; }
+        protected long Id { get; set; }
 
         [DatabaseColumn]
         public string MetricName { get; protected set; }
@@ -50,7 +50,11 @@ namespace Hyena.Metrics
         {
             MetricName = metric.Name;
             Stamp = DateTime.Now;
+            SetValue (value);
+        }
 
+        protected void SetValue (object value)
+        {
             if (value == null) {
                 Value = "";
             } else if (value is DateTime) {
diff --git a/src/Libraries/Hyena/Makefile.am b/src/Libraries/Hyena/Makefile.am
index 9c81ba3..d771c9a 100644
--- a/src/Libraries/Hyena/Makefile.am
+++ b/src/Libraries/Hyena/Makefile.am
@@ -58,10 +58,10 @@ SOURCES =  \
 	Hyena.Jobs/SimpleAsyncJob.cs \
 	Hyena.Jobs/Tests/SchedulerTests.cs \
 	Hyena.Json/Deserializer.cs \
-	Hyena.Json/Serializer.cs \
 	Hyena.Json/IJsonCollection.cs \
 	Hyena.Json/JsonArray.cs \
 	Hyena.Json/JsonObject.cs \
+	Hyena.Json/Serializer.cs \
 	Hyena.Json/Tests/DeserializerTests.cs \
 	Hyena.Json/Tests/SerializerTests.cs \
 	Hyena.Json/Tests/TokenizerTests.cs \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]