Example #1
0
        public SourceTable MakeSourceTable(HtmlNode tableNode, HtmlExtractorBase extractor)
        {
            RecordTemplateTableModel tableModel = new RecordTemplateTableModel();

            foreach (RecordTemplate template in items)
            {
                String xpath = template.BuildXPathQuery();

                HtmlNodeCollection records = tableNode.SelectNodes(xpath);

                if (records == null)
                {
                    continue;
                }
                else
                {
                }


                Int32 rc = 0;
                foreach (HtmlNode recordNode in records)
                {
                    if (template.RecordSelectionLimit >= 0)
                    {
                        if (rc > template.RecordSelectionLimit)
                        {
                            break;
                        }
                    }
                    var takes = template.SelectTakes(recordNode);

                    tableModel.StoreRecord(takes);
                    rc++;
                }
            }

            tableModel.Analyze();

            var sourceTable = tableModel.GetSourceTable(extractor);

            if (sourceTable != null)
            {
                sourceTable.ExpandedData.AddObjectEntry(nameof(RecordTemplateTableModel), tableModel, "Record table model");
            }
            return(sourceTable);
        }
Example #2
0
        public SourceTable GetSourceTable(HtmlExtractorBase htmlExtractor)
        {
            Boolean AddHeaderRow     = false;
            Boolean AddContextColumn = false;

            Int32 Height = Rows.Count;

            if (ColumnContextTakes.Cells.items.Any())
            {
                Height++;
                AddHeaderRow = true;
            }

            Int32 Width = 0;

            if (Rows.Any())
            {
                Width = Rows.Max(x => x.Cells.Count);
            }

            if (Rows.All(x => x.RowContextTake != null))
            {
                Width++;
                AddContextColumn = true;
            }

            SourceTable output = new SourceTable(Width, Height);

            Int32 ri = 0;

            if (AddHeaderRow)
            {
                for (int i = 0; i < ColumnContextTakes.Cells.Count; i++)
                {
                    //Int32 rx = i;


                    RecordTemplateItemTake take = (RecordTemplateItemTake)ColumnContextTakes.Cells.items[i];

                    //String takeSubPath = ItemDescriptors.ValueCellSubXPath[i];
                    //Int32 rx = ItemDescriptors.CellIndex(takeSubPath, AddContextColumn);
                    Int32 rx = ItemDescriptors.CellIndex(take, AddContextColumn);
                    if (rx > -1)
                    {
                        htmlExtractor.SetSourceTableCell(output[rx, ri], take.SelectedNode, null);
                    }
                    //if (AddContextColumn)
                    //{
                    //    rx++;
                    //}
                }
                ri++;
            }

            foreach (var row in Rows)
            {
                if (AddContextColumn)
                {
                    if (row.RowContextTake != null)
                    {
                        htmlExtractor.SetSourceTableCell(output[0, ri], row.RowContextTake.SelectedNode, null);
                    }
                }
                foreach (var take in row.Cells.items)
                {
                    Int32 rx = ItemDescriptors.CellIndex(take, AddContextColumn);
                    if (rx < output.Width)
                    {
                        htmlExtractor.SetSourceTableCell(output[rx, ri], take.SelectedNode, null);
                    }
                }

                ri++;
            }

            output = output.GetDistinctRows();

            return(output);
        }