Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Connections.cs
1using System;
2using System.IO;
3using System.Collections.Generic;
4using System.Xml;
5using System.Xml.Schema;
8
10{
14 public class Connections
15 {
16 private const string xmlRootElement = "ClientConnections";
17 private const string xmlNamespace = "http://waher.se/Schema/ClientConnections.xsd";
18
19 private readonly MainWindow owner;
20 private readonly List<TreeNode> connections = new List<TreeNode>();
21 private bool modified = false;
22
28 {
29 this.owner = Owner;
30 }
31
35 public MainWindow Owner => this.owner;
36
41 public void Add(TreeNode RootNode)
42 {
43 lock (this.connections)
44 {
45 this.connections.Add(RootNode);
46 this.modified = true;
47 }
48 }
49
55 public bool Delete(TreeNode RootNode)
56 {
57 lock (this.connections)
58 {
59 if (this.connections.Remove(RootNode))
60 {
61 this.modified = true;
62 return true;
63 }
64 }
65
66 return false;
67 }
68
74 public bool Remove(TreeNode RootNode)
75 {
76 lock (this.connections)
77 {
78 if (this.connections.Remove(RootNode))
79 {
80 this.modified = true;
81 return true;
82 }
83 else
84 return false;
85 }
86 }
87
91 public bool Modified
92 {
93 get => this.modified;
94 internal set{ this.modified = true; }
95 }
96
101 public void Save(string FileName)
102 {
103 lock (this.connections)
104 {
105 using (FileStream f = File.Create(FileName))
106 {
107 using (XmlWriter w = XmlWriter.Create(f, XML.WriterSettings(true, false)))
108 {
109 w.WriteStartElement(xmlRootElement, xmlNamespace);
110
111 foreach (TreeNode RootNode in this.connections)
112 RootNode.Write(w);
113
114 w.WriteEndElement();
115 w.Flush();
116 }
117 }
118
119 this.modified = false;
120 }
121 }
122
127 public void Load(string FileName)
128 {
129 XmlDocument Xml = new XmlDocument()
130 {
131 PreserveWhitespace = true
132 };
133 Xml.Load(FileName);
134
135 this.Load(FileName, Xml);
136 }
137
142 public void Load(string FileName, XmlDocument Xml)
143 {
144 XSL.Validate(FileName, Xml, xmlRootElement, xmlNamespace, schema);
145
146 lock (this.connections)
147 {
148 this.connections.Clear();
149
150 foreach (XmlNode N in Xml.DocumentElement.ChildNodes)
151 {
152 switch (N.LocalName)
153 {
154 case "XmppAccount":
155 this.connections.Add(new XmppAccountNode((XmlElement)N, this, null));
156 break;
157 }
158 }
159 }
160 }
161
162 private static readonly XmlSchema schema = XSL.LoadSchema("Waher.Client.WPF.Schema.ClientConnections.xsd");
163
167 public void New()
168 {
169 TreeNode[] ToDispose;
170
171 lock (this.connections)
172 {
173 ToDispose = this.connections.ToArray();
174 this.connections.Clear();
175 }
176
177 foreach (TreeNode Node in ToDispose)
178 Node.Dispose();
179 }
180
185 {
186 get
187 {
188 lock (this.connections)
189 {
190 return this.connections.ToArray();
191 }
192 }
193 }
194
195 }
196}
Interaction logic for xaml
Maintains the set of open connections.
Definition: Connections.cs:15
bool Remove(TreeNode RootNode)
Removes an existing connection.
Definition: Connections.cs:74
void Save(string FileName)
Saves connections to an XML file.
Definition: Connections.cs:101
Connections(MainWindow Owner)
Maintains the set of open connections.
Definition: Connections.cs:27
bool Delete(TreeNode RootNode)
Deletes a new connection.
Definition: Connections.cs:55
void Load(string FileName)
Loads the environment from an XML file.
Definition: Connections.cs:127
void New()
Creates a new environment.
Definition: Connections.cs:167
void Add(TreeNode RootNode)
Adds a new connection.
Definition: Connections.cs:41
MainWindow Owner
Owner of connections.
Definition: Connections.cs:35
void Load(string FileName, XmlDocument Xml)
Loads the environment from an XML file.
Definition: Connections.cs:142
TreeNode[] RootNodes
Available root nodes.
Definition: Connections.cs:185
bool Modified
If the source has been changed.
Definition: Connections.cs:92
Abstract base class for tree nodes in the connection view.
Definition: TreeNode.cs:24
abstract void Write(XmlWriter Output)
Saves the object to a file.
virtual void Dispose()
Disposes of the node and its resources.
Definition: TreeNode.cs:129
Class representing a normal XMPP account.
Helps with common XML-related tasks.
Definition: XML.cs:19
static XmlWriterSettings WriterSettings(bool Indent, bool OmitXmlDeclaration)
Gets an XML writer settings object.
Definition: XML.cs:1177
Static class managing loading of XSL resources stored as embedded resources or in content files.
Definition: XSL.cs:15
static XmlSchema LoadSchema(string ResourceName)
Loads an XML schema from an embedded resource.
Definition: XSL.cs:23
static void Validate(string ObjectID, XmlDocument Xml, params XmlSchema[] Schemas)
Validates an XML document given a set of XML schemas.
Definition: XSL.cs:118