Exemplo n.º 1
0
        public ConvetrerWorker(BaseFileReader fileReader, IHandler fileHandler, BaseFileWriter fileWriter)
        {
            this.fileReader  = fileReader ?? throw new ArgumentException("fileReader load ERROR");
            this.fileHandler = fileHandler ?? throw new ArgumentException("fileHandler load ERROR");
            this.fileWriter  = fileWriter ?? throw new ArgumentException("fileWriter load ERROR");

            fileReader.ReadProgress    += ReadingProgress;
            fileReader.ReadedDataAsync += FileReaderOnReadedDataAsync;
            fileWriter.BufferWrited    += FileWriterOnBufferWrited;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens the csv file, and tries to read the headers
        /// </summary>
        /// <param name="setting">The CSVFile fileSetting</param>
        /// <param name="processDisplay">The process display.</param>
        /// <returns>
        ///   <c>True</c> we could use the first row as header, <c>false</c> should not use first row as header
        /// </returns>
        public static bool GuessHasHeader(ICsvFile setting, CancellationToken cancellationToken)
        {
            Contract.Requires(setting != null);
            // Only do so if HasFieldHeader is still true
            if (!setting.HasFieldHeader)
            {
                Log.Info("Without Header Row");
                return(false);
            }

            using (var csvDataReader = new CsvFileReader(setting))
            {
                csvDataReader.Open(false, cancellationToken);

                var defaultNames = 0;

                // In addition check that all columns have real names and did not get an artificial name
                // or are numbers
                for (var counter = 0; counter < csvDataReader.FieldCount; counter++)
                {
                    var columnName = csvDataReader.GetName(counter);

                    // if replaced by a default assume no header
                    if (columnName.Equals(BaseFileReader.GetDefaultName(counter), StringComparison.OrdinalIgnoreCase))
                    {
                        if (defaultNames++ == (int)Math.Ceiling(csvDataReader.FieldCount / 2.0))
                        {
                            Log.Info("Without Header Row");
                            return(false);
                        }
                    }

                    // if its a number assume no headers
                    if (StringConversion.StringToDecimal(columnName, '.', ',', false).HasValue)
                    {
                        Log.Info("Without Header Row");
                        return(false);
                    }

                    // if its rather long assume no header
                    if (columnName.Length > 80)
                    {
                        Log.Info("Without Header Row");
                        return(false);
                    }
                }
                Log.Info("With Header Row");
                // if there is only one line assume its does not have a header
                return(true);
            }
        }
Exemplo n.º 3
0
 public Section(BaseFileReader <T> owner, string section) : base()
 {
     this.owner   = owner;
     this.section = section;
 }
Exemplo n.º 4
0
 protected string TreatNbspTestAsNullTrim([CanBeNull] string inputString) =>
 BaseFileReader.TreatNbspTestAsNullTrim(inputString, m_TreatNbspAsSpace, m_TreatTextAsNull, m_Trim);