private async Task <ListOfRamoComercialDTO> RetrieveRamosComerciales() { Logger.Log(string.Format("Descargando Ramos Comerciales (Id:{0})", _idSync), Category.Info, Priority.Low); using (var client = new HttpClient()) { client.BaseAddress = new Uri(_webSyncServerAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // New code: try { HttpResponseMessage response = await client.GetAsync("api/ramos_comerciales.json"); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsAsync <Object>(); ListOfRamoComercialDTO listOfValues = Newtonsoft.Json.JsonConvert.DeserializeObject <ListOfRamoComercialDTO>(content.ToString()); Logger.Log(string.Format("Ramos Comerciales descargados con exito (Id:{0})", _idSync), Category.Info, Priority.Low); return(listOfValues); } return(null); } catch (HttpRequestException e) { Logger.Log(string.Format("Error descargando Ramos Comerciales (Id:{0}): {1}", _idSync, e.InnerException.Message), Category.Info, Priority.Low); return(null); } } }
private void UpdateRamosComerciales(ListOfRamoComercialDTO listOfRamosComerciales) { if (listOfRamosComerciales == null) { return; } //Repositorios using (var repository = new RamoComercialRepository()) { foreach (var item in listOfRamosComerciales.Ramos_Comerciales) { repository.AddOrUpdate(item); } } //Imagenes foreach (var item in listOfRamosComerciales.Ramos_Comerciales) { if (String.IsNullOrEmpty(item.ImagenURL.image.url)) { continue; } Uri webpath = new Uri("file://localhost" + item.ImagenURL.image.url); if (webpath.IsFile) { string filename = System.IO.Path.GetFileName(webpath.LocalPath); string inputfilepath = AppDomain.CurrentDomain.BaseDirectory + "media\\" + filename; if (!System.IO.File.Exists(inputfilepath)) { //descargo DownloadFileFTP(item.ImagenURL.image.url, inputfilepath); } } } }