Beispiel #1
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            AddQuestionsResult result = null;
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            #if DEBUG
            InvokeSimpleToast("Hello from " + taskInstance.Task.Name);
            #endif

            try
            {
                result = await FeedManager.QueryWebsitesAsync();

                #if DEBUG
                InvokeSimpleToast(String.Format(
                    "There are {0} new questions and {1} updated questions.",
                    result.AddedQuestions,
                    result.UpdatedQuestions));
                #endif
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);

                #if DEBUG
                InvokeSimpleToast(ex.Message);
                #endif
            }

            deferral.Complete();
        }
Beispiel #2
0
        public static void RemoveQuestionsAndSave(IList <string> keysToDelete)
        {
            // Remove from questions-list and add to read-questions-list.
            foreach (string key in keysToDelete)
            {
                if (questionsCollection.Remove(key))
                {
                    ReadListManager.AddReadQuestion(key);
                }
                else
                {
                    // Removing a question that was not in the questions-list.
                    Debugger.Break();
                }
            }

            // Only save if at least one question was deleted.
            if (keysToDelete.Count > 0)
            {
                ReadListManager.LimitTo450AndSave();

                // Do not wait until questions-save is completed.
                var saveOperation = QuestionsManager.SaveAsync();

                // And refresh tile and badge.
                FeedManager.UpdateTileAndBadge();
            }
        }
Beispiel #3
0
        // Notice that tile update, badge update and saveing only occurs if at least one questions is removed.
        public static IAsyncAction RemoveReadQuestionsUpdateTileAndBadgeAndSaveAsync()
        {
            return(AsyncInfo.Run(async(cancellationToken) =>
            {
                uint removedQuestions = await RemoveQuestionsInReadList();

                // Only save if at least one question was deleted.
                if (removedQuestions > 0)
                {
                    await QuestionsManager.SaveAsync();
                    FeedManager.UpdateTileAndBadge();
                }
            }));
        }
Beispiel #4
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;
            }));
        }