Exemple #1
0
        public static void UpdateTileAndBadge()
        {
            IList <BindableQuestion> list = QuestionsManager.GetSortedQuestions();

            UpdateTileWithQuestions(list);
            UpdateBadge(list.Count);
        }
Exemple #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();
            }
        }
Exemple #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();
                }
            }));
        }
Exemple #4
0
        public void DeleteTagAndSave(ListView listView, string tag)
        {
            JsonObject tagsCollection = roamingJsonObject.GetNamedObject(TagsKey);

            if (tagsCollection.Remove(tag))
            {
                SettingsManager.SaveRoaming();
            }

            listView.Items.Remove(tag);

            // Remove only questions containing this website and this tag.
            QuestionsManager.RemoveQuestionsAndSave(id, tag);
        }
Exemple #5
0
        public static void DeleteWebsiteAndSave(BindableWebsite website)
        {
            CheckSettingsAreLoaded();

            string websiteUrl = website.ToString();

            roamingWebsites.Remove(websiteUrl);
            localWebsites.Remove(websiteUrl);

            // Remove only questions containing this website.
            QuestionsManager.RemoveQuestionsAndSave(websiteUrl, null);

            SaveRoaming();
            SaveLocal();
        }
Exemple #6
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;
            }));
        }
Exemple #7
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;
            }));
        }
Exemple #8
0
        public static IAsyncOperation <AddQuestionsResult> QuerySingleWebsiteAsync(
            string websiteUrl,
            string query,
            bool skipLatestPubDate)
        {
            return(AsyncInfo.Run(async(cancellationToken) =>
            {
                AddQuestionsResult result = new AddQuestionsResult();

                Uri uri;
                if (!SettingsManager.TryCreateUri(websiteUrl, query, out uri))
                {
                    Debugger.Break();
                }

                SyndicationFeed feed = null;
                try
                {
                    client.BypassCacheOnRetrieve = true;
                    feed = await client.RetrieveFeedAsync(uri);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("{0} {1}", websiteUrl, ex.Message);

                    int hr = ex.HResult;
                    int facility = (hr & 0x7FFF0000) / 0xFFFF;
                    int error = hr & 0xFFFF;
                    const int WEB_E_INVALID_XML = unchecked ((int)0x83750002);
                    const int FACILITY_WIN32 = 7;
                    const int FACILITY_HTTP = 25;
                    const int NOT_FOUND = 404;

                    if (hr == WEB_E_INVALID_XML)
                    {
                        // An invalid XML is equivalent to file not found.
                        result.FileFound = false;
                        return result;
                    }
                    else if (facility == FACILITY_HTTP && error == NOT_FOUND)
                    {
                        result.FileFound = false;
                        return result;
                    }
                    else if (facility == FACILITY_HTTP)
                    {
                        // Swallow HTTP errors. Treat them as file not found.
                        result.FileFound = false;
                        return result;
                    }
                    else if (facility == FACILITY_WIN32 && error > 12001 && error < 12156)
                    {
                        // Swallow WININET errors. Treat as file not found.
                        result.FileFound = false;
                        return result;
                    }
                    else
                    {
                        throw;
                    }
                }

                result = QuestionsManager.AddQuestions(websiteUrl, feed, skipLatestPubDate);
                result.FileFound = true;
                return result;
            }));
        }