Datei: NDOPackage/NDOMapping.cs

Last Commit (3030986)
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.Linq;
26 using System.Text;
27 using System.Xml.Linq;
28
29 namespace NETDataObjects. NDOVSPackage
30 {
31 ····/// <summary>
32 ····/// This is a small version of NDOMapping to get the pieces of mapping information necessary for configuration
33 ····/// </summary>
34 ····class NDOMapping
35 ····{
36 ········XElement ndoMappingElement;
37 ········string schemaVersion = string.Empty;
38 ········List<Connection> connections = new List<Connection>();
39 ········string fileName;
40
41 ········public NDOMapping(string fileName)
42 ········{
43 ············this.fileName = fileName;
44 ············this.ndoMappingElement = XElement.Load(fileName);
45 ············XAttribute schemaAttribute;
46 ············if ((schemaAttribute = ndoMappingElement.Attribute("SchemaVersion")) != null)
47 ················this.schemaVersion = schemaAttribute.Value;
48 ············XElement connectionsElement = this.ndoMappingElement.Element( "Connections" );
49 ············if (connectionsElement != null)
50 ············{
51 ················foreach (var connectionElement in connectionsElement.Elements("Connection"))
52 ················{
53 ····················this.connections.Add( new Connection( connectionElement ) );
54 ················}
55 ············}
56 ········}
57
58 ········public IEnumerable<Connection> Connections
59 ········{
60 ············get { return connections; }
61 ············set { connections = value.ToList(); }
62 ········}
63
64 ········public string SchemaVersion
65 ········{
66 ············get
67 ············{
68 ················return this.schemaVersion;
69 ············}
70 ············set
71 ············{
72 ················this.schemaVersion = value;
73 ············}
74 ········}
75
76 ········public Connection NewConnection(string name, string type)
77 ········{
78 ············XElement connectionElement = new XElement("Connection",
79 ················new XAttribute("Name", name),
80 ················new XAttribute("Type", type),
81 ················new XAttribute("ID", "C0")
82 ············);
83 ············XElement connectionsElement = this.ndoMappingElement.Element( "Connections" );
84 ············if (connectionsElement == null)
85 ············{
86 ················connectionsElement = new XElement( "Connections" );
87 ················this.ndoMappingElement.AddFirst( connectionsElement );
88 ············}
89 ············connectionsElement.Add(connectionElement);
90 ············Connection result = new Connection(connectionElement);
91 ············this.connections.Add(result);
92 ············return result;
93 ········}
94
95 ········public void Save()
96 ········{
97 ············this.ndoMappingElement.Attribute("SchemaVersion").Value = this.schemaVersion;
98 ············foreach (var conn in this.connections)
99 ············{
100 ················conn.Save();
101 ············}
102 ············this.ndoMappingElement.Save(this.fileName);
 
 
 
103 ········}
104 ····}
105 }
106
New Commit (ed9120d)
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.Linq;
26 using System.Text;
27 using System.Xml.Linq;
28
29 namespace NDOVsPackage
30 {
31 ····/// <summary>
32 ····/// This is a small version of NDOMapping to get the pieces of mapping information necessary for configuration
33 ····/// </summary>
34 ····class NDOMapping
35 ····{
36 ········XElement ndoMappingElement;
37 ········string schemaVersion = string.Empty;
38 ········List<Connection> connections = new List<Connection>();
39 ········string fileName;
40
41 ········public NDOMapping(string fileName)
42 ········{
43 ············this.fileName = fileName;
44 ············this.ndoMappingElement = XElement.Load(fileName);
45 ············XAttribute schemaAttribute;
46 ············if ((schemaAttribute = ndoMappingElement.Attribute("SchemaVersion")) != null)
47 ················this.schemaVersion = schemaAttribute.Value;
48 ············XElement connectionsElement = this.ndoMappingElement.Element( "Connections" );
49 ············if (connectionsElement != null)
50 ············{
51 ················foreach (var connectionElement in connectionsElement.Elements("Connection"))
52 ················{
53 ····················this.connections.Add( new Connection( connectionElement ) );
54 ················}
55 ············}
56 ········}
57
58 ········public IEnumerable<Connection> Connections
59 ········{
60 ············get { return connections; }
61 ············set { connections = value.ToList(); }
62 ········}
63
64 ········public string SchemaVersion
65 ········{
66 ············get
67 ············{
68 ················return this.schemaVersion;
69 ············}
70 ············set
71 ············{
72 ················this.schemaVersion = value;
73 ············}
74 ········}
75
76 ········public Connection NewConnection(string name, string type)
77 ········{
78 ············XElement connectionElement = new XElement("Connection",
79 ················new XAttribute("Name", name),
80 ················new XAttribute("Type", type),
81 ················new XAttribute("ID", "C0")
82 ············);
83 ············XElement connectionsElement = this.ndoMappingElement.Element( "Connections" );
84 ············if (connectionsElement == null)
85 ············{
86 ················connectionsElement = new XElement( "Connections" );
87 ················this.ndoMappingElement.AddFirst( connectionsElement );
88 ············}
89 ············connectionsElement.Add(connectionElement);
90 ············Connection result = new Connection(connectionElement);
91 ············this.connections.Add(result);
92 ············return result;
93 ········}
94
95 ········public void Save()
96 ········{
97 ············this.ndoMappingElement.Attribute("SchemaVersion").Value = this.schemaVersion;
98 ············foreach (var conn in this.connections)
99 ············{
100 ················conn.Save();
101 ············}
102 ············this.ndoMappingElement.Save(this.fileName);
103 ········}
104 ····}
105 }
106 ··}
107 ····}
108 }
109