-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFeatureDataSet.cs
More file actions
296 lines (257 loc) · 9.92 KB
/
FeatureDataSet.cs
File metadata and controls
296 lines (257 loc) · 9.92 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
// Copyright 2005, 2006 - Morten Nielsen (www.iter.dk)
//
// 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;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Schema;
using GeoAPI.Features;
namespace SharpMap.Data
{
/// <summary>
/// Represents an in-memory cache of spatial data. The FeatureDataSet is an extension of System.Data.DataSet
/// </summary>
[Serializable]
public class FeatureDataSet : DataSet, IFeatureCollectionSet
{
private FeatureTableCollection _featureTables;
/// <summary>
/// Initializes a new instance of the FeatureDataSet class.
/// </summary>
public FeatureDataSet()
{
InitClass();
//CollectionChangeEventHandler schemaChangedHandler = new CollectionChangeEventHandler(SchemaChanged);
////this.Tables.CollectionChanged += schemaChangedHandler;
//Relations.CollectionChanged += schemaChangedHandler;
InitClass();
}
/// <summary>
/// Initializes a new instance of the FeatureDataSet class.
/// </summary>
/// <param name="info">serialization info</param>
/// <param name="context">streaming context</param>
protected FeatureDataSet(SerializationInfo info, StreamingContext context)
{
string strSchema = ((string) (info.GetValue("XmlSchema", typeof (string))));
if ((strSchema != null))
{
DataSet ds = new DataSet();
ds.ReadXmlSchema(new XmlTextReader(new StringReader(strSchema)));
if ((ds.Tables["FeatureTable"] != null))
{
Tables.Add(new FeatureDataTable(ds.Tables["FeatureTable"]));
}
DataSetName = ds.DataSetName;
Prefix = ds.Prefix;
Namespace = ds.Namespace;
Locale = ds.Locale;
CaseSensitive = ds.CaseSensitive;
EnforceConstraints = ds.EnforceConstraints;
Merge(ds, false, MissingSchemaAction.Add);
}
else
{
InitClass();
}
GetSerializationData(info, context);
//CollectionChangeEventHandler schemaChangedHandler = new CollectionChangeEventHandler(SchemaChanged);
////this.Tables.CollectionChanged += schemaChangedHandler;
//Relations.CollectionChanged += schemaChangedHandler;
}
/// <summary>
/// Gets the collection of tables contained in the FeatureDataSet
/// </summary>
public new FeatureTableCollection Tables
{
get { return _featureTables; }
}
/// <summary>
/// Copies the structure of the FeatureDataSet, including all FeatureDataTable schemas, relations, and constraints. Does not copy any data.
/// </summary>
/// <returns></returns>
public new FeatureDataSet Clone()
{
var cln = ((FeatureDataSet) (base.Clone()));
return cln;
}
/// <summary>
/// Gets a value indicating whether Tables property should be persisted.
/// </summary>
/// <returns></returns>
protected override bool ShouldSerializeTables()
{
return true;
}
/// <summary>
/// Gets a value indicating whether Relations property should be persisted.
/// </summary>
/// <returns></returns>
protected override bool ShouldSerializeRelations()
{
return true;
}
/// <summary>
///
/// </summary>
/// <param name="reader"></param>
protected override void ReadXmlSerializable(XmlReader reader)
{
Reset();
var ds = new DataSet();
ds.ReadXml(reader);
//if ((ds.Tables["FeatureTable"] != null))
//{
// this.Tables.Add(new FeatureDataTable(ds.Tables["FeatureTable"]));
//}
DataSetName = ds.DataSetName;
Prefix = ds.Prefix;
Namespace = ds.Namespace;
Locale = ds.Locale;
CaseSensitive = ds.CaseSensitive;
EnforceConstraints = ds.EnforceConstraints;
Merge(ds, false, MissingSchemaAction.Add);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected override XmlSchema GetSchemaSerializable()
{
MemoryStream stream = new MemoryStream();
WriteXmlSchema(new XmlTextWriter(stream, null));
stream.Position = 0;
return XmlSchema.Read(new XmlTextReader(stream), null);
}
private void InitClass()
{
_featureTables = new FeatureTableCollection(base.Tables);
//this.DataSetName = "FeatureDataSet";
Prefix = "";
Namespace = "http://tempuri.org/FeatureDataSet.xsd";
Locale = new CultureInfo("en-US");
CaseSensitive = false;
EnforceConstraints = true;
}
#region IFeatureCollectionSet implementation
IFeatureCollection IFeatureCollectionSet.this[string name]
{
get
{
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException("name");
return base.Tables.Contains(name)
? (FeatureDataTable)base.Tables[name]
: null;
}
}
IFeatureCollection IFeatureCollectionSet.this[int index]
{
get
{
return Tables[index];
}
}
bool IFeatureCollectionSet.Contains(string name)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException("name");
return base.Tables.Contains(name);
}
bool IFeatureCollectionSet.Remove(string name)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException("name");
var dt = base.Tables[name];
if (base.Tables.CanRemove(dt))
{
base.Tables.Remove(dt);
return true;
}
return false;
}
public IEnumerator<IFeatureCollection> GetEnumerator()
{
foreach (var table in base.Tables)
{
yield return (FeatureDataTable) table;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
void ICollection<IFeatureCollection>.Add(IFeatureCollection item)
{
if (item == null)
throw new ArgumentNullException("item");
if (!(item is FeatureDataTable))
throw new ArgumentException("Not of type FeatureDataType", "item");
if (base.Tables.Contains(item.Name))
throw new DuplicateNameException(string.Format(""));
base.Tables.Add((DataTable) item);
}
bool ICollection<IFeatureCollection>.Contains(IFeatureCollection item)
{
if (item == null)
throw new ArgumentNullException("item");
if (item is FeatureDataTable)
{
var dt = (DataTable) item;
return base.Tables.Contains(dt.TableName, dt.Namespace);
}
return false;
}
void ICollection<IFeatureCollection>.CopyTo(IFeatureCollection[] array, int arrayIndex)
{
if (array == null)
throw new ArgumentNullException("array");
if (arrayIndex < 0)
throw new ArgumentException("Negative array index", "arrayIndex");
if (arrayIndex + base.Tables.Count >= array.Length)
throw new ArgumentException("Size of provided array is insufficent", "array");
for (var i = 0; i < base.Tables.Count; i++)
{
array[i + arrayIndex] = (FeatureDataTable)base.Tables[i];
}
}
bool ICollection<IFeatureCollection>.Remove(IFeatureCollection item)
{
if (item == null)
return false;
if (item is FeatureDataTable)
if (base.Tables.CanRemove((DataTable) item))
{
base.Tables.Remove((DataTable) item);
return true;
}
return false;
}
int ICollection<IFeatureCollection>.Count { get { return base.Tables.Count; } }
bool ICollection<IFeatureCollection>.IsReadOnly { get { return false; } }
#endregion
[OnDeserialized]
private void OnDeserialized(StreamingContext context)
{
_featureTables = new FeatureTableCollection(base.Tables);
}
}
}