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
42 string? ContractId = Constants.UriSchemes.RemoveScheme(Link.OriginalString) ?? string.Empty;
43 if (ContractId is null)
44 return false;
45
46 int i = ContractId.IndexOf('?');
47
48 if (i > 0)
49 {
50 NameValueCollection QueryParameters = HttpUtility.ParseQueryString(ContractId[i..]);
51
52 foreach (string? Key in QueryParameters.AllKeys)
53 {
54 if (Key is null)
55 continue;
56
57 string? Value= QueryParameters[Key];
58 if (Value is null)
59 continue;
60
61 Parameters[Key] = Value;
62 }
63
64 ContractId = ContractId[..i];
65 }
66
67 await ServiceRef.ContractOrchestratorService.OpenContract(ContractId,
68 ServiceRef.Localizer[nameof(AppResources.ScannedQrCode)], Parameters);
69
70 return true;
71 }
72 }
73}
const string IotSc
The IoT Smart Contract URI Scheme (iotsc)
Definition: Constants.cs:109
static ? string RemoveScheme(string Url)
Removes the URI Schema from an URL.
Definition: Constants.cs:218
A set of never changing property constants and helpful values.
Definition: Constants.cs:7
Base class that references services in the app.
Definition: ServiceRef.cs:31
static IStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:235
static IContractOrchestratorService ContractOrchestratorService
Contract orchestrator service.
Definition: ServiceRef.cs:115
Grade
Grade enumeration
Definition: Grade.cs:7