internal void Validate(ChoAvroRecordConfiguration config)
        {
            try
            {
                if (FieldName.IsNullOrWhiteSpace())
                {
                    FieldName = Name;
                }

                if (Size != null && Size.Value <= 0)
                {
                    throw new ChoRecordConfigurationException("Size must be > 0.");
                }
                if (ErrorMode == null)
                {
                    ErrorMode = config.ErrorMode; // config.ErrorMode;
                }
                if (IgnoreFieldValueMode == null)
                {
                    IgnoreFieldValueMode = config.IgnoreFieldValueMode;
                }
                if (QuoteField == null)
                {
                    QuoteField = config.QuoteAllFields;
                }
                if (NullValue == null)
                {
                    NullValue = config.NullValue;
                }
            }
            catch (Exception ex)
            {
                throw new ChoRecordConfigurationException("Invalid configuration found at '{0}' field.".FormatString(Name), ex);
            }
        }
Exemple #2
0
        public virtual IReqRule ParseRule([NotNull] string fieldName, [NotNull] object value)
        {
            var arr = value.ToString().Split(Split);

            if (arr.Length != 2 || (arr[0].IsNullOrWhiteSpace() || arr[1].IsNullOrWhiteSpace()))
            {
                throw new Exception($"值内容不合法,过滤规则({typeof(ReqBetweenFieldAttribute).FullName})解析失败");
            }
            return(new ReqBetweenRule(FieldName.IsNullOrWhiteSpace() ? fieldName : FieldName, arr[0], arr[1], Link));
        }
Exemple #3
0
 internal string GetXPath(string nsPrefix)
 {
     if (XPath.IsNullOrWhiteSpace())
     {
         if (_defaultXPath.IsNullOrWhiteSpace())
         {
             if (nsPrefix.IsNullOrWhiteSpace())
             {
                 if (!FieldName.IsNullOrWhiteSpace())
                 {
                     _defaultXPath = $"{FieldName}|@{FieldName}";
                 }
                 else
                 {
                     _defaultXPath = $"{Name}|@{Name}";
                 }
             }
             else
             {
                 if (!FieldName.IsNullOrWhiteSpace())
                 {
                     if (FieldName.Contains(":"))
                     {
                         _defaultXPath = $"{FieldName}|@{FieldName}";
                     }
                     else
                     {
                         _defaultXPath = $"{FieldName}|@{FieldName}|{nsPrefix}:{FieldName}";
                     }
                 }
                 else
                 {
                     if (Name.Contains(":"))
                     {
                         _defaultXPath = $"{Name}|@{Name}";
                     }
                     else
                     {
                         _defaultXPath = $"{Name}|@{Name}|{nsPrefix}:{Name}";
                     }
                 }
             }
         }
         return(_defaultXPath);
     }
     else
     {
         return(XPath);
     }
 }
Exemple #4
0
        internal void Validate(ChoXmlRecordConfiguration config)
        {
            try
            {
                if (FieldName.IsNullOrWhiteSpace())
                {
                    FieldName = Name;
                }

                if (XPath.IsNullOrWhiteSpace())
                {
                    throw new ChoRecordConfigurationException("Missing XPath.");
                }
                if (FillChar != null)
                {
                    if (FillChar.Value == ChoCharEx.NUL)
                    {
                        throw new ChoRecordConfigurationException("Invalid '{0}' FillChar specified.".FormatString(FillChar));
                    }
                }

                if (Size != null && Size.Value <= 0)
                {
                    throw new ChoRecordConfigurationException("Size must be > 0.");
                }
                if (ErrorMode == null)
                {
                    ErrorMode = config.ErrorMode; // config.ErrorMode;
                }
                if (IgnoreFieldValueMode == null)
                {
                    IgnoreFieldValueMode = config.IgnoreFieldValueMode;
                }
                if (QuoteField == null)
                {
                    QuoteField = config.QuoteAllFields;
                }
            }
            catch (Exception ex)
            {
                throw new ChoRecordConfigurationException("Invalid configuration found at '{0}' field.".FormatString(Name), ex);
            }
        }
