Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TransactionManager.cs
Go to the documentation of this file.
3using System.IO;
7
8namespace System.Transactions;
9
10public static class TransactionManager
11{
13
15
17
19
20 internal static bool s_currentDelegateSet;
21
22 private static object s_classSyncObject;
23
25
27
28 private static bool s_defaultTimeoutValidated;
29
30 private static TimeSpan s_defaultTimeout;
31
32 private static bool s_cachedMaxTimeout;
33
34 private static TimeSpan s_maximumTimeout;
35
37
39 {
40 get
41 {
42 return s_currentDelegate;
43 }
44 [param: DisallowNull]
45 set
46 {
47 if (value == null)
48 {
49 throw new ArgumentNullException("value");
50 }
51 lock (ClassSyncObject)
52 {
54 {
56 }
58 }
60 }
61 }
62
63 private static object ClassSyncObject => LazyInitializer.EnsureInitialized(ref s_classSyncObject);
64
66 {
67 get
68 {
70 if (log.IsEnabled())
71 {
72 log.MethodEnter(TraceSourceType.TraceSourceBase, "TransactionManager.get_DefaultIsolationLevel");
73 log.MethodExit(TraceSourceType.TraceSourceBase, "TransactionManager.get_DefaultIsolationLevel");
74 }
75 return IsolationLevel.Serializable;
76 }
77 }
78
80 {
81 get
82 {
83 if (s_defaultSettings == null)
84 {
86 }
87 return s_defaultSettings;
88 }
89 }
90
92 {
93 get
94 {
95 if (s_machineSettings == null)
96 {
98 }
99 return s_machineSettings;
100 }
101 }
102
104 {
105 get
106 {
108 if (log.IsEnabled())
109 {
110 log.MethodEnter(TraceSourceType.TraceSourceBase, "TransactionManager.get_DefaultTimeout");
111 }
113 {
115 if (s_defaultTimeout != DefaultSettings.Timeout && log.IsEnabled())
116 {
118 }
120 }
121 if (log.IsEnabled())
122 {
123 log.MethodExit(TraceSourceType.TraceSourceBase, "TransactionManager.get_DefaultTimeout");
124 }
125 return s_defaultTimeout;
126 }
127 }
128
130 {
131 get
132 {
134 if (log.IsEnabled())
135 {
136 log.MethodEnter(TraceSourceType.TraceSourceBase, "TransactionManager.get_DefaultMaximumTimeout");
137 }
138 LazyInitializer.EnsureInitialized(ref s_maximumTimeout, ref s_cachedMaxTimeout, ref s_classSyncObject, () => MachineSettings.MaxTimeout);
139 if (log.IsEnabled())
140 {
141 log.MethodExit(TraceSourceType.TraceSourceBase, "TransactionManager.get_DefaultMaximumTimeout");
142 }
143 return s_maximumTimeout;
144 }
145 }
146
147 internal static Hashtable PromotedTransactionTable => LazyInitializer.EnsureInitialized(ref s_promotedTransactionTable, ref s_classSyncObject, () => new Hashtable(100));
148
150
152
174
176 {
178 {
179 IDictionaryEnumerator enumerator = PromotedTransactionTable.GetEnumerator();
180 while (enumerator.MoveNext())
181 {
182 WeakReference weakReference = (WeakReference)enumerator.Value;
183 if (weakReference.Target is Transaction transaction)
184 {
185 TransactionEventArgs transactionEventArgs = new TransactionEventArgs();
186 transactionEventArgs._transaction = transaction.InternalClone();
187 eventHandler(transactionEventArgs._transaction, transactionEventArgs);
188 }
189 }
190 }
191 }
192
193 internal static void FireDistributedTransactionStarted(Transaction transaction)
194 {
195 TransactionStartedEventHandler transactionStartedEventHandler = null;
196 lock (ClassSyncObject)
197 {
198 transactionStartedEventHandler = s_distributedTransactionStartedDelegate;
199 }
200 if (transactionStartedEventHandler != null)
201 {
202 TransactionEventArgs transactionEventArgs = new TransactionEventArgs();
203 transactionEventArgs._transaction = transaction.InternalClone();
204 transactionStartedEventHandler(transactionEventArgs._transaction, transactionEventArgs);
205 }
206 }
207
208 public static Enlistment Reenlist(Guid resourceManagerIdentifier, byte[] recoveryInformation, IEnlistmentNotification enlistmentNotification)
209 {
210 if (resourceManagerIdentifier == Guid.Empty)
211 {
212 throw new ArgumentException(System.SR.BadResourceManagerId, "resourceManagerIdentifier");
213 }
214 if (recoveryInformation == null)
215 {
216 throw new ArgumentNullException("recoveryInformation");
217 }
218 if (enlistmentNotification == null)
219 {
220 throw new ArgumentNullException("enlistmentNotification");
221 }
223 if (log.IsEnabled())
224 {
225 log.MethodEnter(TraceSourceType.TraceSourceBase, "TransactionManager.Reenlist");
226 log.TransactionManagerReenlist(resourceManagerIdentifier);
227 }
228 MemoryStream memoryStream = new MemoryStream(recoveryInformation);
229 int num = 0;
230 string nodeName = null;
231 byte[] resourceManagerRecoveryInformation = null;
232 try
233 {
234 BinaryReader binaryReader = new BinaryReader(memoryStream);
235 num = binaryReader.ReadInt32();
236 if (num != 1)
237 {
238 if (log.IsEnabled())
239 {
240 log.TransactionExceptionTrace(TraceSourceType.TraceSourceBase, TransactionExceptionType.UnrecognizedRecoveryInformation, "recoveryInformation", string.Empty);
241 }
242 throw new ArgumentException(System.SR.UnrecognizedRecoveryInformation, "recoveryInformation");
243 }
244 nodeName = binaryReader.ReadString();
245 resourceManagerRecoveryInformation = binaryReader.ReadBytes(recoveryInformation.Length - checked((int)memoryStream.Position));
246 }
247 catch (EndOfStreamException ex)
248 {
249 if (log.IsEnabled())
250 {
251 log.TransactionExceptionTrace(TraceSourceType.TraceSourceBase, TransactionExceptionType.UnrecognizedRecoveryInformation, "recoveryInformation", ex.ToString());
252 }
253 throw new ArgumentException(System.SR.UnrecognizedRecoveryInformation, "recoveryInformation", ex);
254 }
255 catch (FormatException ex2)
256 {
257 if (log.IsEnabled())
258 {
259 log.TransactionExceptionTrace(TraceSourceType.TraceSourceBase, TransactionExceptionType.UnrecognizedRecoveryInformation, "recoveryInformation", ex2.ToString());
260 }
261 throw new ArgumentException(System.SR.UnrecognizedRecoveryInformation, "recoveryInformation", ex2);
262 }
263 finally
264 {
265 memoryStream.Dispose();
266 }
268 object syncRoot = new object();
269 Enlistment enlistment = new Enlistment(enlistmentNotification, syncRoot);
271 enlistment.InternalEnlistment.PromotedEnlistment = distributedTransactionManager.ReenlistTransaction(resourceManagerIdentifier, resourceManagerRecoveryInformation, (RecoveringInternalEnlistment)enlistment.InternalEnlistment);
272 if (log.IsEnabled())
273 {
274 log.MethodExit(TraceSourceType.TraceSourceBase, "TransactionManager.Reenlist");
275 }
276 return enlistment;
277 }
278
280 {
282 if ((distributedTransactionManager.NodeName != null || (nodeName != null && nodeName.Length != 0)) && (distributedTransactionManager.NodeName == null || !distributedTransactionManager.NodeName.Equals(nodeName)))
283 {
284 throw new ArgumentException(System.SR.InvalidRecoveryInformation, "recoveryInformation");
285 }
287 }
288
289 public static void RecoveryComplete(Guid resourceManagerIdentifier)
290 {
291 if (resourceManagerIdentifier == Guid.Empty)
292 {
293 throw new ArgumentException(System.SR.BadResourceManagerId, "resourceManagerIdentifier");
294 }
296 if (log.IsEnabled())
297 {
298 log.MethodEnter(TraceSourceType.TraceSourceBase, "TransactionManager.RecoveryComplete");
299 log.TransactionManagerRecoveryComplete(resourceManagerIdentifier);
300 }
302 if (log.IsEnabled())
303 {
304 log.MethodExit(TraceSourceType.TraceSourceBase, "TransactionManager.RecoveryComplete");
305 }
306 }
307
308 internal static void ValidateIsolationLevel(IsolationLevel transactionIsolationLevel)
309 {
310 if ((uint)transactionIsolationLevel > 6u)
311 {
312 throw new ArgumentOutOfRangeException("transactionIsolationLevel");
313 }
314 }
315
316 internal static TimeSpan ValidateTimeout(TimeSpan transactionTimeout)
317 {
318 if (transactionTimeout < TimeSpan.Zero)
319 {
320 throw new ArgumentOutOfRangeException("transactionTimeout");
321 }
322 if (MaximumTimeout != TimeSpan.Zero && (transactionTimeout > MaximumTimeout || transactionTimeout == TimeSpan.Zero))
323 {
324 return MaximumTimeout;
325 }
326 return transactionTimeout;
327 }
328
329 internal static Transaction FindPromotedTransaction(Guid transactionIdentifier)
330 {
331 Hashtable promotedTransactionTable = PromotedTransactionTable;
332 WeakReference weakReference = (WeakReference)promotedTransactionTable[transactionIdentifier];
333 if (weakReference != null)
334 {
335 if (weakReference.Target is Transaction transaction)
336 {
337 return transaction.InternalClone();
338 }
339 lock (promotedTransactionTable)
340 {
341 promotedTransactionTable.Remove(transactionIdentifier);
342 }
343 }
344 return null;
345 }
346
347 internal static Transaction FindOrCreatePromotedTransaction(Guid transactionIdentifier, DistributedTransaction dtx)
348 {
349 Transaction transaction = null;
350 Hashtable promotedTransactionTable = PromotedTransactionTable;
351 lock (promotedTransactionTable)
352 {
353 WeakReference weakReference = (WeakReference)promotedTransactionTable[transactionIdentifier];
354 if (weakReference != null)
355 {
356 transaction = weakReference.Target as Transaction;
357 if (null != transaction)
358 {
359 dtx.Dispose();
360 return transaction.InternalClone();
361 }
362 lock (promotedTransactionTable)
363 {
364 promotedTransactionTable.Remove(transactionIdentifier);
365 }
366 }
367 transaction = new Transaction(dtx);
368 transaction._internalTransaction._finalizedObject = new FinalizedObject(transaction._internalTransaction, dtx.Identifier);
369 weakReference = new WeakReference(transaction, trackResurrection: false);
370 promotedTransactionTable[dtx.Identifier] = weakReference;
371 }
372 dtx.SavedLtmPromotedTransaction = transaction;
374 return transaction;
375 }
376}
virtual void Remove(object key)
static ? Delegate Remove(Delegate? source, Delegate? value)
Definition Delegate.cs:463
static ? Delegate Combine(Delegate? a, Delegate? b)
Definition Delegate.cs:379
override string ToString()
Definition Exception.cs:384
virtual string ReadString()
virtual int ReadInt32()
virtual byte[] ReadBytes(int count)
override long Position
override void Dispose(bool disposing)
static string BadResourceManagerId
Definition SR.cs:18
static string UnrecognizedRecoveryInformation
Definition SR.cs:76
static string InvalidRecoveryInformation
Definition SR.cs:38
static string CurrentDelegateSet
Definition SR.cs:24
Definition SR.cs:7
static EnlistmentStatePromoted EnlistmentStatePromoted
InternalEnlistment InternalEnlistment
Definition Enlistment.cs:7
static TimeSpan ValidateTimeout(TimeSpan transactionTimeout)
static Transaction FindPromotedTransaction(Guid transactionIdentifier)
static DistributedTransactionManager DistributedTransactionManager
static void RecoveryComplete(Guid resourceManagerIdentifier)
static TransactionStartedEventHandler s_distributedTransactionStartedDelegate
static Transaction FindOrCreatePromotedTransaction(Guid transactionIdentifier, DistributedTransaction dtx)
static void FireDistributedTransactionStarted(Transaction transaction)
static DefaultSettingsSection DefaultSettings
static ? HostCurrentTransactionCallback HostCurrentCallback
static HostCurrentTransactionCallback s_currentDelegate
static ? TransactionStartedEventHandler DistributedTransactionStarted
static void ProcessExistingTransactions(TransactionStartedEventHandler eventHandler)
static MachineSettingsSection s_machineSettings
static DistributedTransactionManager CheckTransactionManager(string nodeName)
static Enlistment Reenlist(Guid resourceManagerIdentifier, byte[] recoveryInformation, IEnlistmentNotification enlistmentNotification)
static MachineSettingsSection MachineSettings
static void ValidateIsolationLevel(IsolationLevel transactionIsolationLevel)
static DistributedTransactionManager distributedTransactionManager
static DefaultSettingsSection s_defaultSettings
InternalTransaction _internalTransaction
void TransactionExceptionTrace(TraceSourceType traceSource, TransactionExceptionType type, string message, string innerExceptionStr)
void TransactionManagerRecoveryComplete(Guid resourceManagerID)
void MethodExit(TraceSourceType traceSource, object thisOrContextObject, [CallerMemberName] string methodname=null)
static readonly TransactionsEtwProvider Log
void MethodEnter(TraceSourceType traceSource, object thisOrContextObject, [CallerMemberName] string methodname=null)
virtual ? object Target
delegate void TransactionStartedEventHandler(object? sender, TransactionEventArgs e)
delegate? Transaction HostCurrentTransactionCallback()
static readonly Guid Empty
Definition Guid.cs:86
static readonly TimeSpan Zero
Definition TimeSpan.cs:21