Ejemplo n.º 1
0
        public bool Check(ProtocolTemplate oProtocol)
        {
            _template = oProtocol;
            if (!Enabled)
            {
                return(true);
            }
            if (_method == null)
            {
                BindMethod(Assembly.GetExecutingAssembly());
            }


            Failed = !(bool)_method.Invoke(null, null);
            return(!Failed);
        }
Ejemplo n.º 2
0
        public string GetExpansion(ProtocolTemplate protocol)
        {
            try
            {
                string fullKey;
                var    preparedExpression = new StringBuilder(InnerExpression);
                var    regExpression      = new CheckExpressionLineReferenceRegex();
                var    matches            = regExpression.Matches(InnerExpression);
                var    delta = 0;
                foreach (Match match in matches)
                {
                    if (match.Value.StartsWith("["))
                    {
                        fullKey = match.Value;
                        fullKey = fullKey.TrimStart('[');
                        fullKey = fullKey.TrimEnd(']');


                        int lineNumber;
                        if (!int.TryParse(fullKey, out lineNumber))
                        {
                            continue;
                        }
                        if (lineNumber < 1 || lineNumber > protocol.Lines.Length)
                        {
                            throw new Exception("В протоколе нет строки с порядковым номером " + lineNumber);
                        }
                        var sNewValue = "[" + protocol.Lines[lineNumber - 1].Num + protocol.Lines[lineNumber - 1].AdditionalNum + "]";
                        preparedExpression.Replace(match.Value, sNewValue, match.Index + delta, match.Length);
                        delta += sNewValue.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);
            }
        }
Ejemplo n.º 3
0
 public void SetProtocol(ProtocolTemplate oProtocol)
 {
     _template = oProtocol;
 }
Ejemplo n.º 4
0
        public string BuildCheckTypeText(ProtocolTemplate protocol)
        {
            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 = String.Format(
                            "Managers.VotingResultManager.VotingResults.GetTotalVotesCount(\"{0}\")",
                            protocol.ElectionLink.ElectionId);
                        break;

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

                    case "P":
                    case "[P]":
                        newValue = String.Format(
                            "Managers.VotingResultManager.VotingResults.GetAboveCandidateVotesCount("
                            + "Managers.ElectionManager.SourceData.GetElectionByNum(\"{0}\"))",
                            protocol.ElectionLink.ElectionId);
                        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);
                        }
                        newValue = String.Format(
                            "Managers.ElectionManager.SourceData.GetElectionByNum(\"{0}\").Protocol.Lines[{1}].Value"
                            , protocol.ElectionLink.ElectionId
                            , lineNumber - 1);
                        break;
                    }
                    preparedExpression.Replace(match.Value, newValue, match.Index + delta, match.Length);
                    delta += newValue.Length - match.Length;
                }
                preparedExpression.Replace("=", "@");
                preparedExpression.Replace("<@", " " + "<=" + " ");
                preparedExpression.Replace(">@", " " + ">=" + " ");
                preparedExpression.Replace("@", " " + "==" + " ");
                preparedExpression.Replace("<>", " " + "!=" + " ");
                preparedExpression.Insert(0, ASSEMBLY_BEGIN.Replace(
                                              "_SUFFIX"
                                              , GetExpressionCheckerSuffix()));
                preparedExpression.Append(ASSEMBLY_END);
                return(preparedExpression.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception(
                          String.Format(
                              "Ошибка сборки в выражении : {0}:\n{1}"
                              , InnerExpression
                              , ex.Message)
                          , ex);
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
 public string BuildCheckTypeText(ProtocolTemplate protocol)
 {
     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 = String.Format(
                         "Managers.VotingResultManager.VotingResults.GetTotalVotesCount(\"{0}\")",
                         protocol.ElectionLink.ElectionId);
                     break;
                 case "M":
                 case "[M]":
                     newValue = _template.ElectionLink.MaxMarks.ToString();
                     break;
                 case "P":
                 case "[P]":
                     newValue = String.Format(
                         "Managers.VotingResultManager.VotingResults.GetAboveCandidateVotesCount("
                             + "Managers.ElectionManager.SourceData.GetElectionByNum(\"{0}\"))",
                         protocol.ElectionLink.ElectionId);
                     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);
                     newValue = String.Format(
                         "Managers.ElectionManager.SourceData.GetElectionByNum(\"{0}\").Protocol.Lines[{1}].Value"
                         , protocol.ElectionLink.ElectionId
                         , lineNumber - 1);
                     break;
             }
             preparedExpression.Replace(match.Value, newValue, match.Index + delta, match.Length);
             delta += newValue.Length - match.Length;
         }
         preparedExpression.Replace("=", "@");
         preparedExpression.Replace("<@", " " + "<=" + " ");
         preparedExpression.Replace(">@", " " + ">=" + " ");
         preparedExpression.Replace("@", " " + "==" + " ");
         preparedExpression.Replace("<>", " " + "!=" + " ");
         preparedExpression.Insert(0, ASSEMBLY_BEGIN.Replace(
             "_SUFFIX"
             , GetExpressionCheckerSuffix()));
         preparedExpression.Append(ASSEMBLY_END);
         return preparedExpression.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception(
             String.Format(
                 "Ошибка сборки в выражении : {0}:\n{1}"
                 ,InnerExpression
                 ,ex.Message)
             , ex);
     }
 }
Ejemplo n.º 7
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);
     }
 }
Ejemplo n.º 8
0
        public string GetExpansion(ProtocolTemplate protocol)
        {
            try
            {
                string fullKey;
                var preparedExpression = new StringBuilder(InnerExpression);
                var regExpression = new CheckExpressionLineReferenceRegex();
                var matches = regExpression.Matches(InnerExpression);
                var delta = 0;
                foreach (Match match in matches)
                {
                    if (match.Value.StartsWith("["))
                    {
                        fullKey = match.Value;
                        fullKey = fullKey.TrimStart('[');
                        fullKey = fullKey.TrimEnd(']');

                        int lineNumber;
                        if(!int.TryParse(fullKey, out lineNumber))
                            continue;
                        if (lineNumber < 1 || lineNumber > protocol.Lines.Length)
                            throw new Exception("В протоколе нет строки с порядковым номером " + lineNumber);
                        var sNewValue = "[" + protocol.Lines[lineNumber - 1].Num + protocol.Lines[lineNumber - 1].AdditionalNum + "]";
                        preparedExpression.Replace(match.Value, sNewValue, match.Index + delta, match.Length);
                        delta += sNewValue.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);
            }
        }
Ejemplo n.º 9
0
        public bool Check(ProtocolTemplate oProtocol)
        {
            _template = oProtocol;
            if (!Enabled) return true;
            if (_method == null)
                BindMethod(Assembly.GetExecutingAssembly());

            Failed = !(bool)_method.Invoke(null, null);
            return !Failed;
        }
Ejemplo n.º 10
0
 public void SetProtocol(ProtocolTemplate oProtocol)
 {
     _template = oProtocol;
 }