示例#1
0
 public static bool DownloadFileFromDB(this WebClient webclient, string url, string fileName)
 {
     try
     {
         webclient.SetStandardHeaders();
         DBTimers.Wait(url);
         Debug.WriteLine($"Hit DB at: {url} {DateTime.Now}");
         webclient.DownloadFile(url, fileName);
         return(true);
     }
     catch (WebException ex)
     {
         if (ex.Response != null)
         {
             var response = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
             Debug.WriteLine(response);
             Debug.WriteLine(ex.Message);
             Debug.WriteLine(ex.Source);
             Debug.WriteLine(ex.TargetSite);
             Debug.WriteLine(ex.Status);
             Debug.WriteLine(ex.HResult);
             Reporter.Warn($"Failure getting {url}. The website responded:");
             Reporter.Report(response);
         }
         return(false);
     }
 }
示例#2
0
        public static bool SafeDownloadStringDB(this WebClient webclient, string url, out string downloadtext)
        {
            webclient.SetStandardHeaders();
            try
            {
                DBTimers.Wait(url);
                Debug.WriteLine("Hit DB at: " + url + "  " + DateTime.Now);
                downloadtext = webclient.DownloadString(url);

                return(true);
            }

            catch (WebException ex)
            {
                if (ex.Response != null)
                {
                    var response = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();

                    Debug.WriteLine(response);
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.Source);
                    Debug.WriteLine(ex.TargetSite);
                    Debug.WriteLine(ex.Status);
                    Debug.WriteLine(ex.HResult);
                    downloadtext = response;
                }

                downloadtext = "Unknown web exception.";
                return(false);
            }
        }