private void CreateDaysData(bool isRealSimulation, int days) { var monitorDb = new MonitorDb(); if (days > 0) { for (var i = days; i >= 0; i--) { var date = DateTime.UtcNow.AddDays(-i); if (isRealSimulation) { var realData = GenerateRandomMonitorValues(); foreach (var monitorValue in realData) { monitorDb.DeleteOldHistory(date, (int)FrequencyTypes.Minutes); ProcessHistoryByFrequency(monitorValue, date, FrequencyTypes.Days); } } else { var monitorValue = new MonitorValue { AgentId = 1, MonitorCommandId = 1, Value = GetRandomNumber(), ErrorMessage = "" }; monitorDb.InsertHistory(monitorValue, date, FrequencyTypes.Days); } } } }
public IHttpActionResult Post([FromBody] List <MonitorValue> commandValues) { _logger.Info("-----------------------------------------"); _logger.Info("MonitorValuesController..."); _logger.Info(ObjectDumper.Dump(commandValues)); var headers = Request.Headers; var serverGuid = headers.GetValues("server_guid").First(); if (!Util.IsServerGuidValid(serverGuid)) { throw new HttpResponseException(HttpStatusCode.Unauthorized); } try { var guid = headers.GetValues("agent_guid").First(); var agent = monitorDb.GetAgentByGuid(guid); monitorDb.DeleteOldHistory(DateTime.UtcNow); foreach (var commandValue in commandValues) { var MonitorValue = new BusinessLayer.MonitorValue() { AgentId = agent.AgentId, // This should be derived from header MonitorCommandId = commandValue.Id, ReturnCode = commandValue.ReturnCode, Value = commandValue.Value, ErrorMessage = commandValue.ErrorMessage }; _logger.Debug($"MonitorValuesController : UpsertMonitorValue"); monitorDb.UpsertMonitorValue(MonitorValue); _logger.Debug($"MonitorValuesController : UpdateLastReceivedReply"); monitorDb.UpdateLastReceivedReply(agent.AgentId); } return(Ok()); } catch (Exception e) { _logger.Error($"Post method Exception:{e.Message}"); return(BadRequest()); } }