Esempio n. 1
0
        /// <summary>
        /// Get repository info from GitHub based on the passed in username
        /// </summary>
        public async Task <List <RepoResponse> > GetUserRepoInformation(string username)
        {
            string url = WebConfigHelper.GetUsersReposEndpoint(username);
            List <RepoResponse> userRepoResponse = await WebRequestHelper.GetResponseAsync <List <RepoResponse> >(url);

            // Order by star gazers count descending then take the top [x] amount as set in the web config.
            return(userRepoResponse.OrderByDescending(repo => repo.StargazersCount).Take(WebConfigHelper.GetNumberOfReposToDisplay()).ToList());
        }
Esempio n. 2
0
        public void TestGetGitHubUserInfo_IsExpectedType()
        {
            // arrange
            string url = "https://api.github.com/users/sohail92";

            // act
            var result = WebRequestHelper.GetResponseAsync <UserResponse>(url);

            // assert
            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsInstanceOfType(result.Result, typeof(UserResponse));
        }
Esempio n. 3
0
        public void TestGetGitHubUserInfo_ReturnsData(string username)
        {
            // arrange
            string url = $"https://api.github.com/users/{username}";

            // act
            var result = WebRequestHelper.GetResponseAsync <UserResponse>(url);

            // assert
            NUnit.Framework.Assert.IsNotNull(result);
        }
        static void InternalSendFeedback(XmlElement feedbackElem)
        {
            string email = feedbackElem.GetAttribute("email");
            string body  = feedbackElem.InnerText;

            WebRequestHelper.GetResponseAsync(
                () => (HttpWebRequest)WebRequest.Create(feedbackUrl.Value + "?m=" + email),
                r => {
                r.Method = "POST";
                using (var sw = new StreamWriter(r.GetRequestStream())) {
                    sw.Write(body);
                }
            }
                ).ContinueWith(HandleResponse);
        }
Esempio n. 5
0
        void Load()
        {
            string tempPath = cachePath + ".tmp";

            LoadFromDisk(cachePath, false);

            var finfo = new FileInfo(cachePath);

            WebRequestHelper.GetResponseAsync(
                () => (HttpWebRequest)WebRequest.Create(url),
                r => {
                if (finfo.Exists)
                {
                    r.IfModifiedSince = finfo.LastWriteTime;
                }
            }
                ).ContinueWith(t => {
                try {
                    if (t.IsFaulted)
                    {
                        var wex = t.Exception.Flatten().InnerException as WebException;
                        if (wex != null)
                        {
                            var resp = wex.Response as HttpWebResponse;
                            if (resp != null)
                            {
                                // If the errorcode is NotModified the file we cached on disk is still the latest one.
                                if (resp.StatusCode == HttpStatusCode.NotModified)
                                {
                                    Cleanup();
                                    return;
                                }
                                //if 404, there is no gravatar for the user
                                if (resp.StatusCode == HttpStatusCode.NotFound)
                                {
                                    image = null;
                                    Cleanup();
                                    return;
                                }
                            }
                        }
                    }

                    using (var response = t.Result) {
                        finfo.Directory.Create();

                        // Copy out the new file and reload it
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            using (var tempFile = File.Create(tempPath)) {
                                using (var stream = response.GetResponseStream()) {
                                    stream.CopyTo(tempFile);
                                }
                            }
                            FileService.SystemRename(tempPath, cachePath);
                        }
                        LoadFromDisk(cachePath, true);
                    }
                } catch (Exception ex) {
                    var aex = ex as AggregateException;
                    if (aex != null)
                    {
                        ex = aex.Flatten().InnerException;
                    }
                    var wex = ex as WebException;
                    if (wex != null && wex.Status.IsCannotReachInternetError())
                    {
                        LoggingService.LogWarning("Gravatar service could not be reached.");
                    }
                    else
                    {
                        LoggingService.LogError("Error in Gravatar downloader.", ex);
                    }
                    Cleanup();
                } finally {
                    try {
                        if (File.Exists(tempPath))
                        {
                            File.Delete(tempPath);
                        }
                    } catch (Exception ex) {
                        LoggingService.LogError("Error deleting Gravatar temp file.", ex);
                    }
                }
            });
        }
Esempio n. 6
0
        /// <summary>
        /// Get user info from GitHub based on the passed in username
        /// </summary>
        public Task <UserResponse> GetUserInformation(string username)
        {
            string url = WebConfigHelper.GetUserEndpoint(username);

            return(WebRequestHelper.GetResponseAsync <UserResponse>(url));
        }