Пример #1
0
        public ColumnReaderFacts()
        {
            _calls = new List<string>();

            var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes("line1\nline2"));
            var mParser = new Mock<IDelimiterSeparatedFieldParser>();

            mParser.Setup(parser => parser.Parse(It.IsAny<string>())).Returns(new string[0]).Callback<string>(_calls.Add);

            _reader = new ColumnReader(new StreamReader(memoryStream), mParser.Object);
        }
Пример #2
0
        private static void Main(string[] args)
        {
            string path;
            while ((path = CaptureFeedPath(args)) == null)
            {
            }

            const char delimiter = ',';

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var parser = new DelimiterSeparatedFieldParser(delimiter);

            TriangleDimensions largestTriangle;
            using( var inputFileReader = new StreamReader(path) )
            {
                var collector = new ErrorCollector();

                WriteProgress("Processing file (this may take some time)...");

                var columnReader = new ColumnReader(inputFileReader, parser);
                var dimensionReader = new Reader<TriangleFeedYearExtract>(columnReader, collector);
                var largestTriangleCalculator = new LargestTriangleCalculator(dimensionReader.Read);
                largestTriangle = largestTriangleCalculator.Calculate();
                ReportAndQuitIfErrors(collector, path, "triangle_dimension_calculation_errors.txt");
            }

            using( var inputFileReader = new StreamReader(path) )
            {
                var collector = new ErrorCollector();

                using( var outputFileWriter = new StreamWriter(BuildPathFromInputPath(path, "output.csv")) )
                {
                    var columnReader = new ColumnReader(inputFileReader, parser);
                    var paymentRecordReader = new Reader<TriangleFeedFullDataExtract>(columnReader, collector);
                    var triangleBuilder = new TriangleBuilder(paymentRecordReader, collector);
                    Func<ClaimTriangle, string[]> triangleConverter = triangle => triangle.Accumulate().Flatten(largestTriangle);
                    var header = string.Format("{0}, {1}", largestTriangle.OriginYear, largestTriangle.DevelopmentYears);
                    var writer = new ColumnWriter<ClaimTriangle>(triangleBuilder.BuildNext, triangleConverter, header, outputFileWriter, delimiter);
                    writer.Write();
                }

                ReportAndQuitIfErrors(collector, path, "payment_record_errors.txt");
            }

            stopwatch.Stop();

            WriteProgress("Processing took: {0}", stopwatch.Elapsed);
            System.Console.WriteLine("Press any key to quit...");
            System.Console.ReadKey();
        }