Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
 private static void ReportAndQuitIfErrors(ErrorCollector collector, string inputFilePath, string errorFilename)
 {
     if (collector.ContainsErrors) // so check for errors now
     {
         collector.WriteTo(BuildPathFromInputPath(inputFilePath, errorFilename));
         System.Console.WriteLine(
             "Errors detected in input file. Please check the error report and retry once you have figured it out.");
         System.Console.WriteLine("Press any key to quit...");
         System.Console.ReadKey();
         Environment.Exit((int) ExitCode.InvalidInputFile);
     }
 }
Ejemplo n.º 3
0
 public TriangleBuilder(IReader<TriangleFeedFullDataExtract> reader, ErrorCollector collector)
 {
     _reader = reader;
     _collector = collector;
 }
Ejemplo n.º 4
0
 public ClaimTriangle(string productName, ErrorCollector errorManager)
 {
     ErrorManager = errorManager;
     ProductName = productName;
 }
Ejemplo n.º 5
0
 public OriginBlock(int originYear, ErrorCollector collector)
 {
     _originYear = originYear;
     _collector = collector;
 }
Ejemplo n.º 6
0
 public TentativeErrorCollector(ErrorCollector underlyingCollector, string contextMessage)
 {
     _underlyingCollector = underlyingCollector;
     _contextMessage = contextMessage;
 }