Пример #1
0
        /// <summary>
        /// Run the tally for the specified quest.
        /// </summary>
        /// <param name="quest">The quest to scan.</param>
        /// <param name="token">Cancellation token.</param>
        public async Task RunAsync(IQuest quest, CancellationToken token)
        {
            if (quest == null)
            {
                throw new ArgumentNullException(nameof(quest));
            }

            try
            {
                TallyIsRunning = true;
                TallyResults   = string.Empty;

                // Mark the quest as one that we will listen for changes from.
                quest.PropertyChanged -= Quest_PropertyChanged;
                quest.PropertyChanged += Quest_PropertyChanged;

                VoteCounter.ResetUserDefinedTasks(quest.DisplayName);

                var posts = await ForumReader.Instance.ReadQuestAsync(quest, token).ConfigureAwait(false);

                await VoteCounter.TallyPosts(posts, quest, token).ConfigureAwait(false);
            }
            catch (InvalidOperationException e)
            {
                TallyResults += $"\n{e.Message}";
                return;
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception)
            {
                //VoteCounter.Instance.Quest = null;
                throw;
            }
            finally
            {
                TallyIsRunning = false;

                // Notify the page provider that we're done, and that the cache
                // can be cleared out as needed:
                ViewModelService.MainViewModel.PageProvider.DoneLoading();

                // Free memory used by loading pages as soon as we're done:
                GC.Collect();
            }

            await UpdateResults(token).ConfigureAwait(false);
        }
Пример #2
0
        public async Task NameReferenceTest()
        {
            // Check for non-case sensitivity in referencing other voters.
            PostComponents        p1    = new PostComponents("Beyogi", "12345", "[x] Vote for something");
            PostComponents        p2    = new PostComponents("Mini", "12345", "[x] beyogi");
            List <PostComponents> posts = new List <PostComponents>();

            posts.Add(p1);
            posts.Add(p2);
            Task  t = voteCounter.TallyPosts(posts, sampleQuest, CancellationToken.None);
            await t;

            Assert.AreEqual(2, voteCounter.GetVotersCollection(VoteType.Vote).Count);
            Assert.AreEqual(1, voteCounter.GetVotesCollection(VoteType.Vote).Count);
            Assert.IsTrue(voteCounter.HasVote("[x] Vote for something\r\n", VoteType.Vote));
        }