Beispiel #1
0
        public static void Handle(FileReaderWriterParameters parameters)
        {
            EnsureInputFileExists(parameters.InputPath);
            var fileLines           = File.ReadLines(parameters.InputPath);
            var fileLinesAmount     = fileLines.Count();
            var expectedLinesAmount = parameters.Lines.Max();

            EnsureMaxLineNumberInFileIsGreaterThanExpected(fileLinesAmount, expectedLinesAmount);
            WriteLinesInOutput(parameters, fileLines);
        }
Beispiel #2
0
        private static void WriteLinesInOutput(FileReaderWriterParameters parameters, IEnumerable <string> inputFileLines)
        {
            using StreamWriter streamWriter = new StreamWriter(parameters.OutputPath);

            var index = 1;

            foreach (var line in inputFileLines)
            {
                if (parameters.Lines.Contains(index))
                {
                    var numberOfRepetitions = parameters.Lines.Count(numberOfLine => numberOfLine == index);
                    var linesToWrite        = RepeatLine(line, numberOfRepetitions);
                    streamWriter.WriteLine(linesToWrite);
                }
                index++;
            }
        }