Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XMLDiffLoader.cs
Go to the documentation of this file.
3using System.Xml;
5
6namespace System.Data;
7
8internal sealed class XMLDiffLoader
9{
11
13
15
16 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
18 {
20 _dataSet = ds;
21 while (xmlReader.LocalName == "before" && xmlReader.NamespaceURI == "urn:schemas-microsoft-com:xml-diffgram-v1")
22 {
24 xmlReader.Read();
25 }
26 while (xmlReader.LocalName == "errors" && xmlReader.NamespaceURI == "urn:schemas-microsoft-com:xml-diffgram-v1")
27 {
29 xmlReader.Read();
30 }
31 }
32
34 {
35 foreach (DataRelation childRelation in dt.ChildRelations)
36 {
37 if (!_tables.Contains(childRelation.ChildTable))
38 {
39 _tables.Add(childRelation.ChildTable);
41 }
42 }
43 }
44
45 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
47 {
49 _dataTable = dt;
50 _tables = new ArrayList();
51 _tables.Add(dt);
53 while (xmlReader.LocalName == "before" && xmlReader.NamespaceURI == "urn:schemas-microsoft-com:xml-diffgram-v1")
54 {
56 xmlReader.Read();
57 }
58 while (xmlReader.LocalName == "errors" && xmlReader.NamespaceURI == "urn:schemas-microsoft-com:xml-diffgram-v1")
59 {
61 xmlReader.Read();
62 }
63 }
64
65 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
67 {
68 int pos = -1;
69 int depth = ssync.Depth;
70 ssync.Read();
72 while (depth < ssync.Depth)
73 {
74 DataTable table = null;
75 string text = null;
76 int num = -1;
77 text = ssync.GetAttribute("id", "urn:schemas-microsoft-com:xml-diffgram-v1");
78 bool flag = ssync.GetAttribute("hasErrors", "urn:schemas-microsoft-com:xml-diffgram-v1") == "true";
79 num = ReadOldRowData(ds, ref table, ref pos, ssync);
80 if (num == -1)
81 {
82 continue;
83 }
84 if (table == null)
85 {
87 }
89 if (dataRow != null)
90 {
92 table._recordManager[num] = dataRow;
93 continue;
94 }
95 dataRow = table.NewEmptyRow();
96 table._recordManager[num] = dataRow;
99 table.Rows.DiffInsertAt(dataRow, pos);
100 dataRow.Delete();
101 if (flag)
102 {
103 table.RowDiffId[text] = dataRow;
104 }
105 }
106 }
107
108 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
110 {
111 int pos = -1;
112 int depth = ssync.Depth;
113 ssync.Read();
114 while (depth < ssync.Depth)
115 {
116 DataTable table = null;
117 int num = -1;
118 string attribute = ssync.GetAttribute("id", "urn:schemas-microsoft-com:xml-diffgram-v1");
119 bool flag = ssync.GetAttribute("hasErrors", "urn:schemas-microsoft-com:xml-diffgram-v1") == "true";
120 num = ReadOldRowData(_dataSet, ref table, ref pos, ssync);
121 if (num == -1)
122 {
123 continue;
124 }
125 if (table == null)
126 {
128 }
130 if (dataRow != null)
131 {
132 dataRow._oldRecord = num;
133 table._recordManager[num] = dataRow;
134 continue;
135 }
136 dataRow = table.NewEmptyRow();
137 table._recordManager[num] = dataRow;
138 dataRow._oldRecord = num;
139 dataRow._newRecord = num;
140 table.Rows.DiffInsertAt(dataRow, pos);
141 dataRow.Delete();
142 if (flag)
143 {
144 table.RowDiffId[attribute] = dataRow;
145 }
146 }
147 }
148
149 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
151 {
152 int depth = ssync.Depth;
153 ssync.Read();
154 while (depth < ssync.Depth)
155 {
156 DataTable table = ds.Tables.GetTable(XmlConvert.DecodeName(ssync.LocalName), ssync.NamespaceURI);
157 if (table == null)
158 {
160 }
161 string attribute = ssync.GetAttribute("id", "urn:schemas-microsoft-com:xml-diffgram-v1");
163 string attribute2 = ssync.GetAttribute("Error", "urn:schemas-microsoft-com:xml-diffgram-v1");
164 if (attribute2 != null)
165 {
167 }
168 int depth2 = ssync.Depth;
169 ssync.Read();
170 while (depth2 < ssync.Depth)
171 {
172 if (XmlNodeType.Element == ssync.NodeType)
173 {
174 DataColumn column = table.Columns[XmlConvert.DecodeName(ssync.LocalName), ssync.NamespaceURI];
175 string attribute3 = ssync.GetAttribute("Error", "urn:schemas-microsoft-com:xml-diffgram-v1");
176 dataRow.SetColumnError(column, attribute3);
177 }
178 ssync.Read();
179 }
180 while (ssync.NodeType == XmlNodeType.EndElement && depth < ssync.Depth)
181 {
182 ssync.Read();
183 }
184 }
185 }
186
187 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
189 {
190 int depth = ssync.Depth;
191 ssync.Read();
192 while (depth < ssync.Depth)
193 {
194 DataTable table = GetTable(XmlConvert.DecodeName(ssync.LocalName), ssync.NamespaceURI);
195 if (table == null)
196 {
198 }
199 string attribute = ssync.GetAttribute("id", "urn:schemas-microsoft-com:xml-diffgram-v1");
201 if (dataRow == null)
202 {
203 for (int i = 0; i < dt.Count; i++)
204 {
205 dataRow = (DataRow)((DataTable)dt[i]).RowDiffId[attribute];
206 if (dataRow != null)
207 {
208 table = dataRow.Table;
209 break;
210 }
211 }
212 }
213 string attribute2 = ssync.GetAttribute("Error", "urn:schemas-microsoft-com:xml-diffgram-v1");
214 if (attribute2 != null)
215 {
217 }
218 int depth2 = ssync.Depth;
219 ssync.Read();
220 while (depth2 < ssync.Depth)
221 {
222 if (XmlNodeType.Element == ssync.NodeType)
223 {
224 DataColumn column = table.Columns[XmlConvert.DecodeName(ssync.LocalName), ssync.NamespaceURI];
225 string attribute3 = ssync.GetAttribute("Error", "urn:schemas-microsoft-com:xml-diffgram-v1");
226 dataRow.SetColumnError(column, attribute3);
227 }
228 ssync.Read();
229 }
230 while (ssync.NodeType == XmlNodeType.EndElement && depth < ssync.Depth)
231 {
232 ssync.Read();
233 }
234 }
235 }
236
237 private DataTable GetTable(string tableName, string ns)
238 {
239 if (_tables == null)
240 {
241 return _dataSet.Tables.GetTable(tableName, ns);
242 }
243 if (_tables.Count == 0)
244 {
245 return (DataTable)_tables[0];
246 }
247 for (int i = 0; i < _tables.Count; i++)
248 {
250 if (string.Equals(dataTable.TableName, tableName, StringComparison.Ordinal) && string.Equals(dataTable.Namespace, ns, StringComparison.Ordinal))
251 {
252 return dataTable;
253 }
254 }
255 return null;
256 }
257
258 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
259 private int ReadOldRowData(DataSet ds, ref DataTable table, ref int pos, XmlReader row)
260 {
261 if (ds != null)
262 {
263 table = ds.Tables.GetTable(XmlConvert.DecodeName(row.LocalName), row.NamespaceURI);
264 }
265 else
266 {
267 table = GetTable(XmlConvert.DecodeName(row.LocalName), row.NamespaceURI);
268 }
269 if (table == null)
270 {
271 row.Skip();
272 return -1;
273 }
274 int depth = row.Depth;
275 string text = null;
276 text = row.GetAttribute("rowOrder", "urn:schemas-microsoft-com:xml-msdata");
277 if (!string.IsNullOrEmpty(text))
278 {
279 pos = (int)Convert.ChangeType(text, typeof(int), null);
280 }
281 int num = table.NewRecord();
282 foreach (DataColumn column in table.Columns)
283 {
284 column[num] = DBNull.Value;
285 }
286 foreach (DataColumn column2 in table.Columns)
287 {
288 if (column2.ColumnMapping != MappingType.Element && column2.ColumnMapping != MappingType.SimpleContent)
289 {
290 text = ((column2.ColumnMapping != MappingType.Hidden) ? row.GetAttribute(column2.EncodedColumnName, column2.Namespace) : row.GetAttribute("hidden" + column2.EncodedColumnName, "urn:schemas-microsoft-com:xml-msdata"));
291 if (text != null)
292 {
293 column2[num] = column2.ConvertXmlToObject(text);
294 }
295 }
296 }
297 row.Read();
299 int depth2 = row.Depth;
300 if (depth2 <= depth)
301 {
302 if (depth2 == depth && row.NodeType == XmlNodeType.EndElement)
303 {
304 row.Read();
306 }
307 return num;
308 }
309 if (table.XmlText != null)
310 {
311 DataColumn xmlText = table.XmlText;
312 xmlText[num] = xmlText.ConvertXmlToObject(row.ReadString());
313 }
314 else
315 {
316 while (row.Depth > depth)
317 {
318 string text2 = XmlConvert.DecodeName(row.LocalName);
319 string namespaceURI = row.NamespaceURI;
320 DataColumn dataColumn3 = table.Columns[text2, namespaceURI];
321 if (dataColumn3 == null)
322 {
323 while (row.NodeType != XmlNodeType.EndElement && row.LocalName != text2 && row.NamespaceURI != namespaceURI)
324 {
325 row.Read();
326 }
327 row.Read();
328 continue;
329 }
330 if (dataColumn3.IsCustomType)
331 {
332 bool flag = dataColumn3.DataType == typeof(object) || row.GetAttribute("InstanceType", "urn:schemas-microsoft-com:xml-msdata") != null || row.GetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance") != null;
333 bool flag2 = false;
334 if (dataColumn3.Table.DataSet != null && dataColumn3.Table.DataSet._udtIsWrapped)
335 {
336 row.Read();
337 flag2 = true;
338 }
340 if (!flag && !dataColumn3.ImplementsIXMLSerializable)
341 {
342 if (flag2)
343 {
344 xmlRootAttribute = new XmlRootAttribute(row.LocalName);
345 xmlRootAttribute.Namespace = row.NamespaceURI;
346 }
347 else
348 {
349 xmlRootAttribute = new XmlRootAttribute(dataColumn3.EncodedColumnName);
351 }
352 }
353 dataColumn3[num] = dataColumn3.ConvertXmlToObject(row, xmlRootAttribute);
354 if (flag2)
355 {
356 row.Read();
357 }
358 continue;
359 }
360 int depth3 = row.Depth;
361 row.Read();
362 if (row.Depth > depth3)
363 {
364 if (row.NodeType == XmlNodeType.Text || row.NodeType == XmlNodeType.Whitespace || row.NodeType == XmlNodeType.SignificantWhitespace)
365 {
366 string s = row.ReadString();
367 dataColumn3[num] = dataColumn3.ConvertXmlToObject(s);
368 row.Read();
369 }
370 }
371 else if (dataColumn3.DataType == typeof(string))
372 {
373 dataColumn3[num] = string.Empty;
374 }
375 }
376 }
377 row.Read();
379 return num;
380 }
381
382 internal void SkipWhitespaces(XmlReader reader)
383 {
384 while (reader.NodeType == XmlNodeType.Whitespace || reader.NodeType == XmlNodeType.SignificantWhitespace)
385 {
386 reader.Read();
387 }
388 }
389}
virtual int Add(object? value)
virtual bool Contains(object? item)
static ? object ChangeType(object? value, TypeCode typeCode)
Definition Convert.cs:229
static readonly DBNull Value
Definition DBNull.cs:8
object ConvertXmlToObject(string s)
void DiffInsertAt(DataRow row, int pos)
DataTableCollection Tables
Definition DataSet.cs:396
DataTable GetTable(string name, string ns)
DataRowCollection Rows
Definition DataTable.cs:701
DataColumnCollection Columns
Definition DataTable.cs:327
readonly RecordManager _recordManager
Definition DataTable.cs:74
static XmlReader CreateReader(XmlReader xr)
static Exception DiffgramMissingSQL()
int ReadOldRowData(DataSet ds, ref DataTable table, ref int pos, XmlReader row)
DataTable GetTable(string tableName, string ns)
void SkipWhitespaces(XmlReader reader)
void ProcessErrors(DataSet ds, XmlReader ssync)
void ProcessErrors(ArrayList dt, XmlReader ssync)
void LoadDiffGram(DataTable dt, XmlReader dataTextReader)
void LoadDiffGram(DataSet ds, XmlReader dataTextReader)
void CreateTablesHierarchy(DataTable dt)
void ProcessDiffs(DataSet ds, XmlReader ssync)
void ProcessDiffs(ArrayList tableList, XmlReader ssync)
static ? string DecodeName(string? name)
Definition XmlConvert.cs:55
XmlNodeType NodeType
Definition XmlReader.cs:62