Exemplo n.º 1
0
        // Validates a received DataMessage object's contents (all PerSecondStat objects contained).
        public bool CheckDataMessageValidity(DataMessage message)
        {
            if (message == null || message.IsEmpty())
            {
                return(false);
            }

            // Obtain a list of all valid Camera Keys currently in the system.
            List <string> validCameraKeyList = _dbQueryService.GetAllClaimedCameraKeys();

            for (int z = 0; z < message.GetLength(); z++)
            {
                // Verify the attributes of the PerSecondStat object, except for the  CameraKey.
                if (message.RealTimeStats[z].isValidSecondStat() == false)
                {
                    return(false);
                }

                // Verify its CameraKey.
                string cameraKeyToVerify = message.RealTimeStats[z].CameraKey;

                bool cameraKeyIsValid = validCameraKeyList.Where(o => string.Equals(cameraKeyToVerify, o, StringComparison.OrdinalIgnoreCase)).Any();

                if (cameraKeyIsValid == false)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        // Creates an error response body custom to the characteristics of the received DataMessage object.
        public InvalidDataMessageResponseBody CreateInvalidDataMessageResponseBody(DataMessage message)
        {
            if (message == null || message.IsEmpty())
            {
                return(new InvalidDataMessageResponseBody(true, null));
            }
            else
            {
                List <string> temp = new List <string>();

                for (int c = 0; c < message.GetLength(); c++)
                {
                    if (String.IsNullOrWhiteSpace(message.RealTimeStats[c].CameraKey))
                    {
                        temp.Add("CameraKey");
                    }

                    // Does not query the camera keys again in order to avoid server slow down.

                    if (message.RealTimeStats[c].NumTrackedPeople < 0)
                    {
                        temp.Add("NumTrackedPeople");
                    }

                    if (MySqlDateTimeConverter.CheckIfSQLFormat(message.RealTimeStats[c].DateTime) == false)
                    {
                        temp.Add("DateTime");
                    }
                    else if (message.RealTimeStats[c].DateTime.ToDateTime().ValidateDateTime() == false)
                    {
                        temp.Add("DateTime");
                    }
                }

                // Removes all duplicates from the list of failed attributes.
                temp = temp.Distinct().ToList <string>();

                // Counter for next step.
                int      x = 0;
                string[] failedAttributes = new string[temp.Count];

                // Store values in an array of strings.
                foreach (string distinctAttribute in temp)
                {
                    failedAttributes[x] = distinctAttribute;
                    x++;
                }

                return(new InvalidDataMessageResponseBody(false, failedAttributes));
            }
        }
Exemplo n.º 3
0
        // Validates a received DataMessage object's contents (all PerSecondStat objects contained).
        public bool CheckDataMessageValidity(DataMessage message)
        {
            if (message.IsEmpty())
            {
                return(false);
            }

            for (int z = 0; z < message.GetLength(); z++)
            {
                if (message.RealTimeStats[z].isValidSecondStat() == false)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        public IActionResult GetPerSecondStatsFromTimeInterval([FromBody] PerSecondStatsFromTimeIntervalRequest unverifiedTimeIntervalRequest)
        {
            // Verify device's API Key.
            if (_apiKeyService.VerifyAPIKey(unverifiedTimeIntervalRequest.API_Key) < 0)
            {
                // If API Key does not exist or is deactivated.
                return(Unauthorized());
            }

            if (DataMessageService.CheckTimeIntervalValidity(unverifiedTimeIntervalRequest.TimeInterval) == false)
            {
                return(BadRequest(new JsonResult(new InvalidTimeIntervalResponseBody())));
            }

            DataMessage responseBody = DataMessageService.RetrievePerSecondStatsBetweenInterval(unverifiedTimeIntervalRequest.TimeInterval);

            if (responseBody.IsEmpty())
            {
                return(NoContent());
            }

            return(Ok(new JsonResult(responseBody)));
        }