Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SmartContractLink.cs
1using System.Collections.Specialized;
2using System.Web;
7
9{
14 {
19 {
20 }
21
27 public Grade Supports(Uri Link)
28 {
29 return string.Compare(Link.Scheme, Constants.UriSchemes.IotSc, StringComparison.OrdinalIgnoreCase) == 0 ? Grade.Ok : Grade.NotAtAll;
30 }
31
38 public async Task<bool> TryOpenLink(Uri Link, bool ShowErrorIfUnable)
39 {
40 Dictionary<CaseInsensitiveString, object> Parameters = [];
41 string s = Link.OriginalString.Replace("%40", "@"); // Android has problems with URIs containg @
42
43 string? ContractId = Constants.UriSchemes.RemoveScheme(s) ?? string.Empty;
44 if (ContractId is null)
45 return false;
46
47 int i = ContractId.IndexOf('?');
48
49 if (i > 0)
50 {
51 NameValueCollection QueryParameters = HttpUtility.ParseQueryString(ContractId[i..]);
52
53 foreach (string? Key in QueryParameters.AllKeys)
54 {
55 if (Key is null)
56 continue;
57
58 string? Value = QueryParameters[Key];
59 if (Value is null)
60 continue;
61
62 Parameters[Key] = Value;
63 }
64
65 ContractId = ContractId[..i];
66 }
67
68 await ServiceRef.ContractOrchestratorService.OpenContract(ContractId,
69 ServiceRef.Localizer[nameof(AppResources.ScannedQrCode)], Parameters);
70
71 return true;
72 }
73 }
74}
const string IotSc
The IoT Smart Contract URI Scheme (iotsc)
Definition: Constants.cs:163
static ? string RemoveScheme(string Url)
Removes the URI Schema from an URL.
Definition: Constants.cs:272
A set of never changing property constants and helpful values.
Definition: Constants.cs:24
A strongly-typed resource class, for looking up localized strings, etc.
static string ScannedQrCode
Looks up a localized string similar to Scanned QR Code.
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IContractOrchestratorService ContractOrchestratorService
Contract orchestrator service.
Definition: ServiceRef.cs:238
static IReportingStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:370
Grade
Grade enumeration
Definition: Grade.cs:7