1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
21using System.Collections.ObjectModel;
22using System.ComponentModel;
23using System.Globalization;
46 public override async Task OnInitializeAsync()
48 await base.OnInitializeAsync();
50 if (this.navigationArguments is not
null)
52 this.Created = this.navigationArguments.Token?.Created;
53 this.Updated = this.navigationArguments.Token?.Updated;
54 this.Expires = this.navigationArguments.Token?.Expires;
55 this.ArchiveRequired = this.navigationArguments.Token?.ArchiveRequired;
56 this.ArchiveOptional = this.navigationArguments.Token?.ArchiveOptional;
57 this.SignatureTimestamp = this.navigationArguments.Token?.SignatureTimestamp;
58 this.Signature = this.navigationArguments.Token?.Signature;
59 this.DefinitionSchemaDigest = this.navigationArguments.Token?.DefinitionSchemaDigest;
60 this.DefinitionSchemaHashFunction = this.navigationArguments.Token?.DefinitionSchemaHashFunction;
61 this.CreatorCanDestroy = this.navigationArguments.Token?.CreatorCanDestroy ??
false;
62 this.OwnerCanDestroyBatch = this.navigationArguments.Token?.OwnerCanDestroyBatch ??
false;
63 this.OwnerCanDestroyIndividual = this.navigationArguments.Token?.OwnerCanDestroyIndividual ??
false;
64 this.CertifierCanDestroy = this.navigationArguments.Token?.CertifierCanDestroy ??
false;
65 this.FriendlyName = this.navigationArguments.Token?.FriendlyName;
66 this.Category = this.navigationArguments.Token?.Category;
67 this.Description = this.navigationArguments.Token?.Description is
null ? null : await this.navigationArguments.Token.Description.MarkdownToParsedXaml();
68 this.GlyphContentType = this.navigationArguments.Token?.GlyphContentType;
69 this.Ordinal = this.navigationArguments.Token?.Ordinal;
70 this.Value = this.navigationArguments.Token?.Value;
71 this.TokenIdMethod = this.navigationArguments.Token?.TokenIdMethod;
72 this.TokenId = this.navigationArguments.Token?.TokenId;
73 this.ShortTokenId = this.navigationArguments.Token?.ShortTokenId;
74 this.Visibility = this.navigationArguments.Token?.Visibility;
75 this.Creator = this.navigationArguments.Token?.Creator;
77 this.CreatorJid = this.navigationArguments.Token?.CreatorJid;
78 this.Owner = this.navigationArguments.Token?.Owner;
80 this.OwnerJid = this.navigationArguments.Token?.OwnerJid;
81 this.BatchSize = this.navigationArguments.Token?.BatchSize;
82 this.TrustProvider = this.navigationArguments.Token?.TrustProvider;
84 this.TrustProviderJid = this.navigationArguments.Token?.TrustProviderJid;
85 this.Currency = this.navigationArguments.Token?.Currency;
86 this.Reference = this.navigationArguments.Token?.Reference;
87 this.Definition = this.navigationArguments.Token?.Definition;
88 this.DefinitionNamespace = this.navigationArguments.Token?.DefinitionNamespace;
89 this.CreationContract = this.navigationArguments.Token?.CreationContract;
90 this.OwnershipContract = this.navigationArguments.Token?.OwnershipContract;
91 this.GlyphImage = this.navigationArguments.Token?.GlyphImage;
92 this.HasGlyphImage = this.navigationArguments.Token?.HasGlyphImage ??
false;
93 this.GlyphWidth = this.navigationArguments.Token?.GlyphWidth;
94 this.GlyphHeight = this.navigationArguments.Token?.GlyphHeight;
95 this.TokenXml = this.navigationArguments.Token?.Token.ToXml();
96 this.IsMyToken =
string.Equals(this.OwnerJid,
ServiceRef.
XmppService.BareJid, StringComparison.OrdinalIgnoreCase);
97 this.HasStateMachine = this.navigationArguments.Token?.HasStateMachine ??
false;
98 this.HasEmbeddedLayout = this.navigationArguments.Token?.HasEmbeddedLayout ??
false;
100 if (!
string.IsNullOrEmpty(this.navigationArguments.Token?.Reference))
102 if (Uri.TryCreate(
this.navigationArguments.Token?.Reference, UriKind.Absolute, out Uri? RefUri) &&
103 RefUri.Scheme.ToLower(CultureInfo.InvariantCulture) is
string s &&
104 (s ==
"http" || s ==
"https"))
110 if (this.navigationArguments.Token?.Tags is not
null)
112 foreach (
TokenTag Tag
in this.navigationArguments.Token.Tags)
113 this.page.AddLink(
this, Tag.
Name, Tag.
Value?.ToString() ??
string.Empty);
116 if (this.TokenId is not
null)
126 if (this.navigationArguments.Token?.Tags is not
null)
128 foreach (
TokenTag Tag
in this.navigationArguments.Token.Tags)
132 StringBuilder sb =
new();
133 string Domain = this.TokenId?.After(
"@") ??
string.Empty;
134 Domain = Domain.After(
".");
136 sb.Append(
"https://");
138 sb.Append(
"/ValidationSchema.md?NS=");
139 sb.Append(HttpUtility.UrlEncode(
this.DefinitionNamespace));
142 if (this.DefinitionSchemaDigest is not
null)
143 sb.Append(HttpUtility.UrlEncode(Convert.ToBase64String(
this.DefinitionSchemaDigest)));
145 sb.Append(
"&Download=1");
147 this.DefinitionSchemaUrl = sb.ToString();
151 private async Task Populate(
string LegalIdLabel,
string JidLabel,
string[]? LegalIds,
string[]? Jids, ObservableCollection<PartItem> Parts)
153 int i, c = LegalIds?.Length ?? 0;
154 int d = Jids?.Length ?? 0;
160 for (i = 0; i < c; i++)
163 Jid = i < d ? (Jids![i] ??
string.Empty) :
string.Empty;
165 Parts.Add(
new PartItem(LegalIds[i], Jid, FriendlyName));
167 this.page.AddLegalId(
this, LegalIdLabel, FriendlyName, LegalIds[i]);
169 if (!
string.IsNullOrEmpty(Jid))
170 this.page.AddJid(
this, JidLabel, Jid, LegalIds[i], FriendlyName);
178 private string? definitionSchemaUrl;
185 public ObservableCollection<PartItem> Certifiers {
get; } = [];
190 public ObservableCollection<PartItem> Valuators {
get; } = [];
195 public ObservableCollection<PartItem> Assessors {
get; } = [];
200 public ObservableCollection<PartItem> Witnesses {
get; } = [];
205 public ObservableCollection<TokenTag> Tags {
get; } = [];
211 private DateTime? created;
217 private DateTime? updated;
223 private DateTime? expires;
241 private DateTime? signatureTimestamp;
247 private byte[]? signature;
253 private byte[]? definitionSchemaDigest;
265 private bool creatorCanDestroy;
271 private bool ownerCanDestroyBatch;
277 private bool ownerCanDestroyIndividual;
283 private bool certifierCanDestroy;
289 private string? friendlyName;
295 private string? category;
301 private object? description;
307 private string? glyphContentType;
313 private int? ordinal;
319 private decimal? value;
331 private string? tokenId;
337 private string? shortTokenId;
340 protected override void OnPropertyChanged(PropertyChangedEventArgs e)
342 base.OnPropertyChanged(e);
344 switch (e.PropertyName)
346 case nameof(this.ShortTokenId):
347 this.HasShortTokenId = !
string.IsNullOrEmpty(this.ShortTokenId);
356 private bool hasShortTokenId;
362 private string? tokenXml;
374 private string? creator;
380 private string? creatorFriendlyName;
386 private string? creatorJid;
392 private string? owner;
398 private string? ownerFriendlyName;
404 private string? ownerJid;
410 private int? batchSize;
416 private string? trustProvider;
422 private string? trustProviderFriendlyName;
428 private string? trustProviderJid;
434 private string? currency;
440 private string? reference;
446 private string? definition;
452 private string? definitionNamespace;
458 private string? creationContract;
464 private string? ownershipContract;
470 private ImageSource? glyphImage;
476 private bool hasGlyphImage;
482 private int? glyphWidth;
488 private int? glyphHeight;
494 private bool isMyToken;
500 private bool hasStateMachine;
506 private bool hasEmbeddedLayout;
517 public static async Task CopyToClipboard(
object Parameter)
521 string s =
Parameter?.ToString() ??
string.Empty;
522 int i = s.IndexOf(
'@');
524 if (i > 0 && Guid.TryParse(s[..i], out
_))
532 await Clipboard.SetTextAsync(s);
548 private static async Task ViewId(
object Parameter)
551 if (
string.IsNullOrEmpty(LegalId))
568 private static async Task ViewContract(
object Parameter)
570 string? ContractId =
Parameter?.ToString();
571 if (
string.IsNullOrEmpty(ContractId))
588 private async Task OpenChat(
object Parameter)
591 if (
string.IsNullOrEmpty(s))
596 string? FriendlyName;
601 BareJid = this.OwnerJid;
602 LegalId = this.Owner;
603 FriendlyName = this.OwnerFriendlyName;
607 BareJid = this.CreatorJid;
608 LegalId = this.Creator;
609 FriendlyName = this.CreatorFriendlyName;
612 case "TrustProvider":
613 BareJid = this.TrustProviderJid;
614 LegalId = this.TrustProvider;
615 FriendlyName = this.TrustProviderFriendlyName;
619 string[] Parts = s.Split(
" | ");
620 if (Parts.Length != 3)
625 FriendlyName = Parts[2];
644 private static async Task OpenLink(
object Parameter)
654 private async Task ShowM2mInfo()
656 if (this.Definition is
null)
661 byte[] Bin = Encoding.UTF8.GetBytes(this.Definition);
682 private async Task SendToContact()
684 TaskCompletionSource<ContactInfoModel?> Selected =
new();
687 CanScanQrCode =
true,
696 StringBuilder Markdown =
new();
698 Markdown.Append(
"```");
700 Markdown.AppendLine(this.TokenXml);
701 Markdown.AppendLine(
"```");
705 if (Contact.
Contact is not
null)
707 await Task.Delay(100);
718 private async Task Share()
722 if (this.QrCodeBin is
null)
727 await this.OpenQrPopup(this.FriendlyName);
743 private async Task PublishMarketplace()
750 NewContractNavigationArgs NewContractArgs =
new(Template,
true,
751 new Dictionary<CaseInsensitiveString, object>()
753 {
"TokenID", this.TokenId ?? string.Empty },
754 {
"Category", this.Category ?? string.Empty },
755 {
"FriendlyName", this.FriendlyName ?? string.Empty },
756 {
"CommissionPercent", e.Commission },
757 {
"Currency", e.Currency }
770 LegalId = e.TrustProviderId
788 private async Task OfferToSell()
792 Dictionary<CaseInsensitiveString, object> Parameters = [];
793 string? TrustProviderId =
null;
800 XmlDocument Doc =
new()
802 PreserveWhitespace =
true
808 XmlNamespaceManager NamespaceManager =
new(Doc.NameTable);
811 string? SellerRole = Doc.SelectSingleNode(
"/nft:Transfer/nft:Seller/nft:RoleReference/@role", NamespaceManager)?.Value;
812 string? TrustProviderRole = Doc.SelectSingleNode(
"/nft:Transfer/nft:TrustProvider/nft:RoleReference/@role", NamespaceManager)?.Value;
813 string? TokenIdParameter = Doc.SelectSingleNode(
"/nft:Transfer/nft:TokenID/nft:ParameterReference/@parameter", NamespaceManager)?.Value;
814 string? CurrencyParameter = Doc.SelectSingleNode(
"/nft:Transfer/nft:Currency/nft:ParameterReference/@parameter", NamespaceManager)?.Value;
815 string? CommissionParameter = Doc.SelectSingleNode(
"/nft:Transfer/nft:CommissionPercent/nft:ParameterReference/@parameter", NamespaceManager)?.Value;
816 string? OwnershipContractParameter = Doc.SelectSingleNode(
"/nft:Transfer/nft:OwnershipContract/nft:ParameterReference/@parameter", NamespaceManager)?.Value;
818 if (Template.
Parts is
null)
820 List<Part> Parts = [];
822 if (!
string.IsNullOrEmpty(SellerRole))
831 if (!
string.IsNullOrEmpty(TrustProviderRole))
836 Role = TrustProviderRole
840 Template.Parts = [.. Parts];
849 else if (
Part.
Role == TrustProviderRole)
854 if (!
string.IsNullOrEmpty(TokenIdParameter))
855 Parameters[TokenIdParameter] = this.TokenId ??
string.Empty;
857 if (!
string.IsNullOrEmpty(CurrencyParameter))
858 Parameters[CurrencyParameter] = e.
Currency;
860 if (!
string.IsNullOrEmpty(CommissionParameter))
861 Parameters[CommissionParameter] = e.
Commission;
863 if (!
string.IsNullOrEmpty(OwnershipContractParameter))
864 Parameters[OwnershipContractParameter] = this.OwnershipContract ??
string.Empty;
867 NewContractNavigationArgs NewContractArgs =
new(Template,
true, Parameters);
869 if (!
string.IsNullOrEmpty(TrustProviderId))
870 NewContractArgs.SuppressProposal(TrustProviderId);
884 private async Task OfferToBuy()
888 Dictionary<CaseInsensitiveString, object> Parameters = [];
889 string? TrustProviderId =
null;
896 XmlDocument Doc =
new()
898 PreserveWhitespace =
true
904 XmlNamespaceManager NamespaceManager =
new(Doc.NameTable);
907 string? BuyerRole = Doc.SelectSingleNode(
"/nft:Transfer/nft:Buyer/nft:RoleReference/@role", NamespaceManager)?.Value;
908 string? SellerRole = Doc.SelectSingleNode(
"/nft:Transfer/nft:Seller/nft:RoleReference/@role", NamespaceManager)?.Value;
909 string? TrustProviderRole = Doc.SelectSingleNode(
"/nft:Transfer/nft:TrustProvider/nft:RoleReference/@role", NamespaceManager)?.Value;
910 string? TokenIdParameter = Doc.SelectSingleNode(
"/nft:Transfer/nft:TokenID/nft:ParameterReference/@parameter", NamespaceManager)?.Value;
911 string? CurrencyParameter = Doc.SelectSingleNode(
"/nft:Transfer/nft:Currency/nft:ParameterReference/@parameter", NamespaceManager)?.Value;
912 string? CommissionParameter = Doc.SelectSingleNode(
"/nft:Transfer/nft:CommissionPercent/nft:ParameterReference/@parameter", NamespaceManager)?.Value;
913 string? OwnershipContractParameter = Doc.SelectSingleNode(
"/nft:Transfer/nft:OwnershipContract/nft:ParameterReference/@parameter", NamespaceManager)?.Value;
915 if (Template.
Parts is
null)
917 List<Part> Parts = [];
919 if (!
string.IsNullOrEmpty(BuyerRole))
928 if (!
string.IsNullOrEmpty(SellerRole))
932 LegalId = this.Owner,
937 if (!
string.IsNullOrEmpty(TrustProviderRole))
942 Role = TrustProviderRole
946 Template.Parts = [.. Parts];
956 Part.LegalId = this.Owner;
957 else if (
Part.
Role == TrustProviderRole)
962 if (!
string.IsNullOrEmpty(TokenIdParameter))
963 Parameters[TokenIdParameter] = this.TokenId ??
string.Empty;
965 if (!
string.IsNullOrEmpty(CurrencyParameter))
966 Parameters[CurrencyParameter] = e.
Currency;
968 if (!
string.IsNullOrEmpty(CommissionParameter))
969 Parameters[CommissionParameter] = e.
Commission;
971 if (!
string.IsNullOrEmpty(OwnershipContractParameter))
972 Parameters[OwnershipContractParameter] = this.OwnershipContract ??
string.Empty;
975 NewContractNavigationArgs NewContractArgs =
new(Template,
true, Parameters);
977 if (!
string.IsNullOrEmpty(TrustProviderId))
978 NewContractArgs.SuppressProposal(TrustProviderId);
992 private async Task ViewEvents()
994 if (this.TokenId is
null)
1004 catch (Exception ex)
1011 private async Task PresentEmbeddedLayout()
1013 if (this.TokenId is
null)
1025 private async Task PresentReport()
1027 if (this.TokenId is
null)
1037 private async Task HistoryReport()
1039 if (this.TokenId is
null)
1049 private async Task StatesReport()
1051 if (this.TokenId is
null)
1061 private async Task ProfilingReport()
1063 if (this.TokenId is
null)
1073 private async Task VariablesReport()
1075 if (this.TokenId is
null)
1090 catch (Exception ex)
1096 private async Task ShowReport(TokenReport Report)
1104 catch (Exception ex)
1112 #region ILinkableView
1117 public override Task<string> Title => Task.FromResult<
string>(this.FriendlyName ??
string.Empty);
Represents an instance of the Neuro-Access app.
const string TokenConsignmentTemplate
Contract template for consigning the token to an auctioneer with the purpose of selling it.
const string TransferTokenTemplate
Contract template for transferring a token from a seller to a buyer
static readonly TimeSpan UploadFile
Upload file timeout
const string NeuroFeature
eDaler URI Scheme (edaler)
static string CreateTokenUri(string id)
Generates a Neuro-Feature ID Uri form the specified id.
A set of never changing property constants and helpful values.
A strongly-typed resource class, for looking up localized strings, etc.
static string Assessor
Looks up a localized string similar to Assessor.
static string SendInformationTo
Looks up a localized string similar to Send Information To?.
static string Reference
Looks up a localized string similar to Reference.
static string Certifier
Looks up a localized string similar to Certifier.
static string IdCopiedSuccessfully
Looks up a localized string similar to A link to the ID was copied to the clipboard....
static string TagValueCopiedToClipboard
Looks up a localized string similar to Tag value copied to clipboard.
static string Valuator
Looks up a localized string similar to Valuator.
static string SuccessTitle
Looks up a localized string similar to Success.
static string PurposeReviewToken
Looks up a localized string similar to Reviewing token where you are part..
static string ErrorTitle
Looks up a localized string similar to An error has occurred.
static string Witness
Looks up a localized string similar to Witness.
static string CertifierJid
Looks up a localized string similar to Certifier Address.
Base class that references services in the app.
static ILogService LogService
Log service.
static IUiService UiService
Service serializing and managing UI-related tasks.
static INavigationService NavigationService
The navigation service for navigating between pages.
static ITagProfile TagProfile
TAG Profile service.
static IContractOrchestratorService ContractOrchestratorService
Contract orchestrator service.
static IReportingStringLocalizer Localizer
Localization service
static IXmppService XmppService
The XMPP service for XMPP communication.
Holds navigation parameters specific to views displaying a list of contacts.
A page that displays a list of the current user's contacts.
The view model to bind to when displaying the list of contacts.
Contact Information model, including related notification information.
ContactInfo? Contact
Contact Information object in database.
CaseInsensitiveString? BareJid
Bare JID of contact.
Holds navigation parameters specific to views displaying a list of contacts.
A page that displays a list of the current user's contacts.
A page that allows the user to create a new contract.
A view model that holds the XMPP state.
Navigation arguments used when navigating to the embedded layout page.
Page used to display a token's embedded layout.
Holds navigation parameters specific to a report from a state-machine.
A page that allows the user to view a state-machine report.
Holds navigation parameters specific to the current state of a state-machine.
A page that allows the user to view information about the current state of a state-machine.
Holds navigation parameters specific to a token.
A page that allows the user to view information about a token.
Holds navigation parameters containing the events of a token.
A page that allows the user to view information about a token.
Event arguments for callback methods to token creation attributes queries.
string TrustProviderId
Legal ID used by the trust provider to sign contracts.
string Currency
Default currency used by the broker
decimal Commission
Minimum commission (in %) expected by the trust provider, in order to sign contract.
Event arguments for current state callback methods.
string CurrentState
Current state of state-machine.
Variables Variables
Current state-machine variables.
bool Running
If the state-machine is running.
bool Ended
If the state-machine has ended.
Abstract base class for token events.
const string NamespaceNeuroFeatures
Namespace for Neuro-Features.
Static class managing encoding and decoding of internet content.
static string GetFileExtension(string ContentType)
Gets the file extension of an item, given its content type. It uses the TryGetFileExtension to see if...
Contains the definition of a contract
string ForMachinesLocalName
Local name used by the root node of the machine-readable contents of the contract (ForMachines).
XmlElement ForMachines
Machine-readable contents of the contract.
Part[] Parts
Defined parts for the smart contract.
string ForMachinesNamespace
Namespace used by the root node of the machine-readable contents of the contract (ForMachines).
Abstract base class for contractual parameters
Class defining a part in a contract
string Role
Role of the part in the contract
bool Ok
If the response is an OK result response (true), or an error response (false).
XmppException StanzaError
Any stanza error returned.
string ErrorText
Any error specific text.
Event arguments for HTTP File Upload callback methods.
Task PUT(byte[] Content, string ContentType, int Timeout)
Uploads file content to the server.
Task GoToAsync(string Route)
Navigates to the specified route and pushes the page onto the navigation stack.
Task DisplayException(Exception Exception, string? Title=null)
Displays an alert/message box to the user.
Task< bool > DisplayAlert(string Title, string Message, string? Accept=null, string? Cancel=null)
Displays an alert/message box to the user.
BackMethod
Navigation Back Method
class TokenPresentReport(string TokenId)
Represent a report of the present state of a token and the underlying state-machine.
class TokenStateDiagramReport(string TokenId)
Represent a state diagram of a token and the underlying state-machine.
class TokenHistoryReport(string TokenId)
Represent a report of the historical states of a token and the underlying state-machine.
class TokenProfilingReport(string TokenId)
Represent a profiling report of a token and the underlying state-machine.
partial class TokenDetailsViewModel(TokenDetailsPage Page, TokenDetailsNavigationArgs? Args)
The view model to bind to for when displaying the contents of a token.
class PartItem(string LegalId, string Jid, string FriendlyName)
Represents a part related to a token.
TokenIdMethod
By which mechanism the Token ID was created
ContractParts
How the parts of the contract are defined.
ContractVisibility
Visibility types for contracts.
HashFunction
Hash method enumeration.
Represents a duration value, as defined by the xsd:duration data type: http://www....