/// <summary> /// Gets the Ping information from the Ping endpoint. /// </summary> /// <returns>The ping data.</returns> /// <param name="address">Address to query.</param> private async Task <PingAnalysisResult> GetPingDataAsync(string address) { string pingApiUrl = Config.GetValue <string>("pingApiUrl"); Uri pingAnalyzeRoute = new Uri($"{pingApiUrl}/api/v1/analyze/{address}"); PingWorker pingWorker = new PingWorker(pingAnalyzeRoute); PingAnalysisResult result = await pingWorker.FetchDataAsync(); return(result); }
public async Task ConnectAsync() { if (isDisposed) { throw new ObjectDisposedException("SerialDeviceManager"); } Exception connectException = null; await deviceEventCtrl.RaiseAsync(this, async() => { if (state != OTPDeviceState.Disconnected) { throw new Exception("Device manager is in wrong state: " + state.ToString()); } try { port.Open(); commHelper = new StreamCommHelper(port.BaseStream, config); var lcgInitValues = await CommHelper.Resync(); //run resync; reqLCG.ReInit(lcgInitValues.Key); ansLCG.ReInit(lcgInitValues.Value); } catch (Exception ex) { commHelper = null; connectException = ex; state = OTPDeviceState.Failed; return(new OTPDeviceEventArgs() { State = OTPDeviceState.Failed, Error = ex }); } //run ping worker thread pingWorker = PingWorker.StartNewWorker(pingLock, CommHelper, reqLCG, ansLCG, config.PING_INTERVAL, PingFailedCallback); //state change state = OTPDeviceState.Connected; return(new OTPDeviceEventArgs() { State = OTPDeviceState.Connected, Error = null }); }); if (connectException != null) { throw connectException; } }
public async Task DisconnectAsync() { if (isDisposed) { throw new ObjectDisposedException("SerialDeviceManager"); } Exception disconnectException = null; await deviceEventCtrl.RaiseAsync(this, () => { if (state != OTPDeviceState.Connected) { throw new Exception("Device manager is in wrong state: " + state.ToString()); } try { pingWorker.Stop(); //kill ping worker thread (should not throw exceptions) port.Close(); } catch (Exception ex) { disconnectException = ex; state = OTPDeviceState.Failed; return(Task.FromResult(new OTPDeviceEventArgs() { State = OTPDeviceState.Failed, Error = ex })); } finally { pingWorker = null; commHelper = null; } //state change state = OTPDeviceState.Disconnected; return(Task.FromResult(new OTPDeviceEventArgs() { State = OTPDeviceState.Disconnected, Error = null })); }); if (disconnectException != null) { throw disconnectException; } }
public void Consume(PingWorker message) { PublishWorkerAvailability(); }