Datei: NDOPackage/Connection.cs
Last Commit (33e9857)
1 | // |
2 | // Copyright ( c) 2002-2019 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.Collections.Generic; |
25 | using System.ComponentModel; |
26 | using System.Linq; |
27 | using System.Text; |
28 | using System.Xml.Linq; |
29 | |
30 | namespace NDOVsPackage |
31 | { |
32 | ····/// <summary> |
33 | ····/// This class encapsulates a connection string and makes it available with a short ID. |
34 | ····/// </summary> |
35 | ····/// <remarks>This class is equivalent to the Connection element in the mapping file schema.</remarks> |
36 | ····public class Connection |
37 | ····{ |
38 | ········public const string DummyConnectionString = "Substitute this string with your connection string"; |
39 | ········XElement xElement; |
40 | |
41 | ········private string iD = ""; |
42 | ········/// <summary> |
43 | ········/// Gets or sets the ID, with which the connection is referenced in the Class objects. |
44 | ········/// </summary> |
45 | ········[Description("The ID, with which the connection is referenced in the Class objects.")] |
46 | ········public string ID |
47 | ········{ |
48 | ············get { return iD; } |
49 | ············set { iD = value; } |
50 | ········} |
51 | ········private string name = ""; |
52 | ········/// <summary> |
53 | ········/// Gets or sets the connection string. |
54 | ········/// </summary> |
55 | ········[Description("The connection string.")] |
56 | ········public string Name |
57 | ········{ |
58 | ············get { return name; } |
59 | ············set { name = value; } |
60 | ········} |
61 | ········private string type = "Sql"; |
62 | |
63 | ········/// <summary> |
64 | ········/// Gets or sets the provider type string. |
65 | ········/// </summary> |
66 | ········/// <remarks> |
67 | ········/// This string sould match the Name property of a |
68 | ········/// provider registered in the NDOProviderFactory. |
69 | ········/// <seealso cref="NDOProviderFactory"/> |
70 | ········/// </remarks> |
71 | ········[Description("The provider type string.")] |
72 | ········public string Type |
73 | ········{ |
74 | ············get { return type; } |
75 | ············set { type = value; } |
76 | ········} |
77 | |
78 | ········/// <summary> |
79 | ········/// Construct a Connection object based on a Connection node of the mapping file. |
80 | ········/// </summary> |
81 | ········/// <param name="connNode">Connection node</param> |
82 | ········/// <param name="parent">An object of type NDOMapping, which is the parent of the connection object.</param> |
83 | ········internal Connection(XElement connNode)············ |
84 | ········{ |
85 | ············this.xElement = connNode; |
86 | ············name = connNode.Attribute("Name").Value; |
87 | ············iD = connNode.Attribute("ID").Value; |
88 | ············type = connNode.Attribute("Type").Value; |
89 | ············if (String.IsNullOrEmpty( name )) |
90 | ············{ |
91 | ················name = DummyConnectionString; |
92 | ············} |
93 | ············if (String.IsNullOrEmpty(type)) |
94 | ············{ |
95 | ················type = "SqlServer"; |
96 | ············} |
97 | ············if (String.IsNullOrEmpty(iD)) |
98 | ············{ |
99 | ················iD = "C0"; |
100 | ············} |
101 | ········} |
102 | |
103 | ········/// <summary> |
104 | ········/// Saves the Connection object as a Connection node. Don't use that funktion directly, |
105 | ········/// it will be called by the Save function of the NDOMapping class. |
106 | ········/// </summary> |
107 | ········/// <param name="parentNode">The parent node</param>········ |
108 | ········internal void Save() |
109 | ········{ |
110 | ············xElement.Attribute("ID").Value = iD.ToString(); |
111 | ············xElement.Attribute("Name").Value = name; |
112 | ············xElement.Attribute("Type").Value = type;············ |
113 | ········} |
114 | |
115 | ········/// <summary> |
116 | ········/// String representation of the Connection object |
117 | ········/// </summary> |
118 | ········/// <returns>The connection string</returns> |
119 | ········public override string ToString() |
120 | ········{ |
121 | ············return Name; |
122 | ········} |
123 | ····} |
124 | |
125 | } |
126 | } |
127 | ····} |
128 | |
129 | } |
130 |
New Commit (aa458ff)
1 | // |
2 | // Copyright ( c) 2002-2022 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.Collections.Generic; |
25 | using System.ComponentModel; |
26 | using System.Linq; |
27 | using System.Text; |
28 | using System.Xml.Linq; |
29 | |
30 | namespace NDOVsPackage |
31 | { |
32 | ····/// <summary> |
33 | ····/// This class encapsulates a connection string and makes it available with a short ID. |
34 | ····/// </summary> |
35 | ····/// <remarks>This class is equivalent to the Connection element in the mapping file schema.</remarks> |
36 | ····public class Connection |
37 | ····{ |
38 | ········public const string DummyConnectionString = "Substitute this string with your connection string"; |
39 | ········XElement xElement; |
40 | |
41 | ········private string iD = ""; |
42 | ········/// <summary> |
43 | ········/// Gets or sets the ID, with which the connection is referenced in the Class objects. |
44 | ········/// </summary> |
45 | ········[Description("The ID, with which the connection is referenced in the Class objects.")] |
46 | ········public string ID |
47 | ········{ |
48 | ············get { return iD; } |
49 | ············set { iD = value; } |
50 | ········} |
51 | ········private string name = ""; |
52 | ········/// <summary> |
53 | ········/// Gets or sets the connection string. |
54 | ········/// </summary> |
55 | ········[Description("The connection string.")] |
56 | ········public string Name |
57 | ········{ |
58 | ············get { return name; } |
59 | ············set { name = value; } |
60 | ········} |
61 | ········private string type = "Sql"; |
62 | |
63 | ········/// <summary> |
64 | ········/// Gets or sets the provider type string. |
65 | ········/// </summary> |
66 | ········/// <remarks> |
67 | ········/// This string sould match the Name property of a |
68 | ········/// provider registered in the NDOProviderFactory. |
69 | ········/// <seealso cref="NDOProviderFactory"/> |
70 | ········/// </remarks> |
71 | ········[Description("The provider type string.")] |
72 | ········public string Type |
73 | ········{ |
74 | ············get { return type; } |
75 | ············set { type = value; } |
76 | ········} |
77 | |
78 | ········/// <summary> |
79 | ········/// Construct a Connection object based on a Connection node of the mapping file. |
80 | ········/// </summary> |
81 | ········/// <param name="connNode">Connection node</param> |
82 | ········/// <param name="parent">An object of type NDOMapping, which is the parent of the connection object.</param> |
83 | ········internal Connection(XElement connNode)············ |
84 | ········{ |
85 | ············this.xElement = connNode; |
86 | ············name = connNode.Attribute("Name").Value; |
87 | ············iD = connNode.Attribute("ID").Value; |
88 | ············type = connNode.Attribute("Type").Value; |
89 | ············if (String.IsNullOrEmpty( name )) |
90 | ············{ |
91 | ················name = DummyConnectionString; |
92 | ············} |
93 | ············if (String.IsNullOrEmpty(type)) |
94 | ············{ |
95 | ················type = "SqlServer"; |
96 | ············} |
97 | ············if (String.IsNullOrEmpty(iD)) |
98 | ············{ |
99 | ················iD = "C0"; |
100 | ············} |
101 | ········} |
102 | |
103 | ········/// <summary> |
104 | ········/// Saves the Connection object as a Connection node. Don't use that funktion directly, |
105 | ········/// it will be called by the Save function of the NDOMapping class. |
106 | ········/// </summary> |
107 | ········/// <param name="parentNode">The parent node</param>········ |
108 | ········internal void Save() |
109 | ········{ |
110 | ············xElement.Attribute("ID").Value = iD.ToString(); |
111 | ············xElement.Attribute("Name").Value = name; |
112 | ············xElement.Attribute("Type").Value = type;············ |
113 | ········} |
114 | |
115 | ········/// <summary> |
116 | ········/// String representation of the Connection object |
117 | ········/// </summary> |
118 | ········/// <returns>The connection string</returns> |
119 | ········public override string ToString() |
120 | ········{ |
121 | ············return Name; |
122 | ········} |
123 | ····} |
124 | |
125 | } |
126 |