public void TestMetricsCRUD()
        {
            var repo = Container.Resolve<MetricsRepository>();
            var m = new MetricsEntity() {Name = "Test"};
            repo.Save(m);
            Assert.IsTrue(m.Id>0);

            m.AddEntry(1);
            m.AddEntry(2);
            m.AddEntry(3);
            repo.SaveOrUpdate(m);

            var mm = repo.Load(m.Id);
            Assert.AreEqual(mm.Id, m.Id);
            Assert.AreEqual(3, mm.Entries.Count);
        }
 public void UpdateMetrics(MetricsEntity metrics)
 {
     lock (locker)
     {
         if (metrics == null || metrics.IsTransient())
         {
             throw new Exception(metrics + " is transient or null. Use service to get metrics");
         }
         foreach (var e in metrics.Entries) e.Metrics = metrics;
         metricsRepo.Update(metrics);
     }
 }
 public void EnsureRelation(IClassifiable entity, MetricsEntity metrics)
 {
     if(!relationService.IsRelated(entity, metrics, relationNode))
     {
         relationService.RemoveRelations(metrics, relationNode);
         relationService.AddRelation(entity, metrics, RelationDirection.Forward, relationNode);
     }
     
 }
 public MetricsEntity CreateMetrics(string name, IClassifiable entity, string descr)
 {
     MetricsEntity metrics;
     metrics = new MetricsEntity(name, descr ?? String.Format("for {0}({1})", entity.ObjectName, entity.Id));
     metricsRepo.Save(metrics);
     relationService.AddRelation(entity, metrics, RelationDirection.Forward, relationNode);
     return metrics;
 }
 private decimal[] SparkleValues(MetricsEntity d)
 {
     return d.Entries.Skip(Math.Max(0, d.Entries.Count - 20))
         .Select(e => e.Value).ToArray();
 }