2using System.Collections.Generic;
3using System.Threading.Tasks;
5using System.Windows.Controls;
18 public enum OperationRange
30 private SortedDictionary<string, bool> fieldsSorted =
null;
31 private ListBox typesListBox =
null;
32 private ListBox fieldsListBox =
null;
35 private OperationRange range;
36 private string parameter =
null;
37 private string[] fieldNames =
null;
38 private string[] availableFieldNames =
null;
40 private bool registered =
false;
48 public string[] FieldNames
50 get => this.fieldNames;
51 set => this.fieldNames = value;
55 public string[] AvailableFieldNames
57 get => this.availableFieldNames;
58 set => this.availableFieldNames = value;
64 get => this.categories;
65 set => this.categories = value;
68 public override string QuestionString =>
"Allowed to read?";
80 Details.Children.Add(
new TextBlock()
83 FontWeight = FontWeights.Bold,
84 Text =
"Allowed to read?"
87 Details.Children.Add(TextBlock =
new TextBlock()
89 TextWrapping = TextWrapping.Wrap,
90 Margin =
new Thickness(0, 6, 0, 6)
93 TextBlock.Inlines.Add(
"Device: ");
96 this.AddNodeInfo(Details);
98 Details.Children.Add(TextBlock =
new TextBlock()
100 TextWrapping = TextWrapping.Wrap,
101 Margin =
new Thickness(0, 6, 0, 6)
104 TextBlock.Inlines.Add(
"Caller: ");
107 Details.Children.Add(
new Label()
109 Content =
"Categories:",
110 Margin =
new Thickness(0, 6, 0, 0)
113 Details.Children.Add(ListBox =
new ListBox()
115 SelectionMode = SelectionMode.Multiple,
116 Margin =
new Thickness(0, 0, 0, 6)
119 this.typesListBox = ListBox;
121 ListBox.Items.Add(
new ListBoxItem()
123 Content =
"Momentary values",
124 IsSelected = (this.categories &
FieldType.Momentary) != 0,
128 ListBox.Items.Add(
new ListBoxItem()
130 Content =
"Identity values",
131 IsSelected = (this.categories &
FieldType.Identity) != 0,
135 ListBox.Items.Add(
new ListBoxItem()
137 Content =
"Status values",
138 IsSelected = (this.categories &
FieldType.Status) != 0,
142 ListBox.Items.Add(
new ListBoxItem()
144 Content =
"Computed values",
145 IsSelected = (this.categories &
FieldType.Computed) != 0,
149 ListBox.Items.Add(
new ListBoxItem()
151 Content =
"Peak values",
152 IsSelected = (this.categories &
FieldType.Peak) != 0,
156 ListBox.Items.Add(
new ListBoxItem()
158 Content =
"Historical values",
159 IsSelected = (this.categories &
FieldType.Historical) != 0,
163 AddAllClearButtons(Details, ListBox);
166 Details.Children.Add(
new Label()
168 Content =
"Field restriction:",
169 Margin =
new Thickness(0, 6, 0, 0)
172 Details.Children.Add(ListBox =
new ListBox()
175 SelectionMode = SelectionMode.Multiple,
176 Margin =
new Thickness(0, 0, 0, 6)
179 this.fieldsListBox = ListBox;
181 if (this.availableFieldNames is
null)
183 if (!(this.fieldNames is
null))
185 foreach (
string FieldName
in this.fieldNames)
187 ListBox.Items.Add(
new ListBoxItem()
198 foreach (
string FieldName
in this.availableFieldNames)
200 ListBox.Items.Add(
new ListBoxItem()
203 IsSelected = (this.fieldNames is
null || Array.IndexOf<
string>(this.fieldNames, FieldName) >= 0),
209 StackPanel StackPanel = AddAllClearButtons(Details, ListBox);
211 if (this.availableFieldNames is
null)
213 StackPanel.Children.Add(Button =
new Button()
215 Margin =
new Thickness(6, 6, 6, 6),
216 Padding =
new Thickness(20, 0, 20, 0),
217 Content =
"Get List",
221 Button.Click += this.GetListButton_Click;
224 Details.Children.Add(TextBlock =
new TextBlock()
226 TextWrapping = TextWrapping.Wrap,
227 Margin =
new Thickness(0, 6, 0, 6),
228 Text =
"Is the caller allowed to read your device?"
231 Details.Children.Add(Button =
new Button()
233 Margin =
new Thickness(0, 6, 0, 6),
237 Button.Click += this.YesButton_Click;
239 Details.Children.Add(Button =
new Button()
241 Margin =
new Thickness(0, 6, 0, 6),
245 Button.Click += this.NoButton_Click;
247 string s = this.RemoteJID;
248 int i = s.IndexOf(
'@');
251 s = s.Substring(i + 1);
253 Details.Children.Add(Button =
new Button()
255 Margin =
new Thickness(0, 6, 0, 6),
256 Content =
"Yes, to anyone from " + s
259 Button.Click += this.YesDomainButton_Click;
261 Details.Children.Add(Button =
new Button()
263 Margin =
new Thickness(0, 6, 0, 6),
264 Content =
"No, to no one from " + s
267 Button.Click += this.NoDomainButton_Click;
270 Details.Children.Add(Button =
new Button()
272 Margin =
new Thickness(0, 6, 0, 6),
273 Content =
"Yes, to anyone"
276 Button.Click += this.YesAllButton_Click;
278 Details.Children.Add(Button =
new Button()
280 Margin =
new Thickness(0, 6, 0, 6),
281 Content =
"No, to no one"
284 Button.Click += this.NoAllButton_Click;
286 this.AddTokens(Details, this.client, this.YesTokenButton_Click, this.NoTokenButton_Click);
289 internal static StackPanel AddAllClearButtons(StackPanel Details, ListBox ListBox)
291 StackPanel StackPanel;
294 Details.Children.Add(StackPanel =
new StackPanel()
296 Orientation = Orientation.Horizontal,
297 HorizontalAlignment = HorizontalAlignment.Center
300 StackPanel.Children.Add(Button =
new Button()
302 Margin =
new Thickness(6, 6, 6, 6),
303 Padding =
new Thickness(20, 0, 20, 0),
308 Button.Click += AllButton_Click;
310 StackPanel.Children.Add(Button =
new Button()
312 Margin =
new Thickness(6, 6, 6, 6),
313 Padding =
new Thickness(20, 0, 20, 0),
318 Button.Click += ClearButton_Click;
323 internal static void ClearButton_Click(
object Sender, RoutedEventArgs e)
325 if (Sender is Button Button && Button.Tag is ListBox ListBox)
327 foreach (ListBoxItem Item
in ListBox.Items)
328 Item.IsSelected =
false;
332 internal static void AllButton_Click(
object Sender, RoutedEventArgs e)
334 if (Sender is Button Button && Button.Tag is ListBox ListBox)
336 foreach (ListBoxItem Item
in ListBox.Items)
337 Item.IsSelected =
true;
341 private async
void GetListButton_Click(
object Sender, RoutedEventArgs e)
347 ((Button)Sender).IsEnabled =
false;
352 if (!this.registered)
354 this.registered =
true;
355 this.questionView.Owner.RegisterRosterEventHandler(this.JID, this.RosterItemUpdated);
363 await this.DoRequest(Item);
371 public override void Dispose()
375 this.registered =
false;
376 this.questionView.Owner.UnregisterRosterEventHandler(this.JID, this.RosterItemUpdated);
382 private async Task RosterItemUpdated(
object Sender,
RosterItem Item)
386 this.questionView.Owner.UnregisterRosterEventHandler(this.JID, this.RosterItemUpdated);
387 await this.DoRequest(Item);
395 this.fieldsSorted =
new SortedDictionary<string, bool>();
398 Request = await this.questionView.Owner.SensorClient.RequestReadout(Item.
LastPresenceFullJid,
403 Request.OnStateChanged += this.Request_OnStateChanged;
404 Request.OnFieldsReceived += this.Request_OnFieldsReceived;
413 lock (this.fieldsSorted)
415 Fields =
new string[this.fieldsSorted.Count];
416 this.fieldsSorted.Keys.CopyTo(Fields, 0);
419 this.availableFieldNames = Fields;
424 SortedDictionary<string, bool> Selected =
null;
425 bool AllSelected = this.fieldNames is
null;
429 Selected =
new SortedDictionary<string, bool>(StringComparer.CurrentCultureIgnoreCase);
431 foreach (ListBoxItem Item
in this.fieldsListBox.Items)
434 Selected[(string)Item.Tag] =
true;
438 this.fieldsListBox.Items.Clear();
440 foreach (
string FieldName
in this.availableFieldNames)
442 this.fieldsListBox.Items.Add(
new ListBoxItem()
445 IsSelected = AllSelected || Selected.ContainsKey(FieldName),
450 return Task.CompletedTask;
455 private Task Request_OnFieldsReceived(
object _, IEnumerable<Field> NewFields)
457 lock (this.fieldsSorted)
459 foreach (
Field F
in NewFields)
460 this.fieldsSorted[F.Name] =
true;
463 return Task.CompletedTask;
470 foreach (ListBoxItem Item
in this.typesListBox.Items)
479 private string[] GetFields()
481 List<string> Result =
new List<string>();
484 foreach (ListBoxItem Item
in this.fieldsListBox.Items)
487 Result.Add((
string)Item.Tag);
492 if (this.availableFieldNames is
null || !All)
493 return Result.ToArray();
503 await this.Processed(this.questionView);
514 private void NoAllButton_Click(
object Sender, RoutedEventArgs e)
516 this.range = OperationRange.All;
517 this.client.
CanReadResponseAll(this.Sender, this.JID, this.RemoteJID, this.Key,
false, this.GetFieldType(), this.GetFields(), this.GetNodeReference(), this.RuleCallback,
null);
520 private void YesAllButton_Click(
object Sender, RoutedEventArgs e)
522 this.range = OperationRange.All;
523 this.client.
CanReadResponseAll(this.Sender, this.JID, this.RemoteJID, this.Key,
true, this.GetFieldType(), this.GetFields(), this.GetNodeReference(), this.RuleCallback,
null);
526 private void NoDomainButton_Click(
object Sender, RoutedEventArgs e)
528 this.range = OperationRange.Domain;
529 this.client.
CanReadResponseDomain(this.Sender, this.JID, this.RemoteJID, this.Key,
false, this.GetFieldType(), this.GetFields(), this.GetNodeReference(), this.RuleCallback,
null);
532 private void YesDomainButton_Click(
object Sender, RoutedEventArgs e)
534 this.range = OperationRange.Domain;
535 this.client.
CanReadResponseDomain(this.Sender, this.JID, this.RemoteJID, this.Key,
true, this.GetFieldType(), this.GetFields(), this.GetNodeReference(), this.RuleCallback,
null);
538 private void NoButton_Click(
object Sender, RoutedEventArgs e)
540 this.range = OperationRange.Caller;
541 this.client.
CanReadResponseCaller(this.Sender, this.JID, this.RemoteJID, this.Key,
false, this.GetFieldType(), this.GetFields(), this.GetNodeReference(), this.RuleCallback,
null);
544 private void YesButton_Click(
object Sender, RoutedEventArgs e)
546 this.range = OperationRange.Caller;
547 this.client.
CanReadResponseCaller(this.Sender, this.JID, this.RemoteJID, this.Key,
true, this.GetFieldType(), this.GetFields(), this.GetNodeReference(), this.RuleCallback,
null);
550 private void NoTokenButton_Click(
object Sender, RoutedEventArgs e)
552 this.TokenButtonClick(Sender, e,
false);
555 private void TokenButtonClick(
object Sender, RoutedEventArgs _,
bool Result)
557 Button Button = (Button)Sender;
558 object[] P = (
object[])Button.Tag;
559 this.parameter = (
string)P[0];
560 this.range = (OperationRange)P[1];
564 case OperationRange.ServiceToken:
565 this.client.
CanReadResponseService(this.Sender, this.JID, this.RemoteJID, this.Key, Result, this.GetFieldType(), this.GetFields(), this.parameter, this.GetNodeReference(), this.RuleCallback,
null);
568 case OperationRange.DeviceToken:
569 this.client.
CanReadResponseDevice(this.Sender, this.JID, this.RemoteJID, this.Key, Result, this.GetFieldType(), this.GetFields(), this.parameter, this.GetNodeReference(), this.RuleCallback,
null);
572 case OperationRange.UserToken:
573 this.client.
CanReadResponseUser(this.Sender, this.JID, this.RemoteJID, this.Key, Result, this.GetFieldType(), this.GetFields(), this.parameter, this.GetNodeReference(), this.RuleCallback,
null);
578 private void YesTokenButton_Click(
object Sender, RoutedEventArgs e)
580 this.TokenButtonClick(Sender, e,
true);
592 case OperationRange.Caller:
595 case OperationRange.Domain:
598 case OperationRange.All:
601 case OperationRange.ServiceToken:
604 case OperationRange.DeviceToken:
607 case OperationRange.UserToken:
618 internal static bool MatchesToken(
string Token,
string[] Tokens)
620 if (!(Tokens is
null))
622 foreach (
string Token2
in Tokens)
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 void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
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 CanReadResponseService(string JID, string RemoteJID, string Key, bool CanRead, FieldType FieldTypes, string[] FieldNames, string Token, IThingReference Node, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends a response to a previous "Can Read" question, based on a service token.
Task CanReadResponseUser(string JID, string RemoteJID, string Key, bool CanRead, FieldType FieldTypes, string[] FieldNames, string Token, IThingReference Node, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends a response to a previous "Can Read" question, based on a user token.
Task CanReadResponseAll(string JID, string RemoteJID, string Key, bool CanRead, FieldType FieldTypes, string[] FieldNames, IThingReference Node, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends a response to a previous "Can Read" question, for all future requests.
Task CanReadResponseCaller(string JID, string RemoteJID, string Key, bool CanRead, FieldType FieldTypes, string[] FieldNames, IThingReference Node, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends a response to a previous "Can Read" question, based on the JID of the caller.
Task CanReadResponseDomain(string JID, string RemoteJID, string Key, bool CanRead, FieldType FieldTypes, string[] FieldNames, IThingReference Node, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends a response to a previous "Can Read" question, based on the domain of the caller.
Task CanReadResponseDevice(string JID, string RemoteJID, string Key, bool CanRead, FieldType FieldTypes, string[] FieldNames, string Token, IThingReference Node, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends a response to a previous "Can Read" question, based on a device token.
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 a sensor data client request.
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.
Base class for all sensor data fields.
Contains a reference to a thing
SensorDataReadoutState
Sensor Data Readout States.
SubscriptionState
State of a presence subscription.
FieldType
Field Type flags