本文整理汇总了C#中System.Transactions.Transaction类的典型用法代码示例。如果您正苦于以下问题:C# Transaction类的具体用法?C# Transaction怎么用?C# Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于System.Transactions命名空间,在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetExportCookie
public static byte[] GetExportCookie(Transaction transaction, byte[] whereabouts)
{
if (null == transaction)
{
throw new ArgumentNullException(nameof(transaction));
}
if (null == whereabouts)
{
throw new ArgumentNullException(nameof(whereabouts));
}
if (DiagnosticTrace.Verbose)
{
MethodEnteredTraceRecord.Trace(SR.TraceSourceDistributed, "TransactionInterop.GetExportCookie");
}
// Copy the whereabouts so that it cannot be modified later.
var whereaboutsCopy = new byte[whereabouts.Length];
Buffer.BlockCopy(whereabouts, 0, whereaboutsCopy, 0, whereabouts.Length);
DistributedTransaction dTx = ConvertToDistributedTransaction(transaction);
byte[] cookie = dTx.GetExportCookie(whereaboutsCopy);
if (DiagnosticTrace.Verbose)
{
MethodExitedTraceRecord.Trace(SR.TraceSourceDistributed, "TransactionInterop.GetExportCookie");
}
return cookie;
}
示例2: SharedConnectionInfo
/// <summary>
/// Instantiate an opened connection enlisted to the Transaction
/// if promotable is false, the Transaction wraps a local
/// transaction inside and can never be promoted
/// </summary>
/// <param name="dbResourceAllocator"></param>
/// <param name="transaction"></param>
/// <param name="wantPromotable"></param>
internal SharedConnectionInfo(
DbResourceAllocator dbResourceAllocator,
Transaction transaction,
bool wantPromotable,
ManualResetEvent handle)
{
Debug.Assert((transaction != null), "Null Transaction!");
if (null == handle)
throw new ArgumentNullException("handle");
this.handle = handle;
if (wantPromotable)
{
// Enlist a newly opened connection to this regular Transaction
this.connection = dbResourceAllocator.OpenNewConnection();
this.connection.EnlistTransaction(transaction);
}
else
{
// Make this transaction no longer promotable by attaching our
// IPromotableSinglePhaseNotification implementation (LocalTranscaction)
// and track the DbConnection and DbTransaction associated with the LocalTranscaction
LocalTransaction localTransaction = new LocalTransaction(dbResourceAllocator, handle);
transaction.EnlistPromotableSinglePhase(localTransaction);
this.connection = localTransaction.Connection;
this.localTransaction = localTransaction.Transaction;
}
}
示例3: GetDriverInTransaction
public static Driver GetDriverInTransaction(Transaction transaction)
{
lock (driversInUse.SyncRoot)
{
return (Driver) driversInUse[transaction.GetHashCode()];
}
}
示例4: Unlock
//Releases the transaction lock and allows the next pending transaction to quire it.
public void Unlock()
{
Debug.Assert(Locked);
OwningTransaction = null;
LinkedListNode<KeyValuePair<Transaction,ManualResetEvent>> node = null;
lock(this)
{
if(m_PendingTransactions.Count > 0)
{
node = m_PendingTransactions.First;
m_PendingTransactions.RemoveFirst();
}
}
if(node != null)
{
Transaction transaction = node.Value.Key;
ManualResetEvent manualEvent = node.Value.Value;
Lock(transaction);
lock(manualEvent)//To deal with race condition of the handle closed between the check and the set
{
if(manualEvent.SafeWaitHandle.IsClosed == false)
{
manualEvent.Set();
}
}
}
}
示例5: Commit
internal void Commit(Transaction transaction)
{
lock (this.mutex)
{
this._pendingWorkCollection.Commit(transaction);
}
}
示例6: RemoveDriverInTransaction
public static void RemoveDriverInTransaction(Transaction transaction)
{
lock (driversInUse.SyncRoot)
{
driversInUse.Remove(transaction.GetHashCode());
}
}
示例7: PersistenceDBAccessor
internal PersistenceDBAccessor(DbResourceAllocator dbResourceAllocator, Transaction transaction, WorkflowCommitWorkBatchService transactionService)
{
this.dbResourceAllocator = dbResourceAllocator;
this.localTransaction = DbResourceAllocator.GetLocalTransaction(transactionService, transaction);
this.connection = this.dbResourceAllocator.GetEnlistedConnection(transactionService, transaction, out this.needToCloseConnection);
this.dbRetry = new DbRetry(false);
}
示例8: UseConnection
public DbConnection UseConnection(IConnectionUser user) {
if (user == null) {
throw Error.ArgumentNull("user");
}
if (this.connection.State == ConnectionState.Closed) {
this.connection.Open();
this.autoClose = true;
this.AddInfoMessageHandler();
if (System.Transactions.Transaction.Current != null) {
System.Transactions.Transaction.Current.TransactionCompleted += this.OnTransactionCompleted;
}
}
if (this.transaction == null && System.Transactions.Transaction.Current != null &&
System.Transactions.Transaction.Current != systemTransaction) {
this.ClearConnection();
systemTransaction = System.Transactions.Transaction.Current;
this.connection.EnlistTransaction(System.Transactions.Transaction.Current);
}
if (this.users.Count == this.maxUsers) {
this.BootUser(this.users[0]);
}
this.users.Add(user);
return this.connection;
}
示例9: StringBuilder
/// <summary>
/// Make the transacted changes permanent.
/// </summary>
void IEnlistmentNotification.Commit(Enlistment enlistment)
{
_value = new StringBuilder(_temporaryValue.ToString());
_temporaryValue = null;
_enlistedTransaction = null;
enlistment.Done();
}
示例10: SqlDelegatedTransaction
internal SqlDelegatedTransaction(SqlInternalConnection connection, System.Transactions.Transaction tx)
{
this._connection = connection;
this._atomicTransaction = tx;
this._active = false;
System.Transactions.IsolationLevel isolationLevel = tx.IsolationLevel;
switch (isolationLevel)
{
case System.Transactions.IsolationLevel.Serializable:
this._isolationLevel = System.Data.IsolationLevel.Serializable;
return;
case System.Transactions.IsolationLevel.RepeatableRead:
this._isolationLevel = System.Data.IsolationLevel.RepeatableRead;
return;
case System.Transactions.IsolationLevel.ReadCommitted:
this._isolationLevel = System.Data.IsolationLevel.ReadCommitted;
return;
case System.Transactions.IsolationLevel.ReadUncommitted:
this._isolationLevel = System.Data.IsolationLevel.ReadUncommitted;
return;
case System.Transactions.IsolationLevel.Snapshot:
this._isolationLevel = System.Data.IsolationLevel.Snapshot;
return;
}
throw SQL.UnknownSysTxIsolationLevel(isolationLevel);
}
示例11: AdoPersistenceResourceAccessor
/// <summary>
/// Construct a new <see cref="AdoPersistenceResourceAccessor" /> with the
/// specified <see cref="IAdoResourceProvider" />,
/// <see cref="IPersistenceNameResolver" /> and <see cref="IAdoValueReader" />
/// All work should be performed in the specified <see cref="Transaction" />.
/// </summary>
/// <param name="resourceProvider">
/// An <see cref="IAdoResourceProvider" /> used to provide resources for
/// accessing the tracking store.
/// </param>
/// <param name="nameResolver">
/// An <see cref="IPersistenceNameResolver" /> that resolves names
/// of commands and parameters for the relevant tracking store.
/// </param>
/// <param name="valueReader">
/// An <see cref="IAdoValueReader" /> that reads values from
/// <see cref="IDbCommand" /> and <see cref="IDataReader" /> implementations.
/// </param>
/// <param name="transaction">
/// An <see cref="Transaction" /> in which to perform the work.
/// </param>
public AdoPersistenceResourceAccessor(IAdoResourceProvider resourceProvider,
IPersistenceNameResolver nameResolver, IAdoValueReader valueReader,
Transaction transaction)
{
if (resourceProvider == null)
throw new ArgumentNullException("resourceProvider");
if (nameResolver == null)
throw new ArgumentNullException("nameResolver");
if (valueReader == null)
throw new ArgumentNullException("valueReader");
this.resourceProvider = resourceProvider;
this.nameResolver = nameResolver;
this.valueReader = valueReader;
if (transaction == null)
{
this.isConnectionOwner = true;
this.dbConnection = resourceProvider.CreateConnection();
this.dbConnection.Open();
}
else
this.dbConnection = resourceProvider.CreateEnlistedConnection(transaction, out this.isConnectionOwner);
}
示例12: Create
/// <summary>
/// Given a provider name locate the necessary
/// <see cref="AdoTrackingResourceAccessor" /> in the configuration file.
/// </summary>
/// <returns>
/// An <see cref="AdoTrackingResourceAccessor" />.
/// </returns>
public static AdoTrackingResourceAccessor Create(
IAdoResourceProvider resourceProvider, ITrackingNameResolver nameResolver,
IAdoValueReader valueReader, Transaction transaction, IStateProvider stateProvider)
{
// locate any mappings for the specified provider
ProviderNameTypeMapping mapping = TrackingAdoProviderSettings.Get()
.ResourceAccessors.FindByProviderName(resourceProvider.ProviderName);
AdoTrackingResourceAccessor resourceAccessor;
if (mapping != null)
{
resourceAccessor =
TypeUtilities.CreateInstance<AdoTrackingResourceAccessor>(
mapping.Type, new object[]
{
resourceProvider, nameResolver, valueReader,
transaction, stateProvider
});
}
else
{
return new AdoTrackingResourceAccessor(
resourceProvider, nameResolver, valueReader,
transaction, stateProvider);
}
return resourceAccessor;
}
示例13: Enlist
private void Enlist(Transaction transaction)
{
if (transaction == null)
{
// no enlistment as we are not in a TransactionScope
return;
}
// try to enlist as a PSPE
if (!transaction.EnlistPromotableSinglePhase(this))
{
// our enlistmente fail so we need to enlist ourselves as durable.
// we create a transaction directly instead of using BeginTransaction that GraphClient
// doesn't store it in its stack of scopes.
var localTransaction = new Neo4jTransaction(_client);
localTransaction.ForceKeepAlive();
_transactionId = localTransaction.Id;
var resourceManager = GetResourceManager();
var propagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
var transactionExecutionEnvironment = new TransactionExecutionEnvironment(_client.ExecutionConfiguration)
{
TransactionId = localTransaction.Id,
TransactionBaseEndpoint = _client.TransactionEndpoint
};
resourceManager.Enlist(transactionExecutionEnvironment, propagationToken);
localTransaction.Cancel();
}
_enlistedInTransactions.Add(transaction);
}
示例14: AddReference
internal void AddReference(ref MessageRpc rpc, Transaction tx, bool updateCallCount)
{
lock (this.mutex)
{
if (this.pending == null)
{
this.pending = new Dictionary<Transaction, RemoveReferenceRM>();
}
if (tx != null)
{
RemoveReferenceRM erm;
if (this.pending == null)
{
this.pending = new Dictionary<Transaction, RemoveReferenceRM>();
}
if (!this.pending.TryGetValue(tx, out erm))
{
RemoveReferenceRM erm2 = new RemoveReferenceRM(this.instanceContext, tx, rpc.Operation.Name) {
CallCount = 1L
};
this.pending.Add(tx, erm2);
}
else if (updateCallCount)
{
erm.CallCount += 1L;
}
}
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:TransactionInstanceContextFacet.cs
示例15: TryLoadRunnableWorkflowAsyncResult
public TryLoadRunnableWorkflowAsyncResult(InstancePersistenceContext context, InstancePersistenceCommand command, SqlWorkflowInstanceStore store, SqlWorkflowInstanceStoreLock storeLock, Transaction currentTransaction, TimeSpan timeout, AsyncCallback callback, object state) : base(context, command, store, storeLock, currentTransaction, timeout, callback, state)
{
if (base.Store.WorkflowHostType == Guid.Empty)
{
throw FxTrace.Exception.AsError(new InstancePersistenceCommandException(command.Name, System.Activities.DurableInstancing.SR.TryLoadRequiresWorkflowType, null));
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:TryLoadRunnableWorkflowAsyncResult.cs