Exemplo n.º 1
0
        /// <summary>
        /// Modifies the task of the current vote partition, and returns a new version with the changes.
        /// </summary>
        /// <param name="task">The new task.</param>
        /// <returns>Returns a new VotePartition with the task modified.</returns>
        /// <exception cref="System.ArgumentNullException">task</exception>
        public VotePartition ModifyTask(string task)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            if (VoteLines.Any())
            {
                var revise   = VoteLines.First().Modify(task: task);
                var revLines = VoteLines.Skip(1).ToList();

                List <VoteLine> newList = new List <VoteLine> {
                    revise
                };
                newList.AddRange(revLines);

                return(new VotePartition(newList, VoteType));
            }

            return(new VotePartition()
            {
                VoteType = VoteType
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Extract any vote lines from the message text, and save both the original and
        /// the cleaned (no BBCode) in a list.
        /// Do not record any vote lines if there's a tally marker (#####).
        /// Mark the vote as valid if it has any vote lines.
        /// </summary>
        /// <param name="message">The original, full message text.</param>
        private void ProcessMessageLines(string message)
        {
            var messageLines = message.GetStringLines();

            foreach (var line in messageLines)
            {
                string cleanLine = VoteString.RemoveBBCode(line);

                if (tallyRegex.Match(cleanLine).Success)
                {
                    // If this is a tally post, clear any found vote lines and end processing.
                    VoteLines.Clear();
                    break;
                }

                Match m = voteLineRegex.Match(cleanLine);
                if (m.Success)
                {
                    VoteLines.Add(new VoteLine(line));
                }
            }

            VoteLines.IsReadonly = true;
            IsValid = VoteLines.Any();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the vote grouped by valid marker type.
        /// </summary>
        /// <returns>Returns the vote broken up into groups based on marker type.</returns>
        public IEnumerable <IGrouping <string, VoteLine> > GetVoteMarkerGroups()
        {
            var voteGrouping = VoteLines.GroupAdjacentToPreviousSource(
                source => source.ComparableContent,
                VoteBlockContinues);

            return(voteGrouping);
        }
Exemplo n.º 4
0
        public override bool Equals(object obj)
        {
            if (obj is VotePartition other)
            {
                return(Agnostic.StringComparer.Equals(Task, other.Task) && VoteLines.Equals(other.VoteLines));
            }

            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Add a vote line to the current partition.
        /// This function changes the hash code.
        /// </summary>
        /// <param name="line">The line to add.</param>
        /// <exception cref="ArgumentNullException"/>
        public void AddLine(VoteLine line)
        {
            if (line == null)
            {
                throw new ArgumentNullException(nameof(line));
            }

            if (!VoteLines.Any())
            {
                Task = line.Task;
            }

            VoteLines.Add(line);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Add a list of vote lines to the current partition.
        /// This function changes the hash code.
        /// </summary>
        /// <param name="line">The lines to add.</param>
        /// <exception cref="ArgumentNullException"/>
        public void AddLines(IEnumerable <VoteLine> lines)
        {
            if (lines == null)
            {
                throw new ArgumentNullException(nameof(lines));
            }
            if (!lines.Any())
            {
                return;
            }
            if (lines.Any(a => a == null))
            {
                throw new ArgumentException("Null vote line contained in enumeration.", nameof(lines));
            }

            if (!VoteLines.Any())
            {
                Task = lines.First().Task;
            }

            VoteLines.AddRange(lines);
        }
Exemplo n.º 7
0
 public bool Matches(VotePartition other)
 {
     return(VoteLines.Equals(other.VoteLines));
 }
Exemplo n.º 8
0
 public override int GetHashCode()
 {
     return(VoteLines.GetHashCode());
 }