2using System.Collections.Generic;
3using System.Threading.Tasks;
5using System.Windows.Controls;
18 private SortedDictionary<string, bool> parametersSorted =
null;
19 private ListBox parametersListBox =
null;
22 private OperationRange range;
23 private string parameter =
null;
24 private string[] parameterNames =
null;
25 private string[] availableParameterNames =
null;
26 private bool registered =
false;
34 public string[] ParameterNames
36 get => this.parameterNames;
37 set => this.parameterNames = value;
41 public string[] AvailableParameterNames
43 get => this.availableParameterNames;
44 set => this.availableParameterNames = value;
47 public override string QuestionString =>
"Allowed to control?";
59 Details.Children.Add(
new TextBlock()
62 FontWeight = FontWeights.Bold,
63 Text =
"Allowed to control?"
66 Details.Children.Add(TextBlock =
new TextBlock()
68 TextWrapping = TextWrapping.Wrap,
69 Margin =
new Thickness(0, 6, 0, 6)
72 TextBlock.Inlines.Add(
"Device: ");
75 this.AddNodeInfo(Details);
77 Details.Children.Add(TextBlock =
new TextBlock()
79 TextWrapping = TextWrapping.Wrap,
80 Margin =
new Thickness(0, 6, 0, 6)
83 TextBlock.Inlines.Add(
"Caller: ");
87 Details.Children.Add(
new Label()
89 Content =
"Parameter restriction:",
90 Margin =
new Thickness(0, 6, 0, 0)
93 Details.Children.Add(ListBox =
new ListBox()
96 SelectionMode = SelectionMode.Multiple,
97 Margin =
new Thickness(0, 0, 0, 6)
100 this.parametersListBox = ListBox;
102 if (this.availableParameterNames is
null)
104 if (!(this.parameterNames is
null))
106 foreach (
string ParameterName
in this.parameterNames)
108 ListBox.Items.Add(
new ListBoxItem()
110 Content = ParameterName,
119 foreach (
string ParameterName
in this.availableParameterNames)
121 ListBox.Items.Add(
new ListBoxItem()
123 Content = ParameterName,
124 IsSelected = (this.parameterNames is
null || Array.IndexOf<
string>(this.parameterNames, ParameterName) >= 0),
130 StackPanel StackPanel =
CanReadQuestion.AddAllClearButtons(Details, ListBox);
132 if (this.availableParameterNames is
null)
134 StackPanel.Children.Add(Button =
new Button()
136 Margin =
new Thickness(6, 6, 6, 6),
137 Padding =
new Thickness(20, 0, 20, 0),
138 Content =
"Get List",
142 Button.Click += this.GetListButton_Click;
145 Details.Children.Add(TextBlock =
new TextBlock()
147 TextWrapping = TextWrapping.Wrap,
148 Margin =
new Thickness(0, 6, 0, 6),
149 Text =
"Is the caller allowed to control your device?"
152 Details.Children.Add(Button =
new Button()
154 Margin =
new Thickness(0, 6, 0, 6),
158 Button.Click += this.YesButton_Click;
160 Details.Children.Add(Button =
new Button()
162 Margin =
new Thickness(0, 6, 0, 6),
166 Button.Click += this.NoButton_Click;
168 string s = this.RemoteJID;
169 int i = s.IndexOf(
'@');
172 s = s.Substring(i + 1);
174 Details.Children.Add(Button =
new Button()
176 Margin =
new Thickness(0, 6, 0, 6),
177 Content =
"Yes, to anyone from " + s
180 Button.Click += this.YesDomainButton_Click;
182 Details.Children.Add(Button =
new Button()
184 Margin =
new Thickness(0, 6, 0, 6),
185 Content =
"No, to no one from " + s
188 Button.Click += this.NoDomainButton_Click;
191 Details.Children.Add(Button =
new Button()
193 Margin =
new Thickness(0, 6, 0, 6),
194 Content =
"Yes, to anyone"
197 Button.Click += this.YesAllButton_Click;
199 Details.Children.Add(Button =
new Button()
201 Margin =
new Thickness(0, 6, 0, 6),
202 Content =
"No, to no one"
205 Button.Click += this.NoAllButton_Click;
207 this.AddTokens(Details, this.client, this.YesTokenButton_Click, this.NoTokenButton_Click);
210 private void GetListButton_Click(
object Sender, RoutedEventArgs e)
214 ((Button)Sender).IsEnabled =
false;
219 if (!this.registered)
221 this.registered =
true;
222 this.questionView.Owner.RegisterRosterEventHandler(this.JID, this.RosterItemUpdated);
230 this.DoRequest(Item);
233 public override void Dispose()
237 this.registered =
false;
238 this.questionView.Owner.UnregisterRosterEventHandler(this.JID, this.RosterItemUpdated);
244 private Task RosterItemUpdated(
object Sender,
RosterItem Item)
248 this.questionView.Owner.UnregisterRosterEventHandler(this.JID, this.RosterItemUpdated);
249 this.DoRequest(Item);
252 return Task.CompletedTask;
257 this.parametersSorted =
new SortedDictionary<string, bool>();
261 this.questionView.Owner.ControlClient.GetForm(Item.
LastPresenceFullJid,
"en",
this.ControlFormResponse,
null,
262 this.GetNodeReference());
265 this.questionView.Owner.ControlClient.GetForm(Item.
LastPresenceFullJid,
"en",
this.ControlFormResponse,
null);
276 lock (this.parametersSorted)
280 if (!F.ReadOnly && !F.Exclude)
281 this.parametersSorted[F.Var] =
true;
284 Parameters =
new string[this.parametersSorted.Count];
285 this.parametersSorted.Keys.CopyTo(Parameters, 0);
288 this.availableParameterNames = Parameters;
293 SortedDictionary<string, bool> Selected =
null;
294 bool AllSelected = this.parameterNames is
null;
298 Selected =
new SortedDictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
300 foreach (ListBoxItem Item
in this.parametersListBox.Items)
303 Selected[(string)Item.Tag] =
true;
307 this.parametersListBox.Items.Clear();
309 foreach (
string ParameterName
in this.availableParameterNames)
311 this.parametersListBox.Items.Add(
new ListBoxItem()
313 Content = ParameterName,
314 IsSelected = AllSelected || Selected.ContainsKey(ParameterName),
319 return Task.CompletedTask;
332 private string[] GetParameters()
334 List<string> Result =
new List<string>();
337 foreach (ListBoxItem Item
in this.parametersListBox.Items)
340 Result.Add((
string)Item.Tag);
345 if (this.availableParameterNames is
null || !All)
346 return Result.ToArray();
356 await this.Processed(this.questionView);
367 private void NoAllButton_Click(
object Sender, RoutedEventArgs e)
369 this.range = OperationRange.All;
370 this.client.
CanControlResponseAll(this.Sender, this.JID, this.RemoteJID, this.Key,
false, this.GetParameters(), this.GetNodeReference(), this.RuleCallback,
null);
373 private void YesAllButton_Click(
object Sender, RoutedEventArgs e)
375 this.range = OperationRange.All;
376 this.client.
CanControlResponseAll(this.Sender, this.JID, this.RemoteJID, this.Key,
true, this.GetParameters(), this.GetNodeReference(), this.RuleCallback,
null);
379 private void NoDomainButton_Click(
object Sender, RoutedEventArgs e)
381 this.range = OperationRange.Domain;
382 this.client.
CanControlResponseDomain(this.Sender, this.JID, this.RemoteJID, this.Key,
false, this.GetParameters(), this.GetNodeReference(), this.RuleCallback,
null);
385 private void YesDomainButton_Click(
object Sender, RoutedEventArgs e)
387 this.range = OperationRange.Domain;
388 this.client.
CanControlResponseDomain(this.Sender, this.JID, this.RemoteJID, this.Key,
true, this.GetParameters(), this.GetNodeReference(), this.RuleCallback,
null);
391 private void NoButton_Click(
object Sender, RoutedEventArgs e)
393 this.range = OperationRange.Caller;
394 this.client.
CanControlResponseCaller(this.Sender, this.JID, this.RemoteJID, this.Key,
false, this.GetParameters(), this.GetNodeReference(), this.RuleCallback,
null);
397 private void YesButton_Click(
object Sender, RoutedEventArgs e)
399 this.range = OperationRange.Caller;
400 this.client.
CanControlResponseCaller(this.Sender, this.JID, this.RemoteJID, this.Key,
true, this.GetParameters(), this.GetNodeReference(), this.RuleCallback,
null);
403 private void NoTokenButton_Click(
object Sender, RoutedEventArgs e)
405 this.TokenButtonClick(Sender, e,
false);
408 private void TokenButtonClick(
object Sender, RoutedEventArgs _,
bool Result)
410 Button Button = (Button)Sender;
411 object[] P = (
object[])Button.Tag;
412 this.parameter = (
string)P[0];
413 this.range = (OperationRange)P[1];
417 case OperationRange.ServiceToken:
418 this.client.
CanControlResponseService(this.Sender, this.JID, this.RemoteJID, this.Key, Result, this.GetParameters(), this.parameter, this.GetNodeReference(), this.RuleCallback,
null);
421 case OperationRange.DeviceToken:
422 this.client.
CanControlResponseDevice(this.Sender, this.JID, this.RemoteJID, this.Key, Result, this.GetParameters(), this.parameter, this.GetNodeReference(), this.RuleCallback,
null);
425 case OperationRange.UserToken:
426 this.client.
CanControlResponseUser(this.Sender, this.JID, this.RemoteJID, this.Key, Result, this.GetParameters(), this.parameter, this.GetNodeReference(), this.RuleCallback,
null);
431 private void YesTokenButton_Click(
object Sender, RoutedEventArgs e)
433 this.TokenButtonClick(Sender, e,
true);
445 case OperationRange.Caller:
448 case OperationRange.Domain:
451 case OperationRange.All:
454 case OperationRange.ServiceToken:
457 case OperationRange.DeviceToken:
460 case OperationRange.UserToken:
Interaction logic for QuestionView.xaml
Interaction logic for xaml
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.
Event arguments for responses to IQ queries.
bool Ok
If the response is an OK result response (true), or an error response (false).
string ErrorText
Any error specific text.
bool IsOnline
If contact is online.
Implements an XMPP provisioning client interface.
Task CanControlResponseDevice(string JID, string RemoteJID, string Key, bool CanControl, string[] ParameterNames, string Token, IThingReference Node, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends a response to a previous "Can Control" question, based on a device token.
Task CanControlResponseCaller(string JID, string RemoteJID, string Key, bool CanControl, string[] ParameterNames, IThingReference Node, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends a response to a previous "Can Control" question, based on the JID of the caller.
Task CanControlResponseService(string JID, string RemoteJID, string Key, bool CanControl, string[] ParameterNames, string Token, IThingReference Node, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends a response to a previous "Can Control" question, based on a service token.
Task CanControlResponseUser(string JID, string RemoteJID, string Key, bool CanControl, string[] ParameterNames, string Token, IThingReference Node, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends a response to a previous "Can Control" question, based on a user token.
Task CanControlResponseDomain(string JID, string RemoteJID, string Key, bool CanControl, string[] ParameterNames, IThingReference Node, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends a response to a previous "Can Control" question, based on the domain of the caller.
Task CanControlResponseAll(string JID, string RemoteJID, string Key, bool CanControl, string[] ParameterNames, IThingReference Node, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends a response to a previous "Can Control" question, for all future requests.
Maintains information about an item in the roster.
SubscriptionState State
roup Current subscription state.
bool HasLastPresence
If the roster item has received presence from an online resource having the given bare JID.
string LastPresenceFullJid
Full JID of last resource sending online presence.
PresenceEventArgs LastPresence
Last presence received from a resource having this bare JID.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Task RequestPresenceSubscription(string BareJid)
Requests subscription of presence information from a contact.
XmppClient Client
XMPP Client.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task Update(object Object)
Updates an object in the database.
SubscriptionState
State of a presence subscription.