3using System.Collections.Generic;
6using System.Windows.Controls;
7using System.Windows.Data;
8using System.Windows.Input;
17using System.Threading.Tasks;
26 private string fileName =
string.Empty;
28 private TreeNode selectedNode =
null;
42 this.connections.
New();
52 public string FileName
57 this.fileName = value;
58 if (
string.IsNullOrEmpty(this.fileName))
59 this.MainWindow.Title =
MainWindow.WindowTitle;
61 this.MainWindow.Title = this.fileName +
" - " +
MainWindow.WindowTitle;
65 private void ConnectionTree_SelectedItemChanged(
object Sender, RoutedPropertyChangedEventArgs<object> e)
67 this.ConnectionListView.Items.Clear();
69 if (this.ConnectionListView.View is GridView GridView)
71 while (GridView.Columns.Count > 2)
72 GridView.Columns.RemoveAt(2);
77 this.selectedNode = this.ConnectionTree.SelectedItem as
TreeNode;
78 if (!(this.selectedNode is
null))
81 Dictionary<string, bool> Headers =
null;
84 if (!(Children is
null))
88 this.ConnectionListView.Items.Add(Child);
90 if (!(GridView is
null))
93 if (!(Parameters is
null))
95 foreach (
Parameter P
in Parameters.Ordered)
97 if (P.
Id ==
"NodeId" || P.
Id ==
"Type")
101 Headers =
new Dictionary<string, bool>();
103 if (!Headers.ContainsKey(P.
Id))
105 Headers[P.
Id] =
true;
107 GridViewColumn Column =
new GridViewColumn()
111 DisplayMemberBinding =
new Binding(
"DisplayableParameters[" + P.
Id +
"]")
114 GridView.Columns.Add(Column);
127 public bool SaveFile()
129 if (
string.IsNullOrEmpty(this.fileName))
130 return this.SaveNewFile();
133 this.connections.
Save(this.fileName);
138 public bool CheckSaved()
142 switch (MessageBox.Show(
MainWindow.FindWindow(
this),
"You have unsaved changes. Do you want to save these changes before closing the application?",
143 "Save unsaved changes?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question))
145 case MessageBoxResult.Yes:
151 case MessageBoxResult.No:
154 case MessageBoxResult.Cancel:
162 public bool SaveNewFile()
164 SaveFileDialog Dialog =
new SaveFileDialog()
167 CheckPathExists =
true,
168 CreatePrompt =
false,
170 Filter =
"XML Files (*.xml)|*.xml|All Files (*.*)|*.*",
171 Title =
"Save connection file"
174 bool? Result = Dialog.ShowDialog(
MainWindow.FindWindow(
this));
176 if (Result.HasValue && Result.Value)
178 this.FileName = Dialog.FileName;
186 public async Task Load(
string FileName)
190 XmlDocument Xml =
new XmlDocument()
192 PreserveWhitespace =
true
196 switch (Xml.DocumentElement.LocalName)
198 case "ClientConnections":
199 this.connections.
Load(FileName, Xml);
200 this.FileName = FileName;
202 this.ConnectionTree.Items.Clear();
208 TabItem TabItem =
MainWindow.NewTab(Path.GetFileName(FileName));
216 this.MainWindow.Tabs.SelectedItem = TabItem;
222 TabItem =
MainWindow.NewTab(Path.GetFileName(FileName));
225 bool Muc =
XML.
Attribute(Xml.DocumentElement,
"muc",
false);
227 ChatView.Input.IsEnabled =
false;
228 ChatView.SendButton.IsEnabled =
false;
232 this.MainWindow.Tabs.SelectedItem = TabItem;
238 TabItem =
MainWindow.NewTab(Path.GetFileName(FileName));
244 this.MainWindow.Tabs.SelectedItem = TabItem;
250 TabItem =
MainWindow.NewTab(Path.GetFileName(FileName));
256 this.MainWindow.Tabs.SelectedItem = TabItem;
262 TabItem =
MainWindow.NewTab(Path.GetFileName(FileName));
268 this.MainWindow.Tabs.SelectedItem = TabItem;
274 TabItem =
MainWindow.NewTab(Path.GetFileName(FileName));
280 this.MainWindow.Tabs.SelectedItem = TabItem;
286 TabItem =
MainWindow.NewTab(Path.GetFileName(FileName), out TextBlock HeaderLabel);
290 TabItem.Content = ReportView;
292 this.MainWindow.Tabs.SelectedItem = TabItem;
294 ReportView.Load(Xml, FileName);
298 throw new Exception(
"Unrecognized file format.");
304 MessageBox.Show(ex.Message, ex.Message, MessageBoxButton.OK, MessageBoxImage.Error);
308 public void NewButton_Click(
object Sender, RoutedEventArgs e)
310 if (!this.CheckSaved())
313 this.ConnectionTree.Items.Clear();
314 this.connections.
New();
315 this.FileName =
string.Empty;
318 public void SaveButton_Click(
object Sender, RoutedEventArgs e)
323 public void SaveAsButton_Click(
object Sender, RoutedEventArgs e)
328 public async
void OpenButton_Click(
object Sender, RoutedEventArgs e)
332 if (!this.CheckSaved())
335 OpenFileDialog Dialog =
new OpenFileDialog()
338 CheckFileExists =
true,
339 CheckPathExists =
true,
341 Filter =
"XML Files (*.xml)|*.xml|All Files (*.*)|*.*",
344 Title =
"Open connection file"
347 bool? Result = Dialog.ShowDialog(
MainWindow.FindWindow(
this));
349 if (Result.HasValue && Result.Value)
350 await this.Load(Dialog.FileName);
355 MessageBox.Show(ex.Message,
"Unable to load file.", MessageBoxButton.OK, MessageBoxImage.Error);
359 public void ConnectTo_Executed(
object Sender, ExecutedRoutedEventArgs e)
363 Owner = this.MainWindow
365 bool? Result = Dialog.ShowDialog();
367 if (Result.HasValue && Result.Value)
369 if (!
int.TryParse(Dialog.XmppPort.Text, out
int Port))
373 (TransportMethod)Dialog.ConnectionMethod.SelectedIndex, Port, Dialog.UrlEndpoint.Text,
375 Dialog.TrustServerCertificate.IsChecked.HasValue && Dialog.TrustServerCertificate.IsChecked.Value,
376 Dialog.AllowInsecureAuthentication.IsChecked.HasValue && Dialog.AllowInsecureAuthentication.IsChecked.Value);
378 this.connections.
Add(Node);
385 this.ConnectionTree.Items.Add(Node);
386 this.NodeAdded(
null, Node);
391 ChildNode.Updated += this.Node_Updated;
397 ChildNode.Updated -= this.Node_Updated;
402 this.connections.
Delete(ChildNode);
405 this.ConnectionTree.Items.Remove(ChildNode);
406 return Task.CompletedTask;
412 this.Node_Updated(
this, EventArgs.Empty);
415 private void Node_Updated(
object Sender, EventArgs e)
417 if (this.refreshTimer > DateTime.MinValue)
419 MainWindow.Scheduler?.Remove(this.refreshTimer);
420 this.refreshTimer = DateTime.MinValue;
423 this.refreshTimer =
MainWindow.Scheduler.Add(DateTime.Now.AddMilliseconds(250),
this.RefreshTree,
null);
426 public void ShowStatus(
string Message)
433 if (this.statusTimer > DateTime.MinValue)
435 MainWindow.Scheduler?.Remove(this.statusTimer);
436 this.statusTimer = DateTime.MinValue;
439 this.statusTimer =
MainWindow.Scheduler.Add(DateTime.Now.AddMilliseconds(250),
this.SetStatus,
null);
442 private string status =
string.Empty;
443 private DateTime refreshTimer = DateTime.MinValue;
444 private DateTime statusTimer = DateTime.MinValue;
446 private void RefreshTree(
object _)
448 if (this.statusTimer > DateTime.MinValue)
450 MainWindow.Scheduler?.Remove(this.statusTimer);
451 this.statusTimer = DateTime.MinValue;
456 this.ConnectionTree.Items.Refresh();
457 return Task.CompletedTask;
461 private void SetStatus(
object _)
463 if (this.statusTimer > DateTime.MinValue)
465 MainWindow.Scheduler?.Remove(this.statusTimer);
466 this.statusTimer = DateTime.MinValue;
471 this.ConnectionStatus.Content = this.status;
472 return Task.CompletedTask;
476 private void ConnectionListView_SelectionChanged(
object Sender, SelectionChangedEventArgs e)
478 this.ConnectionListView_GotFocus(Sender, e);
481 public TreeNode SelectedNode => this.selectedNode;
483 private void TreeContextMenu_ContextMenuOpening(
object Sender, ContextMenuEventArgs e)
485 this.PopulateConextMenu(this.TreeContextMenu);
488 private void ListViewContextMenu_ContextMenuOpening(
object Sender, ContextMenuEventArgs e)
490 this.PopulateConextMenu(this.ListViewContextMenu);
493 private void PopulateConextMenu(ContextMenu Menu)
495 string Group =
string.Empty;
502 private void ConnectionListView_GotFocus(
object Sender, RoutedEventArgs e)
504 this.selectedNode = this.ConnectionListView.SelectedItem as
TreeNode;
510 private void ConnectionTree_GotFocus(
object Sender, RoutedEventArgs e)
512 this.selectedNode = this.ConnectionTree.SelectedItem as
TreeNode;
Interaction logic for ChatView.xaml
Interaction logic for ConnectionView.xaml
void InitializeComponent()
InitializeComponent
Interaction logic for LogView.xaml
Interaction logic for QueryResultView.xaml
Interaction logic for ScriptView.xaml
Interaction logic for SensorDataView.xaml
Interaction logic for SensorDataView.xaml
Interaction logic for SnifferView.xaml
Interaction logic for xaml
Maintains the set of open connections.
void Save(string FileName)
Saves connections to an XML file.
bool Delete(TreeNode RootNode)
Deletes a new connection.
void Load(string FileName)
Loads the environment from an XML file.
void New()
Creates a new environment.
void Add(TreeNode RootNode)
Adds a new connection.
TreeNode[] RootNodes
Available root nodes.
bool Modified
If the source has been changed.
Abstract base class for tree nodes in the connection view.
TreeNode[] Children
Children of the node. If null, children are not loaded.
virtual void Added(MainWindow Window)
Is called when the node has been added to the main window.
virtual void Removed(MainWindow Window)
Is called when the node has been removed from the main window.
virtual void AddContexMenuItems(ref string CurrentGroup, ContextMenu Menu)
Adds context sensitive menu items to a context menu.
virtual DisplayableParameters DisplayableParameters
Gets available displayable parameters.
virtual bool RemoveChild(TreeNode Node)
Removes a child node.
Class representing a normal XMPP account.
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Static class managing the application event log. Applications and services log events on this static ...
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
Class containing credentials for an XMPP client connection.
const int DefaultPort
Default XMPP Server port.
Contains information about a message logged on a node.
Base class for all node parameters.
string Name
Parameter Name.
Interface for tab view user controls in the client.