12using System.Collections.Generic;
14using System.Threading.Tasks;
16using System.Windows.Controls;
17using System.Windows.Media.Imaging;
35 private readonly
Token token;
36 private readonly
string language;
39 private BitmapImage glyph;
40 private string currentState =
null;
41 private Variables currentVariables =
null;
43 private readonly
Command viewPresentReport;
44 private readonly
Command viewHistoryReport;
45 private readonly
Command viewStateDiagramReport;
46 private readonly
Command viewProfilingReport;
61 this.language = Language;
63 this.viewPresentReport =
new Command(this.CanExecuteViewStateMachineReport, this.ExecuteViewPresentReport);
64 this.viewHistoryReport =
new Command(this.CanExecuteViewStateMachineReport, this.ExecuteViewHistoryReport);
65 this.viewStateDiagramReport =
new Command(this.CanExecuteViewStateMachineReport, this.ExecuteViewStateDiagramReport);
66 this.viewProfilingReport =
new Command(this.CanExecuteViewStateMachineReport, this.ExecuteViewProfilingReport);
67 this.executeNoteCommand =
new ParametrizedCommand(this.CanExecuteNoteCommand, this.ExecuteNoteCommand);
111 List<TokenDetail>
Details =
new()
136 new TokenDetail(
"Glyph", Convert.ToBase64String(Result.token.
Glyph),
false),
154 foreach (
string s
in Result.token.Witness)
157 foreach (
string s
in Result.token.CertifierJids)
160 foreach (
string s
in Result.token.CertifierJids)
163 foreach (
string s
in Result.token.Certifier)
166 foreach (
string s
in Result.token.Valuator)
169 foreach (
string s
in Result.token.Assessor)
172 foreach (
TokenTag Tag
in Result.token.Tags)
175 if (Result.token.HasStateMachine)
179 Command = Result.viewPresentReport,
180 Content =
"Present State...",
181 Margin =
new Thickness(10, 2, 10, 2),
187 Command = Result.viewHistoryReport,
188 Content =
"History...",
189 Margin =
new Thickness(10, 2, 10, 2),
195 Command = Result.viewStateDiagramReport,
196 Content =
"State Diagram...",
197 Margin =
new Thickness(10, 2, 10, 2),
203 Command = Result.viewProfilingReport,
204 Content =
"Profiling...",
205 Margin =
new Thickness(10, 2, 10, 2),
209 await Result.AddNoteCommands(
Details);
212 Result.details =
Details.ToArray();
222 List<TokenDetail>
Details =
new();
226 if (!Detail.NoteCommand)
230 await this.AddNoteCommands(
Details);
234 this.Details =
Details.ToArray();
235 return Task.CompletedTask;
239 public async Task<KeyValuePair<NoteCommand, int>[]> GetContextSpecificNoteCommands(
bool IsOwner)
243 [
"State"] = this.currentState,
244 [
"<State>"] = this.currentState
246 int i, c = this.noteCommands?.Length ?? 0;
247 List<KeyValuePair<NoteCommand, int>> Result =
new();
249 this.currentVariables?.
CopyTo(v);
251 for (i = 0; i < c; i++)
271 if (Obj is not
bool b || !b)
281 Result.Add(
new KeyValuePair<NoteCommand, int>(
NoteCommand, i));
284 return Result.ToArray();
287 private async Task AddNoteCommands(List<TokenDetail>
Details)
289 KeyValuePair<NoteCommand, int>[] Commands = await this.GetContextSpecificNoteCommands(
true);
291 foreach (KeyValuePair<NoteCommand, int> P
in Commands)
298 Command = this.executeNoteCommand,
299 CommandParameter = i,
301 Margin =
new Thickness(10, 2, 10, 2),
307 private static async Task<object> MarkdownToXaml(
string Markdown)
310 string Xaml = await Doc.GenerateXAML();
311 return Xaml.ParseSimple();
321 if (this.glyph is
null && this.token.Glyph is not
null)
323 BitmapImage Result =
new();
325 Result.CreateOptions = BitmapCreateOptions.None;
326 Result.CacheOption = BitmapCacheOption.Default;
327 Result.StreamSource =
new MemoryStream(this.token.Glyph);
360 public DateTime
Expires => this.token.Expires;
365 public decimal
Value => this.token.Value;
375 public DateTime
Updated => this.token.Updated;
395 this.details = value;
400 private bool CanExecuteViewStateMachineReport()
402 return this.token.HasStateMachine;
405 private async Task ExecuteViewPresentReport()
407 if (!
string.IsNullOrEmpty(this.TokenId))
411 private async Task ExecuteViewHistoryReport()
413 if (!
string.IsNullOrEmpty(this.TokenId))
417 private async Task ExecuteViewStateDiagramReport()
419 if (!
string.IsNullOrEmpty(this.TokenId))
423 private async Task ExecuteViewProfilingReport()
425 if (!
string.IsNullOrEmpty(this.TokenId))
429 private static async Task AddReport(
TokenReport Report)
435 string Title = await Report.
GetTitle();
442 MainWindow.currentInstance.TabControl.Items.Add(Tab);
443 MainWindow.currentInstance.TabControl.SelectedItem = Tab;
455 private bool CanExecuteNoteCommand(
object Parameter)
458 this.token.HasStateMachine &&
459 this.noteCommands is not
null &&
463 i < this.noteCommands.Length));
466 private async
void ExecuteNoteCommand(
object Parameter)
470 if (this.token.HasStateMachine &&
471 this.noteCommands is not
null &&
474 i <
this.noteCommands.Length)
487 Owner = MainWindow.currentInstance
491 Control First = await
Model.PopulateParameters(
null, Dialog.ParametersPanel,
null,
null);
493 if (First is not
null)
497 bool? Result = Dialog.ShowDialog();
498 if (!Result.HasValue || !Result.Value)
501 NoteParameters = await
Model.ValidateParameters()
502 ??
throw new Exception(
"Invalid parameters.");
510 Msg =
Command.Confirmation?.Find(this.language);
511 if (!
string.IsNullOrEmpty(Msg))
514 MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
516 if (Confirmation != MessageBoxResult.Yes)
521 ?? (
string.IsNullOrEmpty(
Command.NoteGenerationScript) ?
522 throw new Exception(
"Missing note script.")
525 if (!Exp.CheckExpressionSafe(out
ScriptNode Prohibited))
526 throw new Exception(
"Command blocked. Unsafe portion of script: " + Prohibited.SubExpression);
528 Task _ = Task.Run(async () =>
535 await this.client.AddTextNoteAsync(
this.TokenId, s,
Command.Personal);
536 else if (Obj is XmlDocument Xml)
537 await this.client.AddXmlNoteAsync(
this.TokenId, Xml.DocumentElement.OuterXml,
Command.Personal);
538 else if (Obj is XmlElement E)
539 await this.client.AddXmlNoteAsync(
this.TokenId, E.OuterXml,
Command.Personal);
540 else if (Obj is
null)
541 throw new Exception(
"Note command returned null.");
543 throw new Exception(
"Command generated note of uncompatible type: " + Obj.GetType().FullName);
545 this.
NoteAdded?.Invoke(
this, EventArgs.Empty);
547 Msg =
Command.Success?.Find(this.language);
548 if (!
string.IsNullOrEmpty(Msg))
553 Msg =
Command.Failure?.Find(this.language);
560 Msg =
Command.Failure?.Find(this.language);
582 this.currentState = NewState;
591 this.currentVariables = NewVariables;
Interaction logic for ParametersDialog.xaml
Interaction logic for MainWindow.xaml
static void MouseHourglass()
Displays an hourglass cursor (or similar for waiting purposes).
static void ErrorBox(string ErrorMessage)
Displays an error message on the screen, on the main UI thread.
static Task< MessageBoxResult > MessageBox(string Text, string Caption, MessageBoxButton Button, MessageBoxImage Icon)
Displays a message box on the screen, on the main UI thread.
static void UpdateGui(GuiDelegate Method)
Calls a method from the Main UI thread.
static void MouseDefault()
Returns to default mouse pointer.
Defines a custom command.
Abstract base class for selectable items. From the IoTGateway project, with permission.
Contract parameters model
Abstract base class for view models
virtual Task Start()
Starts the model.
virtual void RaisePropertyChanged(string PropertyName)
Raises the PropertyChanged event.
Defines a custom parametrized command.
Represent a report of the historical states of a token and the underlying state-machine.
Represent a report of the present state of a token and the underlying state-machine.
Represent a profiling report of a token and the underlying state-machine.
Abstract base class for token reports.
abstract Task< string > GetTitle()
Gets the title of report.
async Task GenerateReport(ReportTab Tab)
Generates the report.
Represent a state diagram of a token and the underlying state-machine.
Contains a detail of information about a token.
string TokenId
ID of token
Variables CurrentVariables
Current variables of state-machine (if known).
async Task UpdateNoteCommands()
Updates visible note commands, based on the current context.
string Creator
Creator of token
Command ViewStateDiagramReport
Command for showing the state diagram.
BitmapImage Glyph
Token glyph.
void VariablesUpdated(Variables NewVariables)
Gets called when the variables of a state-machine has been reported.
string CurrentState
Current state of state-machine (if known).
Command ViewPresentReport
Command for showing the present report.
DateTime Expires
When token expires
string Category
Category of token
Command ViewHistoryReport
Command for showing the history report.
string FriendlyName
Friendly Name of token
DateTime Updated
When Token was last updated (or created)
void StateUpdated(string NewState)
Gets called when a new state has been reported.
Command ViewProfilingReport
Command for showing the profiling report.
string Description
Description of token
NoteCommand[] NoteCommands
Available note commands.
decimal Value
Current value of token
EventHandler NoteAdded
Event raised when a note has been added.
TokenDetail[] Details
Token details.
ContractVisibility Visibility
Visibility of token
Token Token
Referenced token.
Information about a note command related to the state-machine associated with the token.
bool HasNoteContextScript
If a valid expression for note context is available.
Expression ParsedNoteContextScript
Parsed note context script. If null, script is either not defined, or it contains errors.
LocalizedString[] ToolTip
Tool-tip of command.
bool ExternalNote
If note can be added by authorized external sources.
bool OwnerNote
If note can be added by owner.
LocalizedString[] Title
Title of command.
async Task< NoteCommand[]> GetNoteCommands()
Gets
Duration? ArchiveRequired
Duration after which token expires, the token is required to be archived.
string Category
A category for the token.
string Currency
Currency used to represent latest value.
string TrustProvider
Trust Provider, asserting claims in the token.
string TrustProviderJid
JID of Trust Provider, asserting claims in the token.
int GlyphWidth
Width of glyph, in pixels.
DateTime Expires
Expiry date of token.
decimal Value
Latest value of token
DateTime Updated
When token was updated.
int GlyphHeight
Height of glyph, in pixels.
string CreationContract
ID of contract that details the claims of the current owner
int BatchSize
Size of the batch of contracts created.
string OwnershipContract
ID of contract that details the claims of the current owner
string FriendlyName
A friendly name for the token.
bool CertifierCanDestroy
If a certifier is allowed to destroy the token.
Duration? ArchiveOptional
Duration after which token expires, and the required archiving time, the token can optionally be arch...
bool CreatorCanDestroy
If the creator is allowed to destroy the token.
DateTime Created
When token was created.
DateTime SignatureTimestamp
When the Trust Provider signed the contents of the token.
string OwnerJid
JID of Current owner of token
ContractVisibility Visibility
Token visibility
byte[] DefinitionSchemaDigest
Hash Digest of schema used to validate the definition of the token.
HashFunction DefinitionSchemaHashFunction
Hash function used to compute digest of validation schema.
string ShortId
Short ID, if available
string DefinitionNamespace
Namespace of M2M definition of token.
string Creator
Creator of token
string GlyphContentType
Content-Type of glyph
bool OwnerCanDestroyIndividual
If the current owner is allowed to destroy the token individually.
string Description
Description Markdown for the token.
int Ordinal
Ordinal of token created by the creation smart contract.
string Definition
M2M definition of token, in XML, from the original creation contract.
byte[] Signature
Trust Provider Signature of contents in token.
bool OwnerCanDestroyBatch
If the current owner is allowed to destroy the entire batch of tokens, if owner of all.
TokenIdMethod TokenIdMethod
The method used to create the Token ID.
string Owner
Current owner of token
string Reference
Link to reference information.
string CreatorJid
JID of Creator of token
Contains a markdown document. This markdown document class supports original markdown,...
static Task< MarkdownDocument > CreateAsync(string MarkdownText, params Type[] TransparentExceptionTypes)
Contains a markdown document. This markdown document class supports original markdown,...
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Abstract base class for contractual parameters
Class managing a script expression.
async Task< object > EvaluateAsync(Variables Variables)
Evaluates the expression, using the variables provided in the Variables collection....
Base class for all nodes in a parsed script tree.
void CopyTo(Variables Variables)
Copies available variables to another variable collection.
ContractVisibility
Visibility types for contracts.