Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TransactionModule.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using Waher.Events;
6
8{
12 [Singleton]
14 {
15 private readonly static List<ITransactions> transactions = new List<ITransactions>();
16 private static bool running = false;
17
22 {
23 }
24
30 {
31 lock (transactions)
32 {
33 if (!transactions.Contains(Transactions))
34 transactions.Add(Transactions);
35 }
36 }
37
44 {
45 lock (transactions)
46 {
47 return transactions.Remove(Transactions);
48 }
49 }
50
54 public static bool Running => running;
55
59 public Task Start()
60 {
61 running = true;
62 return Task.CompletedTask;
63 }
64
68 public async Task Stop()
69 {
70 ITransactions[] Collections;
71
72 running = false;
73
74 lock (transactions)
75 {
76 Collections = transactions.ToArray();
77 transactions.Clear();
78 }
79
80 foreach (ITransactions Transactions in Collections)
81 {
82 try
83 {
84 ITransaction[] Pending = await Transactions.GetTransactions();
85
86 foreach (ITransaction T in Pending)
87 {
88 try
89 {
90 await T.Abort();
91 }
92 catch (Exception ex)
93 {
94 Log.Exception(ex);
95 }
96 }
97
99 }
100 catch (Exception ex)
101 {
102 Log.Exception(ex);
103 }
104 }
105 }
106
107 }
108}
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
Module making sure no unfinished transactions are left when system ends.
static void Register(ITransactions Transactions)
Registers a collection of transactions with the module.
static bool Running
If the transaction module is running.
static bool Unregister(ITransactions Transactions)
Unregisters a collection of transactions with the module.
TransactionModule()
Module making sure no unfinished transactions are left when system ends.
Maintains a collection of active transactions.
Definition: Transactions.cs:15
void Dispose()
Rolls back any pending transactions and disposes of the object.
Definition: Transactions.cs:54
Task< ITransaction[]> GetTransactions()
Gets pending transactions.
Interface for late-bound modules loaded at runtime.
Definition: IModule.cs:9
Interface for transactions
Definition: ITransaction.cs:10
Task Abort()
Aborts the transaction.
Interface for collections of transactions that can be monitored by TransactionModule.