Esempio n. 1
0
        internal static IEnumerable <ValidationError> ValidateAdAttributePatterns(IEnumerable <Pattern> patterns, string supplementalInfo, bool useLegacyRegex)
        {
            List <ValidationError> list = new List <ValidationError>();

            if (patterns == null || !patterns.Any <Pattern>())
            {
                list.Add(new RulePhrase.RulePhraseValidationError(Strings.ArgumentNotSet, supplementalInfo));
                return(list);
            }
            foreach (Pattern pattern in patterns)
            {
                int num = pattern.Value.IndexOf(':');
                if (num >= 0)
                {
                    string text = pattern.Value.Substring(0, num).Trim().ToLowerInvariant();
                    if (!TransportUtils.GetDisclaimerMacroLookupTable().ContainsKey(text))
                    {
                        list.Add(new RulePhrase.RulePhraseValidationError(Strings.InvalidMacroName(text), supplementalInfo));
                    }
                    else
                    {
                        string   text2     = pattern.Value.Substring(num + 1);
                        string[] patterns2 = text2.Split(new char[]
                        {
                            ','
                        }, StringSplitOptions.RemoveEmptyEntries);
                        IEnumerable <ValidationError> enumerable = PatternValidator.ValidatePatterns(patterns2, supplementalInfo, useLegacyRegex);
                        if (enumerable != null)
                        {
                            list.AddRange(enumerable);
                        }
                    }
                }
                else
                {
                    list.Add(new RulePhrase.RulePhraseValidationError(Strings.MacroNameNotSpecified(pattern.Value), supplementalInfo));
                }
            }
            if (!list.Any <ValidationError>())
            {
                return(null);
            }
            return(list);
        }
        protected override void ValidateRead(List <ValidationError> errors)
        {
            if (this.Words == null || this.Words.Length == 0)
            {
                errors.Add(new RulePhrase.RulePhraseValidationError(RulesTasksStrings.ArgumentNotSet, base.Name));
                return;
            }
            Word[] words = this.Words;
            int    i     = 0;

            while (i < words.Length)
            {
                Word   word  = words[i];
                string value = word.Value;
                int    index;
                if (!string.IsNullOrEmpty(value) && !Utils.CheckIsUnicodeStringWellFormed(value, out index))
                {
                    errors.Add(new RulePhrase.RulePhraseValidationError(RulesTasksStrings.CommentsHaveInvalidChars((int)value[index]), base.Name));
                }
                else
                {
                    int num = value.IndexOf(':');
                    if (num >= 0)
                    {
                        string text = value.Substring(0, num).Trim().ToLowerInvariant();
                        if (TransportUtils.GetDisclaimerMacroLookupTable().ContainsKey(text))
                        {
                            i++;
                            continue;
                        }
                        errors.Add(new RulePhrase.RulePhraseValidationError(RulesTasksStrings.InvalidMacroName(text), base.Name));
                    }
                    else
                    {
                        errors.Add(new RulePhrase.RulePhraseValidationError(RulesTasksStrings.MacroNameNotSpecified(value), base.Name));
                    }
                }
                return;
            }
            base.ValidateRead(errors);
        }