1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
11using System.Collections.ObjectModel;
12using System.ComponentModel;
36 this.navigationArguments = Args;
45 this.@
event = Args.
Event;
56 if (this.FriendlyName == this.BareJid)
59 this.RemoteFriendlyNameAvailable = this.RemoteFriendlyName != this.RemoteJid;
60 if (!this.RemoteFriendlyNameAvailable)
68 await base.OnInitialize();
70 if (this.navigationArguments is not
null)
76 if (Thing?.MetaData is not
null)
83 this.CallerInContactsList = Caller is not
null;
84 if (Caller?.MetaData is not
null)
90 if (this.navigationArguments.UserTokens is not
null &&
this.navigationArguments.UserTokens.Length > 0)
98 if (this.navigationArguments.ServiceTokens is not
null &&
this.navigationArguments.ServiceTokens.Length > 0)
103 this.HasService =
true;
106 if (this.navigationArguments.DeviceTokens is not
null &&
this.navigationArguments.DeviceTokens.Length > 0)
111 this.HasDevice =
true;
116 SortedDictionary<string, bool> PermittedParameters = [];
117 string[]? AllParameters = this.navigationArguments.AllParameters;
119 if (AllParameters is
null && !
string.IsNullOrEmpty(this.BareJid))
122 new ThingReference(this.NodeId, this.SourceId, this.PartitionId));
124 if (AllParameters is not
null && this.navigationArguments?.Event is not
null)
126 this.navigationArguments.Event.AllParameters = AllParameters;
131 bool AllParametersPermitted = this.navigationArguments?.Parameters is
null;
133 if (AllParameters is not
null)
135 foreach (
string Parameter in AllParameters)
136 PermittedParameters[
Parameter] = AllParametersPermitted;
139 if (!AllParametersPermitted && this.navigationArguments?.
Parameters is not
null)
141 foreach (
string Parameter in this.navigationArguments.Parameters)
145 foreach (KeyValuePair<string, bool> P
in PermittedParameters)
147 FieldReference
Parameter =
new(P.Key, P.Value);
166 this.SelectedRuleRangeIndex = 0;
175 public ObservableCollection<HumanReadableTag>
Tags {
get; }
180 public ObservableCollection<HumanReadableTag>
CallerTags {
get; }
185 public ObservableCollection<FieldReference>
Parameters {
get; }
190 public ObservableCollection<RuleRangeModel>
RuleRanges {
get; }
196 private string? bareJid;
202 private string? friendlyName;
208 private string? remoteJid;
215 private string? remoteFriendlyName;
221 private bool remoteFriendlyNameAvailable;
233 private bool hasUser;
239 private bool hasService;
245 private bool hasDevice;
251 private string? provisioningService;
257 private bool callerInContactsList;
263 private int selectedRuleRangeIndex;
269 private string? nodeId;
275 private string? sourceId;
281 private string? partitionId;
289 private static Task Click(
object obj)
293 else if (obj is
string s)
296 return Task.CompletedTask;
303 private async Task AddContact()
305 if (!this.CallerInContactsList)
309 BareJid = this.RemoteJid,
310 FriendlyName = (this.RemoteFriendlyNameAvailable ? this.RemoteFriendlyName : this.RemoteJid) ??
string.Empty
315 this.CallerInContactsList =
true;
323 private async Task RemoveContact()
325 if (this.CallerInContactsList && !
string.IsNullOrEmpty(this.RemoteJid))
328 if (Info is not
null)
331 this.CallerInContactsList =
false;
338 [RelayCommand(CanExecute = nameof(CanExecuteAccept))]
339 private void Accept()
347 base.OnPropertyChanged(e);
349 switch (e.PropertyName)
351 case nameof(this.IsConnected):
352 this.AcceptCommand.NotifyCanExecuteChanged();
357 private bool CanExecuteAccept()
359 if (!this.IsConnected)
364 if (Parameter.Permitted)
374 [RelayCommand(CanExecute = nameof(IsConnected))]
375 private void Reject()
380 private void Respond(
bool Accepts)
382 if (this.SelectedRuleRangeIndex >= 0)
385 ThingReference Thing =
new(this.NodeId, this.SourceId, this.PartitionId);
389 ControlRequestResolver Resolver =
new(this.BareJid!, this.RemoteFriendlyName ??
string.Empty,
RuleRange);
396 this.BareJid!,
this.RemoteJid!,
this.Key!, Accepts,
this.GetParameters(), Thing, this.ResponseHandler, Resolver);
401 this.BareJid!,
this.RemoteJid!,
this.Key!, Accepts,
this.GetParameters(), Thing, this.ResponseHandler, Resolver);
406 this.BareJid!,
this.RemoteJid!,
this.Key!, Accepts,
this.GetParameters(), Thing, this.ResponseHandler, Resolver);
413 ControlRequestResolver Resolver =
new(this.BareJid!, this.RemoteFriendlyName ??
string.Empty, Token);
419 this.BareJid!,
this.RemoteJid!,
this.Key!, Accepts,
this.GetParameters(), Token.Token, Thing, this.ResponseHandler, Resolver);
424 this.BareJid!,
this.RemoteJid!,
this.Key!, Accepts,
this.GetParameters(), Token.Token, Thing, this.ResponseHandler, Resolver);
429 this.BareJid!,
this.RemoteJid!,
this.Key!, Accepts,
this.GetParameters(), Token.Token, Thing, this.ResponseHandler, Resolver);
436 private string[]? GetParameters()
438 List<string> Result = [];
439 bool AllPermitted =
true;
441 foreach (FieldReference
Parameter in this.Parameters)
446 AllPermitted =
false;
455 private async Task ResponseHandler(
object? Sender, IqResultEventArgs e)
459 if (this.@event is not
null)
464 MainThread.BeginInvokeOnMainThread(async () =>
471 MainThread.BeginInvokeOnMainThread(async () => await
ServiceRef.
UiService.DisplayException(e.StanzaError ??
480 private async Task Ignore()
482 if (this.@event is not
null)
492 private void AllParameters()
494 foreach (FieldReference
Parameter in this.Parameters)
495 Parameter.Permitted =
true;
502 private void NoParameters()
504 foreach (FieldReference
Parameter in this.Parameters)
505 Parameter.Permitted =
false;
Contains information about a request to read a thing.
static async Task< string[]?> GetAvailableParameterNames(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-control provisioning question.
new? CanControlNotificationEvent Event
Notification event objcet.
The view model to bind to when displaying a thing.
override void OnPropertyChanged(PropertyChangedEventArgs e)
ObservableCollection< RuleRangeModel > RuleRanges
Available Rule Ranges
CanControlViewModel(CanControlNavigationArgs? Args)
Creates an instance of the CanControlViewModel class.
ObservableCollection< HumanReadableTag > Tags
Holds a list of meta-data tags associated with a thing.
override async Task OnInitialize()
Method called when view is initialized for the first time. Use this method to implement registration ...
ObservableCollection< HumanReadableTag > CallerTags
Holds a list of meta-data tags associated with the caller.
ObservableCollection< FieldReference > Parameters
Holds a list of parameters that will be permitted.
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.
Abstract base class for contractual parameters
string Name
Parameter name
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.
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