private void ConfigAndSetStartDateToRetrieve(ConnectionStringSettings configCS, int daysResend, out Stopwatch timerTokenRefresh, out APIMethods api, out GetLastResult _lastExportDate) { _config = new JobConfig { FarmaticConnectionString = configCS.ConnectionString, ProviderConnectionString = configCS.ProviderName, APIEndpoint = ConfigurationManager.AppSettings["APIEndpoint"], APIUser = ConfigurationManager.AppSettings["APIUser"], APIPwd = ConfigurationManager.AppSettings["APIPwd"], JWTAuthRoute = ConfigurationManager.AppSettings["APITokenEndpoint"], APIGetVentaData = ConfigurationManager.AppSettings["APIGetVentaData"], APIPostVentaData = ConfigurationManager.AppSettings["APIPostVentaData"], APIPostVentaDataRange = ConfigurationManager.AppSettings["APIPostVentaDataRange"], APICodUsuario = ConfigurationManager.AppSettings["APICodUsuario"], DaysToResend = daysResend, UseAPIRangeMethod = bool.Parse(ConfigurationManager.AppSettings["UseAPIRangeMethod"]) }; // try webApi retrieve lastrecord to limit request timerTokenRefresh = new Stopwatch(); timerTokenRefresh.Start(); api = new APIMethods(_config); api.SetToken(); if (api.TokenData == null) { throw new System.Exception($"Could not obtain token from WebAPI, endpoint root was {_config.APIEndpoint}"); } // 2. Get 'last export date' (if I can add column: ExportDate, if not fallback to use FechaVenta) data from webAPI _lastExportDate = api.GetLastExportInfo(); DateTime searchFrom = DateTime.Now; }
private int PrepareLocalDbCommand(int daysResend, APIMethods api) { // 2. Get 'last export date' (if I can add column: ExportDate, if not fallback to use FechaVenta) data from webAPI var _lastExportDate = api.GetLastExportInfo(); DateTime searchFrom = DateTime.Now; // 3. Get all records from a day before 'last export date' to now with SQL in pages of 20 records each if (_lastExportDate.Status == System.Net.HttpStatusCode.OK) { // searchFrom = searchFrom.AddDays(-1); var result = Math.Ceiling(DateTime.Now.Subtract(_lastExportDate.DateLastVenta).TotalDays); if (Config.DaysToResend < result) { daysResend = int.Parse(Math.Ceiling(result).ToString()); Log($"Getting from {daysResend} days ago: {DateTime.Now.AddDays(daysResend * -1).ToString("yyyy-MM-dd")}."); } else { Log($"Getting from {Config.DaysToResend} days ago: {DateTime.Now.AddDays(Config.DaysToResend * -1).ToString("yyyy-MM-dd")}."); } } else if (_lastExportDate.Status == System.Net.HttpStatusCode.NotFound) { // no hay registros, configurar para que envie todo (5 años) var dOld = DateTime.Now.AddYears(-5); var result = DateTime.Now.Subtract(dOld); Log($"Getting all currrent records from {dOld.ToString("yyyy-MM-dd")}"); daysResend = int.Parse(Math.Ceiling(result.TotalDays).ToString()); } return(daysResend); }