Esempio n. 1
0
        /// <summary>
        /// Event which is raised when the Background Worker is started.
        /// </summary>
        /// <param name="sender">Sender object for the event.</param>
        /// <param name="args">Event args for the event.</param>
        private void UploadFile(object sender, DoWorkEventArgs args)
        {
            string connectionString = _configManager.GetConnectionString();

            if (!string.IsNullOrEmpty(connectionString))
            {
                IFileDataReader fileReader             = new FileDataReader();
                IFileDataWriter fileWriter             = new FileDataWriter(connectionString);
                System.Diagnostics.Stopwatch stopWatch = System.Diagnostics.Stopwatch.StartNew();
                string fileExtension = System.IO.Path.GetExtension(SelectedFileName);
                if (fileExtension == ".csv")
                {
                    foreach (var v in fileReader.ReadDataFromCSV(SelectedFileName))
                    {
                        fileWriter.WriteDataToSQL("AccountTransactionData", v.DataTable, GetColumnMappings());
                        _fileUploaderBackgroundWorker.ReportProgress((int)CalculatePercentage(v.TotalBytes, v.BytesRead), string.Format("{0} Lines Processed, {1} Lines Imported", v.LinesProcessed, v.LinesImported));
                        SkippedLinesMessage = ProcessSkippedLines(v.SkippedLines);
                    }
                    logger.Info(string.Format("Processing of File Completed in {0} seconds", stopWatch.Elapsed.Seconds));
                }
                else if (fileExtension == ".xlsx")
                {
                    //Call the ReadDataFromExcel method.
                }
            }
            else
            {
                logger.Error("Connection String not valid in the config file");
                _messageBoxService.ShowMessageBox("Please check the Connection string in Configuration file", "AccountTransactionUploadApp");
            }
        }
        public void CSVFileWriter_WriteWithoutInitialization()
        {
            FileDataWriter writer   = new FileDataWriter();
            string         filePath = GetTempFilePath();

            Assert.Throws <InvalidOperationException>(() => writer.WriteLine(filePath));
        }
Esempio n. 3
0
        private IAggregator CreateAggregator(AggregatorType aggregatorType, int channelId, string instrumentName)
        {
            IDataWriter dataWriter;

            switch (_dataWriterType)
            {
            case DataWriterType.BinaryFile:
                dataWriter = new FileDataWriter(instrumentName, aggregatorType);
                break;

            case DataWriterType.Console:
                dataWriter = new ConsoleDataWriter(aggregatorType);
                break;

            default:
                throw new ArgumentException(nameof(_dataWriterType));
            }

            switch (aggregatorType)
            {
            case AggregatorType.Books:
                return(new BookAggregator(dataWriter, channelId, instrumentName));

            case AggregatorType.RawBooks:
                return(new RawBookAggregator(dataWriter, channelId, instrumentName));

            default:
                throw new ArgumentException(nameof(aggregatorType));
            }
        }
        void WriteOutReadIn()
        {
            string path = "MikeLiuBidirectional.txt";

            using (FileDataWriter <string> w = new FileDataWriter <string>(path))
            {
                w.Append("{First: 'Mike', Last: 'Liu'}");
                w.Append("{First: 'Sergey', Last: 'Shandar'}");
                Assert.True(File.Exists(path));
            }

            string sampleText = File.ReadAllText(path);

            Assert.Equal("\"{First: 'Mike', Last: 'Liu'}\"\0\"{First: 'Sergey', Last: 'Shandar'}\"\0", sampleText);

            //now read using the functionality for FileDatareader

            using (FileDataReader <string> r = new FileDataReader <string>(path))
            {
                (bool, string)currentTuple = r.Read();
                Assert.Equal(true, currentTuple.Item1);
                Assert.Equal("{First: 'Mike', Last: 'Liu'}", currentTuple.Item2);

                currentTuple = r.Read();
                Assert.Equal(true, currentTuple.Item1);
                Assert.Equal("{First: 'Sergey', Last: 'Shandar'}", currentTuple.Item2);

                currentTuple = r.Read();
                Assert.Equal(false, currentTuple.Item1);
                Assert.Equal(null, currentTuple.Item2);
            }

            File.Delete(path);
        }
        public void CSVFileWriter_SuccessfulWrite()
        {
            FileDataWriter writer   = new FileDataWriter();
            string         filePath = GetTempFilePath();

            writer.Open(filePath);
            Assert.DoesNotThrow(() => writer.WriteLine("somedata"));
            writer.Close();
        }
        public void CSVFileWriter_DoubleInitialization()
        {
            FileDataWriter writer   = new FileDataWriter();
            string         filePath = GetTempFilePath();

            writer.Open(filePath);
            Assert.Throws <InvalidOperationException>(() => writer.Open(GetTempFilePath()));
            writer.Close();
        }
        public void CSVFileWriter_MultipleCleanups()
        {
            FileDataWriter writer   = new FileDataWriter();
            string         filePath = GetTempFilePath();

            writer.Open(filePath);

            Assert.DoesNotThrow(() => writer.Close());
            Assert.DoesNotThrow(() => writer.Close());
        }
        void TestDataWriterString()
        {
            string path = "MikeLiuStringTest.txt";

            using (FileDataWriter <string> s = new FileDataWriter <string>(path))
            {
                s.Append("Hello World");
                Assert.True(File.Exists(path));
                s.Append("Goodbye World");
            }

            string sample = File.ReadAllText(path);

            Assert.Equal("\"Hello World\"\0\"Goodbye World\"\0", sample);
            File.Delete(path);
        }
        void TestDataWriterNumber()
        {
            string path = "MikeLiuNumberTest.txt";

            using (FileDataWriter <int> s = new FileDataWriter <int>(path))
            {
                s.Append(1);
                s.Append(2);
                s.Append(3);
                s.Append(4);
                s.Append(5);
                Assert.True(File.Exists(path));
            }

            string sample = File.ReadAllText(path);

            Assert.Equal("1\02\03\04\05\0", sample);
            File.Delete(path);
        }
        public void CSVFileWriter_CleanupWithoutInitialization()
        {
            FileDataWriter writer = new FileDataWriter();

            Assert.DoesNotThrow(() => writer.Close());
        }