Пример #1
0
        public bool ProcessFile(string fileInputPath, string fileOutputPath)
        {
            Canvas canvas;
            List <Tuple <char, string[]> > parameters = _fileReader.ReadFile(fileInputPath);

            if (!parameters.Any(p => p.Item1 == 'C'))
            {
                Console.WriteLine("There is no canvas in the input file");
                return(false);
            }
            else
            {
                var canvasParameter = parameters.FirstOrDefault(p => p.Item1 == 'C');
                canvas = _canvasService.CreateCanvas(int.Parse(canvasParameter.Item2[0]), int.Parse(canvasParameter.Item2[1]));
                parameters.Remove(canvasParameter);
                _fileWriter.ClearFile(fileOutputPath);
                _fileWriter.DrawShapeIntoFile(canvas, fileOutputPath);
            }

            foreach (var parameter in parameters)
            {
                switch (parameter.Item1)
                {
                case 'L':
                {
                    Line line = new Line(new Point(int.Parse(parameter.Item2[0]), int.Parse(parameter.Item2[1])),
                                         new Point(int.Parse(parameter.Item2[2]), int.Parse(parameter.Item2[3])));
                    _lineService.CreateShape(ref canvas, line);
                    _fileWriter.DrawShapeIntoFile(canvas, fileOutputPath);
                }
                break;

                case 'R':
                {
                    Rectangle rectangle = new Rectangle(new Point(int.Parse(parameter.Item2[0]), int.Parse(parameter.Item2[1])),
                                                        new Point(int.Parse(parameter.Item2[2]), int.Parse(parameter.Item2[3])));
                    _rectangleService.CreateShape(ref canvas, rectangle);
                    _fileWriter.DrawShapeIntoFile(canvas, fileOutputPath);
                }
                break;

                case 'B':
                {
                    _bucketFillService.FillCanvas(ref canvas,
                                                  new Point(int.Parse(parameter.Item2[0]), int.Parse(parameter.Item2[1])),
                                                  char.Parse(parameter.Item2[2]));
                    _fileWriter.DrawShapeIntoFile(canvas, fileOutputPath);
                }
                break;
                }
            }
            return(true);
        }
Пример #2
0
        public void FileWriter_Clear_Test()
        {
            // Given
            string outputFilePath = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}{@"\Resource\OutputTest.txt"}";

            //When
            _fileWriter.ClearFile(outputFilePath);

            // Then
            var bytesResult = File.ReadAllBytes(outputFilePath);

            Assert.AreEqual(0, bytesResult.Length);
        }
Пример #3
0
 public void ClearBuffer()
 {
     FlushBuffer();
     FileWriter?.ClearFile();
     RecordsInBuffer = 0;
 }