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);
            }
        }
Пример #2
0
        public static async Task <SystemStatus> GetStatus(string token)
        {
            var client  = GetClient();
            var request = new RestRequest("status", Method.GET);

            request.AddHeader("Authorization", "Bearer " + token);
            IRestResponse response = await client.ExecuteAsync(request);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                SystemStatus systemStatus = JsonConvert.DeserializeObject <SystemStatus>(response.Content);
                return(systemStatus);
            }
            else
            {
                return(null);
            }
        }