protected void AddEntry(Transaction transaction, T key, S value)
 {
     this.key = key;
     if (TransactionCache <T, S> .Add(key, value))
     {
         transaction.TransactionCompleted += new TransactionCompletedEventHandler(this.OnTransactionCompleted);
     }
 }
Esempio n. 2
0
        public void MarshalAsCoordinationContext(Transaction transaction, out CoordinationContext context, out RequestSecurityTokenResponse issuedToken)
        {
            uint                    num;
            IsolationFlags          flags;
            string                  str2;
            WsatExtendedInformation information;
            string                  str3;
            Guid                    distributedIdentifier = transaction.TransactionInformation.DistributedIdentifier;
            string                  contextId             = null;

            context = new CoordinationContext(this.protocolVersion);
            OleTxTransactionFormatter.GetTransactionAttributes(transaction, out num, out flags, out str2);
            context.IsolationFlags = flags;
            context.Description    = str2;
            if (TransactionCache <Transaction, WsatExtendedInformation> .Find(transaction, out information))
            {
                context.Expires = information.Timeout;
                if (!string.IsNullOrEmpty(information.Identifier))
                {
                    context.Identifier = information.Identifier;
                    contextId          = information.Identifier;
                }
            }
            else
            {
                context.Expires = num;
                if (context.Expires == 0)
                {
                    context.Expires = (uint)TimeoutHelper.ToMilliseconds(this.wsatConfig.MaxTimeout);
                }
            }
            if (context.Identifier == null)
            {
                context.Identifier = CoordinationContext.CreateNativeIdentifier(distributedIdentifier);
                contextId          = null;
            }
            if (!this.wsatConfig.IssuedTokensEnabled)
            {
                str3        = null;
                issuedToken = null;
            }
            else
            {
                CoordinationServiceSecurity.CreateIssuedToken(distributedIdentifier, context.Identifier, this.protocolVersion, out issuedToken, out str3);
            }
            AddressHeader refParam = new WsatRegistrationHeader(distributedIdentifier, contextId, str3);

            context.RegistrationService = this.wsatConfig.CreateRegistrationService(refParam, this.protocolVersion);
            context.IsolationLevel      = transaction.IsolationLevel;
            context.LocalTransactionId  = distributedIdentifier;
            if (this.wsatConfig.OleTxUpgradeEnabled)
            {
                context.PropagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
            }
        }
        public override Transaction UnmarshalTransaction()
        {
            Transaction transaction;

            if (!TransactionCache <string, Transaction> .Find(this.context.Identifier, out transaction))
            {
                transaction = this.wsatProxy.UnmarshalTransaction(this);
                new WsatExtendedInformation(this.context.Identifier, this.context.Expires).TryCache(transaction);
                WsatIncomingTransactionCache.Cache(this.context.Identifier, transaction);
            }
            return(transaction);
        }
        public override void WriteTransaction(Transaction transaction, Message message)
        {
            WsatExtendedInformation information;

            byte[] transmitterPropagationToken = TransactionInterop.GetTransmitterPropagationToken(transaction);
            if (!TransactionCache <Transaction, WsatExtendedInformation> .Find(transaction, out information))
            {
                uint timeoutFromTransaction = GetTimeoutFromTransaction(transaction);
                information = (timeoutFromTransaction != 0) ? new WsatExtendedInformation(null, timeoutFromTransaction) : null;
            }
            OleTxTransactionHeader header = new OleTxTransactionHeader(transmitterPropagationToken, information);

            message.Headers.Add(header);
        }
 private void OnTransactionCompleted(object sender, TransactionEventArgs e)
 {
     TransactionCache <T, S> .Remove(this.key);
 }