Example #1
0
        private static bool RunQuery(QueryOptions opts)
        {
            var deviceManager = new DeviceManager(Storage, ApiClient);

            var deviceCode = deviceManager.GetDeviceCode();
            if (deviceCode == null)
                return false;

            var data = AuthenticateAndRetrieveData(deviceCode, opts);

            Console.WriteLine(JsonConvert.SerializeObject(opts.OnlyTotals ? data.totalsForAllResults : data, Formatting.Indented));
            return true;
        }
Example #2
0
        private static dynamic AuthenticateAndRetrieveData(string deviceCode, QueryOptions queryOptions)
        {
            var tokenManager = new TokenManager(deviceCode, Storage, ApiClient);

            dynamic realTimeData = null;

            var policy =
                Policy
                    .Handle<UnauthorizedException>()
                    .Retry(1, (exception, retryCount) =>
                    {
                        tokenManager.CreateRefreshToken();
                        realTimeData = ApiClient.GetRealTimeData(queryOptions, tokenManager.GetAccessToken());
                    });

            policy.Execute(() =>
            {
                realTimeData = ApiClient.GetRealTimeData(queryOptions, tokenManager.GetAccessToken());
            });

            return realTimeData;
        }