Exemplo n.º 1
0
        public async Task <ActionResult <HistoryExtract> > GetComponentStatusHistory(
            string componentUid,
            string statusUid,
            DateTimeOffset?rangeStart,
            DateTimeOffset?rangeEnd,
            TimeSpan?interval,
            HistoryExtractDataType?dataType,
            int maxRowCount = 1000)
        {
            if (rangeEnd == null)
            {
                rangeEnd = DateTimeOffset.UtcNow;
            }

            if (rangeStart == null)
            {
                rangeStart = rangeEnd.Value.AddHours(-1);
            }

            if (dataType == null)
            {
                dataType = HistoryExtractDataType.Text;
            }

            if (dataType == HistoryExtractDataType.Number && interval == null)
            {
                interval = TimeSpan.FromMinutes(5);
            }

            if (dataType == HistoryExtractDataType.Text && interval != null)
            {
                return(new ObjectResult(new ProblemDetails
                {
                    Status = (int)HttpStatusCode.BadRequest,
                    Title = "Parameters are invalid.",
                    Detail = "Interval is not supported for data type TEXT."
                }));
            }

            var path = _componentHistoryService.BuildComponentStatusHistoryPath(componentUid, statusUid);

            var historyExtract = await _historyService.BuildHistoryExtractAsync(
                path,
                rangeStart.Value.UtcDateTime,
                rangeEnd.Value.UtcDateTime,
                interval,
                dataType.Value,
                maxRowCount,
                HttpContext.RequestAborted).ConfigureAwait(false);

            return(new ObjectResult(historyExtract));
        }