Exemplo n.º 1
0
        public IEnumerable <QuoteFmItem> updateRecommendations()
        {
            decimal            maxKnownId      = 0;
            List <QuoteFmItem> newQuoteFmItems = new List <QuoteFmItem>();

            if (Recommendations.Count > 0)
            {
                maxKnownId = Recommendations.Max(r => r.Id);
            }
            ListOfRecommendations listOfRecommendations = QuoteSharp.API.getRecommendationsListByUser(this.username);

            if (listOfRecommendations != null)
            {
                if (listOfRecommendations.entities.Count() > 0)
                {
                    IEnumerable <Recommendation> newRecommendations = listOfRecommendations.entities.Where(r => r.id > maxKnownId);
                    foreach (Recommendation recommendation in newRecommendations)
                    {
                        QuoteFmItem newItem = QuoteFmItem.createFromApi(recommendation);
                        if (newItem != null)
                        {
                            Recommendations.Add(newItem);
                            newQuoteFmItems.Add(newItem);
                        }
                    }
                }
            }
            return(newQuoteFmItems);
        }
Exemplo n.º 2
0
 void backgroundWorkerCategories_DoWork(object sender, DoWorkEventArgs e)
 {
     if (e != null)
     {
         if (e.Cancel)
         {
             return;
         }
     }
     foreach (KeyValuePair <decimal, ThreadSaveObservableCollection <QuoteFmItem> > keyValuePair in Collections)
     {
         List <decimal> catId = new List <decimal>();
         catId.Add(keyValuePair.Key);
         ListOfArticles entries = QuoteSharp.API.getArticlesListByCategories(catId);
         if (entries != null)
         {
             if (entries.entities != null)
             {
                 foreach (Article article in entries.entities)
                 {
                     QuoteFmItem item = QuoteFmItem.createFromApi(article);
                     if (item != null)
                     {
                         item.IsArticleOfCategory = true;
                         item.CategoryTitle       = CategoryNames[keyValuePair.Key];
                         item.QuoteType           = QuoteFmItem.QuoteTypes.Recommendation;
                         IEnumerable <QuoteFmItem> availableItems = keyValuePair.Value.Where(i => i.Id == item.Id && i.IsArticleOfCategory);
                         if (availableItems.Count() > 0)
                         {
                             continue;
                         }
                         backgroundWorkerCategories.ReportProgress(100, new KeyValuePair <decimal, QuoteFmItem>(keyValuePair.Key, item));
                     }
                 }
             }
         }
     }
 }