Example #1
0
        public DataTable ExtractTable()
        {
            var pathSeriesDescriptor = myDescriptor as PathSeriesDescriptor;

            if (pathSeriesDescriptor != null)
            {
                var table = ExtractTable(myDocument, HtmlPath.Parse(pathSeriesDescriptor.Path));
                return(TableFormatter.ToFormattedTable(pathSeriesDescriptor, table));
            }

            var pathTableDescriptor = myDescriptor as PathTableDescriptor;

            if (pathTableDescriptor != null)
            {
                var table = ExtractTable(myDocument, HtmlPath.Parse(pathTableDescriptor.Path));
                return(TableFormatter.ToFormattedTable(pathTableDescriptor, table));
            }

            var pathCellDescriptor = myDescriptor as PathCellDescriptor;

            if (pathCellDescriptor != null)
            {
                var table = ExtractTable(myDocument, HtmlPath.Parse(pathCellDescriptor.Path));
                var value = TableFormatter.GetValue(pathCellDescriptor, table);

                // XXX: this is really ugly - i have to create a table just to satisfy the interface :(
                return(CreateTableForScalar(pathCellDescriptor.ValueFormat.Type, value));
            }

            var pathSingleValueDescriptor = myDescriptor as PathSingleValueDescriptor;

            if (pathSingleValueDescriptor != null)
            {
                var e   = myDocument.GetElementByPath(HtmlPath.Parse(pathSingleValueDescriptor.Path));
                var str = e == null ? null : e.InnerText;

                var value = pathSingleValueDescriptor.ValueFormat.Convert(str);

                // XXX: this is really ugly - i have to create a table just to satisfy the interface :(
                return(CreateTableForScalar(pathSingleValueDescriptor.ValueFormat.Type, value));
            }

            throw new NotSupportedException("Format not supported for Html documents: " + myDescriptor.GetType());
        }
Example #2
0
        public DataTable ExtractTable()
        {
            SeparatorSeriesDescriptor separatorSeriesDescriptor = myDescriptor as SeparatorSeriesDescriptor;
            CsvDescriptor             csvDescriptor             = myDescriptor as CsvDescriptor;

            if (csvDescriptor != null)
            {
                DataTable result = CsvReader.Read(myDocument.Location.LocalPath, csvDescriptor.Separator);
                return(TableFormatter.ToFormattedTable(csvDescriptor, result));
            }
            else if (separatorSeriesDescriptor != null)
            {
                DataTable result = CsvReader.Read(myDocument.Location.LocalPath, separatorSeriesDescriptor.Separator);
                return(TableFormatter.ToFormattedTable(separatorSeriesDescriptor, result));
            }
            else
            {
                throw new NotSupportedException("Format not supported for text files: " + myDescriptor.GetType());
            }
        }