1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
9using System.Collections.ObjectModel;
10using System.ComponentModel;
38 this.thing = Args?.
Thing;
42 if (this.thing is not
null)
44 if (
string.IsNullOrEmpty(this.thing.NodeId) &&
string.IsNullOrEmpty(
this.thing.SourceId) &&
string.IsNullOrEmpty(
this.thing.Partition))
47 this.thingRef =
new ThingReference(this.thing.NodeId,
this.thing.SourceId,
this.thing.Partition);
49 if (this.thing.MetaData is not
null &&
this.thing.MetaData.Length > 0)
53 foreach (
Property Tag
in this.thing.MetaData)
57 this.SupportsSensorEvents = this.thing.SupportsSensorEvents ??
false;
64 await base.OnInitializeAsync();
66 this.CalcThingIsOnline();
68 ServiceRef.XmppService.OnPresence += this.Xmpp_OnPresence;
69 ServiceRef.TagProfile.Changed += this.TagProfile_Changed;
71 string? FullJid = this.GetFullJid();
73 if (!
string.IsNullOrEmpty(FullJid))
75 if (this.thingRef is
null || this.thingRef.IsEmpty)
80 this.request.OnStateChanged += this.Request_OnStateChanged;
81 this.request.OnFieldsReceived += this.Request_OnFieldsReceived;
82 this.request.OnErrorsReceived += this.Request_OnErrorsReceived;
90 this.Status = NewState
switch
102 return Task.CompletedTask;
105 private static string GetFieldTypeString(
FieldType Type)
111 else if (Type.HasFlag(
FieldType.Momentary))
115 else if (Type.HasFlag(
FieldType.Computed))
117 else if (Type.HasFlag(
FieldType.Historical))
123 private Task Request_OnFieldsReceived(
object? Sender, IEnumerable<Field> NewFields)
125 return this.NewFieldsReported(NewFields);
128 private Task NewFieldsReported(IEnumerable<Field> NewFields)
130 MainThread.BeginInvokeOnMainThread(() =>
135 int CategoryIndex = 0;
149 if (FieldName.EndsWith(
", Min", StringComparison.InvariantCultureIgnoreCase))
151 FieldName = FieldName[0..^5];
154 else if (FieldName.EndsWith(
", Max", StringComparison.InvariantCultureIgnoreCase))
156 FieldName = FieldName[0..^5];
160 Category = FieldName;
164 Category = GetFieldTypeString(
Field.
Type);
165 IsMin = IsMax =
false;
168 if (CategoryHeader is
null || CategoryHeader.Label != Category)
170 CategoryHeader =
null;
184 if (CategoryHeader is
null)
187 this.SensorData.Add(CategoryHeader);
193 for (i = CategoryIndex + 1, c = this.SensorData.Count; i < c; i++)
195 object Obj = this.SensorData[i];
213 else if (j > 0 && !IsMin && !IsMax)
231 for (i = CategoryIndex + 1, c = this.SensorData.Count; i < c; i++)
233 object Obj = this.SensorData[i];
235 if (Obj is FieldModel FieldModel)
237 j =
string.Compare(FieldName, FieldModel.Name, StringComparison.OrdinalIgnoreCase);
243 FieldModel.Field =
Field;
245 this.SensorData.Insert(i,
new FieldModel(
Field));
252 this.SensorData.Insert(i,
new FieldModel(
Field));
258 this.SensorData.Add(
new FieldModel(
Field));
263 return Task.CompletedTask;
266 private Task Request_OnErrorsReceived(
object? Sender, IEnumerable<ThingError> NewErrors)
268 return this.NewErrorsReported(NewErrors);
271 private Task NewErrorsReported(IEnumerable<ThingError> NewErrors)
273 MainThread.BeginInvokeOnMainThread(() =>
277 int CategoryIndex = 0;
280 foreach (
object Item
in this.SensorData)
291 if (CategoryHeader is
null)
294 this.SensorData.Add(CategoryHeader);
297 for (i = CategoryIndex + 1, c = this.SensorData.Count; i < c; i++)
299 object Obj = this.SensorData[i];
301 if (Obj is ErrorModel ErrorModel)
307 this.SensorData.Insert(i++,
new ErrorModel(Error));
318 this.SensorData.Add(
new ErrorModel(Error));
322 return Task.CompletedTask;
328 !
string.IsNullOrEmpty(
this.thing?.BareJid) &&
329 string.Equals(
this.thing.BareJid, e.
Publisher, StringComparison.OrdinalIgnoreCase) &&
330 string.IsNullOrEmpty(
this.thing.SourceId) &&
331 string.IsNullOrEmpty(
this.thing.NodeId) &&
332 string.IsNullOrEmpty(
this.thing.Partition))
347 ServiceRef.XmppService.OnPresence -= this.Xmpp_OnPresence;
348 ServiceRef.TagProfile.Changed -= this.TagProfile_Changed;
350 if (this.request is not
null &&
356 await this.request.
Cancel();
359 await base.OnDisposeAsync();
364 this.CalcThingIsOnline();
365 return Task.CompletedTask;
368 private void CalcThingIsOnline()
370 if (this.thing is
null)
371 this.IsThingOnline =
false;
379 private string? GetFullJid()
381 if (this.thing is
null)
394 private void TagProfile_Changed(
object? Sender, PropertyChangedEventArgs e)
396 MainThread.BeginInvokeOnMainThread(this.CalcThingIsOnline);
410 private bool isThingOnline;
416 private bool supportsSensorEvents;
422 private bool hasStatus;
428 private string? status;
433 base.OnPropertyChanged(e);
435 switch (e.PropertyName)
437 case nameof(this.Status):
438 this.HasStatus = !
string.IsNullOrEmpty(this.Status);
441 case nameof(this.IsConnected):
442 this.CalcThingIsOnline();
453 private static Task Click(
object obj)
457 else if (obj is FieldModel
Field)
459 else if (obj is ErrorModel Error)
461 else if (obj is
string s)
464 return Task.CompletedTask;
A strongly-typed resource class, for looking up localized strings, etc.
static string SensorDataHeaderMomentary
Looks up a localized string similar to Momentary.
static string SensorDataHeaderOther
Looks up a localized string similar to Other.
static string SensorDataDone
Looks up a localized string similar to Sensor Data readout has completed..
static string SensorDataHeaderPeak
Looks up a localized string similar to Peak.
static string SensorDataAccepted
Looks up a localized string similar to Request has been accepted..
static string SensorDataHeaderIdentity
Looks up a localized string similar to Identity.
static string Errors
Looks up a localized string similar to Errors.
static string SensorDataCancelled
Looks up a localized string similar to Sensor Data readout has been cancelled..
static string SensorDataStarted
Looks up a localized string similar to Sensor Data readout has started..
static string SensorDataHeaderComputed
Looks up a localized string similar to Computed.
static string SensorDataRequested
Looks up a localized string similar to Sensor Data has been requested..
static string SensorDataReceiving
Looks up a localized string similar to Receiving Sensor Data..
static string GeneralInformation
Looks up a localized string similar to General Information.
static string SensorDataFailure
Looks up a localized string similar to Sensor Data readout has failed..
static string SensorDataHeaderStatus
Looks up a localized string similar to Status.
static string SensorDataHeaderHistorical
Looks up a localized string similar to Historical.
Base class that references services in the app.
static IReportingStringLocalizer Localizer
Localization service
static IXmppService XmppService
The XMPP service for XMPP communication.
Class used to present a meta-data tag in a human interface.
Represents a set of historical field values.
void Add(Field Field)
Adds a historical field value.
string FieldName
Field Name
void AddMax(Field Field)
Adds a historical maximum field value.
void AddMin(Field Field)
Adds a historical minimum field value.
The view model to bind to when displaying a thing.
override async Task OnInitializeAsync()
Method called when view is initialized for the first time. Use this method to implement registration ...
ReadSensorViewModel(ViewThingNavigationArgs? Args)
Creates an instance of the ReadSensorViewModel class.
override void OnPropertyChanged(PropertyChangedEventArgs e)
override async Task OnDisposeAsync()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
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.
Holds navigation parameters specific to viewing things.
ContactInfo? Thing
Thing information.
A view model that holds the XMPP state.
Event arguments for presence events.
bool IsOnline
If contact is online.
Event argument for personal event notification events.
IPersonalEvent PersonalEvent
Parsed personal event, if appropriate type was found.
string Publisher
Publisher of content.
Maintains information about an item in the roster.
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.
virtual Task Cancel()
Cancels the readout.
SensorDataReadoutState State
Current state of readout.
Contains personal sensor data.
IEnumerable< ThingError > Errors
Thing errors.
IEnumerable< Field > Fields
Sensor data fields.
Base class for all sensor data fields.
FieldType Type
Field Type flags.
abstract string ValueString
String representation of field value.
string Name
Unlocalized field name.
Contains information about an error on a thing
Contains a reference to a thing
class HeaderModel(string Label)
Represents a header
class Header(ISimulationNode Parent, Model Model)
Represents an identity property.
SensorDataReadoutState
Sensor Data Readout States.
FieldType
Field Type flags