Esempio n. 1
0
 public MergeResult Merge(VotingResults otherVotingResults)
 {
     lock (s_votesSync)
     {
         var otherVotesMore = false;
         var ourVotesMore   = false;
         foreach (VoteKey key in otherVotingResults._votes.Keys)
         {
             if (!_votes.ContainsKey(key))
             {
                 SetNewVotesValue(key, (int)otherVotingResults._votes[key]);
                 otherVotesMore = true;
             }
             else if ((int)_votes[key] < (int)otherVotingResults._votes[key])
             {
                 UpdateVotesValue(key, (int)otherVotingResults._votes[key]);
                 otherVotesMore = true;
             }
         }
         foreach (VoteKey key in _votes.Keys)
         {
             if (!otherVotingResults._votes.ContainsKey(key) ||
                 (int)otherVotingResults._votes[key] < (int)_votes[key])
             {
                 ourVotesMore = true;
             }
         }
         return(ourVotesMore
                    ? MergeResult.OurContainMoreVotes
                    : (otherVotesMore ? MergeResult.OtherContainMoreVotes : MergeResult.NotNeed));
     }
 }
Esempio n. 2
0
        public string GetFullExpression(ProtocolTemplate protocol, VotingResults results)
        {
            try
            {
                _template = protocol;
                string fullKey;
                var    preparedExpression = new StringBuilder(InnerExpression);
                var    regExpression      = new CheckExpressionLineReferenceRegex();
                var    matches            = regExpression.Matches(InnerExpression);
                var    delta = 0;
                foreach (Match match in matches)
                {
                    string newValue;
                    switch (match.Value)
                    {
                    case "S":
                    case "[S]":
                        newValue = results.GetTotalVotesCount(protocol.ElectionLink.ElectionId).ToString();
                        break;

                    case "M":
                    case "[M]":
                        newValue = protocol.ElectionLink.MaxMarks.ToString();
                        break;

                    case "P":
                    case "[P]":
                        newValue = results.GetAboveCandidateVotesCount(protocol.ElectionLink).ToString();
                        break;

                    default:
                        fullKey = match.Value;
                        fullKey = fullKey.TrimStart('[');
                        fullKey = fullKey.TrimEnd(']');
                        int lineNumber = Convert.ToInt32(fullKey);
                        if (lineNumber < 1 || lineNumber > protocol.Lines.Length)
                        {
                            throw new Exception("В протоколе нет строки с порядковым номером " + lineNumber);
                        }
                        if (protocol.Lines[lineNumber - 1].Value.HasValue)
                        {
                            newValue = protocol.Lines[lineNumber - 1].Value.ToString();
                        }
                        else
                        {
                            throw new Exception("Не заполнена строка протокола номер " + lineNumber);
                        }
                        break;
                    }
                    preparedExpression.Replace(match.Value, newValue, match.Index + delta, match.Length);
                    delta += newValue.Length - match.Length;
                }
                return(preparedExpression.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception(
                          String.Format("Ошибка КС \"{0}\". Выборы № {1}:\n{2}"
                                        , InnerExpression
                                        , protocol.ElectionLink.ElectionId
                                        , ex.Message)
                          , ex);
            }
        }
Esempio n. 3
0
 public MergeResult Merge(VotingResults otherVotingResults)
 {
     lock (s_votesSync)
     {
         var otherVotesMore = false;
         var ourVotesMore = false;
         foreach (VoteKey key in otherVotingResults._votes.Keys)
         {
             if (!_votes.ContainsKey(key))
             {
                 SetNewVotesValue(key, (int) otherVotingResults._votes[key]);
                 otherVotesMore = true;
             }
             else if ((int)_votes[key] < (int)otherVotingResults._votes[key])
             {
                 UpdateVotesValue(key, (int)otherVotingResults._votes[key]);
                 otherVotesMore = true;
             }
         }
         foreach (VoteKey key in _votes.Keys)
         {
             if (!otherVotingResults._votes.ContainsKey(key) ||
                 (int)otherVotingResults._votes[key] < (int)_votes[key])
             {
                 ourVotesMore = true;
             }
         }
         return ourVotesMore
                    ? MergeResult.OurContainMoreVotes
                    : (otherVotesMore ? MergeResult.OtherContainMoreVotes : MergeResult.NotNeed);
     }
 }
Esempio n. 4
0
 public string GetFullExpression(ProtocolTemplate protocol, VotingResults results)
 {
     try
     {
         _template = protocol;
         string fullKey;
         var preparedExpression = new StringBuilder(InnerExpression);
         var regExpression = new CheckExpressionLineReferenceRegex();
         var matches = regExpression.Matches(InnerExpression);
         var delta = 0;
         foreach (Match match in matches)
         {
             string newValue;
             switch (match.Value)
             {
                 case "S":
                 case "[S]":
                     newValue = results.GetTotalVotesCount(protocol.ElectionLink.ElectionId).ToString();
                     break;
                 case "M":
                 case "[M]":
                     newValue = protocol.ElectionLink.MaxMarks.ToString();
                     break;
                 case "P":
                 case "[P]":
                     newValue = results.GetAboveCandidateVotesCount(protocol.ElectionLink).ToString();
                     break;
                 default:
                     fullKey = match.Value;
                     fullKey = fullKey.TrimStart('[');
                     fullKey = fullKey.TrimEnd(']');
                     int lineNumber = Convert.ToInt32(fullKey);
                     if (lineNumber < 1 || lineNumber > protocol.Lines.Length)
                         throw new Exception("В протоколе нет строки с порядковым номером " + lineNumber);
                     if (protocol.Lines[lineNumber - 1].Value.HasValue)
                         newValue = protocol.Lines[lineNumber - 1].Value.ToString();
                     else
                         throw new Exception("Не заполнена строка протокола номер " + lineNumber);
                     break;
             }
             preparedExpression.Replace(match.Value, newValue, match.Index + delta, match.Length);
             delta += newValue.Length - match.Length;
         }
         return preparedExpression.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception(
             String.Format("Ошибка КС \"{0}\". Выборы № {1}:\n{2}"
                 , InnerExpression
                 , protocol.ElectionLink.ElectionId
                 , ex.Message)
             , ex);
     }
 }
Esempio n. 5
0
 protected override void ResetStateInternal()
 {
     VotingResults = new VotingResults();
     VotingResults.Init(Logger, _config.AddBadBlankToCounterValue.Enabled);
     LastVotingResult = VotingResult.Empty;
     _votingResultProtocolVersion = 0;
 }