Ejemplo n.º 1
0
        internal ScalingSequentialPipeline(PipelineContext context)
        {
            m_Pause            = new ManualResetEvent(true);
            m_LatestPauseState = false;
            m_DummyProgress    = new Progress <int>();
            m_ActualProgress   = new Progress <int>();
            m_PauseSyncRoot    = new object();
            m_Context          = context;
            m_LineBuffers      = new List <BoundedConcurrentQueu <string> >();
            m_RecordBuffers    = new List <BoundedConcurrentQueu <object[]> >();
            m_RowBuffers       = new List <BoundedConcurrentQueu <Row> >();
            if (context.SourceFilePath.Contains(".xls"))
            {
                m_ExcelReader = new ExcelDataExtractor();
            }
            else
            {
                m_Reader         = new DIALFlatFileExtractor();
                m_StringSplitter = new StringSplitter(context.Qualifier)
                {
                    Delimiter = context.Delimiter
                };
            }
            m_RowBuilder = new RecordToRowTransformer(context.ColumnNames, context.IsSkippingError);
            m_Loader     = new SQLTableLoader();
            //register event

            m_ActualProgress.ProgressChanged += OnReaderEvent;
        }
Ejemplo n.º 2
0
        public void PausingReportingSQLLoaderTest()
        {
            D2S.LibraryTests.SqlExtractorTestHelper helper = new D2S.LibraryTests.SqlExtractorTestHelper();
            PipelineContext context = new PipelineContext();

            // ToDo: use connection string from app.config (local version)
            //context.SqlServerName = @"(localdb)\MSSQLLocalDB";
            //context.DatabaseName = "master";

            context.DestinationTableName = "loaderstest";
            try
            {
                context.DestinationTableName = helper.Initialize(ConfigVariables.Instance.ConfiguredConnection);
                context.ColumnNames          = new string[] { "col1", "col2" };
                ConcurrentQueue <Row> input = new ConcurrentQueue <Row>();
                Row newRow = new Row();
                newRow["col1"] = new Tuple <object, Type>("TestValue", typeof(string));
                newRow["col2"] = new Tuple <object, Type>(482, typeof(int));

                input.Enqueue(newRow);

                newRow         = new Row();
                newRow["col1"] = new Tuple <object, Type>("Hi", typeof(string));
                newRow["col2"] = new Tuple <object, Type>(483, typeof(int));

                input.Enqueue(newRow);

                SQLTableLoader loader = new SQLTableLoader();

                var action = loader.GetPausableReportingWorkItem();
                ManualResetEvent pauseButton = new ManualResetEvent(true);
                Progress <int>   progress    = new Progress <int>();

                Task work = Task.Factory.StartNew(() => action(context, input, pauseButton, progress));
                //wait for work to finish
                while (!input.IsEmpty)
                {
                    Task.Delay(200).Wait();
                }
                loader.SignalCompletion();

                work.Wait();

                //confirm that it worked
                SqlRecordExtractor reader = new SqlRecordExtractor();

                List <object>            Results = new List <object>();
                ConcurrentQueue <object> result  = new ConcurrentQueue <object>();
                Action <PipelineContext, IProducerConsumerCollection <object>, ManualResetEvent> readaction = reader.GetPausableWorkItem();
                context.SourceTableName          = context.DestinationTableName;
                context.SqlSourceColumnsSelected = new List <string>()
                {
                    "col1", "col2"
                };
                readaction(context, result, null);

                Results = result.ToList();
                Assert.AreEqual(expected: "TestValue", actual: ((object[])Results[2])[0]);
                Assert.AreEqual(expected: 482, actual: ((object[])Results[2])[1]);
                Assert.AreEqual(expected: "Hi", actual: ((object[])Results[3])[0]);
                Assert.AreEqual(expected: 483, actual: ((object[])Results[3])[1]);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                helper.Cleanup(ConfigVariables.Instance.ConfiguredConnection);
            }
        }
Ejemplo n.º 3
0
        public void SQLLoaderTest()
        {
            D2S.LibraryTests.SqlExtractorTestHelper helper = new D2S.LibraryTests.SqlExtractorTestHelper();
            PipelineContext context = new PipelineContext();

            // ToDo: use connection string from app.config (local version)
            //context.SqlServerName = @"(localdb)\MSSQLLocalDB";
            //context.DatabaseName = "master";

            context.DestinationTableName = "loaderstest";

            try
            {
                context.DestinationTableName = helper.Initialize(ConfigVariables.Instance.ConfiguredConnection);
                context.ColumnNames          = new string[] { "col1", "col2" };

                ConcurrentQueue <Row> row = new ConcurrentQueue <Row>();

                Row newRow = new Row();
                newRow["col1"] = new Tuple <object, Type>("TestValue", typeof(string));
                newRow["col2"] = new Tuple <object, Type>(482, typeof(int));

                row.Enqueue(newRow);

                newRow         = new Row();
                newRow["col1"] = new Tuple <object, Type>("Hi", typeof(string));
                newRow["col2"] = new Tuple <object, Type>(483, typeof(int));

                row.Enqueue(newRow);

                SQLTableLoader loader = new SQLTableLoader();

                Action <PipelineContext, IProducerConsumerCollection <Row> > action = loader.GetWorkItem();

                action(context, row);

                SqlRecordExtractor reader = new SqlRecordExtractor();

                List <object>            Results = new List <object>();
                ConcurrentQueue <object> result  = new ConcurrentQueue <object>();
                Action <PipelineContext, IProducerConsumerCollection <object>, ManualResetEvent> readaction = reader.GetPausableWorkItem();
                context.SourceTableName          = context.DestinationTableName;
                context.SqlSourceColumnsSelected = new List <string>()
                {
                    "col1", "col2"
                };
                readaction(context, result, null);

                Results = result.ToList();
                Assert.AreEqual(expected: "TestValue", actual: ((object[])Results[2])[0]);
                Assert.AreEqual(expected: 482, actual: ((object[])Results[2])[1]);
                Assert.AreEqual(expected: "Hi", actual: ((object[])Results[3])[0]);
                Assert.AreEqual(expected: 483, actual: ((object[])Results[3])[1]);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                helper.Cleanup(ConfigVariables.Instance.ConfiguredConnection);
            }
        }