Exemple #5
0
        internal void Validate(ChoFixedLengthRecordConfiguration config)
        {
            try
            {
                if (!AltFieldNames.IsNullOrWhiteSpace())
                {
                    AltFieldNamesArray = AltFieldNames.SplitNTrim();
                }

                if (FieldName.IsNullOrWhiteSpace())
                {
                    FieldName = Name;
                }
                if (StartIndex < 0)
                {
                    throw new ChoRecordConfigurationException("StartIndex must be > 0.");
                }
                if (StartIndex == 0 && (Size == null || Size.Value < 0))
                {
                    throw new ChoRecordConfigurationException("Size must be > 0.");
                }
                if (FillChar != null)
                {
                    if (FillChar.Value == ChoCharEx.NUL)
                    {
                        throw new ChoRecordConfigurationException("Invalid '{0}' FillChar specified.".FormatString(FillChar));
                    }
                    if (config.EOLDelimiter.Contains(FillChar.Value))
                    {
                        throw new ChoRecordConfigurationException("FillChar [{0}] can't be one EOLDelimiter characters [{1}]".FormatString(FillChar, config.EOLDelimiter));
                    }
                }
                if (config.Comments != null)
                {
                    if ((from comm in config.Comments
                         where comm.Contains(FillChar.ToNString(' '))
                         select comm).Any())
                    {
                        throw new ChoRecordConfigurationException("One of the Comments contains FillChar. Not allowed.");
                    }
                    if ((from comm in config.Comments
                         where comm.Contains(config.EOLDelimiter)
                         select comm).Any())
                    {
                        throw new ChoRecordConfigurationException("One of the Comments contains EOLDelimiter. Not allowed.");
                    }
                }
                if (StartIndex == 0 && (Size == null || Size.Value < 0))
                {
                    throw new ChoRecordConfigurationException("Size must be > 0.");
                }
                if (ErrorMode == null)
                {
                    ErrorMode = config.ErrorMode; // config.ErrorMode;
                }
                if (IgnoreFieldValueMode == null)
                {
                    IgnoreFieldValueMode = config.IgnoreFieldValueMode;
                }
                if (QuoteField == null)
                {
                    QuoteField = config.QuoteAllFields;
                }
                if (NullValue == null)
                {
                    NullValue = config.NullValue;
                }
            }
            catch (Exception ex)
            {
                throw new ChoRecordConfigurationException("Invalid configuration found at '{0}' field.".FormatString(Name), ex);
            }
        }
        internal void Validate(ChoKVPRecordConfiguration config)
        {
            try
            {
                if (FieldName.IsNullOrWhiteSpace())
                {
                    FieldName = Name;
                }
                if (FillChar != null)
                {
                    if (FillChar.Value == ChoCharEx.NUL)
                    {
                        throw new ChoRecordConfigurationException("Invalid '{0}' FillChar specified.".FormatString(FillChar));
                    }
                    if (config.Separator.Contains(FillChar.Value))
                    {
                        throw new ChoRecordConfigurationException("FillChar [{0}] can't be one of Delimiter characters [{1}]".FormatString(FillChar, config.Separator));
                    }
                    if (config.EOLDelimiter.Contains(FillChar.Value))
                    {
                        throw new ChoRecordConfigurationException("FillChar [{0}] can't be one of EOLDelimiter characters [{1}]".FormatString(FillChar, config.EOLDelimiter));
                    }
                }
                if (config.Comments != null)
                {
                    if ((from comm in config.Comments
                         where comm.Contains(FillChar.ToNString(' '))
                         select comm).Any())
                    {
                        throw new ChoRecordConfigurationException("One of the Comments contains FillChar. Not allowed.");
                    }
                    if ((from comm in config.Comments
                         where comm.Contains(config.Separator)
                         select comm).Any())
                    {
                        throw new ChoRecordConfigurationException("One of the Comments contains Delimiter. Not allowed.");
                    }
                    if ((from comm in config.Comments
                         where comm.Contains(config.EOLDelimiter)
                         select comm).Any())
                    {
                        throw new ChoRecordConfigurationException("One of the Comments contains EOLDelimiter. Not allowed.");
                    }
                }

                if (Size != null && Size.Value <= 0)
                {
                    throw new ChoRecordConfigurationException("Size must be > 0.");
                }
                if (ErrorMode == null)
                {
                    ErrorMode = config.ErrorMode; // config.ErrorMode;
                }
                if (IgnoreFieldValueMode == null)
                {
                    IgnoreFieldValueMode = config.IgnoreFieldValueMode;
                }
                if (QuoteField == null)
                {
                    QuoteField = config.QuoteAllFields;
                }
            }
            catch (Exception ex)
            {
                throw new ChoRecordConfigurationException("Invalid configuration found at '{0}' field.".FormatString(Name), ex);
            }
        }
 public virtual IReqRule ParseRule([NotNull] string fieldName, [NotNull] object value)
 {
     return(new ReqRule(FieldName.IsNullOrWhiteSpace()? fieldName: FieldName, value, Op, Link));
 }