private async Task <string> WaitForSensorTargetResolutionAsync(int deviceId, int tmpId, Func <int, bool> progressCallback) { var parameters = new SensorTargetProgressParameters(deviceId, tmpId); SensorTargetProgress p; bool continueQuery = true; var stopwatch = new Stopwatch(); var timeout = TimeSpan.FromSeconds(60); stopwatch.Start(); do { p = await ObjectEngine.GetObjectAsync <SensorTargetProgress>(parameters).ConfigureAwait(false); if (progressCallback != null) { continueQuery = progressCallback(p.Percent); } if (p.Percent < 100) { if (!continueQuery) { break; } if (stopwatch.Elapsed > timeout) { throw new TimeoutException("Failed to retrieve sensor information within a reasonable period of time. Check target device is accessible and that valid credentials have been supplied"); } #if !DEBUG await Task.Delay(1000).ConfigureAwait(false); #endif } } while (p.Percent < 100); if (!continueQuery) { return(null); } ResponseParser.ValidateSensorTargetProgressResult(p); var page = await RequestEngine.ExecuteRequestAsync(new SensorTargetCompletedParameters(deviceId, tmpId)).ConfigureAwait(false); return(page); }
private async Task <NotificationTriggerData> GetNotificationTriggerDataAsync(int objectId, CancellationToken token) => await ObjectEngine.GetObjectAsync <NotificationTriggerData>( new NotificationTriggerDataParameters(objectId), ParseNotificationTriggerTypesAsync, token ).ConfigureAwait(false);
/// <summary> /// Asynchronously resolves an address to its latitudinal and longitudinal coordinates. May spuriously return no results. /// </summary> /// <param name="address">The address to resolve.</param> /// <param name="token">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns></returns> internal async Task <List <Location> > ResolveAddressAsync(string address, CancellationToken token) => (await ObjectEngine.GetObjectAsync <GeoResult>(new ResolveAddressParameters(address), m => Task.FromResult(ResponseParser.ResolveParser(m)), token).ConfigureAwait(false)).Results.ToList();