Datei: ClassGenerator/NodeEntities/Database.cs

Last Commit (50beab8)
1 //
2 // Copyright (c) 2002-2016 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.Data;
 
25 using System.Xml;
26 using System.Windows.Forms;
27 using ClassGenerator.AssemblyWizard;
28 using ClassGenerator.SchemaAnalyzer;
29 using NDOInterfaces;
30 using NDO;
31 using System.Text;
32
33 namespace ClassGenerator
34 {
35 ····/// <summary>
36 ····/// Zusammenfassung für Database.
37 ····/// </summary>
38 ····[Serializable]
39 #if DEBUG
40 ····public class Database : IXmlStorable
41 #else
42 ····internal class Database : IXmlStorable
43 #endif
44 ····{
45 ········public Database(AssemblyWizModel model)
46 ········{
47 ············this.connectionString = model.ConnectionString;
48 ············this.connectionType = model.ConnectionType;
49 ············this.ownerName = model.OwnerName;
50 ············this.xmlSchemaFile = model.XmlSchemaFile;
51 ············this.isXmlSchema = model.IsXmlSchema;
52 ············try
53 ············{
54 ················if ( this.isXmlSchema )
55 ················{
56 ····················XsdAnalyzer analyzer = new XsdAnalyzer();
57 ····················this.dataSet = analyzer.Analyze( this.xmlSchemaFile );
58 ····················if (analyzer.ValidationMessages.Count > 0)
59 ····················{
60 ························StringBuilder sb = new StringBuilder();
61 ························foreach (string s in analyzer.ValidationMessages)
62 ························{
63 ····························sb.Append(s);
64 ····························sb.Append("\r\n");
65 ························}
66 ························new ShowWarningsDlg(sb.ToString()).ShowDialog();
67 ····················}
68 ················}
69 ················else
70 ················{
71 ····················if ( string.IsNullOrEmpty( this.connectionString ) )
72 ····················{
73 ························this.dataSet = new DataSet();
74 ····················}
75 ····················else
76 ····················{
77 ························IProvider provider = NDOProviderFactory.Instance[this.connectionType];
78 ························if ( provider == null )
79 ····························throw new Exception( "Can't find NDO provider '" + this.connectionType + "'" );
80
81 IDbConnection conn = provider. NewConnection( this. connectionString ) ;
82 ························conn.Open();
83 ························try
84 ························{
85 ····························this.dataSet = provider.GetDatabaseStructure( conn, null );
86 ························}
87 ························catch ( Exception ex )
88 ························{
89 ····························throw ex;
90 ························}
91 ························finally
92 ························{
93 ····························conn.Close();
94 ························}
95 ····················}
96 ················}
97 ············}
98 ············catch ( Exception ex )
99 ············{
100 ················MessageBox.Show("Can't convert the schema into a dataset. Error Message: " + ex.ToString());
101 ············}
102 ········}
103
104 ········/// <summary>
105 ········/// For serialization only
106 ········/// </summary>
107 ········public Database(){}
108
109 ········DataSet dataSet;
110 ········public DataSet DataSet
111 ········{
112 ············get { return this.dataSet; }
113 ········}
114
115 ········string xmlSchemaFile;
116 ········public string XmlSchemaFile
117 ········{
118 ············get { return this.xmlSchemaFile; }
119 ········}
120 ········bool isXmlSchema;
121 ········public bool IsXmlSchema
122 ········{
123 ············get { return this.isXmlSchema; }
124 ········}
125 ········string connectionString;
126 ········public string ConnectionString
127 ········{
128 ············get { return this.connectionString; }
129 ········}
130 ········string connectionType;
131 ········public string ConnectionType
132 ········{
133 ············get { return this.connectionType; }
134 ········}
135 ········string ownerName;
136 ········public string OwnerName
137 ········{
138 ············get { return this.ownerName; }
139 ········}
140 ········#region IXmlStorable Member
141
142 ········public void ToXml(XmlElement element)
143 ········{
144 ············element.SetAttribute("ConnectionString", this.connectionString);
145 ············element.SetAttribute("ConnectionType", this.connectionType);
146 ············element.SetAttribute("OwnerName", this.ownerName);
147 ········}
148
149 ········public void FromXml(XmlElement element)
150 ········{
151 ············this.connectionString = element.Attributes["ConnectionString"].Value;
152 ············this.connectionType = element.Attributes["ConnectionType"].Value;
153 ············this.ownerName = element.Attributes["OwnerName"].Value;············
154 ········}
155
156 ········#endregion
157 ····}
158 }
159
New Commit (74c26c3)
1 //
2 // Copyright (c) 2002-2016 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.Data;
25 using System.Data.Common;
26 using System.Xml;
27 using System.Windows.Forms;
28 using ClassGenerator.AssemblyWizard;
29 using ClassGenerator.SchemaAnalyzer;
30 using NDOInterfaces;
31 using NDO;
32 using System.Text;
33
34 namespace ClassGenerator
35 {
36 ····/// <summary>
37 ····/// Zusammenfassung für Database.
38 ····/// </summary>
39 ····[Serializable]
40 #if DEBUG
41 ····public class Database : IXmlStorable
42 #else
43 ····internal class Database : IXmlStorable
44 #endif
45 ····{
46 ········public Database(AssemblyWizModel model)
47 ········{
48 ············this.connectionString = model.ConnectionString;
49 ············this.connectionType = model.ConnectionType;
50 ············this.ownerName = model.OwnerName;
51 ············this.xmlSchemaFile = model.XmlSchemaFile;
52 ············this.isXmlSchema = model.IsXmlSchema;
53 ············try
54 ············{
55 ················if ( this.isXmlSchema )
56 ················{
57 ····················XsdAnalyzer analyzer = new XsdAnalyzer();
58 ····················this.dataSet = analyzer.Analyze( this.xmlSchemaFile );
59 ····················if (analyzer.ValidationMessages.Count > 0)
60 ····················{
61 ························StringBuilder sb = new StringBuilder();
62 ························foreach (string s in analyzer.ValidationMessages)
63 ························{
64 ····························sb.Append(s);
65 ····························sb.Append("\r\n");
66 ························}
67 ························new ShowWarningsDlg(sb.ToString()).ShowDialog();
68 ····················}
69 ················}
70 ················else
71 ················{
72 ····················if ( string.IsNullOrEmpty( this.connectionString ) )
73 ····················{
74 ························this.dataSet = new DataSet();
75 ····················}
76 ····················else
77 ····················{
78 ························IProvider provider = NDOProviderFactory.Instance[this.connectionType];
79 ························if ( provider == null )
80 ····························throw new Exception( "Can't find NDO provider '" + this.connectionType + "'" );
81
82 DbConnection conn = provider. NewConnection( this. connectionString ) ;
83 ························conn.Open();
84 ························try
85 ························{
86 ····························this.dataSet = provider.GetDatabaseStructure( conn, null );
87 ························}
88 ························catch ( Exception ex )
89 ························{
90 ····························throw ex;
91 ························}
92 ························finally
93 ························{
94 ····························conn.Close();
95 ························}
96 ····················}
97 ················}
98 ············}
99 ············catch ( Exception ex )
100 ············{
101 ················MessageBox.Show("Can't convert the schema into a dataset. Error Message: " + ex.ToString());
102 ············}
103 ········}
104
105 ········/// <summary>
106 ········/// For serialization only
107 ········/// </summary>
108 ········public Database(){}
109
110 ········DataSet dataSet;
111 ········public DataSet DataSet
112 ········{
113 ············get { return this.dataSet; }
114 ········}
115
116 ········string xmlSchemaFile;
117 ········public string XmlSchemaFile
118 ········{
119 ············get { return this.xmlSchemaFile; }
120 ········}
121 ········bool isXmlSchema;
122 ········public bool IsXmlSchema
123 ········{
124 ············get { return this.isXmlSchema; }
125 ········}
126 ········string connectionString;
127 ········public string ConnectionString
128 ········{
129 ············get { return this.connectionString; }
130 ········}
131 ········string connectionType;
132 ········public string ConnectionType
133 ········{
134 ············get { return this.connectionType; }
135 ········}
136 ········string ownerName;
137 ········public string OwnerName
138 ········{
139 ············get { return this.ownerName; }
140 ········}
141 ········#region IXmlStorable Member
142
143 ········public void ToXml(XmlElement element)
144 ········{
145 ············element.SetAttribute("ConnectionString", this.connectionString);
146 ············element.SetAttribute("ConnectionType", this.connectionType);
147 ············element.SetAttribute("OwnerName", this.ownerName);
148 ········}
149
150 ········public void FromXml(XmlElement element)
151 ········{
152 ············this.connectionString = element.Attributes["ConnectionString"].Value;
153 ············this.connectionType = element.Attributes["ConnectionType"].Value;
154 ············this.ownerName = element.Attributes["OwnerName"].Value;············
155 ········}
156
157 ········#endregion
158 ····}
159 }
160