Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DataSetMapper.cs
Go to the documentation of this file.
2using System.Data;
4
5namespace System.Xml;
6
7internal sealed class DataSetMapper
8{
10
12
14
16
17 internal DataSetMapper()
18 {
21 }
22
24 {
25 if (IsMapped())
26 {
29 }
30 _doc = xd;
31 _dataSet = ds;
32 foreach (DataTable table in _dataSet.Tables)
33 {
34 AddTableSchema(table);
35 foreach (DataColumn column in table.Columns)
36 {
37 if (!IsNotMapped(column))
38 {
40 }
41 }
42 }
43 }
44
45 internal bool IsMapped()
46 {
47 return _dataSet != null;
48 }
49
50 internal DataTable SearchMatchingTableSchema(string localName, string namespaceURI)
51 {
52 object identity = GetIdentity(localName, namespaceURI);
53 return (DataTable)_tableSchemaMap[identity];
54 }
55
57 {
58 DataTable dataTable = SearchMatchingTableSchema(elem.LocalName, elem.NamespaceURI);
59 if (dataTable == null)
60 {
61 return null;
62 }
63 if (rowElem == null)
64 {
65 return dataTable;
66 }
68 if (columnSchemaForNode == null)
69 {
70 return dataTable;
71 }
73 {
74 if ((object)attribute.NamespaceURI != "http://www.w3.org/2000/xmlns/")
75 {
76 return dataTable;
77 }
78 }
79 for (XmlNode xmlNode = elem.FirstChild; xmlNode != null; xmlNode = xmlNode.NextSibling)
80 {
81 if (xmlNode.NodeType == XmlNodeType.Element)
82 {
83 return dataTable;
84 }
85 }
86 return null;
87 }
88
90 {
91 object identity = GetIdentity(rowElem.LocalName, rowElem.NamespaceURI);
92 object identity2 = GetIdentity(node.LocalName, node.NamespaceURI);
93 Hashtable hashtable = (Hashtable)_columnSchemaMap[identity];
94 if (hashtable != null)
95 {
97 if (dataColumn == null)
98 {
99 return null;
100 }
101 MappingType columnMapping = dataColumn.ColumnMapping;
102 if (node.NodeType == XmlNodeType.Attribute && columnMapping == MappingType.Attribute)
103 {
104 return dataColumn;
105 }
106 if (node.NodeType == XmlNodeType.Element && columnMapping == MappingType.Element)
107 {
108 return dataColumn;
109 }
110 return null;
111 }
112 return null;
113 }
114
116 {
117 return be.Row?.Table;
118 }
119
120 internal static bool IsNotMapped(DataColumn c)
121 {
122 return c.ColumnMapping == MappingType.Hidden;
123 }
124
126 {
127 return (e as XmlBoundElement)?.Row;
128 }
129
131 {
132 return be.Row;
133 }
134
136 {
137 while (node != null)
138 {
140 {
142 return true;
143 }
144 node = ((node.NodeType != XmlNodeType.Attribute) ? node.ParentNode : ((XmlAttribute)node).OwnerElement);
145 }
146 rowElem = null;
147 return false;
148 }
149
151 {
152 if (rowElem.ElementState == ElementState.Defoliated)
153 {
154 return true;
155 }
158 int iColumn = 0;
159 int count = rowElem.Attributes.Count;
160 for (int i = 0; i < count; i++)
161 {
163 if (!xmlAttribute.Specified)
164 {
165 return false;
166 }
168 if (columnSchemaForNode == null)
169 {
170 return false;
171 }
173 {
174 return false;
175 }
177 if (firstChild == null || firstChild.NodeType != XmlNodeType.Text || firstChild.NextSibling != null)
178 {
179 return false;
180 }
181 }
182 iColumn = 0;
184 for (xmlNode = rowElem.FirstChild; xmlNode != null; xmlNode = xmlNode.NextSibling)
185 {
186 if (xmlNode.NodeType != XmlNodeType.Element)
187 {
188 return false;
189 }
191 if (GetRowFromElement(xmlElement) != null)
192 {
193 break;
194 }
196 if (columnSchemaForNode2 == null)
197 {
198 return false;
199 }
201 {
202 return false;
203 }
204 if (xmlElement.HasAttributes)
205 {
206 return false;
207 }
209 if (firstChild2 == null || firstChild2.NodeType != XmlNodeType.Text || firstChild2.NextSibling != null)
210 {
211 return false;
212 }
213 }
214 while (xmlNode != null)
215 {
216 if (xmlNode.NodeType != XmlNodeType.Element)
217 {
218 return false;
219 }
221 if (rowFromElement == null)
222 {
223 return false;
224 }
225 xmlNode = xmlNode.NextSibling;
226 }
227 return true;
228 }
229
230 private void AddTableSchema(DataTable table)
231 {
232 object identity = GetIdentity(table.EncodedTableName, table.Namespace);
233 _tableSchemaMap[identity] = table;
234 }
235
237 {
238 DataTable table = col.Table;
239 object identity = GetIdentity(table.EncodedTableName, table.Namespace);
240 object identity2 = GetIdentity(col.EncodedColumnName, col.Namespace);
241 Hashtable hashtable = (Hashtable)_columnSchemaMap[identity];
242 if (hashtable == null)
243 {
244 hashtable = new Hashtable();
245 _columnSchemaMap[identity] = hashtable;
246 }
247 hashtable[identity2] = col;
248 }
249
250 private static object GetIdentity(string localName, string namespaceURI)
251 {
252 return localName + ":" + namespaceURI;
253 }
254
256 {
257 while (iColumn < columns.Count)
258 {
259 if (columns[iColumn] == col)
260 {
261 iColumn++;
262 return true;
263 }
264 iColumn++;
265 }
266 return false;
267 }
268}
DataTableCollection Tables
Definition DataSet.cs:396
DataColumnCollection Columns
Definition DataTable.cs:327
DataRow GetRowFromElement(XmlBoundElement be)
bool IsRegionRadical(XmlBoundElement rowElem)
static object GetIdentity(string localName, string namespaceURI)
void AddColumnSchema(DataColumn col)
bool GetRegion(XmlNode node, [NotNullWhen(true)] out XmlBoundElement rowElem)
DataRow GetRowFromElement(XmlElement e)
DataColumn GetColumnSchemaForNode(XmlBoundElement rowElem, XmlNode node)
void AddTableSchema(DataTable table)
static bool IsNotMapped(DataColumn c)
DataTable SearchMatchingTableSchema(XmlBoundElement rowElem, XmlBoundElement elem)
DataTable SearchMatchingTableSchema(string localName, string namespaceURI)
DataTable GetTableSchemaForElement(XmlBoundElement be)
void SetupMapping(XmlDataDocument xd, DataSet ds)
bool IsNextColumn(DataColumnCollection columns, ref int iColumn, DataColumn col)
virtual ? XmlNode FirstChild
Definition XmlNode.cs:120
virtual ? XmlAttributeCollection Attributes
Definition XmlNode.cs:106