public static XS__diagram[] Load_fromURI( XS__RootMetadata root_ref_in, params Uri[] filePath_in ) { XS__diagram[] _output = new XS__diagram[filePath_in.Length]; for (int i = 0; i < filePath_in.Length; i++) { if (filePath_in[i].IsFile) { _output[i] = XS__diagram.Load_fromFile( filePath_in[i].LocalPath )[0]; // no need! everything's been taken care at: XS__diagram.Load_fromFile(...) //_output[i].root_diagram_ = ROOT + "." + DIAGRAM + "[" + i + "]"; //_output[i].parent_ref = root_ref_in; // ToDos: now! //if (root_ref_in != null) _output[i].root_ref = root_ref_in; } else { try { _output[i] = (XS__diagram) new XmlSerializer(typeof(XS__diagram)).Deserialize( OGen.Libraries.PresentationLayer.WebForms.Utilities.ReadURL( filePath_in[i].ToString() ) ); } catch (Exception _ex) { throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "\n---\n{0}.{1}.Load_fromURI():\nERROR READING XML:\n{2}\n---\n{3}", typeof(XS__diagram).Namespace, typeof(XS__diagram).Name, //(filePath_in[i].IsFile) // ? filePath_in[i].LocalPath // : filePath_in[i].ToString(), _ex.Message )); } _output[i].root_diagram_ = ROOT + "." + DIAGRAM + "[" + i + "]"; _output[i].parent_ref = root_ref_in; // ToDos: now! if (root_ref_in != null) { _output[i].root_ref = root_ref_in; } } } return(_output); }
public XS__RootMetadata( #endif string metadataFilepath_in ) { string _metadataPath = System.IO.Path.GetDirectoryName(metadataFilepath_in); metadatafiles_ = Metadatas.Load_fromFile(metadataFilepath_in); #region int _total_xxx = ...; int _total_diagram = 0; for (int f = 0; f < metadatafiles_.MetadataFiles.Count; f++) { switch (metadatafiles_.MetadataFiles[f].XMLFileType) { case XS__diagram.DIAGRAM: _total_diagram++; break; } } #endregion #region string[] _xxxFilepath = new string[_total_xxx]; string[] _diagramFilepath = new string[ _total_diagram ]; #endregion _total_diagram = 0; for (int f = 0; f < metadatafiles_.MetadataFiles.Count; f++) { switch (metadatafiles_.MetadataFiles[f].XMLFileType) { case XS__diagram.DIAGRAM: _diagramFilepath[_total_diagram] = System.IO.Path.Combine( _metadataPath, metadatafiles_.MetadataFiles[f].XMLFilename ); _total_diagram++; break; } } diagramcollection_ = new XS__diagramCollection( XS__diagram.Load_fromFile( (XS__RootMetadata)this, _diagramFilepath ) ); }
// public void New( // string applicationPath_in, // string documentationName_in, // dNotifyBack notifyBack_in // ) { // if (notifyBack_in != null) notifyBack_in("creating...", true); // #region DocMetadata _metadata_temp = new DocMetadata(); ...; // XS__documentation _metadata_temp = new XS__documentation(); // _metadata_temp.DocumentationName = documentationName_in; // #endregion // // if (notifyBack_in != null) notifyBack_in("- generating xml file", true); // #region string _xmlfile = ...; // string _xmlfile = string.Format( // "{0}{1}OGenDoc-metadatas{1}MD_{2}.OGenDoc-metadata.xml", // /*0*/applicationPath_in, // /*1*/System.IO.Path.DirectorySeparatorChar, // /*2*/documentationName_in // ); // #endregion // _metadata_temp.SaveState_toFile(_xmlfile); // // if (notifyBack_in != null) notifyBack_in("... finished!", true); // if (notifyBack_in != null) notifyBack_in("", true); // // Open( // _xmlfile, // true, // notifyBack_in // ); // } #endregion #region public void Open(...); public void Open( string filename_in, bool force_doNOTsave_in, dNotifyBack notifyBack_in ) { #region Checking... if (this.hasChanges) { if (!force_doNOTsave_in) { throw new Exception(string.Format( "{0}.{1}.Open(): - must save before open", this.GetType().Namespace, this.GetType().Name )); } } #endregion filename_ = filename_in; if (notifyBack_in != null) { notifyBack_in("opening...", true); } if (notifyBack_in != null) { notifyBack_in("- reading metadata from xml file", true); } diagram_ = XS__diagram.Load_fromFile( filename_ )[0]; diagram_.FilePath = filename_; if (notifyBack_in != null) { notifyBack_in("... finished", true); } }
//#endregion #region public Methods... #region //public void New(...); // public void New( // string applicationPath_in, // string documentationName_in, // dNotifyBack notifyBack_in // ) { // if (notifyBack_in != null) notifyBack_in("creating...", true); // #region DocMetadata _metadata_temp = new DocMetadata(); ...; // XS__documentation _metadata_temp = new XS__documentation(); // _metadata_temp.DocumentationName = documentationName_in; // #endregion // // if (notifyBack_in != null) notifyBack_in("- generating xml file", true); // #region string _xmlfile = ...; // string _xmlfile = string.Format( // System.Globalization.CultureInfo.CurrentCulture, // "{0}{1}OGenDoc-metadatas{1}MD_{2}.OGenDoc-metadata.xml", // /*0*/applicationPath_in, // /*1*/System.IO.Path.DirectorySeparatorChar, // /*2*/documentationName_in // ); // #endregion // _metadata_temp.SaveState_toFile(_xmlfile); // // if (notifyBack_in != null) notifyBack_in("... finished!", true); // if (notifyBack_in != null) notifyBack_in("", true); // // Open( // _xmlfile, // true, // notifyBack_in // ); // } #endregion #region public void Open(...); public void Open( string fileName_in, bool force_doNOTSave_in, OGen.Dia.Libraries.Generator.NotifyBack notifyBack_in ) { #region Checking... if (this.HasChanges) { if (!force_doNOTSave_in) { throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "{0}.{1}.Open(): - must save before open", this.GetType().Namespace, this.GetType().Name )); } } #endregion this.filename_ = fileName_in; if (notifyBack_in != null) { notifyBack_in("opening...", true); } if (notifyBack_in != null) { notifyBack_in("- reading metadata from xml file", true); } this.diagram_ = XS__diagram.Load_fromFile( this.filename_ )[0]; this.diagram_.FilePath = this.filename_; if (notifyBack_in != null) { notifyBack_in("... finished", true); } #region more Checking... if (notifyBack_in != null) { notifyBack_in("checking...", true); } OGen.Libraries.DataLayer.PostgreSQL.DBUtilities_convert_Postgresql _utilities_pgsql = new OGen.Libraries.DataLayer.PostgreSQL.DBUtilities_convert_Postgresql(); OGen.Libraries.DataLayer.SQLServer.DBUtilities_convert_SQLServer _utilities_sqls = new OGen.Libraries.DataLayer.SQLServer.DBUtilities_convert_SQLServer(); System.Data.DbType?_dbtype_psql; System.Data.DbType?_dbtype_sqls; bool _isUsingPostgreSQL = false; bool _isUsingSQLServer = false; DBTableField[] _dbtablefields; DBTableField[] _dbtablefields2; OGen.Dia.Libraries.Metadata.Diagram.ForeignKey[] __fks; System.Collections.Generic.Dictionary <string, OGen.Dia.Libraries.Metadata.Diagram.ForeignKey> _fks; bool _foundFKTable; bool _foundFKField; for (int l = 0; l < this.diagram_.LayerCollection.Count; l++) { for (int o = 0; o < this.diagram_.LayerCollection[l].ObjectCollection.Count; o++) { _dbtablefields = this.diagram_.Table_search(l, o).TableFields(); this.diagram_.Table_search(l, o).TableForeignKeys( out __fks, out _fks ); #region checking for invalid foreign keys if ( _fks.ContainsKey("") ) { throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "invalid foreign key at table: {0}.? -> {1}.?", this.diagram_.Table_search(l, o).TableName, _fks[""].ForeignKey_TableName )); } #endregion #region _isUsingPostgreSQL = ...; _isUsingSQLServer = ...; for (int f = 0; f < _dbtablefields.Length; f++) { if (!string.IsNullOrEmpty(_dbtablefields[f].PostgreSQLTypeName)) { _isUsingPostgreSQL = true; } if (!string.IsNullOrEmpty(_dbtablefields[f].SQLServerTypeName)) { _isUsingSQLServer = true; } if ( _isUsingPostgreSQL && _isUsingSQLServer ) { break; } } #endregion for (int f = 0; f < _dbtablefields.Length; f++) { #region checking if db server type supported if ( !_isUsingPostgreSQL && !_isUsingSQLServer ) { throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "no db type defined (should use at least one of the supported db servers: PostgreSQL or SQLServer)", _dbtablefields[f].TableName, _dbtablefields[f].Name )); } #endregion #region checking postgresql field type . . . _dbtype_psql = null; if ( _isUsingPostgreSQL ) { if (string.IsNullOrEmpty(_dbtablefields[f].PostgreSQLTypeName)) { throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "invalid table field type - empty postgresql type: {0}.{1}", _dbtablefields[f].TableName, _dbtablefields[f].Name )); } _dbtype_psql = _utilities_pgsql.XDbType2DbType( _utilities_pgsql.XDbType_Parse( _dbtablefields[f].PostgreSQLTypeName, false ) ); } #endregion #region checking sql server field type . . . _dbtype_sqls = null; if ( _isUsingSQLServer ) { if (string.IsNullOrEmpty(_dbtablefields[f].SQLServerTypeName)) { throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "invalid table field type - empty sql server type: {0}.{1}", _dbtablefields[f].TableName, _dbtablefields[f].Name )); } _dbtype_sqls = _utilities_sqls.XDbType2DbType( _utilities_sqls.XDbType_Parse( _dbtablefields[f].SQLServerTypeName, false ) ); } #endregion #region checking if field types match . . . if ( _isUsingPostgreSQL && _isUsingSQLServer ) { if ( (_dbtype_psql == null) || (_dbtype_sqls == null) || ( _dbtype_psql.Value != _dbtype_sqls.Value ) ) { throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "table field types don't match: {0}.{1}", _dbtablefields[f].TableName, _dbtablefields[f].Name )); } } #endregion #region //checking FKs . . . //if ( // (_dbtablefields[f].ForeignKey_TableName != null) // && // (_dbtablefields[f].ForeignKey_TableName.Trim() != "") //) { // _foundFKTable = false; // _foundFKField = false; // for (int l2 = 0; l2 < diagram_.LayerCollection.Count; l2++) { // for (int o2 = 0; o2 < diagram_.LayerCollection[l2].ObjectCollection.Count; o2++) { // if ( // diagram_.Table_search(l2, o2).TableName // == // _dbtablefields[f].ForeignKey_TableName // ) { // _dbtablefields2 = diagram_.Table_search(l2, o2).TableFields(); // for (int f2 = 0; f2 < _dbtablefields2.Length; f2++) { // if ( // _dbtablefields2[f2].Name // == // _dbtablefields[f].ForeignKey_TableFieldName // ) { // if ( // _dbtablefields2[f2].PostgreSQLTypeName // != // _dbtablefields[f].PostgreSQLTypeName // ) { // throw new Exception(string.Format( // System.Globalization.CultureInfo.CurrentCulture, // "foreign key postgresql db type mismatch: {0}.{1}", // _dbtablefields[f].ForeignKey_TableName, // _dbtablefields[f].ForeignKey_TableFieldName // )); // } // if ( // _dbtablefields2[f2].SQLServerTypeName // != // _dbtablefields[f].SQLServerTypeName // ) { // throw new Exception(string.Format( // System.Globalization.CultureInfo.CurrentCulture, // "foreign key sql server db type mismatch: {0}.{1}", // _dbtablefields[f].ForeignKey_TableName, // _dbtablefields[f].ForeignKey_TableFieldName // )); // } // _foundFKField = true; // break; // } // } // _foundFKTable = true; // break; // } // } // } // if (!_foundFKTable) { // throw new Exception(string.Format( // System.Globalization.CultureInfo.CurrentCulture, // "can't find foreign key TABLE: {0}.{1}", // _dbtablefields[f].ForeignKey_TableName, // _dbtablefields[f].ForeignKey_TableFieldName // )); // } // if (!_foundFKField) { // throw new Exception(string.Format( // System.Globalization.CultureInfo.CurrentCulture, // "can't find foreign key FIELD: {0}.{1}", // _dbtablefields[f].ForeignKey_TableName, // _dbtablefields[f].ForeignKey_TableFieldName // )); // } //} #endregion #region checking FKs . . . if ( _fks.ContainsKey( _dbtablefields[f].Name ) ) { _foundFKTable = false; _foundFKField = false; for (int l2 = 0; l2 < this.diagram_.LayerCollection.Count; l2++) { for (int o2 = 0; o2 < this.diagram_.LayerCollection[l2].ObjectCollection.Count; o2++) { if ( this.diagram_.Table_search(l2, o2).TableName == _fks[_dbtablefields[f].Name].ForeignKey_TableName ) { _dbtablefields2 = this.diagram_.Table_search(l2, o2).TableFields(); for (int f2 = 0; f2 < _dbtablefields2.Length; f2++) { if ( _dbtablefields2[f2].Name == _fks[_dbtablefields[f].Name].ForeignKey_TableFieldName ) { if ( ( (_dbtablefields2[f2].PostgreSQLTypeName == null) != (_dbtablefields[f].PostgreSQLTypeName == null) ) || ( //_dbtablefields2[f2].PostgreSQLTypeName //!= //_dbtablefields[f].PostgreSQLTypeName !( (_dbtablefields2[f2].PostgreSQLTypeName == _dbtablefields[f].PostgreSQLTypeName) || ( (_dbtablefields2[f2].PostgreSQLTypeName == "serial") && (_dbtablefields[f].PostgreSQLTypeName == "integer") ) || ( (_dbtablefields[f].PostgreSQLTypeName == "serial") && (_dbtablefields2[f2].PostgreSQLTypeName == "integer") ) || ( (_dbtablefields2[f2].PostgreSQLTypeName == "bigserial") && (_dbtablefields[f].PostgreSQLTypeName == "bigint") ) || ( (_dbtablefields[f].PostgreSQLTypeName == "bigserial") && (_dbtablefields2[f2].PostgreSQLTypeName == "bigint") ) ) ) ) { throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "foreign key postgresql db type mismatch: {0}.{1} -> {2}.{3}", this.diagram_.Table_search(l, o).TableName, _dbtablefields[f].Name, _fks[_dbtablefields[f].Name].ForeignKey_TableName, _fks[_dbtablefields[f].Name].ForeignKey_TableFieldName )); } if ( ( (_dbtablefields2[f2].SQLServerTypeName == null) != (_dbtablefields[f].SQLServerTypeName == null) ) || ( _dbtablefields2[f2].SQLServerTypeName != _dbtablefields[f].SQLServerTypeName ) ) { throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "foreign key sql server db type mismatch: {0}.{1} -> {2}.{3}", this.diagram_.Table_search(l, o).TableName, _dbtablefields[f].Name, _fks[_dbtablefields[f].Name].ForeignKey_TableName, _fks[_dbtablefields[f].Name].ForeignKey_TableFieldName )); } _foundFKField = true; break; } } _foundFKTable = true; break; } } } if (!_foundFKTable) { throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "can't find foreign key TABLE: {0}.{1} -> {2}.{3}", this.diagram_.Table_search(l, o).TableName, _dbtablefields[f].Name, _fks[_dbtablefields[f].Name].ForeignKey_TableName, _fks[_dbtablefields[f].Name].ForeignKey_TableFieldName )); } if (!_foundFKField) { throw new Exception(string.Format( System.Globalization.CultureInfo.CurrentCulture, "can't find foreign key FIELD: {0}.{1} -> {2}.{3}", this.diagram_.Table_search(l, o).TableName, _dbtablefields[f].Name, _fks[_dbtablefields[f].Name].ForeignKey_TableName, _fks[_dbtablefields[f].Name].ForeignKey_TableFieldName )); } } #endregion } } } if (notifyBack_in != null) { notifyBack_in("... finished", true); } #endregion }
static void Main(string[] args) { XS__diagram _dia = XS__diagram.Load_fromFile( @"X:\test\modeloDados.dia" )[0]; for (int l = 0; l < _dia.LayerCollection.Count; l++) { for (int o = 0; o < _dia.LayerCollection[l].ObjectCollection.Count; o++) { switch (_dia.LayerCollection[l].ObjectCollection[o].Type) { case "Database - Table": for (int a = 0; a < _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection.Count; a++) { switch (_dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].Name) { case "name": Console.WriteLine( "table-name: {0} ('{1}')", _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].String, _dia.LayerCollection[l].ObjectCollection[o].Id ); break; case "comment": Console.WriteLine("table-comments: {0}", _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].String); break; case "attributes": for (int c = 0; c < _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].CompositeCollection.Count; c++) { switch (_dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].CompositeCollection[c].Type) { case "table_attribute": for (int aa = 0; aa < _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].CompositeCollection[c].AttributeCollection.Count; aa++) { switch (_dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].CompositeCollection[c].AttributeCollection[aa].Name) { case "name": Console.WriteLine("\tfield-name: {0}", _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].CompositeCollection[c].AttributeCollection[aa].String); break; case "type": Console.WriteLine("\tfield-type: {0}", _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].CompositeCollection[c].AttributeCollection[aa].String); break; case "comment": Console.WriteLine("\tfield-comments: {0}", _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].CompositeCollection[c].AttributeCollection[aa].String); break; case "primary_key": Console.WriteLine("\tfield-pk: {0}", _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].CompositeCollection[c].AttributeCollection[aa].Boolean.Val); break; case "nullable": Console.WriteLine("\tfield-nullable: {0}", _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].CompositeCollection[c].AttributeCollection[aa].Boolean.Val); break; case "unique": Console.WriteLine("\tfield-unique: {0}", _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].CompositeCollection[c].AttributeCollection[aa].Boolean.Val); break; default: break; } } break; } } break; } } break; case "UML - Association": if (_dia.LayerCollection[l].ObjectCollection[o].Connections.ConnectionCollection.Count != 2) { break; } for (int a = 0; a < _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection.Count; a++) { switch (_dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].Name) { case "role_a": Console.WriteLine( "ROLE_A: {0}.{1}", _dia.LayerCollection[l].ObjectCollection[o].Connections.ConnectionCollection[0].To, _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].String ); break; case "role_b": Console.WriteLine( "ROLE_B: {0}.{1}", _dia.LayerCollection[l].ObjectCollection[o].Connections.ConnectionCollection[1].To, _dia.LayerCollection[l].ObjectCollection[o].AttributeCollection[a].String ); break; } } break; } } } }