Beispiel #1
0
        public static IAsyncOperation <AddQuestionsResult> QueryTagAsync(string websiteUrl, string tagEncoded)
        {
            return(AsyncInfo.Run(async(cancellationToken) =>
            {
                // Retrieve questions, skip the LatestPubDate validation and add all questions.
                AddQuestionsResult result = await FeedManager.QuerySingleWebsiteAsync(websiteUrl, tagEncoded, true);

                // Only limit and save questions if list changed.
                if (result.AddedQuestions > 0 || result.UpdatedQuestions > 0)
                {
                    uint removedQuestions = await QuestionsManager.RemoveQuestionsInReadList();
                    await QuestionsManager.LimitTo150AndSaveAsync();
                    FeedManager.UpdateTileAndBadge();
                }

                return result;
            }));
        }
Beispiel #2
0
        // 1. Load settings.
        // 2. query -> Retrieve feeds.
        // 3. skipLatestPubDate -> Add questions.
        // 4. Sort questions (needed to show tile and badge).
        // 5. Update tile.
        // 6. Update badge.
        // TODO: Maybe check for buzz words here.
        public static IAsyncOperation <AddQuestionsResult> QueryWebsitesAsync()
        {
            return(AsyncInfo.Run(async(cancellationToken) =>
            {
                SettingsManager.Load();
                await QuestionsManager.LoadAsync();

                // Query websites in parallel.

                List <Task <AddQuestionsResult> > tasks = new List <Task <AddQuestionsResult> >();
                IEnumerable <string> keys = SettingsManager.GetWebsiteKeys();
                foreach (string website in keys)
                {
                    string query = SettingsManager.ConcatenateAllTags(website);
                    tasks.Add(QuerySingleWebsiteAsync(website, query, false).AsTask());
                }

                if (tasks.Count == 0)
                {
                    // There is nothing to wait.
                    return new AddQuestionsResult();
                }

                await Task.Factory.ContinueWhenAll(tasks.ToArray(), (tasks2) => {});

                // Add up the results.
                AddQuestionsResult result = new AddQuestionsResult();
                foreach (Task <AddQuestionsResult> task in tasks)
                {
                    AddQuestionsResult taskResult = task.Result;
                    result.AddedQuestions += taskResult.AddedQuestions;
                    result.UpdatedQuestions += taskResult.UpdatedQuestions;
                    if (!taskResult.FileFound)
                    {
                        result.FileFound = false;
                    }
                }

                Debug.WriteLine(
                    "{0} questions added, {0} questions modified.",
                    result.AddedQuestions,
                    result.UpdatedQuestions);

                // Only limit and save questions if list changed.
                if (result.AddedQuestions > 0 || result.UpdatedQuestions > 0)
                {
                    uint removedQuestions = await QuestionsManager.RemoveQuestionsInReadList();
                    await QuestionsManager.LimitTo150AndSaveAsync();
                    UpdateTileAndBadge();

                    SettingsManager.SaveLocal(); // Save updated latestPubDate.
                }

                // Update last query date-time, only if all queries were successful.
                if (result.FileFound)
                {
                    SettingsManager.LatestQueryDate = DateTimeOffset.Now;
                }

                return result;
            }));
        }