public MetricHistory Add(MetricHistory data) { if (data.Id == Guid.Empty) { data.Id = Guid.NewGuid(); } Context.MetricHistories.Add(data); return(data); }
protected IBulbCacheReadObject SetMetricValue( IMetricTypeCacheReadObject metricType, MetricCacheWriteObject metric, double?value, DateTime processDate, DateTime actualDate, MonitoringStatus status, string message, bool hasSignal) { // Обновим текущие значения var equal = (value == null && metric.Value == null) || (value == metric.Value); if (!equal) { metric.BeginDate = processDate; } metric.ActualDate = actualDate; metric.Value = value; // Обновим статус метрики var statusService = Context.BulbService; var noSignalColor = metric.NoSignalColor ?? metricType.NoSignalColor ?? ObjectColor.Red; var noSignalImportance = EventImportanceHelper.Get(noSignalColor); var signal = new BulbSignal() { AccountId = metric.AccountId, ActualDate = metric.ActualDate, StartDate = metric.BeginDate, IsSpace = !hasSignal, EventId = Guid.Empty, Message = message, NoSignalImportance = noSignalImportance, ProcessDate = processDate, Status = status }; var statusData = statusService.SetSignal(metric.StatusDataId, signal); // сохраним историю var color = ObjectColorHelper.Get(status); var history = new MetricHistory() { ComponentId = metric.ComponentId, MetricTypeId = metric.MetricTypeId, Value = value, BeginDate = processDate, ActualDate = actualDate, Color = color, StatusEventId = statusData.StatusEventId, HasSignal = hasSignal }; var accountDbContext = Context.GetAccountDbContext(metric.AccountId); var historyRepository = accountDbContext.GetMetricHistoryRepository(); historyRepository.Add(history); Context.SaveChanges(); return(statusData); }