public TransactionFailedEventArgs(ITransaction tx, TransactionException exception) : base(tx) { _Exception = exception; }
/// <summary> /// This method submits the transaction /// to the PayPal Payment Gateway. /// The response is obtained from the gateway /// and response object is populated with the /// response values along with the sdk specific /// errors in context, if any. /// </summary> /// <returns>Returns response object for Strong assembly transactions</returns> /// <example> /// <code lang="C#" escaped="false"> /// ............ /// //Trans is the transaction object. /// ............ /// /// //Submit the transaction. /// Trans.SubmitTransaction(); /// /// // Get the Response. /// Response Resp = Trans.Response; /// if (Resp != null) /// { /// // Get the Transaction Response parameters. /// TransactionResponse TrxnResponse = Resp.TransactionResponse; /// if (TrxnResponse != null) /// { /// Console.WriteLine("RESULT = " + TrxnResponse.Result); /// Console.WriteLine("PNREF = " + TrxnResponse.Pnref); /// Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg); /// Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode); /// Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr); /// Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip); /// Console.WriteLine("IAVS = " + TrxnResponse.IAVS); /// } /// // Get the Fraud Response parameters. /// FraudResponse FraudResp = Resp.FraudResponse; /// if (FraudResp != null) /// { /// Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg); /// Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg); /// } /// } /// // Get the Context and check for any contained SDK specific errors. /// Context Ctx = Resp.TransactionContext; /// if (Ctx != null && Ctx.getErrorCount() > 0) /// { /// Console.WriteLine(Environment.NewLine + "Errors = " + Ctx.ToString()); /// } /// </code> /// <code lang="Visual Basic" escaped="false"> /// ............ /// 'Trans is the transaction object. /// ............ /// ' Submit the transaction. /// Trans.SubmitTransaction() /// ' Get the Response. /// Dim Resp As Response = Trans.Response /// /// If Not Resp Is Nothing Then /// ' Get the Transaction Response parameters. /// /// Dim TrxnResponse As TransactionResponse = Resp.TransactionResponse /// /// If Not TrxnResponse Is Nothing Then /// Console.WriteLine("RESULT = " + TrxnResponse.Result) /// Console.WriteLine("PNREF = " + TrxnResponse.Pnref) /// Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg) /// Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode) /// Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr) /// Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip) /// Console.WriteLine("IAVS = " + TrxnResponse.IAVS) /// End If /// ' Get the Fraud Response parameters. /// Dim FraudResp As FraudResponse = Resp.FraudResponse /// If Not FraudResp Is Nothing Then /// Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg) /// Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg) /// End If /// End If /// ' Get the Context and check for any contained SDK specific errors. /// Dim Ctx As Context = Resp.TransactionContext /// /// If Not Ctx Is Nothing AndAlso Ctx.getErrorCount() > 0 Then /// Console.WriteLine(Constants.vbLf + "Errors = " + Ctx.ToString()) /// End If /// </code> /// </example> public virtual async Task <Response> SubmitTransactionAsync() { PayflowNetapi pfProNetApi = null; string responseValue = null; var fatal = false; Logger.Instance.Log("##### BEGIN TRANSACTION ##### -- " + RequestId, PayflowConstants.SeverityInfo); Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Entered", PayflowConstants.SeverityDebug); try { if (ClientInfo == null) { ClientInfo = new ClientInfo(); } //Check for the errors in the context now. var errors = PayflowUtility.AlignContext(Context, false); Context.LoadLoggerErrs = false; Context.ClearErrors(); Context.AddErrors(errors); if (Context.HighestErrorLvl == PayflowConstants.SeverityFatal) { Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Exiting", PayflowConstants.SeverityDebug); fatal = true; } if (!fatal) { GenerateRequest(); _mRequest = RequestBuffer.ToString(); //Remove the trailing PayflowConstants.DELIMITER_NVP; var parmListLen = _mRequest.Length; if (parmListLen > 0 && _mRequest[parmListLen - 1] == '&') { _mRequest = _mRequest.Substring(0, parmListLen - 1); } //Call the api from here and submit transaction if (_mPayflowConnectionData != null) { pfProNetApi = new PayflowNetapi(_mPayflowConnectionData.HostAddress, _mPayflowConnectionData.HostPort, _mPayflowConnectionData.TimeOut, _mPayflowConnectionData.ProxyAddress, _mPayflowConnectionData.ProxyPort, _mPayflowConnectionData.ProxyLogon, _mPayflowConnectionData.ProxyPassword); } else { pfProNetApi = new PayflowNetapi(); } pfProNetApi.IsStrongAssemblyTransaction = true; pfProNetApi.ClientInfo = ClientInfo; responseValue = await pfProNetApi.SubmitTransactionAsync(_mRequest, RequestId); Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Exiting", PayflowConstants.SeverityDebug); Logger.Instance.Log("##### END TRANSACTION ##### -- " + RequestId, PayflowConstants.SeverityInfo); } } catch (BaseException baseEx) { var error = baseEx.GetFirstErrorInExceptionContext(); //ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE,BaseEx,PayflowConstants.SEVERITY_FATAL,false, null); Context.AddError(error); } catch (Exception ex) { var transEx = new TransactionException(ex); var error = PayflowUtility.PopulateCommError(PayflowConstants.EUnknownState, transEx, PayflowConstants.SeverityFatal, false, null); Context.AddError(error); } finally { if (pfProNetApi != null) { _mRequest = pfProNetApi.TransactionRequest; Context.AddErrors(pfProNetApi.TransactionContext.GetErrors()); RequestId = pfProNetApi.RequestId; ClientInfo = pfProNetApi.ClientInfo; } else { //There is some error due to which the return //is called even before pfpronetapi object is //created. //Check the first fatal error in context and //put its response value to string. if (_mRequest != null && _mRequest.Length > 0) { _mRequest = PayflowUtility.MaskSensitiveFields(_mRequest); } var errorList = Context.GetErrors(PayflowConstants.SeverityFatal); var firstFatalError = (ErrorObject)errorList[0]; responseValue = firstFatalError.ToString(); } _mResponse = new Response(RequestId, Context); _mResponse.SetRequestString(_mRequest); _mResponse.SetParams(responseValue); //Log the context if (Context.IsErrorContained()) { Context.LogErrors(); } pfProNetApi = null; } return(_mResponse); }
/// <summary> /// Generates the transaction request. /// </summary> internal virtual void GenerateRequest() { Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.GenerateRequest(): Entered", PayflowConstants.SeverityDebug); try { _mRequestBuffer = new StringBuilder(); RequestBuffer.Append(PayflowUtility.AppendToRequest(PayflowConstants.ParamTrxtype, TrxType)); RequestBuffer.Append(PayflowUtility.AppendToRequest(PayflowConstants.ParamVerbosity, Verbosity)); if (_mExtData != null && _mExtData.Count > 0) { foreach (ExtendData ed in _mExtData) { if (ed != null) { ed.RequestBuffer = _mRequestBuffer; ed.GenerateRequest(); } } } if (Tender != null) { Tender.RequestBuffer = _mRequestBuffer; Tender.GenerateRequest(); } if (_mInvoice != null) { _mInvoice.RequestBuffer = _mRequestBuffer; _mInvoice.GenerateRequest(); } if (_mUserInfo != null) { _mUserInfo.RequestBuffer = _mRequestBuffer; _mUserInfo.GenerateRequest(); } if (_mUserItem != null) { _mUserItem.RequestBuffer = _mRequestBuffer; _mUserItem.GenerateRequest(); } if (BuyerAuthStatus != null) { BuyerAuthStatus.RequestBuffer = _mRequestBuffer; BuyerAuthStatus.GenerateRequest(); } Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.GenerateRequest(): Exiting", PayflowConstants.SeverityDebug); } catch (BaseException) { throw; } catch (Exception ex) { var te = new TransactionException(ex); throw te; } }
public TransactionFailedEventArgs(ITransaction tx, TransactionException exception) : base(tx) { _Exception = exception; }
private void MapTxExceptionToHR(TransactionException txException) { this.MapTxExceptionToHR(txException, false); }
internal OletxTransactionManager( string nodeName ) { lock ( ClassSyncObject ) { // If we have not already initialized the shim factory and started the notification // thread, do so now. if (null == OletxTransactionManager.proxyShimFactory) { Int32 error = NativeMethods.GetNotificationFactory( OletxTransactionManager.ShimWaitHandle.SafeWaitHandle, out OletxTransactionManager.proxyShimFactory ); if (0 != error) { throw TransactionException.Create(SR.GetString(SR.TraceSourceOletx), SR.GetString(SR.UnableToGetNotificationShimFactory), null); } ThreadPool.UnsafeRegisterWaitForSingleObject( OletxTransactionManager.ShimWaitHandle, new WaitOrTimerCallback(OletxTransactionManager.ShimNotificationCallback), null, -1, false ); } } this.dtcTransactionManagerLock = new ReaderWriterLock(); this.nodeNameField = nodeName; // The DTC proxy doesn't like an empty string for node name on 64-bit platforms when // running as WOW64. It treats any non-null node name as a "remote" node and turns off // the WOW64 bit, causing problems when reading the registry. So if we got on empty // string for the node name, just treat it as null. if ((null != this.nodeNameField) && (0 == this.nodeNameField.Length)) { this.nodeNameField = null; } if (DiagnosticTrace.Verbose) { DistributedTransactionManagerCreatedTraceRecord.Trace(SR.GetString(SR.TraceSourceOletx), this.GetType(), this.nodeNameField ); } // Initialize the properties from config. configuredTransactionOptions.IsolationLevel = isolationLevelProperty = TransactionManager.DefaultIsolationLevel; configuredTransactionOptions.Timeout = timeoutProperty = TransactionManager.DefaultTimeout; this.internalResourceManager = new OletxInternalResourceManager(this); dtcTransactionManagerLock.AcquireWriterLock(-1); try { this.dtcTransactionManager = new DtcTransactionManager(this.nodeNameField, this); } finally { dtcTransactionManagerLock.ReleaseWriterLock(); } if (resourceManagerHashTable == null) { resourceManagerHashTable = new Hashtable(2); resourceManagerHashTableLock = new System.Threading.ReaderWriterLock(); } }
internal void ReenlistThread(object?state) { int localLoopCount; bool done; OletxEnlistment? localEnlistment; ResourceManagerShim?localResourceManagerShim; bool success; Timer? localTimer = null; bool disposeLocalTimer = false; OletxResourceManager resourceManager = (OletxResourceManager)state !; try { TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log; if (etwLog.IsEnabled()) { etwLog.MethodEnter(TraceSourceType.TraceSourceOleTx, this, $"{nameof(OletxResourceManager)}.{nameof(ReenlistThread)}"); } lock (resourceManager) { localResourceManagerShim = resourceManager.ResourceManagerShim; localTimer = resourceManager.ReenlistThreadTimer; resourceManager.ReenlistThreadTimer = null; resourceManager.reenlistThread = Thread.CurrentThread; } // We only want to do work if we have a resourceManagerShim. if (localResourceManagerShim != null) { lock (resourceManager.ReenlistList) { // Get the current count on the list. localLoopCount = resourceManager.ReenlistList.Count; } done = false; while (!done && localLoopCount > 0 && localResourceManagerShim != null) { lock (resourceManager.ReenlistList) { localEnlistment = null; localLoopCount--; if (resourceManager.ReenlistList.Count == 0) { done = true; } else { localEnlistment = resourceManager.ReenlistList[0] as OletxEnlistment; if (localEnlistment == null) { if (etwLog.IsEnabled()) { etwLog.InternalError(); } throw TransactionException.Create(SR.InternalError, null); } resourceManager.ReenlistList.RemoveAt(0); object syncRoot = localEnlistment; lock (syncRoot) { if (OletxEnlistment.OletxEnlistmentState.Done == localEnlistment.State) { // We may be racing with a RecoveryComplete here. Just forget about this // enlistment. localEnlistment = null; } else if (OletxEnlistment.OletxEnlistmentState.Prepared != localEnlistment.State) { // The app hasn't yet responded to Prepare, so we don't know // if it is indoubt or not yet. So just re-add it to the end // of the list. resourceManager.ReenlistList.Add(localEnlistment); localEnlistment = null; } } } } if (localEnlistment != null) { OletxTransactionOutcome localOutcome = OletxTransactionOutcome.NotKnownYet; try { Debug.Assert(localResourceManagerShim != null, "ReenlistThread - localResourceManagerShim is null"); // Make sure we have a prepare info. if (localEnlistment.ProxyPrepareInfoByteArray == null) { Debug.Assert(false, string.Format(null, "this.prepareInfoByteArray == null in RecoveryInformation()")); if (etwLog.IsEnabled()) { etwLog.InternalError(); } throw TransactionException.Create(SR.InternalError, null); } localResourceManagerShim.Reenlist(localEnlistment.ProxyPrepareInfoByteArray, out localOutcome); if (localOutcome == OletxTransactionOutcome.NotKnownYet) { object syncRoot = localEnlistment; lock (syncRoot) { if (OletxEnlistment.OletxEnlistmentState.Done == localEnlistment.State) { // We may be racing with a RecoveryComplete here. Just forget about this // enlistment. localEnlistment = null; } else { // Put the enlistment back on the end of the list for retry later. lock (resourceManager.ReenlistList) { resourceManager.ReenlistList.Add(localEnlistment); localEnlistment = null; } } } } } catch (COMException ex) when(ex.ErrorCode == OletxHelper.XACT_E_CONNECTION_DOWN) { if (etwLog.IsEnabled()) { etwLog.ExceptionConsumed(TraceSourceType.TraceSourceOleTx, ex); } // Release the resource manager so we can create a new one. resourceManager.ResourceManagerShim = null; // Now create a new resource manager with the proxy. localResourceManagerShim = resourceManager.ResourceManagerShim; } // If we get here and we still have localEnlistment, then we got the outcome. if (localEnlistment != null) { object syncRoot = localEnlistment; lock (syncRoot) { if (OletxEnlistment.OletxEnlistmentState.Done == localEnlistment.State) { // We may be racing with a RecoveryComplete here. Just forget about this // enlistment. localEnlistment = null; } else { // We are going to send the notification to the RM. We need to put the // enlistment on the reenlistPendingList. We lock the reenlistList because // we have decided that is the lock that protects both lists. The entry will // be taken off the reenlistPendingList when the enlistment has // EnlistmentDone called on it. The enlistment will call // RemoveFromReenlistPending. lock (resourceManager.ReenlistList) { resourceManager.ReenlistPendingList.Add(localEnlistment); } if (localOutcome == OletxTransactionOutcome.Committed) { localEnlistment.State = OletxEnlistment.OletxEnlistmentState.Committing; if (etwLog.IsEnabled()) { etwLog.EnlistmentStatus(TraceSourceType.TraceSourceOleTx, localEnlistment.EnlistmentTraceId, NotificationCall.Commit); } localEnlistment.EnlistmentNotification !.Commit(localEnlistment); } else if (localOutcome == OletxTransactionOutcome.Aborted) { localEnlistment.State = OletxEnlistment.OletxEnlistmentState.Aborting; if (etwLog.IsEnabled()) { etwLog.EnlistmentStatus(TraceSourceType.TraceSourceOleTx, localEnlistment.EnlistmentTraceId, NotificationCall.Rollback); } localEnlistment.EnlistmentNotification !.Rollback(localEnlistment); } else { if (etwLog.IsEnabled()) { etwLog.InternalError(); } throw TransactionException.Create(SR.InternalError, null); } } } } // end of if null != localEnlistment } // end of if null != localEnlistment } } localResourceManagerShim = null; // Check to see if there is more work to do. lock (resourceManager.ReenlistList) { lock (resourceManager) { // Get the current count on the list. localLoopCount = resourceManager.ReenlistList.Count; if (localLoopCount <= 0 && resourceManager.ReenlistPendingList.Count <= 0) { // No more entries on the list. Try calling ReenlistComplete on the proxy, if // appropriate. // If the application has called RecoveryComplete, // we are responsible for calling ReenlistComplete on the // proxy. success = resourceManager.CallProxyReenlistComplete(); if (success) { // Okay, the reenlist thread is done and we don't need to schedule another one. disposeLocalTimer = true; } else { // We couldn't talk to the proxy to do ReenlistComplete, so schedule // the thread again for 10 seconds from now. resourceManager.ReenlistThreadTimer = localTimer; if (!localTimer !.Change(10000, Timeout.Infinite)) { throw TransactionException.CreateInvalidOperationException( TraceSourceType.TraceSourceLtm, SR.UnexpectedTimerFailure, null); } } } else { // There are still entries on the list, so they must not be // resovled, yet. Schedule the thread again in 10 seconds. resourceManager.ReenlistThreadTimer = localTimer; if (!localTimer !.Change(10000, Timeout.Infinite)) { throw TransactionException.CreateInvalidOperationException( TraceSourceType.TraceSourceLtm, SR.UnexpectedTimerFailure, null); } } resourceManager.reenlistThread = null; } if (etwLog.IsEnabled()) { etwLog.MethodExit(TraceSourceType.TraceSourceOleTx, this, $"{nameof(OletxResourceManager)}.{nameof(ReenlistThread)}"); } } } // end of outer-most try finally { localResourceManagerShim = null; if (disposeLocalTimer && localTimer != null) { localTimer.Dispose(); } } } // end of ReenlistThread method;
internal OletxEnlistment Reenlist(byte[] prepareInfo, IEnlistmentNotificationInternal enlistmentNotification) { OletxTransactionOutcome outcome = OletxTransactionOutcome.NotKnownYet; OletxTransactionStatus xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_NONE; if (prepareInfo == null) { throw new ArgumentException(SR.InvalidArgument, nameof(prepareInfo)); } // Verify that the resource manager guid in the recovery info matches that of the calling resource manager. byte[] rmGuidArray = new byte[16]; for (int i = 0; i < 16; i++) { rmGuidArray[i] = prepareInfo[i + 16]; } Guid rmGuid = new(rmGuidArray); if (rmGuid != ResourceManagerIdentifier) { throw TransactionException.Create(TraceSourceType.TraceSourceOleTx, SR.ResourceManagerIdDoesNotMatchRecoveryInformation, null); } // Ask the proxy resource manager to reenlist. ResourceManagerShim?localResourceManagerShim = null; try { localResourceManagerShim = ResourceManagerShim; if (localResourceManagerShim == null) { // The TM must be down. Throw the exception that will get caught below and will cause // the enlistment to start the ReenlistThread. The TMDown thread will be trying to reestablish // connection with the TM and will start the reenlist thread when it does. throw new COMException(SR.DtcTransactionManagerUnavailable, OletxHelper.XACT_E_CONNECTION_DOWN); } // Only wait for 5 milliseconds. If the TM doesn't have the outcome now, we will // put the enlistment on the reenlistList for later processing. localResourceManagerShim.Reenlist(prepareInfo, out outcome); if (OletxTransactionOutcome.Committed == outcome) { xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_COMMITTED; } else if (OletxTransactionOutcome.Aborted == outcome) { xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_ABORTED; } else // we must not know the outcome yet. { xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_PREPARED; StartReenlistThread(); } } catch (COMException ex) when(ex.ErrorCode == OletxHelper.XACT_E_CONNECTION_DOWN) { xactStatus = OletxTransactionStatus.OLETX_TRANSACTION_STATUS_PREPARED; ResourceManagerShim = null; StartReenlistThread(); TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log; if (etwLog.IsEnabled()) { etwLog.ExceptionConsumed(TraceSourceType.TraceSourceOleTx, ex); } } finally { localResourceManagerShim = null; } // Now create our enlistment to tell the client the outcome. return(new OletxEnlistment(enlistmentNotification, xactStatus, prepareInfo, this)); }
internal OletxEnlistment EnlistDurable( OletxTransaction oletxTransaction, bool canDoSinglePhase, IEnlistmentNotificationInternal enlistmentNotification, EnlistmentOptions enlistmentOptions) { ResourceManagerShim?localResourceManagerShim; Debug.Assert(oletxTransaction != null, "Argument is null"); Debug.Assert(enlistmentNotification != null, "Argument is null"); EnlistmentShim enlistmentShim; Phase0EnlistmentShim phase0Shim; Guid txUow = Guid.Empty; bool undecidedEnlistmentsIncremented = false; // Create our enlistment object. OletxEnlistment enlistment = new( canDoSinglePhase, enlistmentNotification, oletxTransaction.RealTransaction.TxGuid, enlistmentOptions, this, oletxTransaction); bool enlistmentSucceeded = false; try { if ((enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != 0) { oletxTransaction.RealTransaction.IncrementUndecidedEnlistments(); undecidedEnlistmentsIncremented = true; } // This entire sequence needs to be executed before we can go on. lock (enlistment) { try { // Do the enlistment on the proxy. localResourceManagerShim = ResourceManagerShim; if (localResourceManagerShim == null) { // The TM must be down. Throw the appropriate exception. throw TransactionManagerCommunicationException.Create(SR.TraceSourceOletx, null); } if ((enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != 0) { oletxTransaction.RealTransaction.TransactionShim.Phase0Enlist(enlistment, out phase0Shim); enlistment.Phase0EnlistmentShim = phase0Shim; } localResourceManagerShim.Enlist(oletxTransaction.RealTransaction.TransactionShim, enlistment, out enlistmentShim); enlistment.EnlistmentShim = enlistmentShim; } catch (COMException comException) { // There is no string mapping for XACT_E_TOOMANY_ENLISTMENTS, so we need to do it here. if (comException.ErrorCode == OletxHelper.XACT_E_TOOMANY_ENLISTMENTS) { throw TransactionException.Create( SR.OletxTooManyEnlistments, comException, enlistment == null ? Guid.Empty : enlistment.DistributedTxId); } OletxTransactionManager.ProxyException(comException); throw; } } enlistmentSucceeded = true; } finally { if (!enlistmentSucceeded && (enlistmentOptions & EnlistmentOptions.EnlistDuringPrepareRequired) != 0 && undecidedEnlistmentsIncremented) { oletxTransaction.RealTransaction.DecrementUndecidedEnlistments(); } } return(enlistment); }
public void Mark_nhibernate_transaction_wrapped_exceptions_as_transient() { var e = new TransactionException("Wrapped exception", SqlExceptionGenerator.GetSqlException(40197)); Assert.IsTrue(new TTransientErrorDetectionStrategy().IsTransient(e)); }