public TrendsList GetTrends()
        {
            TrendsList trendsList = CategorizationCacheHelper.ReadTrends();

            if (trendsList == null)
            {
                trendsList = new TrendsList();

                CategoriesList categoriesList = GetCategories();
                foreach (CategoryItem categoryItem in categoriesList)
                {
                    TopicList topicList = categoryItem.TopicList;
                    foreach (TopicItem topicItem in topicList)
                    {
                        TrendItem trendItem = new TrendItem(topicItem.ID, topicItem.Title, ProviderEnum.TheInternetBuzz);
                        trendItem.Weight = 3;
                        trendsList.AddTrend(trendItem);
                    }
                }
                trendsList.Sort();

                CategorizationCacheHelper.CacheTrends(trendsList);
            }
            return trendsList;
        }
Ejemplo n.º 2
0
        static private TrendsList BuildTrends()
        {
            TrendsList trendsList = null;

            try
            {
                ManualResetEvent[] doneEvents = new ManualResetEvent[8];

                doneEvents[0] = new ManualResetEvent(false);
                TrendsWorkerThread googleWorkerThread = new TrendsWorkerThread(new GoogleTrendsService(), doneEvents[0]);
                ThreadPool.QueueUserWorkItem(googleWorkerThread.ThreadPoolCallback);

                doneEvents[1] = new ManualResetEvent(false);
                TrendsWorkerThread twitterWorkerThread = new TrendsWorkerThread(new TwitterTrendsService(), doneEvents[1]);
                ThreadPool.QueueUserWorkItem(twitterWorkerThread.ThreadPoolCallback);

                doneEvents[2] = new ManualResetEvent(false);
                TrendsWorkerThread yahooWorkerThread = new TrendsWorkerThread(new YahooTrendsService(), doneEvents[2]);
                ThreadPool.QueueUserWorkItem(yahooWorkerThread.ThreadPoolCallback);

                doneEvents[3] = new ManualResetEvent(false);
                TrendsWorkerThread whatTheTrendCurrentWorkerThread = new TrendsWorkerThread(new WhatTheTrendTrendsService(WhatTheTrendTypeEnum.Current), doneEvents[3]);
                ThreadPool.QueueUserWorkItem(whatTheTrendCurrentWorkerThread.ThreadPoolCallback);

                doneEvents[4] = new ManualResetEvent(false);
                TrendsWorkerThread whatTheTrendMostEditedWorkerThread = new TrendsWorkerThread(new WhatTheTrendTrendsService(WhatTheTrendTypeEnum.MostEdited), doneEvents[4]);
                ThreadPool.QueueUserWorkItem(whatTheTrendMostEditedWorkerThread.ThreadPoolCallback);

                doneEvents[5] = new ManualResetEvent(false);
                TrendsWorkerThread alexaWorkerThread = new TrendsWorkerThread(new AlexaTrendsService(), doneEvents[5]);
                ThreadPool.QueueUserWorkItem(alexaWorkerThread.ThreadPoolCallback);

                doneEvents[6] = new ManualResetEvent(false);
                TrendsWorkerThread iTunesSongsWorkerThread = new TrendsWorkerThread(new ITunesTrendsService(ITunesTypeEnum.Top10Songs), doneEvents[6]);
                ThreadPool.QueueUserWorkItem(iTunesSongsWorkerThread.ThreadPoolCallback);

                doneEvents[7] = new ManualResetEvent(false);
                TrendsWorkerThread iTunesMoviesWorkerThread = new TrendsWorkerThread(new ITunesTrendsService(ITunesTypeEnum.TopMovies), doneEvents[7]);
                ThreadPool.QueueUserWorkItem(iTunesMoviesWorkerThread.ThreadPoolCallback);

                WaitHandle.WaitAll(doneEvents);

                trendsList = new TrendsList();
                trendsList.AddTrends(googleWorkerThread.TrendsList);
                trendsList.AddTrends(yahooWorkerThread.TrendsList);
                trendsList.AddTrends(twitterWorkerThread.TrendsList);
                trendsList.AddTrends(whatTheTrendCurrentWorkerThread.TrendsList);
                trendsList.AddTrends(whatTheTrendMostEditedWorkerThread.TrendsList);
                trendsList.AddTrends(alexaWorkerThread.TrendsList);
                trendsList.AddTrends(iTunesSongsWorkerThread.TrendsList);
                trendsList.AddTrends(iTunesMoviesWorkerThread.TrendsList);

                if (trendsList != null && trendsList.Count() > 0)
                {
                    trendsList.Sort(new TrendItemComparer(TrendItemComparerEnum.Title));
                }
            }
            catch (Exception exception)
            {
                ErrorService.Log("TrendsBuilder", "BuildTrends", "", exception);
            }

            return trendsList;
        }