Beispiel #1
0
        internal void Validate(ChoFixedLengthRecordConfiguration config)
        {
            try
            {
                if (StartIndex < 0)
                {
                    throw new ChoRecordConfigurationException("StartIndex must be > 0.");
                }
                if (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 ((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 (Size != null && Size.Value <= 0)
                {
                    throw new ChoRecordConfigurationException("Size must be > 0.");
                }
                if (ErrorMode == null)
                {
                    ErrorMode = ChoErrorMode.ReportAndContinue; // 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);
            }
        }
Beispiel #2
0
        internal void Validate(ChoCSVRecordConfiguration config)
        {
            try
            {
                if (!AltFieldNames.IsNullOrWhiteSpace())
                {
                    AltFieldNamesArray = AltFieldNames.SplitNTrim();
                }

                if (FieldName.IsNullOrWhiteSpace())
                {
                    FieldName = Name;
                }
                if (FieldPosition <= 0)
                {
                    throw new ChoRecordConfigurationException("Invalid '{0}' field position specified. Must be > 0.".FormatString(FieldPosition));
                }
                if (FillChar != null)
                {
                    if (FillChar.Value == ChoCharEx.NUL)
                    {
                        throw new ChoRecordConfigurationException("Invalid '{0}' FillChar specified.".FormatString(FillChar));
                    }
                    if (config.Delimiter.Contains(FillChar.Value))
                    {
                        throw new ChoRecordConfigurationException("FillChar [{0}] can't be one of Delimiter characters [{1}]".FormatString(FillChar, config.Delimiter));
                    }
                    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.Delimiter)
                         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;
                }
                if (NullValue == null)
                {
                    NullValue = config.NullValue;
                }
            }
            catch (Exception ex)
            {
                throw new ChoRecordConfigurationException("Invalid configuration found at '{0}' field.".FormatString(Name), ex);
            }
        }