/// <summary> /// Put any plans found in the grouped vote lines into the standard tracking sets, /// after handling any partitioning needed. /// </summary> /// <param name="plans">List of plans to be processed.</param> /// <param name="post">Post the plans were pulled from.</param> /// <param name="partitionMode">Partition mode being used.</param> private void ProcessPlans(IEnumerable <List <string> > plans, PostComponents post, PartitionMode partitionMode) { foreach (var plan in plans) { string planName = VoteString.GetMarkedPlanName(plan.First()); string cleanName = VoteString.RemoveBBCode(planName); cleanName = VoteString.DeUrlContent(cleanName); if (!VoteCounter.HasPlan(cleanName)) { var nPlan = NormalizePlanName(plan); // Get the list of all vote partitions, built according to current preferences. // One of: By line, By block, or By post (ie: entire vote) var votePartitions = GetVotePartitions(nPlan, partitionMode, VoteType.Plan, post.Author); VoteCounter.AddVotes(votePartitions, cleanName, post.ID, VoteType.Plan); } } }
/// <summary> /// Get the lines of the vote that we will be processing out of the post. /// Only take the .VoteLines, and condense any instances of known plans /// to just a reference to the plan name. /// </summary> /// <param name="post">The post we're getting the vote from.</param> /// <returns>Returns the vote with plans compressed.</returns> public List <string> GetWorkingVote(PostComponents post) { List <string> vote = new List <string>(); if (post == null || !post.IsVote) { return(vote); } // First determine if any base plans are copies of an original definition, or being defined in this post. // If they're just copies, then embed them in the working vote. if (post.BasePlans.Any()) { var voters = VoteCounter.GetVotersCollection(VoteType.Plan); bool checkPlan = true; string planName; foreach (var bPlan in post.BasePlans) { planName = VoteString.GetMarkedPlanName(bPlan.Key); if (planName == null) { continue; } // As long as we keep finding base plans that are defined in this post, keep skipping. if (checkPlan) { if (VoteCounter.HasPlan(planName) && voters[planName] == post.ID) { continue; } } checkPlan = false; // If we reach here, any further plans are copy/pastes of defined plans, and should // have the key added to the working vote. vote.Add(bPlan.Key); } } // Then make sure there are actual vote lines to process. if (!post.VoteLines.Any()) { return(vote); } // Then check if the *entire post* should be treated as a complete plan. string postPlanName = VoteString.GetPlanName(post.VoteLines.First()); if (postPlanName != null && VoteCounter.ReferencePlans.ContainsKey(postPlanName) && VoteCounter.ReferencePlans[postPlanName].Skip(1).SequenceEqual(post.VoteLines.Skip(1), Agnostic.StringComparer)) { // Replace known plans with just the plan key. They'll be expanded later. vote.Add(post.VoteLines.First()); } else { // If the entire post isn't an auto-plan, break it down into blocks. // Break the remainder of the vote into blocks so that we can compare vs auto-plans. // Group blocks based on parent vote lines (no prefix). // Key for each block is the parent vote line. var voteBlocks = post.VoteLines.GroupAdjacentToPreviousKey( (s) => string.IsNullOrEmpty(VoteString.GetVotePrefix(s)), (s) => s, (s) => s); foreach (var block in voteBlocks) { // Multi-line blocks might be a plan. Check. if (block.Count() > 1) { // See if the block key marks a known plan. string planName = VoteString.GetPlanName(block.Key); if (planName != null && VoteCounter.ReferencePlans.ContainsKey(planName) && VoteCounter.ReferencePlans[planName].Skip(1).SequenceEqual(block.Skip(1), Agnostic.StringComparer)) { // Replace known plans with just the plan key. They'll be expanded later. vote.Add(block.Key); } else { // If it's not a known plan, pass everything through. vote.AddRange(block); } } else { // Single lines can be added normally vote.AddRange(block); //vote.Add(block.Key); } } } return(vote); }