Exemplo n.º 1
0
 public static string ToText <TRec>(TRec record, ChoCSVRecordConfiguration configuration = null)
     where TRec : class
 {
     return(ToTextAll(ChoEnumerable.AsEnumerable(record), configuration));
 }
Exemplo n.º 2
0
 public ChoCSVWriter(StringBuilder sb, ChoCSVRecordConfiguration configuration = null) : this(new StringWriter(sb), configuration)
 {
 }
Exemplo n.º 3
0
 public ChoCSVWriter(ChoCSVRecordConfiguration configuration = null)
 {
     Configuration = configuration;
     Init();
 }
Exemplo n.º 4
0
        internal static IEnumerator <object> LoadText(Type recType, string inputText, ChoCSVRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null)
        {
            ChoCSVRecordReader rr = new ChoCSVRecordReader(recType, configuration);

            rr.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch;
            return(rr.AsEnumerable(new StreamReader(inputText.ToStream(), encoding, false, bufferSize)).GetEnumerator());
        }
Exemplo n.º 5
0
 public ChoCSVReader(StringBuilder sb, ChoCSVRecordConfiguration configuration = null) : this(new StringReader(sb.ToString()), configuration)
 {
 }
Exemplo n.º 6
0
        public IEnumerable <T> DeserializeText(string inputText, Encoding encoding = null, ChoCSVRecordConfiguration configuration = null, TraceSwitch traceSwitch = null)
        {
            if (configuration == null)
            {
                configuration = Configuration;
            }

            return(new ChoCSVReader <T>(inputText.ToStream(encoding), configuration)
            {
                TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch
            });
        }
Exemplo n.º 7
0
        public static ChoCSVReader <T> LoadText(string inputText, Encoding encoding = null, ChoCSVRecordConfiguration configuration = null, TraceSwitch traceSwitch = null)
        {
            var r = new ChoCSVReader <T>(inputText.ToStream(encoding), configuration)
            {
                TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch
            };

            r._closeStreamOnDispose = true;

            return(r);
        }
Exemplo n.º 8
0
 public static string ToText <TRec>(TRec record, ChoCSVRecordConfiguration configuration = null, TraceSwitch traceSwitch = null)
     where TRec : class
 {
     return(ToText(ChoEnumerable.AsEnumerable(record), configuration, traceSwitch));
 }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
 public static ChoCSVReader <T> LoadLines(IEnumerable <string> inputLines, ChoCSVRecordConfiguration configuration = null, TraceSwitch traceSwitch = null)
 {
     return(ChoCSVReader <T> .LoadLines(inputLines, configuration, traceSwitch).WithDelimiter(delimiter));
 }
Exemplo n.º 11
0
 public static ChoCSVReader <T> LoadText(string inputText, ChoCSVRecordConfiguration config, TraceSwitch traceSwitch = null)
 {
     return(LoadText(inputText, null, config, traceSwitch));
 }
Exemplo n.º 12
0
 public static ChoCSVReader <T> LoadText(string inputText, ChoCSVRecordConfiguration configuration, TraceSwitch traceSwitch = null)
 {
     return(ChoCSVReader <T> .LoadText(inputText, configuration, traceSwitch).WithDelimiter(delimiter));
 }
Exemplo n.º 13
0
 public static ChoCSVReader <T> New(Stream inStream, ChoCSVRecordConfiguration configuration = null)
 {
     return(new ChoCSVReader <T>(inStream, configuration).WithDelimiter(delimiter));
 }
Exemplo n.º 14
0
 public static ChoCSVReader <T> New(TextReader textReader, ChoCSVRecordConfiguration configuration = null)
 {
     return(new ChoCSVReader <T>(textReader, configuration).WithDelimiter(delimiter));
 }
Exemplo n.º 15
0
 public static ChoCSVReader <T> New(string filePath, ChoCSVRecordConfiguration configuration = null)
 {
     return(new ChoCSVReader <T>(filePath, configuration).WithDelimiter(delimiter));
 }
Exemplo n.º 16
0
 public static ChoCSVReader <T> New(StringBuilder sb, ChoCSVRecordConfiguration configuration = null)
 {
     return(new ChoCSVReader <T>(sb, configuration).WithDelimiter(delimiter));
 }