Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ParametrizedCommand.cs
1using System;
2using System.Threading.Tasks;
3using System.Windows.Input;
4using Waher.Events;
5
6namespace LegalLab.Models
7{
13 public delegate bool CanExecuteParametrizedHandler(object Parameter);
14
19 public delegate void ExecuteParametrizedHandler(object Parameter);
20
24 public class ParametrizedCommand : ICommand
25 {
26 private readonly CanExecuteParametrizedHandler canExecuteCallback;
27 private readonly ExecuteParametrizedHandler executeCallback;
28
34 : this(null, ExecuteCallback)
35 {
36 }
37
44 {
45 this.canExecuteCallback = CanExecuteCallback;
46 this.executeCallback = ExecuteCallback;
47 }
48
52 public event EventHandler CanExecuteChanged;
53
58 {
60 {
61 try
62 {
63 this.CanExecuteChanged?.Invoke(this, EventArgs.Empty);
64 }
65 catch (Exception ex)
66 {
67 Log.Exception(ex);
68 }
69
70 return Task.CompletedTask;
71 });
72 }
73
79 public bool CanExecute(object parameter)
80 {
81 if (this.canExecuteCallback is null)
82 return true;
83 else
84 {
85 try
86 {
87 return this.canExecuteCallback(parameter);
88 }
89 catch (Exception ex)
90 {
91 Log.Exception(ex);
92 return false;
93 }
94 }
95 }
96
101 public void Execute(object parameter)
102 {
103 if (this.executeCallback is not null)
104 {
105 try
106 {
107 this.executeCallback(parameter);
108 }
109 catch (Exception ex)
110 {
111 Log.Exception(ex);
112 MainWindow.ErrorBox(ex.Message);
113 }
114 }
115 }
116 }
117}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
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.
Definition: Log.cs:1647