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); }
//###################################### // WaitForSensorTargetResolution //###################################### private string WaitForSensorTargetResolution(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 = GetObject <SensorTargetProgress>(JsonFunction.GetAddSensorProgress, parameters); 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 Thread.Sleep(1000); #endif } } while (p.Percent < 100); if (!continueQuery) { return(null); } ResponseParser.ValidateSensorTargetProgressResult(p); var page = requestEngine.ExecuteRequest(HtmlFunction.AddSensor4, parameters); return(page); }