Beispiel #1
0
        private void splitTokens(StringValueObject template,
                                 ref List <TokenBase> templateTokens)
        {
            TemplateTokenFactory ttf = TemplateTokenFactory.Instance;

            List <SplitElement> splitElements = SplitNonTokenizedElements(template.Value);

            foreach (SplitElement elem in splitElements)
            {
                if (elem.isFixedToken)
                {
                    // Treat fixed tokens like constant strings between placeholders
                    templateTokens.Add(ttf.createConstStringToken(elem.text));
                }
                else
                {
                    for (int curPos = 0; curPos < elem.text.Length;)
                    {
                        Match curMatch = PLACEHOLDER_REGEX.Match(elem.text, curPos);
                        if (curMatch.Success && (curMatch.Length >= 2))
                        {
                            // Constant string before placeholder
                            templateTokens.Add(ttf.createConstStringToken(
                                                   elem.text.Substring(curPos, curMatch.Index - curPos)));
                            // Placeholder string between delimiters
                            templateTokens.Add(
                                ttf.createPlaceholderToken(
                                    elem.text.Substring(curMatch.Index + 1, curMatch.Length - 2),
                                    getGroupSeparator(), getDecimalSeparator()
                                    )
                                );
                            curPos = curMatch.Index + curMatch.Length;
                        }
                        else
                        {
                            // Constant string after last placeholder
                            templateTokens.Add(ttf.createConstStringToken(
                                                   elem.text.Substring(curPos)));
                            curPos = elem.text.Length;
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Called when the logic sheets are checked for correctness, in order to check
        /// this node's correct configuration.
        /// </summary>
        /// <param name="language">
        /// The language key which is used for localizing the validation message.
        /// </param>
        ///
        public override sealed ValidationResult Validate(string language)
        {
            mLanguage = language; // memorize for localization in Execute

            ValidationResult result = validateSeparators(language);

            if (result.HasError)
            {
                return(result);
            }

            TemplateTokenFactory ttf = TemplateTokenFactory.Instance;

            ttf.restart();

            foreach (var template in mTemplates)
            {
                result = validateTemplate(template, language, doFullCheck: true);
                if (result.HasError)
                {
                    return(result);
                }
                int binCountDummy = 0;
                int intCountDummy = 0;
                int numCountDummy = 0;
                int strCountDummy = 0;
                List <TokenBase> localTokensDummy = new List <TokenBase>(10);
                result = validateInternal(template, ref localTokensDummy,
                                          ref binCountDummy, ref intCountDummy,
                                          ref numCountDummy, ref strCountDummy,
                                          language, doFullCheck: true);
                if (result.HasError)
                {
                    return(result);
                }
            }
            return(base.Validate(language));
        }
Beispiel #3
0
        /// <summary>
        /// Called when the logic sheets are checked for correctness, in order to check
        /// this node's correct configuration.
        /// </summary>
        /// <param name="language">
        /// The language key which is used for localizing the validation message.
        /// </param>
        ///
        public override sealed ValidationResult Validate(string language)
        {
            TemplateTokenFactory ttf = TemplateTokenFactory.Instance;

            ttf.restart();

            foreach (var template in mTemplates)
            {
                int binCountDummy            = 0;
                int intCountDummy            = 0;
                int numCountDummy            = 0;
                int strCountDummy            = 0;
                List <TokenBase> localTokens = new List <TokenBase>(10);
                ValidationResult result      = validateInternal(template, ref localTokens,
                                                                ref binCountDummy, ref intCountDummy,
                                                                ref numCountDummy, ref strCountDummy, language);
                if (result.HasError)
                {
                    return(result);
                }
            }
            return(base.Validate(language));
        }
Beispiel #4
0
        private ValidationResult validateInternal(StringValueObject template,
                                                  ref List <TokenBase> templateTokens,
                                                  ref int binCount,
                                                  ref int intCount,
                                                  ref int numCount,
                                                  ref int strCount,
                                                  string language)
        {
            if ((!template.HasValue) || (template.Value.Length <= 0))
            {
                return(new ValidationResult
                {
                    HasError = true,
                    Message = Localize(language, "EmptyTemplate")
                });
            }

            TemplateTokenFactory ttf = TemplateTokenFactory.Instance;

            for (int curPos = 0; curPos < template.Value.Length;)
            {
                Match curMatch = PLACEHOLDER_REGEX.Match(template.Value, curPos);
                if (curMatch.Success && (curMatch.Length >= 2))
                {
                    // constant string before placeholder
                    templateTokens.Add(ttf.createConstStringToken(
                                           template.Value.Substring(curPos, curMatch.Index - curPos)));
                    // placeholder string between delimiters
                    templateTokens.Add(ttf.createPlaceholderToken(
                                           template.Value.Substring(curMatch.Index + 1, curMatch.Length - 2)));
                    curPos = curMatch.Index + curMatch.Length;
                }
                else
                {
                    // constant string after last placeholder
                    templateTokens.Add(ttf.createConstStringToken(
                                           template.Value.Substring(curPos)));

                    curPos = template.Value.Length;
                }
            }
            ValidationResult result = validateNumberOfTokens(language, ref templateTokens);

            if (result.HasError)
            {
                return(result);
            }

            foreach (TokenBase token in templateTokens)
            {
                switch (token.getType())
                {
                case TokenType.ConstString:
                case TokenType.VarReference:
                    // nothing to do
                    break;

                case TokenType.VarBoolean:
                    binCount++;
                    break;

                case TokenType.VarInteger:
                    intCount++;
                    break;

                case TokenType.VarNumber:
                    numCount++;
                    break;

                case TokenType.VarString:
                    strCount++;
                    break;

                case TokenType.Error:
                default:
                    return(createTokenError(language, template.Name, token));
                }
            }
            if (binCount > MAX_INPUTS)
            {
                return(new ValidationResult
                {
                    HasError = true,
                    Message = Localize(language, "TooManyBinPlaceholders")
                });
            }
            if (intCount > MAX_INPUTS)
            {
                return(new ValidationResult
                {
                    HasError = true,
                    Message = Localize(language, "TooManyIntPlaceholders")
                });
            }
            if (numCount > MAX_INPUTS)
            {
                return(new ValidationResult
                {
                    HasError = true,
                    Message = Localize(language, "TooManyNumPlaceholders")
                });
            }
            if (strCount > MAX_INPUTS)
            {
                return(new ValidationResult
                {
                    HasError = true,
                    Message = Localize(language, "TooManyStrPlaceholders")
                });
            }
            return(validateTokens(language, template.Name, ref templateTokens));
        }
Beispiel #5
0
        /// <summary>
        /// This method has been added as a ValueSet handler to the template
        /// parameters. It will therefore be called whenever a template string
        /// is edited, in order to update the tokens and inputs.
        /// </summary>
        private void updateTemplate(object sender = null,
                                    ValueChangedEventArgs evArgs = null)
        {
            // Even though only one template has changed we must re-evaluate all
            // templates, because these depend on each other because of their
            // placeholder re-use.
            TemplateTokenFactory ttf = TemplateTokenFactory.Instance;

            ttf.restart();

            int binCount = 0;
            int intCount = 0;
            int numCount = 0;
            int strCount = 0;

            List <TokenBase> allTokens = new List <TokenBase>(100);

            for (int i = 0; i < mTemplates.Count; i++)
            {
                // Check parameter.
                // Along the way fill mTemplateTokens and count numbers of inputs
                List <TokenBase> localTokens = new List <TokenBase>(10);
                ValidationResult res         = validateInternal(mTemplates[i], ref localTokens,
                                                                ref binCount, ref intCount, ref numCount, ref strCount, "en");
                if (res.HasError)
                {
                    return;
                }
                mTokensPerTemplate[i] = localTokens;
                allTokens.AddRange(localTokens);
            }

            // Update the input counts if successful
            mBinInputCount.Value = binCount;
            mIntInputCount.Value = intCount;
            mNumInputCount.Value = numCount;
            mStrInputCount.Value = strCount;

            int binIdx = 0;
            int intIdx = 0;
            int numIdx = 0;
            int strIdx = 0;

            foreach (TokenBase token in allTokens)
            {
                if (token is VarTokenBase varToken)
                {
                    switch (varToken.getType())
                    {
                    case TokenType.VarBoolean:
                        mBinInputs[binIdx].Name = varToken.getName();
                        varToken.setInput(mBinInputs[binIdx]);
                        binIdx++;
                        break;

                    case TokenType.VarInteger:
                        mIntInputs[intIdx].Name = varToken.getName();
                        varToken.setInput(mIntInputs[intIdx]);
                        intIdx++;
                        break;

                    case TokenType.VarNumber:
                        mNumInputs[numIdx].Name = varToken.getName();
                        varToken.setInput(mNumInputs[numIdx]);
                        numIdx++;
                        break;

                    case TokenType.VarString:
                        mStrInputs[strIdx].Name = varToken.getName();
                        varToken.setInput(mStrInputs[strIdx]);
                        strIdx++;
                        break;

                    default:
                        // Nothing to do
                        break;
                    }
                }
            }
            updateTemplateHelpers();
        }