Ejemplo n.º 1
0
        private void ProcessRecordsExcel(object x)
        {
            ConcurrentExcelReader reader = x as ConcurrentExcelReader;
            SimpleSqlTableLoader  writer = new SimpleSqlTableLoader(m_Context);

            string[] line;
            int      rowsProcessed = 0;
            int      numColumns    = m_Context.ColumnNames.Count();

            while (reader.TryExtractRecord(out line))
            {
                var newRow = writer.GetEmptyRow();
                for (int i = 0; i < numColumns; i++)
                {
                    newRow[i] = line[i];
                }
                writer.PostRecord(newRow);
                if (++rowsProcessed % numberOfLines == 0)
                {
                    OnRecordsProcessed(Thread.CurrentThread.Name);
                }
            }
            //flush final records and trigger last event
            writer.WriteRecords();
            OnRecordsProcessed(Thread.CurrentThread.Name, rowsProcessed % numberOfLines);
        }
Ejemplo n.º 2
0
        public override async Task StartAsync()
        {
            //create, truncate, drop tables if specified
            HandeTableOptions();

            List <Task> Tasklist = new List <Task>();

            if (Regex.IsMatch(m_Context.SourceFilePath, @"\.xls"))
            {
                ConcurrentExcelReader reader = new ConcurrentExcelReader(m_Context);
                for (int i = 0; i < m_Context.CpuCountUsedToComputeParallalism; i++)
                {
                    Tasklist.Add(
                        Task.Factory.StartNew(
                            x => ProcessRecordsExcel(x), reader));
                }
            }
            else
            {
                ConcurrentFlatFileExtractor reader = new ConcurrentFlatFileExtractor(m_Context);
                for (int i = 0; i < m_Context.CpuCountUsedToComputeParallalism; i++)
                {
                    Tasklist.Add(
                        Task.Factory.StartNew(
                            x => ProcessRecords(x), reader));
                }
            }
            await Task.WhenAll(Tasklist);
        }
Ejemplo n.º 3
0
        public void TryExtractRecordTest()
        {
            ConcurrentExcelReader reader = new ConcurrentExcelReader(context);

            string[]        line;
            List <string[]> results = new List <string[]>();

            while (reader.TryExtractRecord(out line))
            {
                results.Add(line);
            }
            string[] firstColumn = new string[2] {
                "Nisha", "Jasper"
            };
            Assert.AreEqual(firstColumn[0], results[0][0]);
            Assert.AreEqual(firstColumn[1], results[1][0]);
        }