Exemple #1
0
        [Route("DataMessage")] // "api/datareceival/datamessage"
        public IActionResult DataMessage([FromBody] DataMessage receivedMessage)
        {
            if (receivedMessage == null)
            {
                return(BadRequest(new JsonResult(DataMessageService.CreateInvalidDataMessageResponseBody(receivedMessage))));
            }

            // Verify device's API Key.
            if (APIKeyService.VerifyAPIKey(receivedMessage.API_Key) < 0)
            {
                // If API Key does not exist or is deactivated.
                return(Unauthorized());
            }

            if (DataMessageService.CheckDataMessageValidity(receivedMessage) == false)
            {
                return(BadRequest(new JsonResult(DataMessageService.CreateInvalidDataMessageResponseBody(receivedMessage))));
            }
            else if (DataMessageService.StoreStatsFromDataMessage(receivedMessage))
            {
                // Asynchronously check hourly stats are ready for calculation and perform if needed.
                //Task hourlyStatsCheck = Task.Factory.StartNew(
                //() => _hourlyStatsService.AutoCalculateHourlyStats(receivedMessage));
                DataReceivalResponse receivalResponse = AlertSummaryService.GetReceivalResponse(receivedMessage);
                // Return HTTP OK, without waiting on asynchronous Task.
                return(StatusCode(200, new JsonResult(receivalResponse)));
            }

            return(StatusCode(500, new JsonResult(new FailedPersistResponseBody())));
        }
Exemple #2
0
        public DataReceivalResponse GetReceivalResponse(DataMessage receivedMessage)
        {
            DataReceivalResponse response = new DataReceivalResponse();

            response.NumberOfReceivedStats = receivedMessage.GetLength();
            bool sendAlertSummaryValue;

            lock (SendAlertSummaryLock)
            {
                sendAlertSummaryValue = SendAlertSummary;
                SendAlertSummary      = false;
            }
            if (sendAlertSummaryValue && receivedMessage.RealTimeStats.Length > 0)
            {
                //Assumes the entire message is only reporting for one camera
                response.ActiveAlertsForCamera = _alertService.GetAllActiveAlertsForCameraKey(receivedMessage.RealTimeStats.First().CameraKey);
            }

            return(response);
        }