Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlTreeGen.cs
Go to the documentation of this file.
7using System.IO;
9using System.Text;
10using System.Xml;
11
12namespace System.Data;
13
14internal sealed class XmlTreeGen
15{
17
19
21
23
24 private DataSet _ds;
25
26 private readonly ArrayList _tables = new ArrayList();
27
28 private readonly ArrayList _relations = new ArrayList();
29
31
33
34 private int _prefixCount;
35
36 private readonly SchemaFormat _schFormat = SchemaFormat.Public;
37
38 private string _filePath;
39
40 private string _fileName;
41
42 private string _fileExt;
43
45
47
49
51 {
53 }
54
59
61 {
62 if (props == null)
63 {
64 return;
65 }
66 foreach (DictionaryEntry prop in props)
67 {
70 if (type == typeof(DataRelation))
71 {
72 text = "rel_" + text;
73 }
74 else if (type == typeof(ForeignKeyConstraint))
75 {
76 text = "fk_" + text;
77 }
78 node.SetAttribute(XmlConvert.EncodeLocalName(text), "urn:schemas-microsoft-com:xml-msprop", value);
79 }
80 }
81
82 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
83 internal void AddXdoProperties(object instance, XmlElement root, XmlDocument xd)
84 {
85 if (instance == null)
86 {
87 return;
88 }
90 if (instance is DataSet || instance is DataTable || instance is DataColumn || instance is DataRelation)
91 {
92 for (int i = 0; i < properties.Count; i++)
93 {
94 AddXdoProperty(properties[i], instance, root, xd);
95 }
96 }
97 }
98
99 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
100 internal void AddXdoProperty(PropertyDescriptor pd, object instance, XmlElement root, XmlDocument xd)
101 {
102 Type propertyType = pd.PropertyType;
103 bool flag = false;
104 DataColumn dataColumn = null;
105 bool flag2 = false;
106 bool flag3 = false;
107 if (instance is DataColumn)
108 {
109 dataColumn = (DataColumn)instance;
110 flag = true;
111 flag2 = dataColumn.IsSqlType;
112 flag3 = dataColumn.ImplementsINullable;
113 }
114 if ((!flag3 && propertyType != typeof(string) && propertyType != typeof(bool) && propertyType != typeof(Type) && propertyType != typeof(object) && propertyType != typeof(CultureInfo) && propertyType != typeof(long) && propertyType != typeof(int)) || ((!pd.ShouldSerializeValue(instance) || !ContainsDesignerSerializationVisibleAttribute(pd)) && !flag2))
115 {
116 return;
117 }
118 object value = pd.GetValue(instance);
119 if (value is InternalDataCollectionBase || value is PropertyCollection || string.Equals(pd.Name, "Namespace", StringComparison.Ordinal) || string.Equals(pd.Name, "PrimaryKey", StringComparison.Ordinal) || string.Equals(pd.Name, "ColumnName", StringComparison.Ordinal) || string.Equals(pd.Name, "DefaultValue", StringComparison.Ordinal) || string.Equals(pd.Name, "TableName", StringComparison.Ordinal) || string.Equals(pd.Name, "DataSetName", StringComparison.Ordinal) || string.Equals(pd.Name, "AllowDBNull", StringComparison.Ordinal) || string.Equals(pd.Name, "Unique", StringComparison.Ordinal) || string.Equals(pd.Name, "NestedInDataSet", StringComparison.Ordinal) || string.Equals(pd.Name, "Locale", StringComparison.Ordinal) || string.Equals(pd.Name, "CaseSensitive", StringComparison.Ordinal) || string.Equals(pd.Name, "RemotingFormat", StringComparison.Ordinal))
120 {
121 return;
122 }
123 if (flag)
124 {
125 if (string.Equals(pd.Name, "DataType", StringComparison.Ordinal))
126 {
127 string text = XmlDataTypeName(dataColumn.DataType);
128 if (flag2 || dataColumn.DataType == typeof(BigInteger))
129 {
130 root.SetAttribute("DataType", "urn:schemas-microsoft-com:xml-msdata", dataColumn.DataType.FullName);
131 }
132 else if (text.Length == 0 || flag3 || (text == "anyType" && dataColumn.XmlDataType != "anyType") || dataColumn.DataType == typeof(DateTimeOffset))
133 {
134 SetMSDataAttribute(root, dataColumn.DataType);
135 }
136 return;
137 }
138 if (string.Equals(pd.Name, "Attribute", StringComparison.Ordinal))
139 {
140 return;
141 }
142 }
143 string value2 = pd.Converter.ConvertToString(value);
144 root.SetAttribute(pd.Name, "urn:schemas-microsoft-com:xml-msdata", value2);
145 }
146
148 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The DynamicDependency ensures the correct members are preserved.")]
153
154 internal static string XmlDataTypeName(Type type)
155 {
156 if (type == typeof(char))
157 {
158 return "_";
159 }
160 if (type == typeof(byte[]) || type == typeof(SqlBytes))
161 {
162 return "base64Binary";
163 }
164 if (type == typeof(DateTime) || type == typeof(SqlDateTime))
165 {
166 return "dateTime";
167 }
168 if (type == typeof(TimeSpan))
169 {
170 return "duration";
171 }
172 if (type == typeof(decimal) || type == typeof(SqlDecimal) || type == typeof(SqlMoney))
173 {
174 return "decimal";
175 }
176 if (type == typeof(int))
177 {
178 return "int";
179 }
180 if (type == typeof(bool) || type == typeof(SqlBoolean))
181 {
182 return "boolean";
183 }
184 if (type == typeof(float) || type == typeof(SqlSingle))
185 {
186 return "float";
187 }
188 if (type == typeof(double) || type == typeof(SqlDouble))
189 {
190 return "double";
191 }
192 if (type == typeof(sbyte) || type == typeof(SqlByte))
193 {
194 return "byte";
195 }
196 if (type == typeof(byte))
197 {
198 return "unsignedByte";
199 }
200 if (type == typeof(short) || type == typeof(SqlInt16))
201 {
202 return "short";
203 }
204 if (type == typeof(int) || type == typeof(SqlInt32))
205 {
206 return "int";
207 }
208 if (type == typeof(long) || type == typeof(SqlInt64))
209 {
210 return "long";
211 }
212 if (type == typeof(ushort))
213 {
214 return "unsignedShort";
215 }
216 if (type == typeof(uint))
217 {
218 return "unsignedInt";
219 }
220 if (type == typeof(ulong))
221 {
222 return "unsignedLong";
223 }
224 if (type == typeof(BigInteger))
225 {
226 return "anyType";
227 }
228 if (type == typeof(Uri))
229 {
230 return "anyURI";
231 }
232 if (type == typeof(SqlBinary))
233 {
234 return "hexBinary";
235 }
236 if (type == typeof(string) || type == typeof(SqlGuid) || type == typeof(SqlString) || type == typeof(SqlChars))
237 {
238 return "string";
239 }
240 if (type == typeof(object) || type == typeof(SqlXml) || type == typeof(DateTimeOffset))
241 {
242 return "anyType";
243 }
244 return string.Empty;
245 }
246
248 {
250 foreach (Constraint constraint in table.Constraints)
251 {
252 if (fromTable && constraint is ForeignKeyConstraint && !_tables.Contains(((ForeignKeyConstraint)constraint).RelatedTable))
253 {
254 continue;
255 }
256 int num = 0;
257 string text = constraint.ConstraintName;
259 {
260 if (stringBuilder == null)
261 {
263 }
264 stringBuilder.Append(table.TableName).Append('_').Append(constraint.ConstraintName);
265 if (0 < num)
266 {
267 stringBuilder.Append('_').Append(num);
268 }
269 num++;
270 text = stringBuilder.ToString();
272 }
275 }
276 }
277
279 {
280 for (int i = 0; i < tables.Count; i++)
281 {
283 }
284 }
285
287 {
288 foreach (DataTable table in ds.Tables)
289 {
290 GenerateConstraintNames(table, fromTable: false);
291 }
292 }
293
295 {
296 if (props != null)
297 {
298 return props.Count != 0;
299 }
300 return false;
301 }
302
304 {
305 if (_PropsNotEmpty(ds._extendedProperties))
306 {
307 return true;
308 }
309 for (int i = 0; i < ds.Tables.Count; i++)
310 {
311 DataTable dataTable = ds.Tables[i];
312 if (_PropsNotEmpty(dataTable._extendedProperties))
313 {
314 return true;
315 }
316 for (int j = 0; j < dataTable.Columns.Count; j++)
317 {
318 if (_PropsNotEmpty(dataTable.Columns[j]._extendedProperties))
319 {
320 return true;
321 }
322 }
323 }
324 for (int k = 0; k < ds.Relations.Count; k++)
325 {
326 if (_PropsNotEmpty(ds.Relations[k]._extendedProperties))
327 {
328 return true;
329 }
330 }
331 return false;
332 }
333
335 {
336 if (!string.IsNullOrEmpty(targetNamespace))
337 {
338 rootSchema.SetAttribute("targetNamespace", targetNamespace);
339 rootSchema.SetAttribute("xmlns:mstns", targetNamespace);
340 }
341 rootSchema.SetAttribute("xmlns", targetNamespace);
342 rootSchema.SetAttribute("xmlns:xs", "http://www.w3.org/2001/XMLSchema");
343 rootSchema.SetAttribute("xmlns:msdata", "urn:schemas-microsoft-com:xml-msdata");
344 if (_ds != null && HaveExtendedProperties(_ds))
345 {
346 rootSchema.SetAttribute("xmlns:msprop", "urn:schemas-microsoft-com:xml-msprop");
347 }
348 if (!string.IsNullOrEmpty(targetNamespace))
349 {
350 rootSchema.SetAttribute("attributeFormDefault", "qualified");
351 rootSchema.SetAttribute("elementFormDefault", "qualified");
352 }
353 }
354
362
364 {
365 foreach (DataTable table in ds.Tables)
366 {
367 SetupAutoGenerated(table);
368 }
369 }
370
372 {
373 for (int i = 0; i < dt.Count; i++)
374 {
376 }
377 }
378
380 {
381 foreach (DataColumn column in dt.Columns)
382 {
384 {
386 }
387 }
388 foreach (Constraint constraint in dt.Constraints)
389 {
391 {
393 {
395 continue;
396 }
397 if (_autogenerated[foreignKeyConstraint.Columns[0]] != null)
398 {
399 _autogenerated[foreignKeyConstraint.Columns[0]] = null;
400 }
401 if (_autogenerated[foreignKeyConstraint.RelatedColumnsReference[0]] != null)
402 {
403 _autogenerated[foreignKeyConstraint.RelatedColumnsReference[0]] = null;
404 }
405 UniqueConstraint uniqueConstraint = (UniqueConstraint)foreignKeyConstraint.RelatedTable.Constraints.FindConstraint(new UniqueConstraint("TEMP", foreignKeyConstraint.RelatedColumnsReference));
406 if (uniqueConstraint != null)
407 {
408 if (_autogenerated[uniqueConstraint] != null)
409 {
411 }
412 if (_autogenerated[uniqueConstraint.Key.ColumnsReference[0]] != null)
413 {
414 _autogenerated[uniqueConstraint.Key.ColumnsReference[0]] = null;
415 }
416 }
417 }
418 else
419 {
422 {
424 }
425 else if (_autogenerated[uniqueConstraint2.Key.ColumnsReference[0]] != null)
426 {
427 _autogenerated[uniqueConstraint2.Key.ColumnsReference[0]] = null;
428 }
429 }
430 }
431 }
432
434 {
435 foreach (DataRelation childRelation in dt.ChildRelations)
436 {
437 if (!_tables.Contains(childRelation.ChildTable))
438 {
439 _tables.Add(childRelation.ChildTable);
441 }
442 }
443 }
444
446 {
447 foreach (DataRelation childRelation in dt.ChildRelations)
448 {
450 {
452 CreateRelations(childRelation.ChildTable);
453 }
454 }
455 }
456
458 {
460 for (int i = 0; i < _tables.Count; i++)
461 {
463 if (dataTable.ParentRelations.Count == 0)
464 {
466 continue;
467 }
468 bool flag = false;
469 for (int j = 0; j < dataTable.ParentRelations.Count; j++)
470 {
471 if (dataTable.ParentRelations[j].Nested)
472 {
473 if (dataTable.ParentRelations[j].ParentTable == dataTable)
474 {
475 flag = false;
476 break;
477 }
478 flag = true;
479 }
480 }
481 if (!flag)
482 {
483 arrayList.Add(dataTable);
484 }
485 }
486 if (arrayList.Count == 0)
487 {
488 return Array.Empty<DataTable>();
489 }
490 DataTable[] array = new DataTable[arrayList.Count];
491 arrayList.CopyTo(array, 0);
492 return array;
493 }
494
495 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
497 {
500 bool flag = _filePath != null;
501 _dsElement = xd.CreateElement("xs", "element", "http://www.w3.org/2001/XMLSchema");
502 bool flag2 = false;
503 if (ds != null)
504 {
505 _ds = ds;
506 foreach (DataTable table in ds.Tables)
507 {
508 _tables.Add(table);
509 }
510 }
511 else
512 {
513 if (dt.DataSet != null)
514 {
515 _ds = dt.DataSet;
516 }
517 _tables.Add(dt);
518 if (writeHierarchy)
519 {
521 }
522 }
523 _dc = xd;
524 _namespaces = new Hashtable();
525 _prefixes = new Hashtable();
526 XmlElement xmlElement = (_sRoot = xd.CreateElement("xs", "schema", "http://www.w3.org/2001/XMLSchema"));
527 if (_ds != null)
528 {
530 }
531 else
532 {
533 xmlElement.SetAttribute("id", XmlConvert.EncodeLocalName("NewDataSet"));
534 }
535 if (_ds != null)
536 {
538 }
539 else
540 {
541 WriteSchemaRoot(xd, xmlElement, dt.Namespace);
542 }
543 if (_schFormat == SchemaFormat.Remoting)
544 {
545 if (_ds != null)
546 {
548 }
549 else
550 {
551 _namespaces[dt.Namespace] = xmlElement;
552 }
553 }
554 if (_schFormat != SchemaFormat.Remoting && _ds != null)
555 {
557 if (_ds.Namespace.Length == 0)
558 {
559 _prefixes[_ds.Namespace] = null;
560 }
561 else
562 {
563 xmlElement.SetAttribute("xmlns:mstns", _ds.Namespace);
564 _prefixes[_ds.Namespace] = "mstns";
565 }
566 }
567 if (ds != null)
568 {
570 }
571 else
572 {
574 }
575 if (_schFormat != SchemaFormat.Remoting)
576 {
577 if (ds != null)
578 {
580 }
581 else
582 {
584 }
585 }
586 DataTable[] array = ((ds != null) ? ds.TopLevelTables(forSchema: true) : CreateToplevelTables());
587 if (array.Length == 0 || _schFormat == SchemaFormat.WebServiceSkipSchema || _schFormat == SchemaFormat.RemotingSkipSchema)
588 {
590 xmlElement.AppendChild(_dsElement);
592 AddExtendedProperties(ds._extendedProperties, _dsElement);
593 xd.AppendChild(xmlElement);
594 xd.Save(xmlWriter);
595 xmlWriter.Flush();
596 return;
597 }
599 _constraintSeparator = xd.CreateElement("xs", "SHOULDNOTBEHERE", "http://www.w3.org/2001/XMLSchema");
601 if (_ds != null)
602 {
605 }
606 for (int i = 0; i < array.Length; i++)
607 {
609 if ((_ds != null && _ds.Namespace == array[i].Namespace) || string.IsNullOrEmpty(array[i].Namespace) || _schFormat == SchemaFormat.Remoting)
610 {
611 bool flag3 = array[i]._fNestedInDataset;
612 if (_ds != null && _ds.Namespace.Length != 0 && string.IsNullOrEmpty(array[i].Namespace))
613 {
614 flag3 = true;
615 }
616 if (array[i].SelfNested)
617 {
618 flag3 = false;
619 }
620 if (array[i].NestedParentsCount > 1)
621 {
622 flag3 = false;
623 }
624 if (flag3)
625 {
626 if (array[i].MinOccurs != 1m)
627 {
628 xmlElement3.SetAttribute("minOccurs", array[i].MinOccurs.ToString(CultureInfo.InvariantCulture));
629 }
630 if (array[i].MaxOccurs == -1m)
631 {
632 xmlElement3.SetAttribute("maxOccurs", "unbounded");
633 }
634 else if (array[i].MaxOccurs != 1m)
635 {
636 xmlElement3.SetAttribute("maxOccurs", array[i].MaxOccurs.ToString(CultureInfo.InvariantCulture));
637 }
638 }
639 if (!flag3)
640 {
641 xmlElement.AppendChild(xmlElement3);
642 XmlElement xmlElement4 = xd.CreateElement("xs", "element", "http://www.w3.org/2001/XMLSchema");
643 if ((_ds != null && _ds.Namespace == array[i].Namespace) || string.IsNullOrEmpty(array[i].Namespace) || _schFormat == SchemaFormat.Remoting)
644 {
645 xmlElement4.SetAttribute("ref", array[i].EncodedTableName);
646 }
647 else
648 {
649 xmlElement4.SetAttribute("ref", (string)_prefixes[array[i].Namespace] + ":" + array[i].EncodedTableName);
650 }
651 xmlElement2.AppendChild(xmlElement4);
652 }
653 else
654 {
655 xmlElement2.AppendChild(xmlElement3);
656 }
657 }
658 else
659 {
660 AppendChildWithoutRef(xmlElement, array[i].Namespace, xmlElement3, "element");
661 XmlElement xmlElement5 = xd.CreateElement("xs", "element", "http://www.w3.org/2001/XMLSchema");
662 xmlElement5.SetAttribute("ref", (string)_prefixes[array[i].Namespace] + ":" + array[i].EncodedTableName);
663 xmlElement2.AppendChild(xmlElement5);
664 }
665 }
669 if (ds != null && _tables.Count > 0)
670 {
671 array2 = new DataRelation[ds.Relations.Count];
672 for (int j = 0; j < ds.Relations.Count; j++)
673 {
674 array2[j] = ds.Relations[j];
675 }
676 }
677 else if (writeHierarchy && _tables.Count > 0)
678 {
682 }
683 XmlElement xmlElement6 = null;
684 XmlElement xmlElement7 = null;
685 foreach (DataRelation dataRelation in array2)
686 {
687 if ((!dataRelation.Nested || flag2) && dataRelation.ChildKeyConstraint == null)
688 {
689 if (xmlElement6 == null)
690 {
691 xmlElement6 = xd.CreateElement("xs", "annotation", "http://www.w3.org/2001/XMLSchema");
693 xmlElement7 = xd.CreateElement("xs", "appinfo", "http://www.w3.org/2001/XMLSchema");
695 }
697 }
698 }
699 XmlComment xmlComment = null;
700 bool flag4 = _namespaces.Count > 1 && !flag;
701 if (_schFormat != SchemaFormat.Remoting && _schFormat != SchemaFormat.RemotingSkipSchema)
702 {
703 foreach (string key in _namespaces.Keys)
704 {
705 if (!(key == ((_ds != null) ? _ds.Namespace : dt.Namespace)) && !string.IsNullOrEmpty(key))
706 {
707 XmlElement xmlElement8 = xd.CreateElement("xs", "import", "http://www.w3.org/2001/XMLSchema");
708 xmlElement8.SetAttribute("namespace", key);
709 if (_schFormat != SchemaFormat.WebService && !flag4)
710 {
711 xmlElement8.SetAttribute("schemaLocation", _fileName + "_" + _prefixes[key]?.ToString() + ".xsd");
712 }
713 xmlElement.PrependChild(xmlElement8);
714 }
715 }
716 if (_schFormat != SchemaFormat.WebService && flag4)
717 {
718 xmlElement.SetAttribute("schemafragmentcount", "urn:schemas-microsoft-com:xml-msdata", _namespaces.Count.ToString(CultureInfo.InvariantCulture));
719 }
720 xd.AppendChild(xmlElement);
721 if (_schFormat != SchemaFormat.WebService && flag4)
722 {
723 xd.WriteTo(xmlWriter);
724 }
725 else
726 {
727 xd.Save(xmlWriter);
728 }
729 xd.RemoveChild(xmlElement);
730 foreach (string key2 in _namespaces.Keys)
731 {
732 if (key2 == ((_ds != null) ? _ds.Namespace : dt.Namespace) || string.IsNullOrEmpty(key2))
733 {
734 continue;
735 }
736 XmlWriter xmlWriter2 = null;
737 xmlWriter2 = (flag ? new XmlTextWriter(_filePath + _fileName + "_" + _prefixes[key2]?.ToString() + ".xsd", null) : xmlWriter);
738 try
739 {
740 if (flag)
741 {
743 {
744 ((XmlTextWriter)xmlWriter2).Formatting = Formatting.Indented;
745 }
747 }
750 foreach (string key3 in _namespaces.Keys)
751 {
752 if (key2 == key3)
753 {
754 continue;
755 }
756 string text4 = (string)_prefixes[key3];
757 if (text4 == null)
758 {
759 continue;
760 }
761 xmlElement9.SetAttribute("xmlns:" + text4, key3);
762 XmlElement xmlElement10 = _dc.CreateElement("xs", "import", "http://www.w3.org/2001/XMLSchema");
763 xmlElement10.SetAttribute("namespace", key3);
764 if (_schFormat != SchemaFormat.WebService && !flag4)
765 {
766 if (key3 == ((_ds != null) ? _ds.Namespace : dt.Namespace))
767 {
768 xmlElement10.SetAttribute("schemaLocation", _fileName + _fileExt);
769 }
770 else
771 {
772 xmlElement10.SetAttribute("schemaLocation", _fileName + "_" + text4 + ".xsd");
773 }
774 }
775 xmlElement9.PrependChild(xmlElement10);
776 }
777 if (_schFormat != SchemaFormat.WebService && flag4)
778 {
780 }
781 else
782 {
784 }
786 if (flag)
787 {
788 xmlWriter2.WriteEndDocument();
789 }
790 }
791 finally
792 {
793 if (flag)
794 {
795 xmlWriter2.Close();
796 }
797 }
798 }
799 }
800 else
801 {
803 xd.Save(xmlWriter);
804 }
805 if (xmlComment != null)
806 {
808 }
809 if (!flag)
810 {
811 xmlWriter.Flush();
812 }
813 }
814
815 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
817 {
818 _dsElement = xd.CreateElement("xs", "element", "http://www.w3.org/2001/XMLSchema");
820 _ds = dt.DataSet;
821 _dc = xd;
822 _namespaces = new Hashtable();
823 _prefixes = new Hashtable();
824 if (_schFormat != SchemaFormat.Remoting)
825 {
827 }
828 XmlElement xmlElement = (_sRoot = xd.CreateElement("xs", "schema", "http://www.w3.org/2001/XMLSchema"));
829 WriteSchemaRoot(xd, xmlElement, dt.Namespace);
830 FillDataSetElement(xd, null, dt);
831 _constraintSeparator = xd.CreateElement("xs", "SHOULDNOTBEHERE", "http://www.w3.org/2001/XMLSchema");
833 if (_schFormat != SchemaFormat.Remoting)
834 {
835 if (_ds != null)
836 {
838 if (_ds.Namespace.Length == 0)
839 {
840 _prefixes[_ds.Namespace] = null;
841 }
842 else
843 {
844 xmlElement.SetAttribute("xmlns:mstns", _ds.Namespace);
845 _prefixes[_ds.Namespace] = "mstns";
846 }
847 }
848 else
849 {
850 _namespaces[dt.Namespace] = xmlElement;
851 if (dt.Namespace.Length == 0)
852 {
853 _prefixes[dt.Namespace] = null;
854 }
855 else
856 {
857 xmlElement.SetAttribute("xmlns:mstns", dt.Namespace);
858 _prefixes[dt.Namespace] = "mstns";
859 }
860 }
861 }
867 return xmlElement;
868 }
869
871 {
872 DataSet dataSet = ((ds != null) ? ds : dt.DataSet);
873 if (dataSet != null)
874 {
876 _dsElement.SetAttribute("IsDataSet", "urn:schemas-microsoft-com:xml-msdata", "true");
877 if (ds == null)
878 {
879 _dsElement.SetAttribute("MainDataTable", "urn:schemas-microsoft-com:xml-msdata", XmlConvert.EncodeLocalName((dt.Namespace.Length == 0) ? dt.TableName : (dt.Namespace + ":" + dt.TableName)));
880 }
881 if (dataSet.CaseSensitive)
882 {
883 _dsElement.SetAttribute("CaseSensitive", "urn:schemas-microsoft-com:xml-msdata", "true");
884 }
885 if (dataSet.ShouldSerializeLocale() || !dataSet.Locale.Equals(CultureInfo.CurrentCulture))
886 {
887 _dsElement.SetAttribute("Locale", "urn:schemas-microsoft-com:xml-msdata", dataSet.Locale.ToString());
888 }
889 else
890 {
891 _dsElement.SetAttribute("UseCurrentLocale", "urn:schemas-microsoft-com:xml-msdata", "true");
892 }
893 }
894 else if (dt != null)
895 {
896 _dsElement.SetAttribute("name", XmlConvert.EncodeLocalName("NewDataSet"));
897 _dsElement.SetAttribute("IsDataSet", "urn:schemas-microsoft-com:xml-msdata", "true");
898 _dsElement.SetAttribute("MainDataTable", "urn:schemas-microsoft-com:xml-msdata", XmlConvert.EncodeLocalName((dt.Namespace.Length == 0) ? dt.TableName : (dt.Namespace + ":" + dt.TableName)));
899 if (dt.CaseSensitive)
900 {
901 _dsElement.SetAttribute("CaseSensitive", "urn:schemas-microsoft-com:xml-msdata", "true");
902 }
903 if (dt.ShouldSerializeLocale() || !dt.Locale.Equals(CultureInfo.CurrentCulture))
904 {
905 _dsElement.SetAttribute("Locale", "urn:schemas-microsoft-com:xml-msdata", dt.Locale.ToString());
906 }
907 else
908 {
909 _dsElement.SetAttribute("UseCurrentLocale", "urn:schemas-microsoft-com:xml-msdata", "true");
910 }
911 }
912 XmlElement xmlElement = xd.CreateElement("xs", "complexType", "http://www.w3.org/2001/XMLSchema");
914 XmlElement xmlElement2 = xd.CreateElement("xs", "choice", "http://www.w3.org/2001/XMLSchema");
915 xmlElement2.SetAttribute("minOccurs", "0");
916 xmlElement2.SetAttribute("maxOccurs", "unbounded");
917 xmlElement.AppendChild(xmlElement2);
918 return xmlElement2;
919 }
920
921 internal void SetPath(XmlWriter xw)
922 {
923 FileStream fileStream = null;
925 if (fileStream == null)
926 {
928 {
929 return;
930 }
932 if (fileStream == null)
933 {
934 return;
935 }
936 }
940 if (!string.IsNullOrEmpty(_filePath))
941 {
942 _filePath += "\\";
943 }
944 }
945
946 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
947 internal void Save(DataSet ds, XmlWriter xw)
948 {
949 Save(ds, null, xw);
950 }
951
952 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
953 internal void Save(DataTable dt, XmlWriter xw)
954 {
956 if (_schFormat == SchemaFormat.Public)
957 {
958 SetPath(xw);
959 }
961 xmlDocument.AppendChild(newChild);
962 xmlDocument.Save(xw);
963 }
964
965 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
967 {
968 Save(ds, dt, xw, writeHierarchy: false);
969 }
970
971 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
973 {
974 Save(ds, dt, xw, writeHierarchy, null);
975 }
976
977 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
979 {
981 XmlDocument xd = new XmlDocument();
982 if (_schFormat == SchemaFormat.Public)
983 {
984 SetPath(xw);
985 }
986 if (_schFormat == SchemaFormat.WebServiceSkipSchema && xw.WriteState == WriteState.Element)
987 {
988 xw.WriteAttributeString("msdata", "SchemaSerializationMode", "urn:schemas-microsoft-com:xml-msdata", "ExcludeSchema");
989 }
991 }
992
994 {
995 XmlElement xmlElement = dc.CreateElement("msdata", "Relationship", "urn:schemas-microsoft-com:xml-msdata");
997 xmlElement.SetAttribute("parent", "urn:schemas-microsoft-com:xml-msdata", rel.ParentKey.Table.EncodedTableName);
998 xmlElement.SetAttribute("child", "urn:schemas-microsoft-com:xml-msdata", rel.ChildKey.Table.EncodedTableName);
999 if (_ds == null || _ds.Tables.InternalIndexOf(rel.ParentKey.Table.TableName) == -3)
1000 {
1001 xmlElement.SetAttribute("ParentTableNamespace", "urn:schemas-microsoft-com:xml-msdata", rel.ParentKey.Table.Namespace);
1002 }
1003 if (_ds == null || _ds.Tables.InternalIndexOf(rel.ChildKey.Table.TableName) == -3)
1004 {
1005 xmlElement.SetAttribute("ChildTableNamespace", "urn:schemas-microsoft-com:xml-msdata", rel.ChildKey.Table.Namespace);
1006 }
1007 DataColumn[] columnsReference = rel.ParentKey.ColumnsReference;
1010 if (1 < columnsReference.Length)
1011 {
1013 stringBuilder.Append(value);
1014 for (int i = 1; i < columnsReference.Length; i++)
1015 {
1016 stringBuilder.Append(' ').Append(columnsReference[i].EncodedColumnName);
1017 }
1018 value = stringBuilder.ToString();
1019 }
1020 xmlElement.SetAttribute("parentkey", "urn:schemas-microsoft-com:xml-msdata", value);
1021 columnsReference = rel.ChildKey.ColumnsReference;
1022 value = columnsReference[0].EncodedColumnName;
1023 if (1 < columnsReference.Length)
1024 {
1025 if (stringBuilder != null)
1026 {
1028 }
1029 else
1030 {
1032 }
1033 stringBuilder.Append(value);
1034 for (int j = 1; j < columnsReference.Length; j++)
1035 {
1036 stringBuilder.Append(' ').Append(columnsReference[j].EncodedColumnName);
1037 }
1038 value = stringBuilder.ToString();
1039 }
1040 xmlElement.SetAttribute("childkey", "urn:schemas-microsoft-com:xml-msdata", value);
1041 AddExtendedProperties(rel._extendedProperties, xmlElement);
1042 return xmlElement;
1043 }
1044
1045 private static XmlElement FindSimpleType(XmlElement schema, string name)
1046 {
1047 for (XmlNode xmlNode = schema.FirstChild; xmlNode != null; xmlNode = xmlNode.NextSibling)
1048 {
1049 if (xmlNode is XmlElement)
1050 {
1052 if (xmlElement.GetAttribute("name") == name)
1053 {
1054 return xmlElement;
1055 }
1056 }
1057 }
1058 return null;
1059 }
1060
1061 internal XmlElement GetSchema(string NamespaceURI)
1062 {
1064 if (xmlElement == null)
1065 {
1066 xmlElement = _dc.CreateElement("xs", "schema", "http://www.w3.org/2001/XMLSchema");
1067 WriteSchemaRoot(_dc, xmlElement, NamespaceURI);
1068 if (!string.IsNullOrEmpty(NamespaceURI))
1069 {
1071 _sRoot.SetAttribute("xmlns:" + text, NamespaceURI);
1072 xmlElement.SetAttribute("xmlns:" + text, NamespaceURI);
1073 _prefixes[NamespaceURI] = text;
1074 }
1075 _namespaces[NamespaceURI] = xmlElement;
1076 }
1077 return xmlElement;
1078 }
1079
1081 {
1082 string name = "type";
1083 if (col.ColumnMapping == MappingType.SimpleContent)
1084 {
1085 name = "base";
1086 }
1087 if (col.SimpleType != null)
1088 {
1089 for (SimpleType simpleType = col.SimpleType; simpleType != null; simpleType = simpleType.BaseSimpleType)
1090 {
1091 string name2 = simpleType.Name;
1092 if (name2 != null && name2.Length != 0)
1093 {
1094 string text = ((_schFormat != SchemaFormat.Remoting) ? simpleType.Namespace : ((col.Table.DataSet != null) ? col.Table.DataSet.Namespace : col.Table.Namespace));
1096 if (simpleType.BaseSimpleType != null && simpleType.BaseSimpleType.Namespace != null && simpleType.BaseSimpleType.Namespace.Length > 0)
1097 {
1098 GetSchema(simpleType.BaseSimpleType.Namespace);
1099 }
1101 if (simpleType == col.SimpleType)
1102 {
1103 string text2 = (string)_prefixes[text];
1104 if (text2 != null && text2.Length > 0)
1105 {
1106 if (_schFormat != SchemaFormat.Remoting)
1107 {
1108 root.SetAttribute(name, text2 + ":" + name2);
1109 }
1110 else
1111 {
1112 root.SetAttribute(name, name2);
1113 }
1114 }
1115 else
1116 {
1117 root.SetAttribute(name, name2);
1118 }
1119 }
1121 if (xmlElement == null)
1122 {
1123 schema2.AppendChild(newChild);
1124 }
1125 }
1126 else
1127 {
1128 if (simpleType.BaseSimpleType != null && simpleType.BaseSimpleType.Namespace != null && simpleType.BaseSimpleType.Namespace.Length > 0)
1129 {
1130 GetSchema(simpleType.BaseSimpleType.Namespace);
1131 }
1133 root.AppendChild(newChild);
1134 }
1135 }
1136 return;
1137 }
1138 if (col.XmlDataType != null && col.XmlDataType.Length != 0 && XSDSchema.IsXsdType(col.XmlDataType))
1139 {
1140 root.SetAttribute(name, XSDSchema.QualifiedName(col.XmlDataType));
1141 return;
1142 }
1143 string text3 = XmlDataTypeName(col.DataType);
1144 if (text3 == null || text3.Length == 0)
1145 {
1146 if (col.DataType == typeof(Guid) || col.DataType == typeof(Type))
1147 {
1148 text3 = "string";
1149 }
1150 else
1151 {
1152 if (col.ColumnMapping == MappingType.Attribute)
1153 {
1154 ValidateColumnMapping(col.DataType);
1155 }
1156 text3 = "anyType";
1157 }
1158 }
1160 }
1161
1163 {
1164 if (col.DataType != typeof(string))
1165 {
1166 string text = XmlDataTypeName(col.DataType);
1167 if ((col.IsSqlType && (text.Length == 0 || col.ImplementsINullable)) || typeof(SqlXml) == col.DataType || col.DataType == typeof(DateTimeOffset) || col.DataType == typeof(BigInteger))
1168 {
1169 root.SetAttribute("DataType", "urn:schemas-microsoft-com:xml-msdata", col.DataType.FullName);
1170 }
1171 else if (text.Length == 0 || col.ImplementsINullable || (text == "anyType" && col.XmlDataType != "anyType"))
1172 {
1173 SetMSDataAttribute(root, col.DataType);
1174 }
1175 }
1176 if (col.ReadOnly)
1177 {
1178 root.SetAttribute("ReadOnly", "urn:schemas-microsoft-com:xml-msdata", "true");
1179 }
1180 if (col.Expression.Length != 0)
1181 {
1182 root.SetAttribute("Expression", "urn:schemas-microsoft-com:xml-msdata", col.Expression);
1183 }
1184 if (col.AutoIncrement)
1185 {
1186 root.SetAttribute("AutoIncrement", "urn:schemas-microsoft-com:xml-msdata", "true");
1187 }
1188 if (col.AutoIncrementSeed != 0L)
1189 {
1190 root.SetAttribute("AutoIncrementSeed", "urn:schemas-microsoft-com:xml-msdata", col.AutoIncrementSeed.ToString(CultureInfo.InvariantCulture));
1191 }
1192 if (col.AutoIncrementStep != 1)
1193 {
1194 root.SetAttribute("AutoIncrementStep", "urn:schemas-microsoft-com:xml-msdata", col.AutoIncrementStep.ToString(CultureInfo.InvariantCulture));
1195 }
1196 if (col.Caption != col.ColumnName)
1197 {
1198 root.SetAttribute("Caption", "urn:schemas-microsoft-com:xml-msdata", col.Caption);
1199 }
1200 if (col.Prefix.Length != 0)
1201 {
1202 root.SetAttribute("Prefix", "urn:schemas-microsoft-com:xml-msdata", col.Prefix);
1203 }
1204 if (col.DataType == typeof(DateTime) && col.DateTimeMode != DataSetDateTime.UnspecifiedLocal)
1205 {
1206 root.SetAttribute("DateTimeMode", "urn:schemas-microsoft-com:xml-msdata", col.DateTimeMode.ToString());
1207 }
1208 }
1209
1210 private string FindTargetNamespace(DataTable table)
1211 {
1213 if (string.IsNullOrEmpty(text))
1214 {
1216 if (nestedParentRelations.Length != 0)
1217 {
1218 for (int i = 0; i < nestedParentRelations.Length; i++)
1219 {
1221 if (table != parentTable)
1222 {
1224 if (!string.IsNullOrEmpty(text))
1225 {
1226 break;
1227 }
1228 }
1229 }
1230 }
1231 else
1232 {
1233 text = _ds.Namespace;
1234 }
1235 }
1236 return text;
1237 }
1238
1239 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
1241 {
1242 string localName = ((col.ColumnMapping != MappingType.Element) ? "attribute" : "element");
1243 XmlElement xmlElement = dc.CreateElement("xs", localName, "http://www.w3.org/2001/XMLSchema");
1244 xmlElement.SetAttribute("name", col.EncodedColumnName);
1245 if (col.Namespace.Length == 0)
1246 {
1247 DataTable table = col.Table;
1248 string text = FindTargetNamespace(table);
1249 if (col.Namespace != text)
1250 {
1251 xmlElement.SetAttribute("form", "unqualified");
1252 }
1253 }
1254 if (col.GetType() != typeof(DataColumn))
1255 {
1257 }
1258 else
1259 {
1261 }
1262 AddExtendedProperties(col._extendedProperties, xmlElement);
1264 if (col.ColumnMapping == MappingType.Hidden)
1265 {
1266 if (!col.AllowDBNull)
1267 {
1268 xmlElement.SetAttribute("AllowDBNull", "urn:schemas-microsoft-com:xml-msdata", "false");
1269 }
1270 if (!col.DefaultValueIsNull)
1271 {
1272 if (col.DataType == typeof(bool))
1273 {
1274 xmlElement.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", ((bool)col.DefaultValue) ? "true" : "false");
1275 }
1276 else
1277 {
1278 ValidateColumnMapping(col.DataType);
1279 xmlElement.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", col.ConvertObjectToXml(col.DefaultValue));
1280 }
1281 }
1282 }
1283 if (!col.DefaultValueIsNull && col.ColumnMapping != MappingType.Hidden)
1284 {
1285 ValidateColumnMapping(col.DataType);
1286 if (col.ColumnMapping == MappingType.Attribute && !col.AllowDBNull)
1287 {
1288 if (col.DataType == typeof(bool))
1289 {
1290 xmlElement.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", ((bool)col.DefaultValue) ? "true" : "false");
1291 }
1292 else
1293 {
1294 xmlElement.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", col.ConvertObjectToXml(col.DefaultValue));
1295 }
1296 }
1297 else if (col.DataType == typeof(bool))
1298 {
1299 xmlElement.SetAttribute("default", ((bool)col.DefaultValue) ? "true" : "false");
1300 }
1301 else if (!col.IsCustomType)
1302 {
1303 xmlElement.SetAttribute("default", col.ConvertObjectToXml(col.DefaultValue));
1304 }
1305 }
1306 if (_schFormat == SchemaFormat.Remoting)
1307 {
1308 xmlElement.SetAttribute("targetNamespace", "urn:schemas-microsoft-com:xml-msdata", col.Namespace);
1309 }
1310 else if (col.Namespace != (col.Table.TypeName.IsEmpty ? col.Table.Namespace : col.Table.TypeName.Namespace) && col.Namespace.Length != 0)
1311 {
1312 XmlElement schema2 = GetSchema(col.Namespace);
1313 if (FindTypeNode(schema2, col.EncodedColumnName) == null)
1314 {
1315 schema2.AppendChild(xmlElement);
1316 }
1317 xmlElement = _dc.CreateElement("xs", localName, "http://www.w3.org/2001/XMLSchema");
1318 xmlElement.SetAttribute("ref", _prefixes[col.Namespace]?.ToString() + ":" + col.EncodedColumnName);
1319 if (col.Table.Namespace != _ds.Namespace)
1320 {
1321 GetSchema(col.Table.Namespace);
1322 }
1323 }
1324 int num = ((!col.AllowDBNull) ? 1 : 0);
1325 if (col.ColumnMapping == MappingType.Attribute && num != 0)
1326 {
1327 xmlElement.SetAttribute("use", "required");
1328 }
1329 if (col.ColumnMapping == MappingType.Hidden)
1330 {
1331 xmlElement.SetAttribute("use", "prohibited");
1332 }
1333 else if (col.ColumnMapping != MappingType.Attribute && num != 1)
1334 {
1335 xmlElement.SetAttribute("minOccurs", num.ToString(CultureInfo.InvariantCulture));
1336 }
1337 if (col.ColumnMapping == MappingType.Element && fWriteOrdinal)
1338 {
1339 xmlElement.SetAttribute("Ordinal", "urn:schemas-microsoft-com:xml-msdata", col.Ordinal.ToString(CultureInfo.InvariantCulture));
1340 }
1341 return xmlElement;
1342 }
1343
1345 {
1346 return rule switch
1347 {
1348 AcceptRejectRule.Cascade => "Cascade",
1349 AcceptRejectRule.None => "None",
1350 _ => null,
1351 };
1352 }
1353
1354 internal static string TranslateRule(Rule rule)
1355 {
1356 return rule switch
1357 {
1358 Rule.Cascade => "Cascade",
1359 Rule.None => "None",
1360 Rule.SetNull => "SetNull",
1361 Rule.SetDefault => "SetDefault",
1362 _ => null,
1363 };
1364 }
1365
1366 internal void AppendChildWithoutRef(XmlElement node, string Namespace, XmlElement el, string refString)
1367 {
1368 XmlElement schema = GetSchema(Namespace);
1369 if (FindTypeNode(schema, el.GetAttribute("name")) == null)
1370 {
1371 schema.AppendChild(el);
1372 }
1373 }
1374
1376 {
1377 if (node == null)
1378 {
1379 return null;
1380 }
1381 for (XmlNode xmlNode = node.FirstChild; xmlNode != null; xmlNode = xmlNode.NextSibling)
1382 {
1383 if (xmlNode is XmlElement)
1384 {
1386 if ((XMLSchema.FEqualIdentity(xmlElement, "element", "http://www.w3.org/2001/XMLSchema") || XMLSchema.FEqualIdentity(xmlElement, "attribute", "http://www.w3.org/2001/XMLSchema") || XMLSchema.FEqualIdentity(xmlElement, "complexType", "http://www.w3.org/2001/XMLSchema") || XMLSchema.FEqualIdentity(xmlElement, "simpleType", "http://www.w3.org/2001/XMLSchema")) && xmlElement.GetAttribute("name") == strType)
1387 {
1388 return xmlElement;
1389 }
1390 }
1391 }
1392 return null;
1393 }
1394
1395 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
1397 {
1398 return HandleTable(table, dc, schema, genNested: true);
1399 }
1400
1401 private bool HasMixedColumns(DataTable table)
1402 {
1403 bool flag = false;
1404 bool flag2 = false;
1405 foreach (DataColumn column in table.Columns)
1406 {
1407 if (!flag2 && column.ColumnMapping == MappingType.Element)
1408 {
1409 flag2 = true;
1410 }
1411 if (!flag && (column.ColumnMapping == MappingType.Attribute || column.ColumnMapping == MappingType.Hidden))
1412 {
1413 flag = !AutoGenerated(column);
1414 }
1415 if (flag && flag2)
1416 {
1417 return true;
1418 }
1419 }
1420 return false;
1421 }
1422
1423 internal static bool AutoGenerated(DataColumn col)
1424 {
1425 if (col.ColumnMapping != MappingType.Hidden)
1426 {
1427 return false;
1428 }
1429 if (col.DataType != typeof(int))
1430 {
1431 return false;
1432 }
1433 string text = col.Table.TableName + "_Id";
1434 if (col.ColumnName == text || col.ColumnName == text + "_0")
1435 {
1436 return true;
1437 }
1438 text = string.Empty;
1439 foreach (DataRelation parentRelation in col.Table.ParentRelations)
1440 {
1441 if (parentRelation.Nested && parentRelation.ChildColumnsReference.Length == 1 && parentRelation.ChildColumnsReference[0] == col && parentRelation.ParentColumnsReference.Length == 1)
1442 {
1443 text = parentRelation.ParentColumnsReference[0].Table.TableName + "_Id";
1444 }
1445 }
1446 if (col.ColumnName == text || col.ColumnName == text + "_0")
1447 {
1448 return true;
1449 }
1450 return false;
1451 }
1452
1453 internal static bool AutoGenerated(DataRelation rel)
1454 {
1455 string value = rel.ParentTable.TableName + "_" + rel.ChildTable.TableName;
1456 if (!rel.RelationName.StartsWith(value, StringComparison.Ordinal))
1457 {
1458 return false;
1459 }
1460 if (rel.ExtendedProperties.Count > 0)
1461 {
1462 return false;
1463 }
1464 return true;
1465 }
1466
1468 {
1469 if (!unique.ConstraintName.StartsWith("Constraint", StringComparison.Ordinal))
1470 {
1471 return false;
1472 }
1473 if (unique.Key.ColumnsReference.Length != 1)
1474 {
1475 return false;
1476 }
1477 if (unique.ExtendedProperties.Count > 0)
1478 {
1479 return false;
1480 }
1481 return AutoGenerated(unique.Key.ColumnsReference[0]);
1482 }
1483
1485 {
1486 return AutoGenerated(fk, checkRelation: true);
1487 }
1488
1490 {
1491 DataRelation dataRelation = fk.FindParentRelation();
1492 if (checkRelation)
1493 {
1494 if (dataRelation == null)
1495 {
1496 return false;
1497 }
1499 {
1500 return false;
1501 }
1502 if (dataRelation.RelationName != fk.ConstraintName)
1503 {
1504 return false;
1505 }
1506 }
1507 if (fk.ExtendedProperties.Count > 0)
1508 {
1509 return false;
1510 }
1511 if (fk.AcceptRejectRule != 0)
1512 {
1513 return false;
1514 }
1515 if (fk.DeleteRule != Rule.Cascade)
1516 {
1517 return false;
1518 }
1519 if (fk.DeleteRule != Rule.Cascade)
1520 {
1521 return false;
1522 }
1523 if (fk.RelatedColumnsReference.Length != 1)
1524 {
1525 return false;
1526 }
1527 return AutoGenerated(fk.RelatedColumnsReference[0]);
1528 }
1529
1530 private bool IsAutoGenerated(object o)
1531 {
1532 if (_schFormat != SchemaFormat.Remoting)
1533 {
1534 return _autogenerated[o] != null;
1535 }
1536 return false;
1537 }
1538
1539 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
1541 {
1542 XmlElement xmlElement = dc.CreateElement("xs", "element", "http://www.w3.org/2001/XMLSchema");
1543 bool flag = false;
1544 bool flag2 = false;
1545 if ((table.DataSet == null || (_ds != null && table.Namespace != _ds.Namespace)) && _schFormat == SchemaFormat.Remoting)
1546 {
1547 xmlElement.SetAttribute("targetNamespace", "urn:schemas-microsoft-com:xml-msdata", table.Namespace);
1548 }
1549 xmlElement.SetAttribute("name", table.EncodedTableName);
1550 if (table.Namespace.Length == 0)
1551 {
1552 DataTable dataTable = table;
1553 string text = dataTable.Namespace;
1554 while (string.IsNullOrEmpty(text))
1555 {
1556 DataRelation[] nestedParentRelations = dataTable.NestedParentRelations;
1557 if (nestedParentRelations.Length == 0)
1558 {
1559 text = ((_ds != null) ? _ds.Namespace : "");
1560 break;
1561 }
1562 int num = -1;
1563 for (int i = 0; i < nestedParentRelations.Length; i++)
1564 {
1565 if (nestedParentRelations[i].ParentTable != dataTable)
1566 {
1567 num = i;
1568 break;
1569 }
1570 }
1571 if (num == -1)
1572 {
1573 break;
1574 }
1575 dataTable = nestedParentRelations[num].ParentTable;
1576 text = dataTable.Namespace;
1577 }
1578 if (table.Namespace != text)
1579 {
1580 xmlElement.SetAttribute("form", "unqualified");
1581 flag2 = true;
1582 }
1583 }
1584 if (table.ShouldSerializeCaseSensitive())
1585 {
1586 xmlElement.SetAttribute("CaseSensitive", "urn:schemas-microsoft-com:xml-msdata", table.CaseSensitive.ToString());
1587 }
1588 if (table.ShouldSerializeLocale())
1589 {
1590 xmlElement.SetAttribute("Locale", "urn:schemas-microsoft-com:xml-msdata", table.Locale.ToString());
1591 }
1594 int count = columns.Count;
1595 int num2 = 0;
1596 if (count == 1 || count == 2)
1597 {
1598 for (int j = 0; j < count; j++)
1599 {
1601 if (dataColumn.ColumnMapping == MappingType.Hidden)
1602 {
1604 for (int k = 0; k < childRelations.Count; k++)
1605 {
1606 if (childRelations[k].Nested && childRelations[k].ParentKey.ColumnsReference.Length == 1 && childRelations[k].ParentKey.ColumnsReference[0] == dataColumn)
1607 {
1608 num2++;
1609 }
1610 }
1611 }
1612 if (dataColumn.ColumnMapping == MappingType.Element)
1613 {
1614 num2++;
1615 }
1616 }
1617 }
1618 if (table._repeatableElement && num2 == 1)
1619 {
1620 DataColumn dataColumn2 = table.Columns[0];
1621 string text2 = XmlDataTypeName(dataColumn2.DataType);
1622 if (text2 == null || text2.Length == 0)
1623 {
1624 text2 = "anyType";
1625 }
1626 xmlElement.SetAttribute("type", XSDSchema.QualifiedName(text2));
1627 return xmlElement;
1628 }
1629 XmlElement xmlElement2 = dc.CreateElement("xs", "complexType", "http://www.w3.org/2001/XMLSchema");
1630 if (!table.TypeName.IsEmpty && _schFormat != SchemaFormat.Remoting)
1631 {
1633 if (string.IsNullOrEmpty(table.TypeName.Namespace))
1634 {
1635 xmlElement3 = ((_ds != null) ? (flag2 ? GetSchema(_ds.Namespace) : GetSchema(table.Namespace)) : GetSchema(table.Namespace));
1636 }
1637 if (FindTypeNode(xmlElement3, table.TypeName.Name) == null)
1638 {
1639 xmlElement3.AppendChild(xmlElement2);
1640 }
1641 xmlElement2.SetAttribute("name", table.TypeName.Name);
1642 }
1643 else
1644 {
1645 xmlElement.AppendChild(xmlElement2);
1646 }
1647 if (!table.TypeName.IsEmpty && _schFormat != SchemaFormat.Remoting)
1648 {
1649 xmlElement.SetAttribute("type", NewDiffgramGen.QualifiedName((string)_prefixes[table.TypeName.Namespace], table.TypeName.Name));
1650 }
1651 XmlElement xmlElement4 = null;
1652 DataColumn xmlText = table.XmlText;
1653 if (xmlText != null)
1654 {
1655 XmlElement xmlElement5 = dc.CreateElement("xs", "simpleContent", "http://www.w3.org/2001/XMLSchema");
1656 if (xmlText.GetType() != typeof(DataColumn))
1657 {
1659 }
1660 else
1661 {
1663 }
1664 AddExtendedProperties(xmlText._extendedProperties, xmlElement5);
1665 if (xmlText.AllowDBNull)
1666 {
1667 xmlElement.SetAttribute("nillable", string.Empty, "true");
1668 }
1669 if (!xmlText.DefaultValueIsNull)
1670 {
1672 xmlElement5.SetAttribute("DefaultValue", "urn:schemas-microsoft-com:xml-msdata", xmlText.ConvertObjectToXml(xmlText.DefaultValue));
1673 }
1674 xmlElement5.SetAttribute("ColumnName", "urn:schemas-microsoft-com:xml-msdata", xmlText.ColumnName);
1675 xmlElement5.SetAttribute("Ordinal", "urn:schemas-microsoft-com:xml-msdata", xmlText.Ordinal.ToString(CultureInfo.InvariantCulture));
1676 xmlElement2.AppendChild(xmlElement5);
1677 XmlElement xmlElement6 = dc.CreateElement("xs", "extension", "http://www.w3.org/2001/XMLSchema");
1681 }
1682 xmlElement4 = dc.CreateElement("xs", "sequence", "http://www.w3.org/2001/XMLSchema");
1683 xmlElement2.AppendChild(xmlElement4);
1684 flag = HasMixedColumns(table);
1685 for (int l = 0; l < count; l++)
1686 {
1688 if (dataColumn3.ColumnMapping != MappingType.SimpleContent && (dataColumn3.ColumnMapping == MappingType.Attribute || dataColumn3.ColumnMapping == MappingType.Element || dataColumn3.ColumnMapping == MappingType.Hidden) && !IsAutoGenerated(dataColumn3))
1689 {
1694 }
1695 }
1696 if (table.XmlText == null && genNested)
1697 {
1699 for (int m = 0; m < childRelations2.Count; m++)
1700 {
1701 if (!childRelations2[m].Nested)
1702 {
1703 continue;
1704 }
1705 DataTable childTable = childRelations2[m].ChildTable;
1707 if (childTable == table)
1708 {
1709 xmlElement8 = dc.CreateElement("xs", "element", "http://www.w3.org/2001/XMLSchema");
1711 }
1712 else if (childTable.NestedParentsCount > 1)
1713 {
1714 xmlElement8 = dc.CreateElement("xs", "element", "http://www.w3.org/2001/XMLSchema");
1715 xmlElement8.SetAttribute("ref", childTable.EncodedTableName);
1716 }
1717 else
1718 {
1720 }
1721 if (childTable.Namespace == table.Namespace)
1722 {
1723 xmlElement8.SetAttribute("minOccurs", "0");
1724 xmlElement8.SetAttribute("maxOccurs", "unbounded");
1725 }
1726 if (childTable.Namespace == table.Namespace || childTable.Namespace.Length == 0 || _schFormat == SchemaFormat.Remoting)
1727 {
1728 xmlElement4.AppendChild(xmlElement8);
1729 }
1730 else
1731 {
1732 if (childTable.NestedParentsCount <= 1)
1733 {
1735 }
1736 xmlElement8 = dc.CreateElement("xs", "element", "http://www.w3.org/2001/XMLSchema");
1737 xmlElement8.SetAttribute("ref", (string)_prefixes[childTable.Namespace] + ":" + childTable.EncodedTableName);
1739 }
1740 if (childRelations2[m].ChildKeyConstraint == null)
1741 {
1742 XmlElement xmlElement9 = _dc.CreateElement("xs", "annotation", "http://www.w3.org/2001/XMLSchema");
1744 XmlElement xmlElement10 = _dc.CreateElement("xs", "appinfo", "http://www.w3.org/2001/XMLSchema");
1747 }
1748 }
1749 }
1750 if (xmlElement4 != null && !xmlElement4.HasChildNodes)
1751 {
1753 }
1755 string text3 = ((_ds == null) ? string.Empty : ((_ds.Namespace.Length != 0) ? "mstns:" : string.Empty));
1756 if (_schFormat != SchemaFormat.Remoting)
1757 {
1758 GetSchema(table.Namespace);
1759 text3 = ((table.Namespace.Length != 0) ? ((string)_prefixes[table.Namespace] + ":") : string.Empty);
1760 }
1761 for (int n = 0; n < constraints.Count; n++)
1762 {
1763 XmlElement xmlElement11 = null;
1765 {
1768 {
1769 continue;
1770 }
1771 DataColumn[] columnsReference = uniqueConstraint.Key.ColumnsReference;
1772 xmlElement11 = dc.CreateElement("xs", "unique", "http://www.w3.org/2001/XMLSchema");
1773 if (_ds == null || _ds.Tables.InternalIndexOf(table.TableName) == -3)
1774 {
1775 xmlElement11.SetAttribute("TableNamespace", "urn:schemas-microsoft-com:xml-msdata", table.Namespace);
1776 }
1777 xmlElement11.SetAttribute("name", XmlConvert.EncodeLocalName(uniqueConstraint.SchemaName));
1778 if (uniqueConstraint.ConstraintName != uniqueConstraint.SchemaName)
1779 {
1780 xmlElement11.SetAttribute("ConstraintName", "urn:schemas-microsoft-com:xml-msdata", uniqueConstraint.ConstraintName);
1781 }
1783 XmlElement xmlElement12 = dc.CreateElement("xs", "selector", "http://www.w3.org/2001/XMLSchema");
1784 xmlElement12.SetAttribute("xpath", ".//" + text3 + table.EncodedTableName);
1785 xmlElement11.AppendChild(xmlElement12);
1786 if (uniqueConstraint.IsPrimaryKey)
1787 {
1788 xmlElement11.SetAttribute("PrimaryKey", "urn:schemas-microsoft-com:xml-msdata", "true");
1789 }
1790 if (columnsReference.Length != 0)
1791 {
1793 for (int num3 = 0; num3 < columnsReference.Length; num3++)
1794 {
1796 if (_schFormat != SchemaFormat.Remoting)
1797 {
1798 GetSchema(columnsReference[num3].Namespace);
1799 if (!string.IsNullOrEmpty(columnsReference[num3].Namespace))
1800 {
1801 stringBuilder.Append(_prefixes[columnsReference[num3].Namespace]).Append(':');
1802 }
1803 stringBuilder.Append(columnsReference[num3].EncodedColumnName);
1804 }
1805 else
1806 {
1807 stringBuilder.Append(text3).Append(columnsReference[num3].EncodedColumnName);
1808 }
1809 if (columnsReference[num3].ColumnMapping == MappingType.Attribute || columnsReference[num3].ColumnMapping == MappingType.Hidden)
1810 {
1811 stringBuilder.Insert(0, '@');
1812 }
1813 XmlElement xmlElement13 = dc.CreateElement("xs", "field", "http://www.w3.org/2001/XMLSchema");
1814 xmlElement13.SetAttribute("xpath", stringBuilder.ToString());
1815 xmlElement11.AppendChild(xmlElement13);
1816 }
1817 }
1819 }
1820 else
1821 {
1823 {
1824 continue;
1825 }
1828 {
1829 continue;
1830 }
1831 DataRelation dataRelation = foreignKeyConstraint.FindParentRelation();
1832 DataColumn[] columnsReference = foreignKeyConstraint.RelatedColumnsReference;
1833 UniqueConstraint uniqueConstraint2 = (UniqueConstraint)foreignKeyConstraint.RelatedTable.Constraints.FindConstraint(new UniqueConstraint("TEMP", columnsReference));
1835 if (uniqueConstraint2 == null)
1836 {
1837 xmlElement11 = dc.CreateElement("xs", "key", "http://www.w3.org/2001/XMLSchema");
1839 if (_ds == null || _ds.Tables.InternalIndexOf(table.TableName) == -3)
1840 {
1841 xmlElement11.SetAttribute("TableNamespace", "urn:schemas-microsoft-com:xml-msdata", table.Namespace);
1842 }
1843 xmlElement12 = dc.CreateElement("xs", "selector", "http://www.w3.org/2001/XMLSchema");
1844 xmlElement12.SetAttribute("xpath", ".//" + text3 + foreignKeyConstraint.RelatedTable.EncodedTableName);
1845 xmlElement11.AppendChild(xmlElement12);
1846 if (columnsReference.Length != 0)
1847 {
1849 for (int num4 = 0; num4 < columnsReference.Length; num4++)
1850 {
1852 if (_schFormat != SchemaFormat.Remoting)
1853 {
1854 GetSchema(columnsReference[num4].Namespace);
1855 if (!string.IsNullOrEmpty(columnsReference[num4].Namespace))
1856 {
1857 stringBuilder2.Append(_prefixes[columnsReference[num4].Namespace]).Append(':');
1858 }
1859 stringBuilder2.Append(columnsReference[num4].EncodedColumnName);
1860 }
1861 else
1862 {
1863 stringBuilder2.Append(text3).Append(columnsReference[num4].EncodedColumnName);
1864 }
1865 if (columnsReference[num4].ColumnMapping == MappingType.Attribute || columnsReference[num4].ColumnMapping == MappingType.Hidden)
1866 {
1867 stringBuilder2.Insert(0, '@');
1868 }
1869 XmlElement xmlElement13 = dc.CreateElement("xs", "field", "http://www.w3.org/2001/XMLSchema");
1870 xmlElement13.SetAttribute("xpath", stringBuilder2.ToString());
1871 xmlElement11.AppendChild(xmlElement13);
1872 }
1873 }
1875 }
1876 xmlElement11 = dc.CreateElement("xs", "keyref", "http://www.w3.org/2001/XMLSchema");
1877 xmlElement11.SetAttribute("name", XmlConvert.EncodeLocalName(foreignKeyConstraint.SchemaName));
1878 if (_ds == null || _ds.Tables.InternalIndexOf(foreignKeyConstraint.RelatedTable.TableName) == -3)
1879 {
1880 xmlElement11.SetAttribute("TableNamespace", "urn:schemas-microsoft-com:xml-msdata", foreignKeyConstraint.Table.Namespace);
1881 }
1882 if (uniqueConstraint2 == null)
1883 {
1884 xmlElement11.SetAttribute("refer", XmlConvert.EncodeLocalName(foreignKeyConstraint.SchemaName));
1885 }
1886 else
1887 {
1888 xmlElement11.SetAttribute("refer", XmlConvert.EncodeLocalName(uniqueConstraint2.SchemaName));
1889 }
1891 if (foreignKeyConstraint.ConstraintName != foreignKeyConstraint.SchemaName)
1892 {
1893 xmlElement11.SetAttribute("ConstraintName", "urn:schemas-microsoft-com:xml-msdata", foreignKeyConstraint.ConstraintName);
1894 }
1895 if (dataRelation == null)
1896 {
1897 xmlElement11.SetAttribute("ConstraintOnly", "urn:schemas-microsoft-com:xml-msdata", "true");
1898 }
1899 else
1900 {
1901 if (dataRelation.Nested)
1902 {
1903 xmlElement11.SetAttribute("IsNested", "urn:schemas-microsoft-com:xml-msdata", "true");
1904 }
1906 if (foreignKeyConstraint.ConstraintName != dataRelation.RelationName)
1907 {
1908 xmlElement11.SetAttribute("RelationName", "urn:schemas-microsoft-com:xml-msdata", XmlConvert.EncodeLocalName(dataRelation.RelationName));
1909 }
1910 }
1911 xmlElement12 = dc.CreateElement("xs", "selector", "http://www.w3.org/2001/XMLSchema");
1912 xmlElement12.SetAttribute("xpath", ".//" + text3 + table.EncodedTableName);
1913 xmlElement11.AppendChild(xmlElement12);
1914 if (foreignKeyConstraint.AcceptRejectRule != 0)
1915 {
1916 xmlElement11.SetAttribute("AcceptRejectRule", "urn:schemas-microsoft-com:xml-msdata", TranslateAcceptRejectRule(foreignKeyConstraint.AcceptRejectRule));
1917 }
1918 if (foreignKeyConstraint.UpdateRule != Rule.Cascade)
1919 {
1920 xmlElement11.SetAttribute("UpdateRule", "urn:schemas-microsoft-com:xml-msdata", TranslateRule(foreignKeyConstraint.UpdateRule));
1921 }
1922 if (foreignKeyConstraint.DeleteRule != Rule.Cascade)
1923 {
1924 xmlElement11.SetAttribute("DeleteRule", "urn:schemas-microsoft-com:xml-msdata", TranslateRule(foreignKeyConstraint.DeleteRule));
1925 }
1927 if (columnsReference.Length != 0)
1928 {
1930 for (int num5 = 0; num5 < columnsReference.Length; num5++)
1931 {
1933 if (_schFormat != SchemaFormat.Remoting)
1934 {
1935 GetSchema(columnsReference[num5].Namespace);
1936 if (!string.IsNullOrEmpty(columnsReference[num5].Namespace))
1937 {
1938 stringBuilder3.Append(_prefixes[columnsReference[num5].Namespace]).Append(':');
1939 }
1940 stringBuilder3.Append(columnsReference[num5].EncodedColumnName);
1941 }
1942 else
1943 {
1944 stringBuilder3.Append(text3).Append(columnsReference[num5].EncodedColumnName);
1945 }
1946 if (columnsReference[num5].ColumnMapping == MappingType.Attribute || columnsReference[num5].ColumnMapping == MappingType.Hidden)
1947 {
1948 stringBuilder3.Insert(0, '@');
1949 }
1950 XmlElement xmlElement13 = dc.CreateElement("xs", "field", "http://www.w3.org/2001/XMLSchema");
1951 xmlElement13.SetAttribute("xpath", stringBuilder3.ToString());
1952 xmlElement11.AppendChild(xmlElement13);
1953 }
1954 }
1956 }
1957 }
1959 return xmlElement;
1960 }
1961
1963 {
1965 try
1966 {
1967 if (_targetConverter != null)
1968 {
1970 }
1971 if (!string.IsNullOrEmpty(value))
1972 {
1973 root.SetAttribute("DataType", "urn:schemas-microsoft-com:xml-msdata", value);
1974 }
1975 }
1977 {
1979 }
1980 if (string.IsNullOrEmpty(value))
1981 {
1983 }
1984 }
1985}
virtual int Add(object? value)
virtual bool Contains(object? item)
virtual void CopyTo(Array array)
virtual ICollection Keys
Definition Hashtable.cs:532
static PropertyDescriptorCollection GetProperties([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType)
static ? string ToString(object? value)
Definition Convert.cs:2321
static bool IsCatchableExceptionType(Exception e)
Definition ADP.cs:790
static object ConvertFromBigInteger(BigInteger value, Type type, IFormatProvider formatProvider)
static string GetQualifiedName(Type type)
static bool IsTypeCustomType(Type type)
static object ChangeTypeForXML(object value, Type type)
virtual string ConstraintName
Definition Constraint.cs:24
DataTableCollection Tables
Definition DataSet.cs:396
PropertyCollection _extendedProperties
Definition DataSet.cs:61
PropertyCollection _extendedProperties
Definition DataTable.cs:82
DataColumn? XmlText
Definition DataTable.cs:855
ConstraintCollection Constraints
Definition DataTable.cs:332
DataColumnCollection Columns
Definition DataTable.cs:327
XmlQualifiedName TypeName
Definition DataTable.cs:950
bool ShouldSerializeCaseSensitive()
DataRelation[] NestedParentRelations
Definition DataTable.cs:586
DataRelationCollection ChildRelations
Definition DataTable.cs:324
static Exception InvalidDataColumnMapping(Type type)
static void ThrowMultipleTargetConverter(Exception innerException)
static string QualifiedName(string prefix, string name)
SimpleType(string baseType)
Definition SimpleType.cs:76
static bool FEqualIdentity(XmlNode node, string name, string ns)
Definition XMLSchema.cs:68
static bool IsXsdType(string name)
static string QualifiedName(string name)
Definition XSDSchema.cs:207
static void ValidateColumnMapping(Type columnType)
static void AddExtendedProperties(PropertyCollection props, XmlElement node, Type type)
Definition XmlTreeGen.cs:60
void GenerateConstraintNames(ArrayList tables)
void Save(DataTable dt, XmlWriter xw)
void Save(DataSet ds, DataTable dt, XmlWriter xw)
static bool AutoGenerated(ForeignKeyConstraint fk, bool checkRelation)
static bool AutoGenerated(DataColumn col)
XmlElement FillDataSetElement(XmlDocument xd, DataSet ds, DataTable dt)
void Save(DataSet ds, DataTable dt, XmlWriter xw, bool writeHierarchy)
void SetupAutoGenerated(DataSet ds)
void SetupAutoGenerated(DataTable dt)
static bool AutoGenerated(DataRelation rel)
readonly ArrayList _tables
Definition XmlTreeGen.cs:26
static string TranslateRule(Rule rule)
static string XmlDataTypeName(Type type)
void HandleColumnType(DataColumn col, XmlDocument dc, XmlElement root, XmlElement schema)
void Save(DataSet ds, XmlWriter xw)
void SetPath(XmlWriter xw)
XmlElement HandleColumn(DataColumn col, XmlDocument dc, XmlElement schema, bool fWriteOrdinal)
void SetMSDataAttribute(XmlElement root, Type type)
XmlTreeGen(SchemaFormat format)
Definition XmlTreeGen.cs:50
XmlElement GetSchema(string NamespaceURI)
static string TranslateAcceptRejectRule(AcceptRejectRule rule)
static bool _PropsNotEmpty(PropertyCollection props)
void AddXdoProperties(object instance, XmlElement root, XmlDocument xd)
Definition XmlTreeGen.cs:83
XmlElement SchemaTree(XmlDocument xd, DataTable dt)
DataTable[] CreateToplevelTables()
void AddColumnProperties(DataColumn col, XmlElement root)
void Save(DataSet ds, DataTable dt, XmlWriter xw, bool writeHierarchy, Converter< Type, string > multipleTargetConverter)
bool AutoGenerated(ForeignKeyConstraint fk)
void SchemaTree(XmlDocument xd, XmlWriter xmlWriter, DataSet ds, DataTable dt, bool writeHierarchy)
Converter< Type, string > _targetConverter
Definition XmlTreeGen.cs:48
XmlElement HandleRelation(DataRelation rel, XmlDocument dc)
readonly SchemaFormat _schFormat
Definition XmlTreeGen.cs:36
void AppendChildWithoutRef(XmlElement node, string Namespace, XmlElement el, string refString)
bool IsAutoGenerated(object o)
ArrayList _constraintNames
Definition XmlTreeGen.cs:16
bool HaveExtendedProperties(DataSet ds)
void WriteSchemaRoot(XmlDocument xd, XmlElement rootSchema, string targetNamespace)
static void AddExtendedProperties(PropertyCollection props, XmlElement node)
Definition XmlTreeGen.cs:55
bool ContainsDesignerSerializationVisibleAttribute(PropertyDescriptor pd)
void CreateRelations(DataTable dt)
XmlElement _constraintSeparator
Definition XmlTreeGen.cs:46
XmlElement FindTypeNode(XmlElement node, string strType)
void GenerateConstraintNames(DataTable table, bool fromTable)
readonly ArrayList _relations
Definition XmlTreeGen.cs:28
XmlElement HandleTable(DataTable table, XmlDocument dc, XmlElement schema)
void GenerateConstraintNames(DataSet ds)
bool HasMixedColumns(DataTable table)
static bool AutoGenerated(UniqueConstraint unique)
void AddXdoProperty(PropertyDescriptor pd, object instance, XmlElement root, XmlDocument xd)
string FindTargetNamespace(DataTable table)
void CreateTablesHierarchy(DataTable dt)
static XmlElement FindSimpleType(XmlElement schema, string name)
XmlElement HandleTable(DataTable table, XmlDocument dc, XmlElement schema, bool genNested)
void SetupAutoGenerated(ArrayList dt)
static CultureInfo CurrentCulture
static CultureInfo InvariantCulture
static ? string GetFileNameWithoutExtension(string? path)
Definition Path.cs:229
static ? string GetExtension(string? path)
Definition Path.cs:168
static ? string GetDirectoryName(string? path)
Definition Path.cs:121
static ? string EncodeLocalName(string? name)
Definition XmlConvert.cs:49
virtual void Save(string filename)
XmlElement CreateElement(string name)
override void WriteTo(XmlWriter w)
virtual void SetAttribute(string name, string? value)
virtual ? XmlNode AppendChild(XmlNode newChild)
Definition XmlNode.cs:739
virtual ? XmlNode PrependChild(XmlNode newChild)
Definition XmlNode.cs:734
virtual ? XmlNode InsertAfter(XmlNode newChild, XmlNode? refChild)
Definition XmlNode.cs:548
virtual ? XmlNode InsertBefore(XmlNode newChild, XmlNode? refChild)
Definition XmlNode.cs:445
virtual XmlNode RemoveChild(XmlNode oldChild)
Definition XmlNode.cs:662
virtual ? XmlNode FirstChild
Definition XmlNode.cs:120