Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DelayedActionProperty.cs
1using System;
2using System.Threading.Tasks;
3using Waher.Events;
4
5namespace LegalLab.Models
6{
11 {
12 private readonly bool liveUpdates = false;
13 private readonly TimeSpan delay;
14 private DateTime scheduledFor = DateTime.MinValue;
15 private bool changed = false;
16
23 public DelayedActionProperty(string Name, TimeSpan Delay, T DefaultValue, IModel Model)
24 : this(Name, Delay, true, DefaultValue, Model)
25 {
26 }
27
36 public DelayedActionProperty(string Name, TimeSpan Delay, bool LiveUpdates, T DefaultValue, IModel Model)
37 : base(Name, DefaultValue, Model)
38 {
39 this.liveUpdates = LiveUpdates;
40 this.delay = Delay;
41 }
42
46 public bool LiveUpdates => this.liveUpdates;
47
51 public override T Value
52 {
53 get => this.@value;
54 set
55 {
56 if (this.@value is null && value is null)
57 return;
58
59 if (this.@value?.Equals(value) ?? false)
60 return;
61
62 this.@value = value;
63 this.changed = true;
64
65 if (this.liveUpdates)
66 DelayedActions.Add(this, DateTime.Now + this.delay);
67
69 }
70 }
71
75 public bool Changed
76 {
77 get => this.changed;
78 protected set => this.changed = value;
79 }
80
84 public DateTime ScheduledFor
85 {
86 get => this.scheduledFor;
87 set => this.scheduledFor = value;
88 }
89
93 public virtual Task Action()
94 {
95 try
96 {
97 this.OnAction?.Invoke(this, EventArgs.Empty);
98 }
99 catch (Exception ex)
100 {
101 Log.Exception(ex);
102 }
103 finally
104 {
105 this.changed = false;
106 }
107
108 return Task.CompletedTask;
109 }
110
114 public event EventHandler OnAction;
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