/// <summary>
 /// Initializes a new instance of the <see cref="SelectCommandHandler"/> class.
 /// DeleteCommandHandler constructor.
 /// </summary>
 /// <param name="cabinetService">fileCabinetService.</param>
 /// <param name="printer">The printer.</param>
 /// <param name="expressionExtensions">expressionExtensions.</param>
 /// <param name="modelWriter">console writer.</param>
 public SelectCommandHandler(IFileCabinetService cabinetService, IExpressionExtensions expressionExtensions, ITablePrinter printer, ModelWriters modelWriter)
     : base(cabinetService)
 {
     this.printer = printer;
     this.expressionExtensions = expressionExtensions;
     this.modelWriter          = modelWriter;
 }
        public void Setup()
        {
            _consoleOutWriter = new StringWriter();
            Console.SetOut(_consoleOutWriter);

            _tablePrinter = new TabDelimitedTablePrinter();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Renders the current instance in the specified <see cref="ITablePrinter"/>.
        /// </summary>
        /// <param name="tablePrinter">The <see cref="ITablePrinter"/> instance that will display the rendered title row.</param>
        /// <param name="size">The minimum width into which the current instance must be rendered.</param>
        public void Render(ITablePrinter tablePrinter, Size size)
        {
            BorderTemplate borderTemplate = ParentDataGrid?.BorderTemplate;

            bool displayBorder = borderTemplate != null && ParentDataGrid?.DisplayBorder == true;

            Size cellSize = displayBorder
                ? size.InflateWidth(-2)
                : size;

            IEnumerable <string> cellContents = TitleCell.Render(cellSize);

            // Write title
            foreach (string line in cellContents)
            {
                if (displayBorder)
                {
                    tablePrinter.WriteBorder(borderTemplate.Left);
                }

                tablePrinter.WriteTitle(line);

                if (displayBorder)
                {
                    tablePrinter.WriteBorder(borderTemplate.Right);
                }

                tablePrinter.WriteLine();
            }
        }
Ejemplo n.º 4
0
        public void Render(ITablePrinter tablePrinter, IReadOnlyList <ColumnX> columns)
        {
            for (int lineIndex = 0; lineIndex < Size.Height; lineIndex++)
            {
                Border?.RenderRowLeftBorder(tablePrinter);

                for (int columnIndex = 0; columnIndex < Cells.Count; columnIndex++)
                {
                    CellX cellX    = Cells[columnIndex];
                    Size  cellSize = CalculateCellSize(columns, columnIndex, cellX.HorizontalMerge);

                    cellX.RenderNextLine(tablePrinter, cellSize);

                    bool isLastCell = columnIndex >= Cells.Count - 1;

                    if (isLastCell)
                    {
                        Border?.RenderRowRightBorder(tablePrinter);
                    }
                    else
                    {
                        Border?.RenderRowInsideBorder(tablePrinter);
                    }
                }

                tablePrinter.WriteLine();
            }
        }
Ejemplo n.º 5
0
        private void RenderData(ITablePrinter tablePrinter)
        {
            DataTopBorder?.Render(tablePrinter);

            RenderDataRows(tablePrinter);

            DataBottomBorder?.Render(tablePrinter);
        }
        public void Render(ITablePrinter tablePrinter)
        {
            if (borderText == null)
            {
                borderText = GenerateDataRowSeparatorBorder();
            }

            tablePrinter.WriteLineBorder(borderText);
        }
Ejemplo n.º 7
0
        private void RenderHeader(ITablePrinter tablePrinter)
        {
            HeaderTopBorder?.Render(tablePrinter);

            headerRowX?.Render(tablePrinter, columnsWidths);

            HeaderDataSeparator?.Render(tablePrinter);
            HeaderBottomBorder?.Render(tablePrinter);
        }
Ejemplo n.º 8
0
        public void Render(ITablePrinter tablePrinter)
        {
            if (borderText == null)
            {
                borderText = borderTemplate.GenerateTopBorder(columnsWidths);
            }

            tablePrinter.WriteLineBorder(borderText);
        }
Ejemplo n.º 9
0
        public void Render(ITablePrinter tablePrinter)
        {
            if (borderText == null)
            {
                borderText = GenerateTitleHeaderSeparator();
            }

            tablePrinter.WriteLineBorder(borderText);
        }
        public void Render(ITablePrinter tablePrinter)
        {
            if (borderText == null)
            {
                borderText = borderTemplate.GenerateBottomBorder(width - 2);
            }

            tablePrinter.WriteLineBorder(borderText);
        }
Ejemplo n.º 11
0
        private void RenderTitle(ITablePrinter tablePrinter)
        {
            TitleTopBorder?.Render(tablePrinter);

            titleRowX?.Render(tablePrinter);

            TitleHeaderSeparator?.Render(tablePrinter);
            TitleDataSeparator?.Render(tablePrinter);
            TitleBottomBorder?.Render(tablePrinter);
        }
Ejemplo n.º 12
0
        public void RenderNextLine(ITablePrinter tablePrinter, Size actualSize)
        {
            if (lineEnumerator == null)
            {
                lineEnumerator = RenderContent(actualSize).GetEnumerator();
            }

            string content = lineEnumerator.MoveNext()
                ? lineEnumerator.Current
                : null;

            tablePrinter.Write(content, ForegroundColor, BackgroundColor);
        }
Ejemplo n.º 13
0
        public void RenderDataRows(ITablePrinter tablePrinter)
        {
            List <int> cellWidths = columnsWidths;

            for (int rowIndex = 0; rowIndex < dataRowXs.Count; rowIndex++)
            {
                DataRowX row = dataRowXs[rowIndex];
                row.Render(tablePrinter, cellWidths);

                bool isLastRow = rowIndex == dataRowXs.Count - 1;

                if (!isLastRow)
                {
                    DataDataSeparator?.Render(tablePrinter);
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Renders the row containing the column headers.
        /// </summary>
        /// <param name="tablePrinter">The destination where the current instance must be rendered.</param>
        /// <param name="cellWidths">The widths of each header cell that must be rendered.</param>
        /// <param name="rowHeight">The height of the row to be rendered. If there are not enough text lines
        /// in the content of a cell, spaces are written instead.</param>
        public void RenderHeaderRow(ITablePrinter tablePrinter, List <int> cellWidths, int rowHeight)
        {
            // Get cells content.
            List <List <string> > cellContents = columns
                                                 .Select((x, i) =>
            {
                Size size = new Size(cellWidths[i], rowHeight);
                return(x.HeaderCell.Render(size).ToList());
            })
                                                 .ToList();

            bool           displayBorder  = parentDataGrid?.DisplayBorder ?? true;
            BorderTemplate borderTemplate = parentDataGrid?.BorderTemplate;

            for (int headerLineIndex = 0; headerLineIndex < rowHeight; headerLineIndex++)
            {
                // Write left border.
                if (displayBorder && borderTemplate != null)
                {
                    tablePrinter.WriteBorder(borderTemplate.Left);
                }

                for (int columnIndex = 0; columnIndex < columns.Count; columnIndex++)
                {
                    // Write cell content.
                    string content = cellContents[columnIndex][headerLineIndex];
                    tablePrinter.WriteHeader(content);

                    // Write intermediate or right border.
                    if (displayBorder && borderTemplate != null)
                    {
                        char cellBorderRight = columnIndex < columns.Count - 1
                            ? borderTemplate.Vertical
                            : borderTemplate.Right;

                        tablePrinter.WriteBorder(cellBorderRight);
                    }
                }

                tablePrinter.WriteLine();
            }
        }
Ejemplo n.º 15
0
        public void Render(ITablePrinter tablePrinter)
        {
            TitleTopBorder?.Render(tablePrinter);
            HeaderTopBorder?.Render(tablePrinter);
            DataTopBorder?.Render(tablePrinter);

            titleRowX?.Render(tablePrinter);

            TitleHeaderSeparator?.Render(tablePrinter);
            TitleDataSeparator?.Render(tablePrinter);
            TitleBottomBorder?.Render(tablePrinter);

            headerRowX?.Render(tablePrinter, columnsWidths);

            HeaderDataSeparator?.Render(tablePrinter);
            HeaderBottomBorder?.Render(tablePrinter);

            RenderDataRows(tablePrinter);

            DataBottomBorder?.Render(tablePrinter);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Renders the row current row.
        /// </summary>
        /// <param name="tablePrinter">The destination where the current instance must be rendered.</param>
        /// <param name="cellWidths">The widths of each cell that must be rendered.</param>
        /// <param name="height">The height of the row to be rendered. If there are not enough text lines
        /// in the content of a cell, spaces are written instead.</param>
        public void Render(ITablePrinter tablePrinter, List <int> cellWidths, int height)
        {
            List <List <string> > cellContents = cells
                                                 .Select((x, i) =>
            {
                Size size = new Size(cellWidths[i], height);
                return(x.Render(size).ToList());
            })
                                                 .ToList();

            BorderTemplate borderTemplate = ParentDataGrid?.BorderTemplate;

            bool displayBorder = borderTemplate != null && ParentDataGrid?.DisplayBorder == true;

            for (int rowLineIndex = 0; rowLineIndex < height; rowLineIndex++)
            {
                if (displayBorder)
                {
                    tablePrinter.WriteBorder(borderTemplate.Left);
                }

                for (int columnIndex = 0; columnIndex < cells.Count; columnIndex++)
                {
                    string content = cellContents[columnIndex][rowLineIndex];
                    tablePrinter.WriteNormal(content);

                    if (displayBorder)
                    {
                        char cellBorderRight = columnIndex < cells.Count - 1
                            ? borderTemplate.Vertical
                            : borderTemplate.Right;

                        tablePrinter.WriteBorder(cellBorderRight);
                    }
                }

                tablePrinter.WriteLine();
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>RecordIdValidator
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            xsdValidatorFile = XsdValidatorFile;
            InitModelWriters();

            Parser.Default.ParseArguments <CommandLineOptions>(args)
            .WithParsed(o =>
            {
                if (o.ValidationRules != null && o.ValidationRules.ToLower(Culture) == "custom")
                {
                    (CommandHandlerBase.RecordValidator, ValidatorParams) = new ValidatorBuilder().CreateCustom(ValidationRulesFile);
                    Console.WriteLine("Custom validator");
                }
                else
                {
                    (CommandHandlerBase.RecordValidator, ValidatorParams) = new ValidatorBuilder().CreateDefault(ValidationRulesFile);
                    Console.WriteLine("Default validator");
                }

                if (o.Storage != null && o.Storage.ToLower(Culture) == "file")
                {
                    CommandHandlerBase.ServiceStorageFileStream = new FileStream(ServiceStorageFile, FileMode.OpenOrCreate);
                    fileCabinetService = new FileCabinetFilesystemService(CommandHandlerBase.ServiceStorageFileStream, CommandHandlerBase.RecordValidator);
                    Console.WriteLine("Used filesystem service");
                }
                else
                {
                    fileCabinetService = new FileCabinetMemoryService(CommandHandlerBase.RecordValidator);
                    Console.WriteLine("Used memory service");
                }

                if (o.StopWatcher)
                {
                    fileCabinetService = new ServiceMeter(fileCabinetService, modelWriters);
                    Console.WriteLine("Used timer");
                }

                if (o.Logger)
                {
                    string sourceFilePath = CreateValidPath("logger.log");
                    fileCabinetService    = new ServiceLogger(fileCabinetService, sourceFilePath);
                    Console.WriteLine("Used logger");
                }
            });

            Console.WriteLine($"File Cabinet Application, developed by {Program.DeveloperName}");
            Console.WriteLine(Program.HintMessage);
            Console.WriteLine();

            tablePrinter         = new DefaultTablePrinter(modelWriters.LineWriter);
            expressionExtensions = new ExpressionExtensions(fileCabinetService);
            xmlValidator         = new XmlValidator();

            ICommandHandler commandHandler = CreateCommandHandlers();

            do
            {
                Console.Write("> ");
                var       inputs       = Console.ReadLine().Split(' ', 2);
                const int commandIndex = 0;
                var       command      = inputs[commandIndex];

                if (string.IsNullOrEmpty(command))
                {
                    Console.WriteLine(Program.HintMessage);
                    continue;
                }

                const int parametersIndex = 1;
                var       parameters      = inputs.Length > 1 ? inputs[parametersIndex] : string.Empty;
                commandHandler.Handle(new AppCommandRequest
                {
                    Command    = command,
                    Parameters = parameters,
                });
            }while (isRunning);
        }
 public PrintTableToConsole(ITablePrinter tablePrinter)
 {
     _tablePrinter = tablePrinter;
 }
Ejemplo n.º 19
0
 public void RenderRowInsideBorder(ITablePrinter tablePrinter)
 {
     tablePrinter.Write(Template.Vertical, ForegroundColor, BackgroundColor);
 }
Ejemplo n.º 20
0
 public void RenderRowRightBorder(ITablePrinter tablePrinter)
 {
     tablePrinter.Write(Template.Right, ForegroundColor, BackgroundColor);
 }
Ejemplo n.º 21
0
 public void Render(ITablePrinter tablePrinter)
 {
     TitleRow?.Render(tablePrinter, Size);
 }
Ejemplo n.º 22
0
 public void Render(ITablePrinter tablePrinter, List <int> cellWidths)
 {
     dataRow.Render(tablePrinter, cellWidths, Size.Height);
 }
Ejemplo n.º 23
0
        public void Render(ITablePrinter tablePrinter, List <int> cellWidths)
        {
            int rowHeight = Size.Height;

            columns.RenderHeaderRow(tablePrinter, cellWidths, rowHeight);
        }
Ejemplo n.º 24
0
 public void Render(ITablePrinter tablePrinter)
 {
     RenderTitle(tablePrinter);
     RenderHeader(tablePrinter);
     RenderData(tablePrinter);
 }
Ejemplo n.º 25
0
        public void Render(ITablePrinter tablePrinter, IReadOnlyList <ColumnX> columns)
        {
            string line = BuildLine(columns);

            tablePrinter.WriteLine(line, ForegroundColor, BackgroundColor);
        }