1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
10using System.Collections.ObjectModel;
11using System.ComponentModel;
37 this.navigationArguments = Args;
46 this.@
event = Args.
Event;
65 if (this.FriendlyName == this.BareJid)
68 this.RemoteFriendlyNameAvailable = this.RemoteFriendlyName != this.RemoteJid;
69 if (!this.RemoteFriendlyNameAvailable)
77 await base.OnInitialize();
79 if (this.navigationArguments is not
null)
85 if (Thing?.MetaData is not
null)
92 this.CallerInContactsList = Caller is not
null;
93 if (Caller?.MetaData is not
null)
99 if (this.navigationArguments.UserTokens is not
null &&
this.navigationArguments.UserTokens.Length > 0)
107 if (this.navigationArguments.ServiceTokens is not
null &&
this.navigationArguments.ServiceTokens.Length > 0)
112 this.HasService =
true;
115 if (this.navigationArguments.DeviceTokens is not
null &&
this.navigationArguments.DeviceTokens.Length > 0)
120 this.HasDevice =
true;
125 SortedDictionary<string, bool> PermittedFields = [];
126 string[]? AllFields = this.navigationArguments.AllFields;
128 if (AllFields is
null && !
string.IsNullOrEmpty(this.BareJid))
132 if (AllFields is not
null && this.navigationArguments.Event is not
null)
134 this.navigationArguments.Event.AllFields = AllFields;
139 bool AllFieldsPermitted = this.navigationArguments.Fields is
null;
141 if (AllFields is not
null)
143 foreach (
string Field in AllFields)
144 PermittedFields[
Field] = AllFieldsPermitted;
147 if (!AllFieldsPermitted && this.navigationArguments?.
Fields is not
null)
149 foreach (
string Field in this.navigationArguments.Fields)
150 PermittedFields[
Field] =
true;
153 foreach (KeyValuePair<string, bool> P
in PermittedFields)
155 FieldReference
Field =
new(P.Key, P.Value);
174 this.SelectedRuleRangeIndex = 0;
183 public ObservableCollection<HumanReadableTag>
Tags {
get; }
188 public ObservableCollection<HumanReadableTag>
CallerTags {
get; }
193 public ObservableCollection<FieldReference>
Fields {
get; }
198 public ObservableCollection<RuleRangeModel>
RuleRanges {
get; }
204 private string? bareJid;
210 private string? friendlyName;
216 private string? remoteJid;
222 private string? remoteFriendlyName;
228 private bool remoteFriendlyNameAvailable;
240 private bool hasUser;
246 private bool hasService;
252 private bool hasDevice;
258 private string? provisioningService;
264 private bool callerInContactsList;
270 private int selectedRuleRangeIndex;
282 [NotifyCanExecuteChangedFor(nameof(AcceptCommand))]
283 private bool permitMomentary;
289 [NotifyCanExecuteChangedFor(nameof(AcceptCommand))]
290 private bool permitIdentity;
296 [NotifyCanExecuteChangedFor(nameof(AcceptCommand))]
297 private bool permitStatus;
303 [NotifyCanExecuteChangedFor(nameof(AcceptCommand))]
304 private bool permitComputed;
310 [NotifyCanExecuteChangedFor(nameof(AcceptCommand))]
311 private bool permitPeak;
317 [NotifyCanExecuteChangedFor(nameof(AcceptCommand))]
318 private bool permitHistorical;
324 private string? nodeId;
330 private string? sourceId;
336 private string? partitionId;
344 private static Task Click(
object obj)
348 else if (obj is
string s)
351 return Task.CompletedTask;
358 private async Task AddContact()
360 if (!this.CallerInContactsList)
364 BareJid = this.RemoteJid,
365 FriendlyName = (this.RemoteFriendlyNameAvailable ? this.RemoteFriendlyName : this.RemoteJid) ??
string.Empty
370 this.CallerInContactsList =
true;
378 private async Task RemoveContact()
380 if (this.CallerInContactsList)
383 if (Info is not
null)
386 this.CallerInContactsList =
false;
393 [RelayCommand(CanExecute = nameof(CanExecuteAccept))]
394 private void Accept()
402 base.OnPropertyChanged(e);
404 switch (e.PropertyName)
406 case nameof(this.IsConnected):
407 this.AcceptCommand.NotifyCanExecuteChanged();
412 private bool CanExecuteAccept()
414 if (!this.IsConnected)
417 if (this.PermitMomentary || this.PermitIdentity || this.PermitStatus || this.PermitComputed || this.PermitPeak || this.PermitHistorical)
432 [RelayCommand(CanExecute = nameof(this.IsConnected))]
433 private void Reject()
438 private void Respond(
bool Accepts)
440 if (this.SelectedRuleRangeIndex >= 0)
443 ThingReference Thing =
new(this.NodeId, this.SourceId, this.PartitionId);
446 if (this.PermitMomentary)
449 if (this.PermitIdentity)
452 if (this.PermitStatus)
455 if (this.PermitComputed)
461 if (this.PermitHistorical)
466 ReadoutRequestResolver Resolver =
new(this.BareJid ??
string.Empty, this.RemoteFriendlyName ??
string.Empty,
RuleRange);
473 this.BareJid!,
this.RemoteJid!,
this.Key!, Accepts, FieldTypes,
this.GetFields(), Thing, this.ResponseHandler, Resolver);
478 this.BareJid!,
this.RemoteJid!,
this.Key!, Accepts, FieldTypes,
this.GetFields(), Thing, this.ResponseHandler, Resolver);
483 this.BareJid!,
this.RemoteJid!,
this.Key!, Accepts, FieldTypes,
this.GetFields(), Thing, this.ResponseHandler, Resolver);
490 ReadoutRequestResolver Resolver =
new(this.BareJid ??
string.Empty, this.RemoteFriendlyName ??
string.Empty, Token);
496 this.BareJid!,
this.RemoteJid!,
this.Key!, Accepts, FieldTypes,
this.GetFields(), Token.Token, Thing, this.ResponseHandler, Resolver);
501 this.BareJid!,
this.RemoteJid!,
this.Key!, Accepts, FieldTypes,
this.GetFields(), Token.Token, Thing, this.ResponseHandler, Resolver);
506 this.BareJid!,
this.RemoteJid!,
this.Key!, Accepts, FieldTypes,
this.GetFields(), Token.Token, Thing, this.ResponseHandler, Resolver);
513 private string[]? GetFields()
515 List<string> Result = [];
516 bool AllPermitted =
true;
518 foreach (FieldReference
Field in this.Fields)
523 AllPermitted =
false;
532 private async Task ResponseHandler(
object? Sender, IqResultEventArgs e)
536 if (this.@event is not
null)
541 MainThread.BeginInvokeOnMainThread(async () =>
548 MainThread.BeginInvokeOnMainThread(async () => await
ServiceRef.
UiService.DisplayException(e.StanzaError ??
557 private async Task Ignore()
559 if (this.@event is not
null)
569 private void AllFieldTypes()
571 this.PermitMomentary =
true;
572 this.PermitIdentity =
true;
573 this.PermitStatus =
true;
574 this.PermitComputed =
true;
575 this.PermitPeak =
true;
576 this.PermitHistorical =
true;
583 private void NoFieldTypes()
585 this.PermitMomentary =
false;
586 this.PermitIdentity =
false;
587 this.PermitStatus =
false;
588 this.PermitComputed =
false;
589 this.PermitPeak =
false;
590 this.PermitHistorical =
false;
597 private void AllFields()
599 foreach (FieldReference
Field in this.Fields)
600 Field.Permitted =
true;
607 private void NoFields()
609 foreach (FieldReference
Field in this.Fields)
610 Field.Permitted =
false;
Contains information about a request to read a thing.
static async Task< string[]?> GetAvailableFieldNames(string BareJid, ThingReference Thing)
Gets available fields for a thing.
A record of a token used in provisioning.
string? FriendlyName
Friendly Name of certificate
Base class that references services in the app.
static IUiService UiService
Service serializing and managing UI-related tasks.
static INotificationService NotificationService
Service for managing notifications for the user.
static ITagProfile TagProfile
TAG Profile service.
static IStringLocalizer Localizer
Localization service
static IXmppService XmppService
The XMPP service for XMPP communication.
virtual async Task GoBack()
Method called when user wants to navigate to the previous screen.
Holds navigation parameters specific to displaying the can-read provisioning question.
FieldType FieldTypes
Field Types
new? CanReadNotificationEvent Event
Notification event objcet.
The view model to bind to when displaying a thing.
ObservableCollection< HumanReadableTag > CallerTags
Holds a list of meta-data tags associated with the caller.
ObservableCollection< HumanReadableTag > Tags
Holds a list of meta-data tags associated with a thing.
override void OnPropertyChanged(PropertyChangedEventArgs e)
override async Task OnInitialize()
Method called when view is initialized for the first time. Use this method to implement registration ...
ObservableCollection< FieldReference > Fields
Holds a list of fields that will be permitted.
ObservableCollection< RuleRangeModel > RuleRanges
Available Rule Ranges
CanReadViewModel(CanReadNavigationArgs? Args)
Creates an instance of the CanReadViewModel class.
string? PartitionId
Partition ID
string? SourceId
Source ID
Class used to present a meta-data tag in a human interface.
string? Key
Provisioning key
string? BareJid
Bare JID of device.
string? RemoteFriendlyName
Friendly name of remote entity.
string? FriendlyName
Friendly name of device.
string? RemoteJid
Bare JID of remote entity trying to connect to device.
string? ProvisioningService
Provisioning Service
The view model to bind to for when displaying thing claim information.
static async Task LabelClicked(string Name, string Value, string LocalizedValue)
Processes the click of a localized meta-data label.
A view model that holds the XMPP state.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
static string GetDomain(string JID)
Gets the domain part of a JID.
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.
static async Task Delete(object Object)
Deletes an object in the database.
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
Base class for all sensor data fields.
string Name
Unlocalized field name.
Contains a reference to a thing
Interface for event resolvers. Such can be used to resolve multiple pending notifications at once.
Task DeleteEvents(NotificationEventType Type, CaseInsensitiveString Category)
Deletes events for a given button and category.
Task DeleteResolvedEvents(IEventResolver Resolver)
Deletes pending events that have already been resolved.
TokenType
Provisioning Token Type
abstract class NotificationEvent()
Abstract base class of notification events.
class RuleRangeModel(object RuleRange, string Label)
Rule Range model
RuleRange
Range of a rule change
FieldType
Field Type flags