예제 #1
0
        private int GetLongestColumn(string[,] csvReport, Func <int, int, string[, ], bool> cellValidator)
        {
            int longestDepth = 0;

            foreach (ICSVAddress address in _addresses)
            {
                int         length      = 0;
                ICSVAddress nextAddress = new CSVAddress(address.Row, address.Column + 1, csvReport);
                while (cellValidator(nextAddress.Row, nextAddress.Column, csvReport))
                {
                    length++;
                    nextAddress = new CSVAddress(nextAddress.Row, nextAddress.Column + 1, csvReport);
                }
                longestDepth = longestDepth > length ? longestDepth : length;
            }
            return(longestDepth);
        }
예제 #2
0
        private int GetRowCount(ICSVAddress topLeftCorner, string[,] csvReport, Func <ICSVAddress, bool> cellValidator)
        {
            List <int>  lengths   = new List <int>();
            ICSVAddress checkAddr = new CSVAddress(topLeftCorner.Row, topLeftCorner.Column, csvReport);

            for (int columnIndex = topLeftCorner.Column; cellValidator(checkAddr); columnIndex++)
            {
                int         length      = 0;
                ICSVAddress nextAddress = new CSVAddress(checkAddr.Row, checkAddr.Column, csvReport);
                while (cellValidator(nextAddress))
                {
                    length++;
                    nextAddress = new CSVAddress(nextAddress.Row + 1, nextAddress.Column, csvReport);
                }
                lengths.Add(length);
                checkAddr = new CSVAddress(topLeftCorner.Row, columnIndex, csvReport);
            }
            return(lengths.Count > 0 ? lengths.Max() : 0);
        }
예제 #3
0
        public static CSVTable FindTable(IUniqueNameProvider _nameProvider, int row, int col, string[,] csvReport)
        {
            CSVTable    table         = new CSVTable();
            ICSVAddress topLeftAddess = GoToTopLeftAddress(row, col, csvReport);
            ICSVAddress nextAddress   = topLeftAddess;

            while (nextAddress.IsValid() && !nextAddress.IsBlank() && !nextAddress.Value.IsNumeric())
            {
                ICSVAddress address = nextAddress;
                table.AddAddress(address);

                //Add the header while you're at it
                table.AddHeader(_nameProvider.GetUniqueName(table.Headers.ToArray(), address.Value));

                nextAddress = new CSVAddress(address.Row, address.Column + 1, csvReport);
            }
            if (table.Headers.Count() < 3)
            {
                return(null);
            }

            //int columnDepth = table.GetLongestColumn(csvReport, (r, c, report) => { return report[r, c] != string.Empty; });
            int endColumns = GetTopRightAddress(row, col, csvReport).Column + 1;

            int rowWidth = table.Addresses.Count(); //The current count of the addresses is only the header width: g2g
            //int endRows = topLeftAddess.Row + table.GetRowCount(topLeftAddess, csvReport, (a)=> { return a.IsValid() && !a.IsBlank() && !a.IsZero(); });

            //Add the headers to the table addresses
            //for(int header = topLeftAddess.Column; header < endColumns; header++)
            //{
            //    table.AddAddress(new CSVAddress(topLeftAddess.Row, header, csvReport));
            //}

            //int currentCol = topLeftAddess.Column;
            int currentRow = topLeftAddess.Row + 1;

            //List<string[]> records = new List<string[]>();
            string[] record = csvReport.SubArray(currentRow, topLeftAddess.Column, rowWidth);
            //while (!record.OnlyContains(new string[]{ string.Empty, "0" }))
            while (!record.OnlyContains(new Func <string, bool>[]
            {
                (s) => s == string.Empty,
                (s) => s == "0",
                (s) => s.IsNumeric() && double.Parse(s) == 0
            }
                                        ))
            {
                table.AddRecord(record);
                for (int tableColumn = 0; tableColumn < rowWidth; tableColumn++)
                {
                    table.AddAddress(new CSVAddress(currentRow, topLeftAddess.Column + tableColumn, csvReport));
                }
                currentRow++;
                if (currentRow < csvReport.GetLength(0))
                {
                    record = csvReport.SubArray(currentRow, topLeftAddess.Column, rowWidth);
                }
                else
                {
                    break;
                }
            }
            //while (currentRow < endRows)
            //{
            //    CSVAddress address = new CSVAddress(currentRow, currentCol, csvReport);
            //    table.AddAddress(address);
            //    record.Add(address.Value);
            //    currentCol++;
            //    if (currentCol >= endColumns)
            //    {
            //        string[] tuple = record.ToArray();
            //        if (!tuple.OnlyContains(new string[] { string.Empty, "0"}))
            //        {
            //            table.AddRecord(record.ToArray());
            //            record = new List<string>();
            //            currentCol = topLeftAddess.Column;
            //            currentRow++;
            //        }
            //        else break;
            //    }
            //}
            if (table.Records.Count() < 1)
            {
                return(null);
            }

            return(table);
        }
예제 #4
0
        public IReportContainer GetProperties()
        {
            if (_reportContainer == null)
            {
                return(_reportContainer);
            }

            for (int row = 0; row < CsvReport.GetLength(0); row++)
            {
                for (int col = 0; col < this.CsvReport.GetLength(1); col++)
                {
                    if (!IsInspected(row, col))
                    {
                        string      cell    = this.CsvReport[row, col].Trim(new char[] { '\r', '\n' });
                        ICSVAddress address = new CSVAddress(row, col, CsvReport);


                        //If the cell contains both the property name and the value
                        if (cell.Split(':').Length == 2 && cell.Split(':')[1].Trim() != string.Empty)
                        {
                            string[] parts = cell.Split(':');
                            _reportContainer.AddProperty(parts[0].Trim(), parts[1].Trim());
                            _inspected[row, col] = true;
                            continue;
                        }

                        //If the cell is empty
                        if (cell == string.Empty || cell == "0")
                        {
                            _inspected[row, col] = true;
                            continue;
                        }

                        //If the cell is part of a table
                        if (address.IsTableHeader())
                        {
                            CSVTable table = CSVTable.FindTable(_nameProvider, row, col, CsvReport);

                            if (table != null)
                            {
                                _reportContainer.AddTable(table);
                                foreach (ICSVAddress addr in table.Addresses)
                                {
                                    MarkInspected(addr);
                                }
                                continue;
                            }
                        }

                        //If the cell has a numeric value to the right
                        if (address.IsLeftLabel())
                        {
                            _reportContainer.AddProperty(cell, CsvReport[row, col + 1]);
                            _inspected[row, col]     = true;
                            _inspected[row, col + 1] = true;
                            continue;
                        }

                        //If the cell has a numeric value beneath
                        if (address.IsTopLabel())
                        {
                            _reportContainer.AddProperty(cell, CsvReport[row + 1, col]);
                            _inspected[row, col]     = true;
                            _inspected[row + 1, col] = true;
                            continue;
                        }

                        //If the cell property name and value is separated by a whitepace
                        if (cell.Split(' ').Length == 2)
                        {
                            string[] parts = cell.Split(' ');
                            _reportContainer.AddProperty(parts[0], parts[1]);
                            _inspected[row, col] = true;
                            continue;
                        }

                        //If the cell value is stand-alone
                        if (address.IsStandAlone())
                        {
                            _reportContainer.AddProperty(cell);
                            _inspected[row, col] = true;
                            continue;
                        }
                    }
                }
            }

            return(_reportContainer);
        }