Example #1
0
        /// <summary>
        /// Read the headers.
        /// </summary>
        /// <param name="format">The format of this CSV file.</param>
        /// <param name="headers">Are headers present.</param>
        private void Begin(bool headers, CSVFormat format)
        {
            try
            {
                DateFormat     = "yyyy-MM-dd";
                TimeFormat     = "HHmmss";
                this.parseLine = new ParseCSVLine(format);
                // read the column heads
                if (headers)
                {
                    String         line = _reader.ReadLine();
                    IList <String> tok  = parseLine.Parse(line);

                    int i = 0;
                    foreach (String header in tok)
                    {
                        if (_columns.ContainsKey(header.ToLower()))
                        {
                            throw new EncogError("Two columns cannot have the same name");
                        }
                        _columns.Add(header.ToLower(), i++);
                        _columnNames.Add(header);
                    }
                }

                _data = null;
            }
            catch (IOException e)
            {
#if logging
                if (logger.IsErrorEnabled)
                {
                    logger.Error("Exception", e);
                }
#endif
                throw new EncogError(e);
            }
        }
Example #2
0
        /// <summary>
        /// Read the headers.
        /// </summary>
        /// <param name="format">The format of this CSV file.</param>
        /// <param name="headers">Are headers present.</param>
        private void Begin(bool headers, CSVFormat format)
        {
            try
            {
                DateFormat = "yyyy-MM-dd";
                TimeFormat = "HHmmss";
                this.parseLine = new ParseCSVLine(format);
                // read the column heads
                if (headers)
                {
                    String line = _reader.ReadLine();
                    IList<String> tok = parseLine.Parse(line);

                    int i = 0;
                    foreach (String header in tok)
                    {
                        if (_columns.ContainsKey(header.ToLower()))
                            throw new EncogError("Two columns cannot have the same name");
                        _columns.Add(header.ToLower(), i++);
                        _columnNames.Add(header);
                    }
                }

                _data = null;
            }
            catch (IOException e)
            {
            #if logging
                if (logger.IsErrorEnabled)
                {
                    logger.Error("Exception", e);
                }
            #endif
                throw new EncogError(e);
            }
        }