Esempio n. 1
0
        private void SendVentaPage2API(Stopwatch timerTokenRefresh, APIMethods api, VentaDTOBatch ventaListJson)
        {
            string ventaToPostJson = JsonConvert.SerializeObject(ventaListJson);

            Debug.WriteLine($"Sending page of records: {ventaToPostJson}");

            var done = api.PostVentaPage(ventaListJson, out ListProcessResult result);

            if (!done)
            {
                var msg = $"ERROR enviando ventas en paginas.";
                Debug.WriteLine(msg);
                throw new Exception(msg);
            }
            else
            {
                Debug.WriteLine($"Send result info - Creates: {result.Creations}; Updates: {result.Updates}");
            }

            if (timerTokenRefresh.Elapsed.TotalMinutes > 4)
            {
                //refresh token
                Debug.WriteLine("Refreshing api token");
                api.SetToken();
                if (api.TokenData == null)
                {
                    throw new System.Exception($"Could not refresh token from WebAPI, endpoint root was {_config.APIEndpoint}");
                }
                else
                {
                    timerTokenRefresh.Restart();
                }
            }
        }