Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ SchemaTree() [2/2]

void System.Data.XmlTreeGen.SchemaTree ( XmlDocument xd,
XmlWriter xmlWriter,
DataSet ds,
DataTable dt,
bool writeHierarchy )
inlinepackage

Definition at line 496 of file XmlTreeGen.cs.

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 }
668 DataRelation[] array2 = Array.Empty<DataRelation>();
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 {
679 CreateRelations((DataTable)_tables[0]);
680 array2 = new DataRelation[_relations.Count];
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 }
virtual int Add(object? value)
virtual void CopyTo(Array array)
virtual ICollection Keys
Definition Hashtable.cs:532
PropertyCollection _extendedProperties
Definition DataSet.cs:61
XmlElement FillDataSetElement(XmlDocument xd, DataSet ds, DataTable dt)
void SetupAutoGenerated(DataSet ds)
readonly ArrayList _tables
Definition XmlTreeGen.cs:26
void AddXdoProperties(object instance, XmlElement root, XmlDocument xd)
Definition XmlTreeGen.cs:83
DataTable[] CreateToplevelTables()
XmlElement HandleRelation(DataRelation rel, XmlDocument dc)
readonly SchemaFormat _schFormat
Definition XmlTreeGen.cs:36
void AppendChildWithoutRef(XmlElement node, string Namespace, XmlElement el, string refString)
ArrayList _constraintNames
Definition XmlTreeGen.cs:16
void WriteSchemaRoot(XmlDocument xd, XmlElement rootSchema, string targetNamespace)
static void AddExtendedProperties(PropertyCollection props, XmlElement node)
Definition XmlTreeGen.cs:55
void CreateRelations(DataTable dt)
XmlElement _constraintSeparator
Definition XmlTreeGen.cs:46
void GenerateConstraintNames(DataTable table, bool fromTable)
readonly ArrayList _relations
Definition XmlTreeGen.cs:28
XmlElement HandleTable(DataTable table, XmlDocument dc, XmlElement schema)
void CreateTablesHierarchy(DataTable dt)
static CultureInfo InvariantCulture
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 RemoveChild(XmlNode oldChild)
Definition XmlNode.cs:662

References System.Data.DataSet.DataSet(), System.Data.XmlTreeGen._autogenerated, System.Data.XmlTreeGen._constraintNames, System.Data.XmlTreeGen._constraintSeparator, System.Data.XmlTreeGen._dc, System.Data.XmlTreeGen._ds, System.Data.XmlTreeGen._dsElement, System.Data.DataSet._extendedProperties, System.Data.XmlTreeGen._fileExt, System.Data.XmlTreeGen._fileName, System.Data.XmlTreeGen._filePath, System.Data.XmlTreeGen._namespaces, System.Data.XmlTreeGen._prefixes, System.Data.XmlTreeGen._relations, System.Data.XmlTreeGen._schFormat, System.Data.XmlTreeGen._sRoot, System.Data.XmlTreeGen._tables, System.Collections.ArrayList.Add(), System.Data.XmlTreeGen.AddExtendedProperties(), System.Data.XmlTreeGen.AddXdoProperties(), System.Xml.XmlNode.AppendChild(), System.Data.XmlTreeGen.AppendChildWithoutRef(), System.array, System.Collections.ArrayList.CopyTo(), System.Collections.ArrayList.Count, System.Collections.Hashtable.Count, System.Xml.XmlDocument.CreateElement(), System.Data.XmlTreeGen.CreateRelations(), System.Data.XmlTreeGen.CreateTablesHierarchy(), System.Data.XmlTreeGen.CreateToplevelTables(), System.Data.DataSet.DataSetName, System.Xml.Dictionary, System.Xml.XmlConvert.EncodeLocalName(), System.Data.XmlTreeGen.FillDataSetElement(), System.Data.XmlTreeGen.GenerateConstraintNames(), System.Data.XmlTreeGen.HandleRelation(), System.Data.XmlTreeGen.HandleTable(), System.Globalization.CultureInfo.InvariantCulture, System.key, System.Collections.Hashtable.Keys, System.Data.DataSet.Namespace, System.Xml.XmlNode.PrependChild(), System.Xml.XmlNode.RemoveChild(), System.Xml.XmlDocument.Save(), System.Xml.XmlElement.SetAttribute(), System.Data.XmlTreeGen.SetupAutoGenerated(), System.ToString, System.Data.XmlTreeGen.WriteSchemaRoot(), System.Xml.XmlWriter.WriteStartDocument(), and System.Xml.XmlDocument.WriteTo().

Referenced by System.Data.XmlTreeGen.Save(), and System.Data.XmlTreeGen.Save().