Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mcs/class/System.Transactions/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SUBDIRS =
include ../../build/rules.make

LIBRARY = System.Transactions.dll
LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll
LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll /r:System.Configuration.dll

TEST_MCS_FLAGS = /nowarn:1595 $(LIB_MCS_FLAGS)

Expand Down
3 changes: 3 additions & 0 deletions mcs/class/System.Transactions/System.Transactions.dll.sources
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ System.Transactions/TransactionPromotionException.cs
System.Transactions/TransactionScope.cs
System.Transactions/TransactionScopeOption.cs
System.Transactions/TransactionStatus.cs
System.Transactions/Configuration/DefaultSettingsSection.cs
System.Transactions/Configuration/MachineSettingsSection.cs
System.Transactions/Configuration/TransactionsSectionGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// DefaultSettingsSection.cs
//
// Author:
// Pablo Ruiz <[email protected]>
//
// (C) 2010 Pablo Ruiz.
//

#if NET_2_0

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;

namespace System.Transactions.Configuration
{
public class DefaultSettingsSection : ConfigurationSection
{
// http://msdn.microsoft.com/en-us/library/system.transactions.configuration.defaultsettingssection.timeout.aspx
[ConfigurationProperty ("timeout", DefaultValue = "00:01:00")]
[TimeSpanValidator (MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
public TimeSpan Timeout {
get { return (TimeSpan)base["timeout"]; }
set {
// FIXME: Validate timespan value
base["timeout"] = value;
}
}

// http://msdn.microsoft.com/en-us/library/system.transactions.configuration.defaultsettingssection.distributedtransactionmanagername(v=VS.90).aspx
[ConfigurationProperty ("distributedTransactionManagerName", DefaultValue = "")]
public string DistributedTransactionManagerName {
get { return base["distributedTransactionManagerName"] as string; }
set { base["distributedTransactionManagerName"] = value; }
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// MachineSettingsSection.cs
//
// Author:
// Pablo Ruiz <[email protected]>
//
// (C) 2010 Pablo Ruiz.
//

#if NET_2_0

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;

namespace System.Transactions.Configuration
{
public class MachineSettingsSection : ConfigurationSection
{
// http://msdn.microsoft.com/en-us/library/system.transactions.configuration.machinesettingssection.maxtimeout.aspx
[ConfigurationProperty("maxTimeout", DefaultValue = "00:10:00")]
[TimeSpanValidator(MinValueString = "00:00:00", MaxValueString = "10675199.02:48:05.4775807")]
public TimeSpan MaxTimeout {
get { return (TimeSpan)base["maxTimeout"]; }
set {
// FIXME: Validate timespan value..
base["maxTimeout"] = value;
}
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// TransactionSectionGroup.cs
//
// Author:
// Pablo Ruiz <[email protected]>
//
// (C) 2010 Pablo Ruiz.
//

#if NET_2_0

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;

namespace System.Transactions.Configuration
{
// http://msdn.microsoft.com/en-us/library/system.transactions.configuration.transactionssectiongroup.aspx
public class TransactionsSectionGroup : ConfigurationSectionGroup
{
public static TransactionsSectionGroup GetSectionGroup(System.Configuration.Configuration config)
{
if (config == null)
throw new ArgumentNullException("config");

return config.GetSectionGroup("system.transactions") as TransactionsSectionGroup;
}

[ConfigurationProperty("defaultSettings")]
public DefaultSettingsSection DefaultSettings
{
get { return (DefaultSettingsSection)base.Sections["defaultSettings"]; }
}

[ConfigurationProperty("machineSettings")]
public MachineSettingsSection MachineSettings
{
get { return (MachineSettingsSection)base.Sections["machineSettings"]; }
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public class PreparingEnlistment : Enlistment
bool prepared = false;
Transaction tx;
IEnlistmentNotification enlisted;
//WaitHandle waitHandle;
WaitHandle waitHandle;

internal PreparingEnlistment (Transaction tx, IEnlistmentNotification enlisted)
{
this.tx = tx;
this.enlisted = enlisted;
//waitHandle = new ManualResetEvent (false);
waitHandle = new ManualResetEvent (false);
}

public void ForceRollback ()
Expand All @@ -38,16 +38,16 @@ public void ForceRollback ()
public void ForceRollback (Exception ex)
{
tx.Rollback (ex, enlisted);
/* See test RMFail2
((ManualResetEvent) waitHandle).Set (); */
/* See test RMFail2 */
((ManualResetEvent) waitHandle).Set ();
}

[MonoTODO]
public void Prepared ()
{
prepared = true;
/* See test RMFail2
((ManualResetEvent) waitHandle).Set ();*/
/* See test RMFail2 */
((ManualResetEvent) waitHandle).Set ();
}

[MonoTODO]
Expand All @@ -60,9 +60,14 @@ internal bool IsPrepared {
get { return prepared; }
}

/*internal WaitHandle WaitHandle {
internal WaitHandle WaitHandle {
get { return waitHandle; }
}*/
}

internal IEnlistmentNotification EnlistmentNotification
{
get { return enlisted; }
}
}
}

Expand Down
129 changes: 83 additions & 46 deletions mcs/class/System.Transactions/System.Transactions/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,12 @@ public void Rollback (Exception ex)
}

internal void Rollback (Exception ex, IEnlistmentNotification enlisted)
{
if (aborted)
return;
{
if (aborted)
{
FireCompleted ();
return;
}

/* See test ExplicitTransaction7 */
if (info.Status == TransactionStatus.Committed)
Expand All @@ -249,7 +252,9 @@ internal void Rollback (Exception ex, IEnlistmentNotification enlisted)
if (durables.Count > 0 && durables [0] != enlisted)
durables [0].Rollback (e);

Aborted = true;
Aborted = true;

FireCompleted ();
}

bool Aborted {
Expand Down Expand Up @@ -289,7 +294,17 @@ internal void CommitInternal ()

this.committing = true;

DoCommit ();
try {
DoCommit ();
}
catch (TransactionException)
{
throw;
}
catch (Exception ex)
{
throw new TransactionAbortedException("Transaction failed", ex);
}
}

private void DoCommit ()
Expand All @@ -299,28 +314,30 @@ private void DoCommit ()
/* See test ExplicitTransaction8 */
Rollback (null, null);
CheckAborted ();
}

if (volatiles.Count == 1 && durables.Count == 0) {
/* Special case */
ISinglePhaseNotification single = volatiles [0] as ISinglePhaseNotification;
if (single != null) {
DoSingleCommit (single);
Complete ();
return;
}
}

if (volatiles.Count > 0)
DoPreparePhase ();

if (durables.Count > 0)
DoSingleCommit (durables [0]);

if (volatiles.Count > 0)
DoCommitPhase ();

Complete ();
}

if (volatiles.Count == 1 && durables.Count == 0)
{
/* Special case */
ISinglePhaseNotification single = volatiles[0] as ISinglePhaseNotification;
if (single != null)
{
DoSingleCommit(single);
Complete();
return;
}
}

if (volatiles.Count > 0)
DoPreparePhase();

if (durables.Count > 0)
DoSingleCommit(durables[0]);

if (volatiles.Count > 0)
DoCommitPhase();

Complete();
}

private void Complete ()
Expand All @@ -329,7 +346,9 @@ private void Complete ()
committed = true;

if (!aborted)
info.Status = TransactionStatus.Committed;
info.Status = TransactionStatus.Committed;

FireCompleted ();
}

internal void InitScope (TransactionScope scope)
Expand All @@ -342,28 +361,40 @@ internal void InitScope (TransactionScope scope)
throw new InvalidOperationException ("Commit has already been called on this transaction.");

Scope = scope;
}

static void PrepareCallbackWrapper(object state)
{
PreparingEnlistment enlist = state as PreparingEnlistment;
enlist.EnlistmentNotification.Prepare(enlist);
}

void DoPreparePhase ()
{
PreparingEnlistment pe;
foreach (IEnlistmentNotification enlisted in volatiles) {
pe = new PreparingEnlistment (this, enlisted);

enlisted.Prepare (pe);

/* FIXME: Where should this timeout value come from?
current scope?
Wait after all Prepare()'s are sent
pe.WaitHandle.WaitOne (new TimeSpan (0,0,5), true); */

if (!pe.IsPrepared) {
{
// Call prepare on all volatile managers.
foreach (IEnlistmentNotification enlist in volatiles)
{
PreparingEnlistment pe = new PreparingEnlistment (this, enlist);
ThreadPool.QueueUserWorkItem (new WaitCallback(PrepareCallbackWrapper), pe);

/* Wait (with timeout) for manager to prepare */
TimeSpan timeout = Scope != null ? Scope.Timeout : TransactionManager.DefaultTimeout;

// FIXME: Should we managers in parallel or on-by-one?
if (!pe.WaitHandle.WaitOne(timeout, true))
{
this.Aborted = true;
throw new TimeoutException("Transaction timedout");
}

if (!pe.IsPrepared)
{
/* FIXME: if not prepared & !aborted as yet, then
this is inDoubt ? . For now, setting aborted = true */
Aborted = true;
break;
}
}
this is inDoubt ? . For now, setting aborted = true */
Aborted = true;
break;
}
}

/* Either InDoubt(tmp) or Prepare failed and
Tx has rolledback */
Expand Down Expand Up @@ -393,6 +424,12 @@ void CheckAborted ()
{
if (aborted)
throw new TransactionAbortedException ("Transaction has aborted", innerException);
}

void FireCompleted ()
{
if (TransactionCompleted != null)
TransactionCompleted (this, new TransactionEventArgs(this));
}

static void EnsureIncompleteCurrentScope ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@
namespace System.Transactions
{
public class TransactionEventArgs : EventArgs
{
{
private Transaction transaction;

public TransactionEventArgs()
{
}

internal TransactionEventArgs(Transaction transaction)
: this()
{
this.transaction = transaction;
}

public Transaction Transaction {
get { throw new NotImplementedException (); }
get { return transaction; }
}
}
}
Expand Down
Loading