public async Task <ProcessValues> ReadProcessDataAsync(DatanodeQueryCriteria criteria, CancellationToken cancellationToken = default(CancellationToken)) { if (criteria == null) { throw new ArgumentNullException("criteria"); } string uri = String.Format(ReadDataResourceFormat, criteria.DeviceId, Uri.EscapeUriString(String.Join(",", criteria.Datanodes))); if (criteria.SortOrder != DatanodeQueryCriteria.Order.Unset) { uri += String.Format("&order={0}", criteria.SortOrder.ToString().ToLower()); } if (criteria.StartDate.HasValue) { uri += "&fromdate=" + criteria.StartDate.Value.ToUnixTime(); } if (criteria.EndDate.HasValue) { uri += "&todate=" + criteria.EndDate.Value.ToUnixTime(); } if (criteria.Count.HasValue) { uri += "&limit=" + criteria.Count.Value; } using (var response = await _client.HandledGetAsync(uri, cancellationToken)) { var processValues = await JsonSerializer.DeserializeAsync <ProcessValues>(response.Content); return(processValues); } }
public void ReadProcessData_NoCancellationToken_ResultsReturned() { var criteria = new DatanodeQueryCriteria(DeviceId, "MyTestDatapoint") { Count = 5, StartDate = DateTime.Now.AddDays(-7), EndDate = DateTime.Now, SortOrder = DatanodeQueryCriteria.Order.Descending }; var processData = _client.ReadProcessDataAsync(criteria).Result; Assert.IsNotNull(processData); Assert.IsNotNull(processData.Datanodes); Assert.IsNotNull(processData.Datanodes.First()); Assert.IsTrue(processData.Datanodes.First().Values.Any()); Assert.AreNotEqual(DateTime.MinValue, processData.Datanodes.First().Values.First().Timestamp); Assert.AreNotEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), processData.Datanodes.First().Values.First().Timestamp); Assert.IsNotNull(DateTime.MinValue, processData.Datanodes.First().Values.First().StringValue); }