-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathLoadFeaturesAdapter.cs
More file actions
88 lines (72 loc) · 3.08 KB
/
LoadFeaturesAdapter.cs
File metadata and controls
88 lines (72 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2006 - 2008: Rory Plaire (codekaizen@gmail.com)
//
// This file is part of SharpMap.
// SharpMap is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SharpMap is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with SharpMap; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using GeoAPI.Geometries;
using SharpMap.Data;
namespace SharpMap.Data
{
internal sealed class LoadFeaturesAdapter : DataAdapter
{
private readonly IGeometryFactory _factory;
public LoadFeaturesAdapter(IGeometryFactory factory)
{
_factory = factory;
}
public Int32 Fill(FeatureDataTable table, IFeatureDataReader dataReader)
{
return Fill(new FeatureDataTable[] { table }, dataReader);
}
public Int32 Fill(ICollection<FeatureDataTable> dataTables, IFeatureDataReader dataReader)
{
FeatureDataTable[] tables = new FeatureDataTable[dataTables.Count];
dataTables.CopyTo(tables, 0);
return Fill(tables, dataReader, 0, 0);
}
protected override Int32 Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
{
if (dataTables.Length == 0)
{
return 0;
}
Int32 tableIndex = 0;
IFeatureDataReader featureReader = dataReader as IFeatureDataReader;
if (featureReader == null)
{
throw new ArgumentException("Parameter 'dataReader' " +
"must be a IFeatureDataReader instance.");
}
do
{
FeatureDataTable table = dataTables[tableIndex] as FeatureDataTable;
if (table == null)
{
throw new ArgumentException("Components of 'dataTables' must be " +
"FeatureDataTable instances.");
}
if (table.Columns.Count == 0)
{
FillSchema(table, SchemaType.Mapped, featureReader);
}
table.Merge((IEnumerable<IFeatureDataRecord>)featureReader, null, _factory, SchemaMergeAction.AddWithKey | SchemaMergeAction.CaseInsensitive);
tableIndex++;
} while (dataReader.NextResult());
return dataTables[0].Rows.Count;
}
}
}