Exemplo n.º 1
0
        public void CreateRowTest()
        {
            string[]   columns   = new string[] { "AnInteger", "AString", "ADouble", "ADate" };
            RowFactory Factory   = new RowFactory(columns);
            int        AnInteger = 5;
            string     AString   = "Number 1 sister";
            double     ADouble   = 3.50d;
            DateTime   ADate     = DateTime.Now;

            object[] Record = new object[] { AnInteger, AString, ADouble, ADate };

            Row MyRow = Factory.CreateRow(Record);

            Console.WriteLine(JsonConvert.SerializeObject(MyRow));

            for (int i = 0; i < 4; i++)
            {
                //check types
                Assert.AreEqual(expected: Record[i].GetType(), actual: MyRow[columns[i]].Item2);

                //check values
                Assert.AreEqual(expected: Record[i], actual: MyRow[columns[i]].Item1);
            }

            Record = new object[] { "haha" };
            bool errorThrown = false;

            try
            {
                MyRow = Factory.CreateRow(Record);
            }
            catch (Exception ex)
            {
                // if we reach here its good
                errorThrown = true;
            }
            finally
            {
                if (!errorThrown)
                {
                    Assert.Fail();
                }
            }
        }
Exemplo n.º 2
0
        private void DoWorkAndReport(IProducerConsumerCollection <object[]> input, IProducerConsumerCollection <Row> output, ManualResetEvent pauseEvent, IProgress <int> progressMonitor)
        {
            RowFactory Factory             = new RowFactory(ColumnNames);
            int        ExpectedColumnCount = ColumnNames.Count();
            int        processedCount      = 0;

            while (HasWork)
            {
                pauseEvent.WaitOne();
                object[] currentInput;
                if (input.TryTake(out currentInput))
                {
                    if (ExpectedColumnCount != currentInput.Count())
                    {
                        var errorMsg = $"A row was skipped over because it had too many or too few columns, expected: {ExpectedColumnCount}, actual: {currentInput.Count()}";
                        if (IsSkippingError)
                        {
                            LogService.Instance.Warn(errorMsg);
                        }
                        else
                        {
                            Exception ex = new Exception(errorMsg);
                            LogService.Instance.Error(ex);
                            throw ex;
                        }
                    }
                    else
                    {
                        Row newRow = Factory.CreateRow(currentInput);
                        while (!output.TryAdd(newRow))
                        {
                            pauseEvent.WaitOne();
                        }
                        processedCount++;
                    }
                }
                else
                {
                    Thread.Sleep(10);
                }
                if (processedCount % 1000 == 0)
                {
                    progressMonitor.Report(processedCount);
                }
            }
            progressMonitor.Report(processedCount);
        }