private void ConfigureEnlistment(WsatRegistrationHeader header)
        {
            Enlistment enlistment = new Enlistment();
            string     contextId  = header.ContextId;

            if (contextId == null)
            {
                contextId = CoordinationContext.CreateNativeIdentifier(header.TransactionId);
            }
            enlistment.LocalTransactionId  = header.TransactionId;
            enlistment.RemoteTransactionId = contextId;
            Notifications twoPhaseCommit = Notifications.TwoPhaseCommit;

            switch (this.protocol)
            {
            case Microsoft.Transactions.Wsat.Messaging.ControlProtocol.Volatile2PC:
                twoPhaseCommit |= Notifications.Volatile | Notifications.Phase0;
                break;

            case Microsoft.Transactions.Wsat.Messaging.ControlProtocol.Durable2PC:
                break;

            default:
                Microsoft.Transactions.Bridge.DiagnosticUtility.FailFast("Invalid protocol");
                break;
            }
            enlistment.NotificationMask        = twoPhaseCommit;
            enlistment.ProtocolProviderContext = this;
            base.enlistment = enlistment;
        }
        private TransactionContext CreateTransactionContext()
        {
            Microsoft.Transactions.Bridge.EnlistmentOptions enlistmentOptions = this.enlistment.EnlistmentOptions;
            string remoteTransactionId  = this.enlistment.RemoteTransactionId;
            Guid   localTransactionId   = this.enlistment.LocalTransactionId;
            CoordinationContext context = new CoordinationContext(this.state.ProtocolVersion)
            {
                Expires            = (enlistmentOptions.Expires == TimeSpan.MaxValue) ? uint.MaxValue : ((uint)((int)enlistmentOptions.Expires.TotalMilliseconds)),
                Identifier         = remoteTransactionId,
                LocalTransactionId = localTransactionId,
                IsolationLevel     = enlistmentOptions.IsoLevel,
                IsolationFlags     = enlistmentOptions.IsolationFlags,
                Description        = enlistmentOptions.Description
            };
            string contextId = CoordinationContext.IsNativeIdentifier(remoteTransactionId, localTransactionId) ? null : remoteTransactionId;
            string sctId     = null;
            RequestSecurityTokenResponse issuedToken = null;

            if (this.state.Config.PortConfiguration.SupportingTokensEnabled)
            {
                CoordinationServiceSecurity.CreateIssuedToken(localTransactionId, remoteTransactionId, this.state.ProtocolVersion, out issuedToken, out sctId);
            }
            AddressHeader refParam = new WsatRegistrationHeader(localTransactionId, contextId, sctId);

            context.RegistrationService = this.state.RegistrationCoordinatorListener.CreateEndpointReference(refParam);
            return(new TransactionContext(context, issuedToken));
        }
        public bool FaultInSupportingToken(Message message)
        {
            DebugTrace.TraceEnter(this, "FaultInSupportingToken");
            bool flag = false;
            WsatRegistrationHeader header = this.ReadRegistrationHeader(message);

            if (((header == null) || (header.TransactionId == Guid.Empty)) || string.IsNullOrEmpty(header.TokenId))
            {
                if (DebugTrace.Warning)
                {
                    DebugTrace.Trace(TraceLevel.Warning, "Invalid or absent RegisterInfo in register message");
                }
            }
            else
            {
                currentSct = this.DeriveToken(header.TransactionId, header.TokenId);
                flag       = true;
                if (DebugTrace.Verbose)
                {
                    DebugTrace.Trace(TraceLevel.Verbose, "Created SCT with id {0} for transaction {1}", header.TokenId, header.TransactionId);
                }
            }
            DebugTrace.TraceLeave(this, "FaultInSupportingToken");
            return(flag);
        }
        private WsatRegistrationHeader ReadRegistrationHeader(Message message)
        {
            WsatRegistrationHeader header = null;

            try
            {
                header = WsatRegistrationHeader.ReadFrom(message);
            }
            catch (InvalidEnlistmentHeaderException exception)
            {
                DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Error);
                if (DebugTrace.Error)
                {
                    DebugTrace.Trace(TraceLevel.Error, "Invalid RegisterInfo header found in register message: {0}", exception.Message);
                }
            }
            return(header);
        }
        public ParticipantEnlistment(ProtocolState state, WsatRegistrationHeader header, Microsoft.Transactions.Wsat.Messaging.ControlProtocol protocol, TwoPhaseCommitParticipantProxy proxy) : base(state)
        {
            this.protocol = protocol;
            proxy.AddRef();
            this.participantProxy = proxy;
            this.ConfigureEnlistment(header);
            this.CreateCoordinatorService();
            switch (protocol)
            {
            case Microsoft.Transactions.Wsat.Messaging.ControlProtocol.Volatile2PC:
                base.stateMachine = new VolatileStateMachine(this);
                base.stateMachine.ChangeState(state.States.VolatileRegistering);
                return;

            case Microsoft.Transactions.Wsat.Messaging.ControlProtocol.Durable2PC:
                base.stateMachine = new DurableStateMachine(this);
                base.stateMachine.ChangeState(state.States.DurableRegistering);
                return;
            }
            Microsoft.Transactions.Bridge.DiagnosticUtility.FailFast("Invalid protocol");
        }
        public void Register(Message message, Microsoft.Transactions.Wsat.Messaging.RequestAsyncResult result)
        {
            Microsoft.Transactions.Wsat.Messaging.Register register = new Microsoft.Transactions.Wsat.Messaging.Register(message, this.state.ProtocolVersion);
            EndpointAddress        participantProtocolService       = register.ParticipantProtocolService;
            WsatRegistrationHeader header = WsatRegistrationHeader.ReadFrom(message);

            if (header == null)
            {
                if (DebugTrace.Warning)
                {
                    DebugTrace.Trace(TraceLevel.Warning, "Rejecting Register message with no registration header");
                }
                this.SendFault(result, this.state.Faults.InvalidParameters);
                return;
            }
            switch (register.Protocol)
            {
            case ControlProtocol.Completion:
            {
                CompletionEnlistment completion = this.state.Lookup.FindEnlistment(header.TransactionId) as CompletionEnlistment;
                if (completion != null)
                {
                    CompletionParticipantProxy proxy = this.state.TryCreateCompletionParticipantProxy(participantProtocolService);
                    if (proxy == null)
                    {
                        if (DebugTrace.Warning)
                        {
                            DebugTrace.Trace(TraceLevel.Warning, "Rejecting Register message for completion on no completion enlistment");
                        }
                        this.SendFault(result, this.state.Faults.InvalidParameters);
                        return;
                    }
                    try
                    {
                        completion.StateMachine.Enqueue(new MsgRegisterCompletionEvent(completion, ref register, result, proxy));
                        return;
                    }
                    finally
                    {
                        proxy.Release();
                    }
                    break;
                }
                if (DebugTrace.Warning)
                {
                    DebugTrace.Trace(TraceLevel.Warning, "Rejecting uncorrelated Register message for completion");
                }
                this.SendFault(result, this.state.Faults.UnknownCompletionEnlistment);
                return;
            }

            case ControlProtocol.Volatile2PC:
            case ControlProtocol.Durable2PC:
                break;

            default:
                goto Label_0222;
            }
            if (!this.state.TransactionManager.Settings.NetworkOutboundAccess)
            {
                if (DebugTrace.Warning)
                {
                    DebugTrace.Trace(TraceLevel.Warning, "Rejecting Register message because outbound transactions are disabled");
                }
                this.SendFault(result, this.state.Faults.ParticipantRegistrationNetAccessDisabled);
                return;
            }
            if (register.Loopback == this.state.ProcessId)
            {
                if (DebugTrace.Warning)
                {
                    DebugTrace.Trace(TraceLevel.Warning, "Rejecting recursive Register message from self");
                }
                this.SendFault(result, this.state.Faults.ParticipantRegistrationLoopback);
                return;
            }
            TwoPhaseCommitParticipantProxy proxy2 = this.state.TryCreateTwoPhaseCommitParticipantProxy(participantProtocolService);

            if (proxy2 == null)
            {
                if (DebugTrace.Warning)
                {
                    DebugTrace.Trace(TraceLevel.Warning, "Rejecting Register message because 2PC proxy could not be created");
                }
                this.SendFault(result, this.state.Faults.InvalidParameters);
                return;
            }
            try
            {
                ParticipantEnlistment participant = new ParticipantEnlistment(this.state, header, register.Protocol, proxy2);
                this.state.TransactionManagerSend.Register(participant, new MsgRegisterEvent(participant, ref register, result));
                return;
            }
            finally
            {
                proxy2.Release();
            }
Label_0222:
            Microsoft.Transactions.Bridge.DiagnosticUtility.FailFast("Registration protocol should have been validated");
        }