예제 #1
0
        public string BuildCheckTypeText(SourceData sourceData)
        {
            const string ASSEMBLY_TEXT
                = @"public class LineExpression_SUFFIX{FUNCTIONS static public int check(){return EXPRESSION;}} ";

            if (Type != LineType.DontQueryUser)
            {
                return(null);
            }
            try
            {
                var regExpression      = new VotingCountReferenceRegex();
                var matches            = regExpression.Matches(Expression);
                var preparedExpression = new StringBuilder((matches.Count + 1) * 1024);
                preparedExpression.Append(ASSEMBLY_TEXT);
                preparedExpression.Replace(
                    "_SUFFIX",
                    String.Format("_{0}_{1}_{2}", Num, AdditionalNum, _template.ElectionLink.ElectionId));
                preparedExpression.Replace("EXPRESSION", Expression);
                var functions = new StringBuilder(matches.Count * 1024);
                int num       = 0;
                foreach (Match match in matches)
                {
                    string fullKey = match.Value;
                    var    blankId = sourceData.GetBlankIdByElectionNumber(_template.ElectionLink.ElectionId);
                    functions.Append(СompileSimpleExpression(blankId, fullKey, ++num));
                    preparedExpression.Replace(fullKey, " " + "Expression" + num + "()" + " " + "\n");
                }
                preparedExpression.Replace("FUNCTIONS", functions.ToString());
                return(preparedExpression.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception(
                          String.Format(
                              "Ошибка сборки в выражении № {0}{1} \"{2}\". Выборы № {3}:\n{4}"
                              , Num
                              , AdditionalNum
                              , Expression
                              , _template.ElectionLink.ElectionId
                              , ex.Message)
                          , ex);
            }
        }
예제 #2
0
파일: Line.cs 프로젝트: nico-izo/KOIB
 public string BuildCheckTypeText(SourceData sourceData)
 {
     const string ASSEMBLY_TEXT
         = @"public class LineExpression_SUFFIX{FUNCTIONS static public int check(){return EXPRESSION;}} ";
     if (Type != LineType.DontQueryUser) return null;
     try
     {
         var regExpression = new VotingCountReferenceRegex();
         var matches = regExpression.Matches(Expression);
         var preparedExpression = new StringBuilder((matches.Count + 1)*1024);
         preparedExpression.Append(ASSEMBLY_TEXT);
         preparedExpression.Replace(
             "_SUFFIX",
             String.Format("_{0}_{1}_{2}", Num, AdditionalNum, _template.ElectionLink.ElectionId));
         preparedExpression.Replace("EXPRESSION", Expression);
         var functions = new StringBuilder(matches.Count * 1024);
         int num = 0;
         foreach (Match match in matches)
         {
             string fullKey = match.Value;
             var blankId = sourceData.GetBlankIdByElectionNumber(_template.ElectionLink.ElectionId);
             functions.Append(СompileSimpleExpression(blankId, fullKey, ++num));
             preparedExpression.Replace(fullKey, " " + "Expression" + num + "()" + " " + "\n");
         }
         preparedExpression.Replace("FUNCTIONS", functions.ToString());
         return preparedExpression.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception(
             String.Format(
                 "Ошибка сборки в выражении № {0}{1} \"{2}\". Выборы № {3}:\n{4}"
                 , Num
                 , AdditionalNum
                 , Expression
                 , _template.ElectionLink.ElectionId
                 , ex.Message)
             , ex);
     }
 }