コード例 #1
0
 public Task <ICollection <QueryResult> > Query([FromBody] ICollection <QueryDescriptor> queries)
 {
     try
     {
         return(_measurementsRepository.Query(queries));
     }
     catch (ArgumentException ex)
     {
         throw new HttpException(HttpStatusCode.BadRequest, "Bad request parameters.", ex);
     }
     catch (MeasurementsRepositoryException ex)
     {
         throw new HttpException(HttpStatusCode.InternalServerError, "Cannot query measurements from repository.", ex);
     }
 }
コード例 #2
0
        public async Task <QueryResult> GetMeasurements(string deviceId, DateTime?dateFrom = null, DateTime?dateTo = null)
        {
            try
            {
                ICollection <QueryResult> queryResults = await _measurementsRepository.Query(new[] { new QueryDescriptor(deviceId, dateFrom, dateTo) });

                QueryResult queryResult = queryResults.FirstOrDefault();
                if (queryResult == null)
                {
                    throw new HttpException(HttpStatusCode.NotFound, $"Measurements for device identifier {deviceId} not found.");
                }

                return(queryResult);
            }
            catch (ArgumentException ex)
            {
                throw new HttpException(HttpStatusCode.BadRequest, "Bad request parameters.", ex);
            }
            catch (MeasurementsRepositoryException ex)
            {
                throw new HttpException(HttpStatusCode.InternalServerError, "Cannot query measurements from repository.", ex);
            }
        }