Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmppNode.cs
1using System;
2using System.Windows.Controls;
4using System.Windows;
6using System.Threading.Tasks;
7
9{
10 public abstract class XmppNode : TreeNode
11 {
13 : base(Parent)
14 {
15 }
16
17 public abstract string FullJID
18 {
19 get;
20 }
21
22 public XmppAccountNode Account
23 {
24 get { return this.Parent as XmppAccountNode; }
25 }
26
27 public override void AddContexMenuItems(ref string CurrentGroup, ContextMenu Menu)
28 {
29 base.AddContexMenuItems(ref CurrentGroup, Menu);
30
31 MenuItem Item;
32
33 this.GroupSeparator(ref CurrentGroup, "XMPP", Menu);
34
35 Menu.Items.Add(Item = new MenuItem()
36 {
37 Header = "Send XMPP Message...",
38 IsEnabled = true
39 });
40
41 Item.Click += this.SendXmppMessage_Click;
42
43 Menu.Items.Add(Item = new MenuItem()
44 {
45 Header = "Send XMPP IQ GET...",
46 IsEnabled = true
47 });
48
49 Item.Click += this.SendXmppIqGet_Click;
50
51 Menu.Items.Add(Item = new MenuItem()
52 {
53 Header = "Send XMPP IQ SET...",
54 IsEnabled = true
55 });
56
57 Item.Click += this.SendXmppIqSet_Click;
58 }
59
60 private async void SendXmppMessage_Click(object Sender, RoutedEventArgs e)
61 {
62 try
63 {
64 MessageForm Form = new MessageForm
65 {
66 Owner = MainWindow.currentInstance
67 };
68
69 Form.To.Text = this.FullJID;
70
71 bool? Result = Form.ShowDialog();
72
73 if (Result.HasValue && Result.Value)
74 {
75 await this.Account.Client.SendMessage((MessageType)Enum.Parse(typeof(MessageType), Form.Type.Text),
76 Form.To.Text.Trim(), Form.CustomXml.Text, Form.Body.Text, Form.Subject.Text, Form.MessageLanguage.Text,
77 Form.ThreadId.Text, Form.ParentThreadId.Text);
78 }
79 }
80 catch (Exception ex)
81 {
82 MainWindow.ErrorBox(ex.Message);
83 }
84 }
85
86 private async void SendXmppIqGet_Click(object Sender, RoutedEventArgs e)
87 {
88 try
89 {
90 IqForm Form = new IqForm
91 {
92 Owner = MainWindow.currentInstance
93 };
94
95 Form.Type.SelectedIndex = 0;
96 Form.To.Text = this.FullJID;
97
98 bool? Result = Form.ShowDialog();
99
100 if (Result.HasValue && Result.Value)
101 {
102 await this.Account.Client.SendIqGet(Form.To.Text.Trim(), Form.CustomXml.Text, (sender2, e2) =>
103 {
104 if (e2.Ok)
105 {
106 MainWindow.UpdateGui(() =>
107 {
108 IqResultForm ResultForm = new IqResultForm()
109 {
110 Owner = MainWindow.currentInstance
111 };
112
113 ResultForm.From.Text = e2.From;
114 ResultForm.XmlResponse.Text = e2.Response.OuterXml;
115
116 ResultForm.ShowDialog();
117
118 return Task.CompletedTask;
119 });
120 }
121 else
122 MainWindow.ErrorBox(string.IsNullOrEmpty(e2.ErrorText) ? "Error returned." : e2.ErrorText);
123
124 return Task.CompletedTask;
125 }, null);
126 }
127 }
128 catch (Exception ex)
129 {
130 MainWindow.ErrorBox(ex.Message);
131 }
132 }
133
134 private async void SendXmppIqSet_Click(object Sender, RoutedEventArgs e)
135 {
136 try
137 {
138 IqForm Form = new IqForm
139 {
140 Owner = MainWindow.currentInstance
141 };
142
143 Form.Type.SelectedIndex = 1;
144 Form.To.Text = this.FullJID;
145
146 bool? Result = Form.ShowDialog();
147
148 if (Result.HasValue && Result.Value)
149 {
150 await this.Account.Client.SendIqSet(Form.To.Text.Trim(), Form.CustomXml.Text, (sender2, e2) =>
151 {
152 if (e2.Ok)
153 {
154 MainWindow.UpdateGui(() =>
155 {
156 IqResultForm ResultForm = new IqResultForm()
157 {
158 Owner = MainWindow.currentInstance
159 };
160
161 ResultForm.From.Text = e2.From;
162 ResultForm.XmlResponse.Text = e2.Response.OuterXml;
163
164 ResultForm.ShowDialog();
165
166 return Task.CompletedTask;
167 });
168 }
169 else
170 MainWindow.ErrorBox(string.IsNullOrEmpty(e2.ErrorText) ? "Error returned." : e2.ErrorText);
171
172 return Task.CompletedTask;
173 }, null);
174 }
175 }
176 catch (Exception ex)
177 {
178 MainWindow.ErrorBox(ex.Message);
179 }
180 }
181 }
182}
Interaction logic for IqForm.xaml
Definition: IqFrom.xaml.cs:13
Interaction logic for MessageForm.xaml
Interaction logic for xaml
Abstract base class for tree nodes in the connection view.
Definition: TreeNode.cs:24
TreeNode Parent
Parent node. May be null if a root node.
Definition: TreeNode.cs:107
abstract string Header
Tree Node header text.
Definition: TreeNode.cs:122
Class representing a normal XMPP account.
override void AddContexMenuItems(ref string CurrentGroup, ContextMenu Menu)
Adds context sensitive menu items to a context menu.
Definition: XmppNode.cs:27
Task SendMessage(MessageType Type, string To, string CustomXml, string Body, string Subject, string Language, string ThreadId, string ParentThreadId)
Sends a simple chat message
Definition: XmppClient.cs:5395
Task< uint > SendIqGet(string To, string Xml, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends an IQ Get request.
Definition: XmppClient.cs:3559
MessageType
Type of message received.
Definition: MessageType.cs:7