private async Task <ListOfEnteComercialDTO> RetrieveEntesComerciales() { Logger.Log(string.Format("Descargando Entes 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/entes_comerciales.json"); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsAsync <Object>(); ListOfEnteComercialDTO listOfValues = Newtonsoft.Json.JsonConvert.DeserializeObject <ListOfEnteComercialDTO>(content.ToString()); Logger.Log(string.Format("Entes Comerciales descargados con exito (Id:{0})", _idSync), Category.Info, Priority.Low); return(listOfValues); } return(null); } catch (HttpRequestException e) { Logger.Log(string.Format("Error descargando Entes Comerciales (Id:{0}): {1}", _idSync, e.InnerException.Message), Category.Info, Priority.Low); return(null); } } }
private void UpdateEntesComerciales(ListOfEnteComercialDTO listOfEntesComerciales) { if (listOfEntesComerciales == null) { return; } //Repositorios using (var repository = new EnteComercialRepository()) { foreach (var item in listOfEntesComerciales.Entes_Comerciales) { repository.AddOrUpdate(item); } } //Imagenes foreach (var item in listOfEntesComerciales.Entes_Comerciales) { Uri webpath; //Imagen if (!String.IsNullOrEmpty(item.ImagenURL.image.url)) { 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); } } } //Logo if (!String.IsNullOrEmpty(item.LogoURL.logo.url)) { webpath = new Uri("file://localhost" + item.LogoURL.logo.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.LogoURL.logo.url, inputfilepath); } } } //Video if (!String.IsNullOrEmpty(item.VideoUrl)) { var path = _videosPath + "\\" + item.VideoUrl; if (System.IO.File.Exists(path)) { string inputfilepath = AppDomain.CurrentDomain.BaseDirectory + "videos\\" + item.VideoUrl; if (!System.IO.File.Exists(inputfilepath)) { System.IO.File.Copy(path, inputfilepath); } } } } }