Пример #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());
        }