Exemplo n.º 1
0
        /// <summary>
        /// Two calls are made to this method to emulate Incremental Loading. First call (second parameter = true) returns first 7 repositories,
        /// Second call (second parameter = false) returns the rest
        ///</summary>
        /// <param name="range">Today, weekly or monthly</param>
        /// <param name="firstCall">Indicates if this is the first call in incremental calls or not</param>
        /// <returns>Trending Repositories in a Time range</returns>
        public static async Task <ObservableCollection <Repository> > GetTrendingRepos(TimeRange range, bool firstCall)
        {
            try
            {
                ObservableCollection <Repository> repos = new ObservableCollection <Repository>();
                var trendingReposNames = await HtmlParseService.ExtractTrendingRepos(range);

                var client = await UserUtility.GetAuthenticatedClient();

                if (firstCall)
                {
                    for (int i = 0; i < 7; i++)
                    {
                        repos.Add(await client.Repository.Get(trendingReposNames[i].Item1, trendingReposNames[i].Item2));
                    }
                }
                else
                {
                    for (int i = 7; i < trendingReposNames.Count; i++)
                    {
                        repos.Add(await client.Repository.Get(trendingReposNames[i].Item1, trendingReposNames[i].Item2));
                    }
                }

                return(repos);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns trending repos. First call (second parameter = true) returns first 7 repositories,
        /// Second call (second parameter = false) returns the rest
        ///</summary>
        /// <param name="range">Today, weekly or monthly</param>
        /// <param name="firstCall">Indicates if this is the first call in incremental calls or not</param>
        /// <returns>Trending Repositories in a Time range</returns>
        public static async Task <ObservableCollection <Repository> > GetTrendingRepos(TimeRange range, bool firstCall)
        {
            try
            {
                ObservableCollection <Repository> repos     = new ObservableCollection <Repository>();
                List <Tuple <string, string> >    repoNames = new List <Tuple <string, string> >();

                if (firstCall)
                {
                    repoNames = await HtmlParseService.ExtractTrendingRepos(range);
                }
                else
                {
                    switch (range)
                    {
                    case TimeRange.TODAY:

                        repoNames = GlobalHelper.TrendingTodayRepoNames;
                        break;

                    case TimeRange.WEEKLY:

                        repoNames = GlobalHelper.TrendingWeekRepoNames;
                        break;

                    case TimeRange.MONTHLY:

                        repoNames = GlobalHelper.TrendingMonthRepoNames;
                        break;
                    }
                }

                GitHubClient client = await UserUtility.GetAuthenticatedClient();

                if (firstCall)
                {
                    for (int i = 0; i < 7; i++)
                    {
                        repos.Add(await client.Repository.Get(repoNames[i].Item1, repoNames[i].Item2));
                    }
                }
                else
                {
                    for (int i = 7; i < repoNames.Count; i++)
                    {
                        repos.Add(await client.Repository.Get(repoNames[i].Item1, repoNames[i].Item2));
                    }
                }

                return(repos);
            }
            catch
            {
                return(null);
            }
        }