/// <summary> /// Donwload a file from given <paramref name="url"/> and save it to <paramref name="downloadFile"/>. /// </summary> /// <param name="url">Url to download</param> /// <param name="downloadFile">Target file name</param> /// <returns><c>true</c> if successful</returns> public bool DownloadFile(string url, string downloadFile) { if (File.Exists(downloadFile)) { return(true); } try { try { _fileLock.EnterWriteLock(); if (File.Exists(downloadFile)) { return(true); } using (WebClient webClient = new CompressionWebClient()) webClient.DownloadFile(url, downloadFile); return(true); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Warn("OnlineLibraries.Downloader: Exception when downloading file {0} from {1} ({2})", downloadFile, url, ex.Message); return(false); } } finally { _fileLock.ExitWriteLock(); } }
/// <summary> /// Donwload a file from given <paramref name="url"/> and save it to <paramref name="downloadFile"/>. /// </summary> /// <param name="url">Url to download</param> /// <param name="downloadFile">Target file name</param> /// <returns><c>true</c> if successful</returns> public bool DownloadFile(string url, string downloadFile) { if (File.Exists(downloadFile)) { return(true); } try { WebClient webClient = new CompressionWebClient(); webClient.DownloadFile(url, downloadFile); return(true); } catch (Exception ex) { // TODO: logging return(false); } }