Exemplo n.º 1
0
        public static IEnumerable<GitHubFileInfo> GetFiles(string relativePath)
        {
            try
            {
                using (var client = new WebClientWithCustomTimeout(TimeSpan.FromSeconds(10)))
                {
                    var uri = Uri.EscapeUriString(RepositoryRootUrl + relativePath);
                    var responseJson = client.DownloadString(uri);
                    if (string.IsNullOrEmpty(responseJson)) return null;
                    if (responseJson.Contains("Not Found")) return null;

                    var serializer = new DataContractJsonSerializer(typeof(List<GitHubFileInfo>));
                    var fileInfos = serializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(responseJson))) as List<GitHubFileInfo>;
                    return fileInfos;
                }
            }
            catch (WebException ex)
            {
                var httpWebresponse = ex.Response as HttpWebResponse;
                if (httpWebresponse == null)
                {
                    s_logger.Warn(ex, "An unexpected response received. Path: '{0}'.", relativePath);
                }
                else if (httpWebresponse.StatusCode == HttpStatusCode.NotFound)
                {
                    s_logger.Info(ex, "Requested repository directory '{0}' not found.", relativePath);
                }
                return null;
            }
            catch (Exception ex)
            {
                s_logger.Warn(ex, "An error occurred during retrieving rep files from '{0}'.", relativePath);
                return null;
            }
        }
Exemplo n.º 2
0
 public static void DownloadFile(string url, string filePath)
 {
     try
     {
         using (var client = new WebClientWithCustomTimeout(TimeSpan.FromSeconds(10)))
         {
             client.DownloadFile(url, filePath);
         }
     }
     catch (Exception ex)
     {
         s_logger.Warn(ex, "An error occurred during patch file download.");
     }
 }
Exemplo n.º 3
0
        public static void DownloadFile([NotNull] string url, [NotNull] string filePath)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            try
            {
                using (var client = new WebClientWithCustomTimeout(TimeSpan.FromSeconds(10)))
                {
                    client.DownloadFile(url, filePath);
                }
            }
            catch (Exception ex)
            {
                Trace.Warn(ex, "An error occurred during file download. " + url);
            }
        }
Exemplo n.º 4
0
 public static GitHubRelease GetLatestRelease()
 {
     try
     {
         using (var client = new WebClientWithCustomTimeout(TimeSpan.FromSeconds(10)))
         {
             var responseJson = client.DownloadString(LatestReleaseUrl);
             var serializer = new DataContractJsonSerializer(typeof(GitHubRelease));
             var releaseObject = serializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(responseJson))) as GitHubRelease;
             return releaseObject;
         }
     }
     catch (Exception ex)
     {
         s_logger.Warn(ex, "An error occurred during checking for updates.");
         return null;
     }
 }