Exemple #1
0
        //Получение сгенерированных строк
        public List<Row> GetRandomRows(int columnQuantity, int rowQuantity, int stringLenght)
        {
            var randomRows = new List<Row>(); 
            var factory = new Factory(stringLenght);

            factory.GenerateListRandomTypes(columnQuantity); //Генерация случайных типов
            var header = new Row(0);

            //Получение заголовка
            for(var headcellIndex = 0; headcellIndex < columnQuantity; headcellIndex++)
            {
                var cell = new Cell(headcellIndex);
                cell.Value = factory.GetHeaderRandomValue(headcellIndex);
                header.Cells.Add(cell);
            }
            randomRows.Add(header);

            //Генерация остальных строк
            for(var rowIndex = 1; rowIndex <= rowQuantity; rowIndex++)
            {
                var row = new Row(rowIndex); //Создание строки с ID
                for(var cellIndex = 0; cellIndex < columnQuantity; cellIndex++)
                {
                    var cell = new Cell(cellIndex);
                    cell.Value = factory.GetRandomValue(cellIndex); //Генерация значения
                    row.Cells.Add(cell);
                }
                randomRows.Add(row);
            }
            return randomRows;
        }
Exemple #2
0
        //Парсинг CSV
        public List<Row> ParseCSV()
        {
            Factory factory = new Factory();
            List<Row> result = new List<Row>();
            string[] rows = GetRows();
            string headRow = rows[0];
            List<string> types = GetTypes(headRow);

            for (var rowIndex = 0; rowIndex < rows.Length; rowIndex++)
            {
                var row = new Row(rowIndex);
                string line = rows[rowIndex];

                if (string.IsNullOrWhiteSpace(line))
                {
                    Console.WriteLine("Строка пуста, файл некорректен");
                    Console.ReadKey();
                    Environment.Exit(1);
                }

                string[] parts = SplitLine(line);

                for (var cellIndex = 0; cellIndex < parts.Length; cellIndex++)
                {
                    var cell = new Cell(cellIndex);
                    string part = parts[cellIndex]; //Значение
                    string type = types[cellIndex]; //Тип

                    string piece;

                    //Обработка правил CSV формата
                    if (rowIndex == 0)
                    {
                        string columnName = part.Split(nameTypeSeparator).First();
                        string typeName = part.Split(nameTypeSeparator).Last(); 
                        var handledColumnName = HandleSpecialSymbolsAndQoute(columnName);
                        piece = handledColumnName + nameTypeSeparator + typeName; //Получение обработанного значения ячейки
                        cell.Value = factory.GetValueFromString(piece, headerType); //Получение значения необходимого типа
                    }
                    else 
                    {
                        piece = HandleSpecialSymbolsAndQoute(part); //Получение обработанного значения
                        cell.Value = factory.GetValueFromString(piece, type); //Получение значения необходимого типа
                    }
                    row.Cells.Add(cell);
                }
                result.Add(row);
            }
            return result;
        }
Exemple #3
0
        private void New( IList<Line> columns, IList<Line> rows )
        {
            if ( !Validator.Validate( columns, rows ) )
            {
                throw new Exception( "Ряды составлены не верно." );
            }

            Cells = new Cell[Columns.Count,Rows.Count];
            foreach ( var column in columns )
            {
                foreach ( var row in rows )
                {
                    Cells[columns.IndexOf( column ), rows.IndexOf( row )] = new Cell( column, row );
                }
            }
        }
Exemple #4
0
        public bool CheckFilled( Cell cell )
        {
            var indexColumn = Columns.IndexOf( cell.Column );
            var res = ( ( Columns.Count - cell.Column.Clues[0].Value ) <= indexColumn );
            if ( res )
            {
                return true;
            }

            indexColumn = Columns.IndexOf( cell.Column );
            res = ( ( Columns.Count - cell.Row.Clues[0].Value ) <= indexColumn );
            if ( res )
            {
                return true;
            }

            return false;
        }
Exemple #5
0
 //Получение имени столбца
 private string GetColumnName(Cell cell)
 {
     return cell.ToString().Trim().Split(nameTypeSeparator).First();
 }