protected virtual void OnNewSystemError(NewSystemErrorArgs e) { EventHandler <NewSystemErrorArgs> handler = NewSystemError; if (handler != null) { handler(this, e); } }
private async Task RunSystem() { _runSystem = true; while (_runSystem) { // check for token refresh required if (localSettings.Values["access_token"] == null || localSettings.Values["access_token_expire"] == null || !IsTokenValid(Convert.ToDateTime(localSettings.Values["access_token_expire"].ToString()))) { if (await GetAPIToken() == null) { _runSystem = false; NewSystemErrorArgs args = new NewSystemErrorArgs(); args.systemError = SystemError.no_connection; OnNewSystemError(args); break; } } // get the status SystemStatus systemStatus = await CashGenicAPIService.GetStatus(localSettings.Values["access_token"].ToString()); if (systemStatus == null) { _runSystem = false; NewSystemErrorArgs args = new NewSystemErrorArgs(); args.systemError = SystemError.no_connection; OnNewSystemError(args); break; } ParseStatus(systemStatus.Events); // any commands if (_cancelPayment) { _cancelPayment = false; SystemResponse systemResponse = await CashGenicAPIService.CancelSession(localSettings.Values["access_token"].ToString()); } if (_closeSession) { _closeSession = false; SystemResponse systemResponse = await CashGenicAPIService.EndSession(localSettings.Values["access_token"].ToString()); } // poll delay Thread.Sleep(500); } }