public static void DownloadFile(string url, string path)
 {
     var tempFileInfo = new FileInfo(Path.Combine(FolderUtils.SystemTempFolder.FullName, Guid.NewGuid().ToString("N")));
     var targetFileInfo = new FileInfo(path);
     using (var client = new TerminologyWebClient())
     {
         client.DownloadFile(url, tempFileInfo.FullName);
         if (targetFileInfo.Directory != null && !targetFileInfo.Directory.Exists)
         {
             targetFileInfo.Directory.Create();
         }
         File.Copy(tempFileInfo.FullName, targetFileInfo.FullName, true);
     }
 }
        public static void DownloadFile(LeafNodeProgress progress, string url, string path)
        {
            var task = new Task(() =>
            {
                var tempFileInfo = new FileInfo(Path.Combine(FolderUtils.SystemTempFolder.FullName, Guid.NewGuid().ToString("N")));
                var targetFileInfo = new FileInfo(path);
                using (var client = new TerminologyWebClient())
                {
                    client.DownloadProgressChanged += (i, o) =>
                    {
                        progress.Percent = o.ProgressPercentage;
                    };
                    try
                    {
                        client.DownloadFileTaskAsync(url, tempFileInfo.FullName).Wait();
                    }
                    catch (AggregateException ex)
                    {
                        throw ex.GetBaseException();
                    }
                    catch (ArgumentException ex)
                    {
                        throw new ArgumentException(ex.Message + $"Url:{url}", ex);
                    }

                    if (targetFileInfo.Directory != null && !targetFileInfo.Directory.Exists)
                    {
                        targetFileInfo.Directory.Create();
                    }
                    File.Copy(tempFileInfo.FullName, targetFileInfo.FullName, true);
                }
            });
            task.Start();
            try
            {
                task.Wait();
            }
            catch (AggregateException ae)
            {

                throw ae.InnerException;
            }
        }
 public static string GetWebContent(LeafNodeProgress progress, string url)
 {
     var task = new Task<string>(() =>
     {
         using (var client = new TerminologyWebClient())
         {
             client.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
             client.Encoding = EncodeUtils.NoneBomUTF8;
             client.DownloadProgressChanged += (i, o) =>
             {
                 progress.Percent = o.ProgressPercentage;
             };
             try
             {
                 return client.DownloadStringTaskAsync(url).Result;
             }
             catch (ArgumentException ex)
             {
                 throw new ArgumentException(ex.Message + $"Url:{url}", ex);
             }
         }
     });
     task.Start();
     task.Wait();
     return task.Result;
 }
 public static string GetWebContent(string url)
 {
     using (var client = new TerminologyWebClient())
     {
         client.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
         client.Encoding = EncodeUtils.NoneBomUTF8;
         return client.DownloadString(url);
     }
 }