本文整理汇总了C#中TransactionMode类的典型用法代码示例。如果您正苦于以下问题:C# TransactionMode类的具体用法?C# TransactionMode怎么用?C# TransactionMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransactionMode类属于命名空间,在下文中一共展示了TransactionMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StandardTransaction
public StandardTransaction(TransactionDelegate onTransactionCommitted, TransactionDelegate onTransactionRolledback,
TransactionMode transactionMode, IsolationMode isolationMode, bool distributedTransaction) :
this(transactionMode, isolationMode, distributedTransaction)
{
this.onTransactionCommitted = onTransactionCommitted;
this.onTransactionRolledback = onTransactionRolledback;
}
示例2: ProcessPayment
/// <summary>
/// Processes the Authorize and AuthorizeAndCapture transactions
/// </summary>
/// <param name="invoice">The <see cref="IInvoice" /> to be paid</param>
/// <param name="payment">The <see cref="IPayment" /> record</param>
/// <param name="transactionMode">Authorize or AuthorizeAndCapture</param>
/// <param name="amount">The money amount to be processed</param>
/// <returns>The <see cref="IPaymentResult" /></returns>
public IPaymentResult ProcessPayment(IInvoice invoice, IPayment payment, TransactionMode transactionMode, decimal amount)
{
if (!IsValidCurrencyCode(invoice.CurrencyCode()))
return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Invalid currency. Invoice Currency: '{0}'", invoice.CurrencyCode()))), invoice, false);
if (transactionMode == TransactionMode.Authorize) {
//var paymentId = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.QuickpayPaymentId);
var currency = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.PaymentCurrency);
var amountAuthorizedMinorString = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.PaymentAmount);
var amountAuthorized = decimal.Parse(amountAuthorizedMinorString) / (IsZeroDecimalCurrency(currency) ? 100 : 1);
if (invoice.CurrencyCode() != currency) {
return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Currency mismatch. Invoice Currency: {0}, Payment Currency: {1}", invoice.CurrencyCode(), currency))), invoice, false);
}
if (invoice.Total > amountAuthorized) {
return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Amount mismatch. Invoice Amount: {0}, Payment Amount: {1}", invoice.Total.ToString("F2"), amountAuthorized.ToString("F2")))), invoice, false);
}
payment.Authorized = true;
return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, invoice.ShippingLineItems().Any());
}
return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("{0}", "QuickPay Payment AuthorizeAndCapture Not Implemented Yet"))), invoice, false);
}
示例3: Hurl
public int Hurl(string storedProcedureName, System.Collections.Generic.List<dynamic> objects, TransactionMode transMode)
{
// This has slightly different logic because we need to scope the transaction differently.
int numberOfRecordsAffected = 0;
SqlTransaction transaction = null;
using (SqlConnection dbConn = new SqlConnection(this.ConnectionString))
{
using (SqlCommand dbComm = new SqlCommand(storedProcedureName, dbConn) { CommandType = System.Data.CommandType.StoredProcedure })
{
if (transMode == TransactionMode.On)
{
transaction = dbConn.BeginTransaction();
}
foreach (dynamic obj in objects)
{
dbComm.Parameters.Clear();
string jsonString = JsonConvert.SerializeObject(obj);
dbComm.Parameters.AddRange(jsonString.DeserializeJsonIntoSqlParameters());
if (dbConn.State != System.Data.ConnectionState.Open) { dbConn.Open(); }
numberOfRecordsAffected += dbComm.ExecuteNonQuery();
}
if (transaction != null) { transaction.Commit(); }
}
}
return numberOfRecordsAffected;
}
示例4: ProcessPayment
private IPaymentResult ProcessPayment(IInvoice invoice, TransactionMode transactionMode, decimal amount, ProcessorArgumentCollection args)
{
var po = args.AsPurchaseOrderFormData();
var payment = GatewayProviderService.CreatePayment(PaymentMethodType.PurchaseOrder, invoice.Total, PaymentMethod.Key);
payment.CustomerKey = invoice.CustomerKey;
payment.Authorized = false;
payment.Collected = false;
payment.PaymentMethodName = "Purchase Order";
var result = _processor.ProcessPayment(invoice, payment, amount, po);
GatewayProviderService.Save(payment);
if (!result.Payment.Success)
{
GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, result.Payment.Exception.Message, 0);
}
else
{
MerchelloContext.Current.Services.InvoiceService.Save(invoice, false);
GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit,
payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.AuthorizationTransactionResult) +
(transactionMode == TransactionMode.AuthorizeAndCapture ? string.Empty : " to show record of Authorization"),
transactionMode == TransactionMode.AuthorizeAndCapture ? invoice.Total : 0);
}
return result;
}
示例5: OnNewTransaction
private void OnNewTransaction(ITransaction transaction, TransactionMode transactionMode, IsolationMode isolationMode, bool distributedTransaction)
{
if (!transaction.DistributedTransaction)
{
transaction.Enlist(new RhinoTransactionResourceAdapter(transactionMode));
}
}
示例6: ProcessPayment
private IPaymentResult ProcessPayment(IInvoice invoice, TransactionMode transactionMode, decimal amount, ProcessorArgumentCollection args)
{
var cc = args.AsCreditCardFormData();
var payment = GatewayProviderService.CreatePayment(PaymentMethodType.CreditCard, invoice.Total, PaymentMethod.Key);
payment.CustomerKey = invoice.CustomerKey;
payment.Authorized = false;
payment.Collected = false;
payment.PaymentMethodName = string.Format("{0} Stripe Credit Card", cc.CreditCardType);
payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.CcLastFour, cc.CardNumber.Substring(cc.CardNumber.Length - 4, 4).EncryptWithMachineKey());
var result = _processor.ProcessPayment(invoice, payment, transactionMode, amount, cc);
GatewayProviderService.Save(payment);
if (!result.Payment.Success)
{
GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Denied, result.Payment.Exception.Message, 0);
}
else
{
GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit,
//payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.AuthorizationTransactionResult) +
(transactionMode == TransactionMode.AuthorizeAndCapture ? string.Empty : " to show record of Authorization"),
transactionMode == TransactionMode.AuthorizeAndCapture ? invoice.Total : 0);
}
return result;
}
示例7: TransactionBase
protected TransactionBase(string name, TransactionMode mode, IsolationMode isolationMode)
{
theName = name ?? string.Empty;
_TransactionMode = mode;
_IsolationMode = isolationMode;
Status = TransactionStatus.NoTransaction;
Context = new Hashtable();
}
示例8: CreateTransaction
public ITransaction CreateTransaction(TransactionMode transactionMode, IsolationMode isolationMode,
bool distributedTransaction)
{
_current = new MockTransaction();
_transactions++;
return _current;
}
示例9: BeginTransaction
public ITransaction BeginTransaction(IsolationLevel isolationLevel, TransactionMode mode)
{
Guard.Against<InvalidOperationException>(Transaction != null, "There is a active transcation, cannot begin a new transaction.");
var scope = TransactionScopeHelper.CreateScope(isolationLevel, mode);
var transaction = new UnitOfWorkTransaction(this, scope);
return transaction;
}
示例10: CreateScope
///<summary>
/// Create a new <typeparamref name="TransactionScope"/> using the supplied parameters.
///</summary>
///<param name="isolationLevel"></param>
///<param name="txMode"></param>
///<returns></returns>
///<exception cref="NotImplementedException"></exception>
public static TransactionScope CreateScope(IsolationLevel isolationLevel, TransactionMode txMode) {
if (txMode == TransactionMode.New) {
Logger.Debug(x => x("Creating a new TransactionScope with TransactionScopeOption.RequiresNew"));
return new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = isolationLevel });
}
if (txMode == TransactionMode.Supress) {
Logger.Debug(x => x("Creating a new TransactionScope with TransactionScopeOption.Supress"));
return new TransactionScope(TransactionScopeOption.Suppress);
}
Logger.Debug(x => x("Creating a new TransactionScope with TransactionScopeOption.Required"));
return new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = isolationLevel });
}
示例11: CreateTransaction
public ITransaction CreateTransaction(TransactionMode txMode, IsolationMode iMode, bool isAmbient, bool isReadOnly)
{
txMode = ObtainDefaultTransactionMode(txMode);
AssertModeSupported(txMode);
if (CurrentTransaction == null &&
(txMode == TransactionMode.Supported ||
txMode == TransactionMode.NotSupported))
{
return null;
}
TransactionBase transaction = null;
if (CurrentTransaction != null)
{
if (txMode == TransactionMode.Requires || txMode == TransactionMode.Supported)
{
transaction = ((TransactionBase)CurrentTransaction).CreateChildTransaction();
logger.DebugFormat("Child transaction \"{0}\" created with mode '{1}'.", transaction.Name, txMode);
}
}
if (transaction == null)
{
transaction = InstantiateTransaction(txMode, iMode, isAmbient, isReadOnly);
if (isAmbient)
{
#if MONO
throw new NotSupportedException("Distributed transactions are not supported on Mono");
#else
transaction.CreateAmbientTransaction();
#endif
}
logger.DebugFormat("Transaction \"{0}\" created. ", transaction.Name);
}
activityManager.CurrentActivity.Push(transaction);
if (transaction.IsChildTransaction)
ChildTransactionCreated.Fire(this, new TransactionEventArgs(transaction));
else
TransactionCreated.Fire(this, new TransactionEventArgs(transaction));
return transaction;
}
示例12: BeginTransactionWithMode
internal static string BeginTransactionWithMode(TransactionMode mode)
{
switch (mode)
{
case TransactionMode.Deferred:
return "BEGIN DEFERRED TRANSACTION";
case TransactionMode.Exclusive:
return "BEGIN EXCLUSIVE TRANSACTION";
case TransactionMode.Immediate:
return "BEGIN IMMEDIATE TRANSACTION";
default:
throw new ArgumentException("Not a valid TransactionMode");
}
}
示例13: BeginThreadTransaction
public override void BeginThreadTransaction(TransactionMode mode)
{
if (mode != TransactionMode.ReplicationSlave)
{
throw new ArgumentException("Illegal transaction mode");
}
lck.SharedLock();
Page pg = pool.getPage(0);
header.unpack(pg.data);
pool.unfix(pg);
currIndex = 1 - header.curr;
currIndexSize = header.root[1 - currIndex].indexUsed;
committedIndexSize = currIndexSize;
usedSize = header.root[currIndex].size;
}
示例14: AbstractTransaction
public AbstractTransaction(TransactionMode transactionMode, IsolationMode isolationMode, bool distributedTransaction,
string name) : this()
{
this.transactionMode = transactionMode;
this.isolationMode = isolationMode;
this.distributedTransaction = distributedTransaction;
if (String.IsNullOrEmpty(name))
{
this.name = ObtainName();
}
else
{
this.name = name;
}
}
示例15: FileBasedPersistentSource
public FileBasedPersistentSource(string basePath, string prefix, TransactionMode transactionMode)
{
SyncLock = new object();
this.basePath = basePath;
this.prefix = prefix;
this.transactionMode = transactionMode;
dataPath = Path.Combine(basePath, prefix + ".data");
logPath = Path.Combine(basePath, prefix + ".log");
RecoverFromFailedRename(dataPath);
RecoverFromFailedRename(logPath);
CreatedNew = File.Exists(logPath) == false;
OpenFiles();
}