Faults.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / TransactionBridge / Microsoft / Transactions / Wsat / Messaging / Faults.cs / 1 / Faults.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

// Implement the fault codes defined in WS-Coor, WS-AT and .NET-AT 

using System; 
using System.Globalization; 
using System.ServiceModel;
using System.Transactions; 
using System.Xml;
using System.ServiceModel.Security;
using System.ServiceModel.Channels;
using Microsoft.Transactions.Wsat.Protocol; 
using Microsoft.Transactions.Bridge;
 
namespace Microsoft.Transactions.Wsat.Messaging 
{
    class Fault 
    {
        string action;
        FaultCode code;
 
        string reasonText;
        FaultReason reason; 
 
        public Fault(string action, FaultCode code, string reasonText)
        { 
            this.action = action;
            this.code = code;

            this.reasonText = reasonText; 
            this.reason = new FaultReason(reasonText, CultureInfo.CurrentCulture);
        } 
 
        public string Action
        { 
            get { return this.action; }
        }

        public FaultCode Code 
        {
            get { return this.code; } 
        } 

        public string ReasonText 
        {
            get { return this.reasonText; }
        }
 
        public FaultReason Reason
        { 
            get { return this.reason; } 
        }
    } 

    abstract class Faults
    {
        protected CoordinationStrings coordinationStrings; 
        protected AtomicTransactionStrings atomicTransactionStrings;
 
        // WS-COOR 
        protected Fault invalidState;
        protected Fault invalidProtocol; 
        protected Fault invalidParameters;

        // WS-AT
        protected Fault inconsistentInternalState; 

        // .NET-AT 
        protected Fault invalidPolicy; 

        public static readonly FaultCode CoordinatorRegistrationFailedCode = new FaultCode(DotNetAtomicTransactionExternalStrings.CoordinatorRegistrationFailed, DotNetAtomicTransactionExternalStrings.Namespace); 


        protected Faults(ProtocolVersion protocolVersion)
        { 
            this.coordinationStrings = CoordinationStrings.Version(protocolVersion);
            this.atomicTransactionStrings = AtomicTransactionStrings.Version(protocolVersion); 
 
            //
            // WS-Coordination 
            //

            string invalidStateReason = SR.GetString(SR.InvalidStateReason);
            FaultCode invalidStateCode = new FaultCode(this.coordinationStrings.InvalidState, this.coordinationStrings.Namespace); 
            this.invalidState = new Fault(this.coordinationStrings.FaultAction, invalidStateCode, invalidStateReason);
 
            string invalidProtocolReason = SR.GetString(SR.InvalidProtocolReason); 
            FaultCode invalidProtocolCode = new FaultCode(this.coordinationStrings.InvalidProtocol, this.coordinationStrings.Namespace);
            this.invalidProtocol = new Fault(this.coordinationStrings.FaultAction, invalidProtocolCode, invalidProtocolReason); 

            string invalidParametersReason = SR.GetString(SR.InvalidParametersReason);
            FaultCode invalidParametersCode = new FaultCode(this.coordinationStrings.InvalidParameters, this.coordinationStrings.Namespace);
            this.invalidParameters = new Fault(this.coordinationStrings.FaultAction, invalidParametersCode, invalidParametersReason); 

 
            // 
            // WS-AT
            // 

            string inconsistentInternalStateReason = SR.GetString(SR.InconsistentInternalStateReason);
            FaultCode inconsistentInternalStateCode = new FaultCode(atomicTransactionStrings.InconsistentInternalState, atomicTransactionStrings.Namespace);
            this.inconsistentInternalState = new Fault(atomicTransactionStrings.FaultAction, inconsistentInternalStateCode, inconsistentInternalStateReason); 

            // 
            // .NET-AT 
            //
 
            string invalidPolicyReason = SR.GetString(SR.InvalidPolicyReason);
            FaultCode invalidPolicyCode = new FaultCode(DotNetAtomicTransactionExternalStrings.InvalidPolicy, DotNetAtomicTransactionExternalStrings.Namespace);
            this.invalidPolicy = new Fault(atomicTransactionStrings.FaultAction, invalidPolicyCode, invalidPolicyReason);
        } 

        public static Fault CreateAccessDeniedFault(MessageVersion version) 
        { 
            FaultException fe = (FaultException)System.ServiceModel.Dispatcher.AuthorizationBehavior.CreateAccessDeniedFaultException();
            return new Fault(version.Addressing.DefaultFaultAction, fe.Code, fe.Reason.ToString()); 
        }


        // WS-Coordination 
        public Fault InvalidState
        { 
            get { return this.invalidState; } 
        }
 
        public Fault InvalidProtocol
        {
            get { return this.invalidProtocol; }
        } 

        public Fault InvalidParameters 
        { 
            get { return this.invalidParameters; }
        } 

        public abstract Fault CannotCreateContext
        {
            get; 
        }
 
        public abstract Fault UnknownCompletionEnlistment 
        {
            get; 
        }

        public abstract Fault RegistrationDispatchFailed
        { 
            get;
        } 
 
        public abstract Fault CreateContextDispatchFailed
        { 
            get;
        }

        public abstract Fault RegistrationProxyFailed 
        {
            get; 
        } 

        public abstract Fault ParticipantRegistrationNetAccessDisabled 
        {
            get;
        }
 
        public abstract Fault SubordinateRegistrationNetAccessDisabled
        { 
            get; 
        }
 
        public abstract Fault ParticipantRegistrationLoopback
        {
            get;
        } 

        public abstract Fault CompletionAlreadyRegistered 
        { 
            get;
        } 

        public abstract Fault ParticipantTMRegistrationFailed(Status status);

        public abstract Fault SubordinateTMRegistrationFailed(Status status); 

        public abstract Fault TMEnlistFailed(Status status); 
 

        // WS-AT 
        public Fault InconsistentInternalState
        {
            get { return this.inconsistentInternalState; }
        } 

        public abstract Fault UnknownTransaction 
        { 
            get;
        } 


        // .NET-AT
        public Fault InvalidPolicy 
        {
            get { return this.invalidPolicy; } 
        } 

 
        public static Faults Version(ProtocolVersion protocolVersion)
        {
            ProtocolVersionHelper.AssertProtocolVersion(protocolVersion, typeof(Faults), "V"); //assert valid protocol version
 
            switch (protocolVersion)
            { 
                case ProtocolVersion.Version10: 
                    return Faults10.Instance;
 
                case ProtocolVersion.Version11:
                    return Faults11.Instance;

                default: 
                    return null; // inaccessible path
            } 
        } 
    }
 
    class Faults10 : Faults
    {
        // WS-Coordination
        Fault contextRefused; 
        Fault alreadyRegistered;
 
        // WS-AT no extra faults compared to 'Faults' 

        // .NET-AT 
        Fault tooManyEnlistments;
        Fault disabled;

        static Faults10 instance = new Faults10(); 
        public static Faults Instance
        { 
            get { return instance; } 
        }
 

        Faults10() : base(ProtocolVersion.Version10)
        {
            // WS-Coordination 
            string contextRefusedReason = SR.GetString(SR.ContextRefusedReason);
            FaultCode contextRefusedCode = new FaultCode(this.coordinationStrings.ContextRefused, this.coordinationStrings.Namespace); 
            contextRefused = new Fault(this.coordinationStrings.FaultAction, contextRefusedCode, contextRefusedReason); 

            string alreadyRegisteredReason = SR.GetString(SR.AlreadyRegisteredReason); 
            FaultCode alreadyRegisteredCode = new FaultCode(this.coordinationStrings.AlreadyRegistered, this.coordinationStrings.Namespace);
            alreadyRegistered = new Fault(this.coordinationStrings.FaultAction, alreadyRegisteredCode, alreadyRegisteredReason);

 
            // .NET-AT
            string tooManyEnlistmentsReason = SR.GetString(SR.TooManyEnlistmentsReason); 
            FaultCode tooManyEnlistmentsCode = new FaultCode(DotNetAtomicTransactionExternalStrings.TooManyEnlistments, DotNetAtomicTransactionExternalStrings.Namespace); 
            tooManyEnlistments = new Fault(atomicTransactionStrings.FaultAction, tooManyEnlistmentsCode, tooManyEnlistmentsReason);
 
            string disabledReason = SR.GetString(SR.DisabledReason);
            FaultCode disabledCode = new FaultCode(DotNetAtomicTransactionExternalStrings.Disabled, DotNetAtomicTransactionExternalStrings.Namespace);
            disabled = new Fault(this.atomicTransactionStrings.FaultAction, disabledCode, disabledReason);
        } 

        // WS-COOR 
        public override Fault CannotCreateContext 
        {
            get 
            {
                return this.invalidState;
            }
        } 

        public override Fault UnknownCompletionEnlistment 
        { 
            get
            { 
                return this.invalidState;
            }
        }
 
        public override Fault RegistrationDispatchFailed
        { 
            get 
            {
                return this.invalidParameters; 
            }
        }

        public override Fault CreateContextDispatchFailed 
        {
            get 
            { 
                return this.invalidParameters;
            } 
        }

        public override Fault RegistrationProxyFailed
        { 
            get
            { 
                return this.contextRefused; 
            }
        } 

        public override Fault ParticipantRegistrationNetAccessDisabled
        {
            get 
            {
                return this.disabled; 
            } 
        }
 
        public override Fault SubordinateRegistrationNetAccessDisabled
        {
            get
            { 
                return this.disabled;
            } 
        } 

        public override Fault ParticipantRegistrationLoopback 
        {
            get
            {
                return this.contextRefused; 
            }
        } 
 
        public override Fault CompletionAlreadyRegistered
        { 
            get
            {
                return this.alreadyRegistered;
            } 
        }
 
        public override Fault ParticipantTMRegistrationFailed(Status status) 
        {
            if (status == Status.TooManySubordinateEnlistments) 
            {
                return this.tooManyEnlistments;
            }
            else 
            {
                return this.invalidState; 
            } 
        }
 
        public override Fault SubordinateTMRegistrationFailed(Status status)
        {
            if (status == Status.TooManySubordinateEnlistments)
            { 
                return this.tooManyEnlistments;
            } 
            else 
            {
                return this.invalidState; 
            }
        }

        public override Fault TMEnlistFailed(Status status) 
        {
            if (status == Status.TooManySubordinateEnlistments) 
            { 
                return this.tooManyEnlistments;
            } 
            else
            {
                return this.invalidState;
            } 
        }
 
        // WS-AT 
        public override Fault UnknownTransaction
        { 
            get
            {
                return this.invalidState;
            } 
        }
    } 
 
    class Faults11 : Faults
    { 
        // WS-COOR
        Fault cannotCreateContext;
        Fault cannotRegisterParticipant;
 
        // WS-AT
        Fault unknownTransaction; 
 
        // .NET-AT - no extra faults compared to 'Faults'
 
        static Faults11 instance = new Faults11();
        public static Faults Instance
        {
            get { return instance; } 
        }
 
        Faults11() : base(ProtocolVersion.Version11) 
        {
            // WS-Coordination 
            string cannotCreateContextReason = SR.GetString(SR.CannotCreateContextReason);
            FaultCode cannotCreateContextCode = new FaultCode(this.coordinationStrings.CannotCreateContext, this.coordinationStrings.Namespace);
            cannotCreateContext = new Fault (this.coordinationStrings.FaultAction, cannotCreateContextCode, cannotCreateContextReason);
 
            string cannotRegisterParticipantReason = SR.GetString(SR.CannotRegisterParticipant);
            FaultCode cannotRegisterParticipantCode = new FaultCode(this.coordinationStrings.CannotRegisterParticipant, this.coordinationStrings.Namespace); 
            cannotRegisterParticipant = new Fault (this.coordinationStrings.FaultAction, cannotRegisterParticipantCode, cannotRegisterParticipantReason); 

            // WS-AT 
            string unknownTransactionReason = SR.GetString(SR.UnknownTransactionReason);
            FaultCode unknownTransactionCode = new FaultCode(this.atomicTransactionStrings.UnknownTransaction, this.atomicTransactionStrings.Namespace);
            unknownTransaction = new Fault(this.atomicTransactionStrings.FaultAction, unknownTransactionCode, unknownTransactionReason);
        } 

        // WS-COOR 
        public override Fault CannotCreateContext 
        {
            get 
            {
                return this.cannotCreateContext;
            }
        } 

        public override Fault UnknownCompletionEnlistment 
        { 
            get
            { 
                return this.cannotRegisterParticipant;
            }
        }
 
        public override Fault RegistrationDispatchFailed
        { 
            get 
            {
                return this.cannotRegisterParticipant; 
            }
        }

        public override Fault CreateContextDispatchFailed 
        {
            get 
            { 
                return this.cannotCreateContext;
            } 
        }

        public override Fault RegistrationProxyFailed
        { 
            get
            { 
                return this.cannotCreateContext; 
            }
        } 

        public override Fault ParticipantRegistrationNetAccessDisabled
        {
            get 
            {
                return this.cannotRegisterParticipant; 
            } 
        }
 
        public override Fault SubordinateRegistrationNetAccessDisabled
        {
            get
            { 
                return this.cannotCreateContext;
            } 
        } 

        public override Fault ParticipantRegistrationLoopback 
        {
            get
            {
                return this.cannotRegisterParticipant; 
            }
        } 
 
        public override Fault CompletionAlreadyRegistered
        { 
            get
            {
                return this.cannotRegisterParticipant;
            } 
        }
 
        public override Fault ParticipantTMRegistrationFailed(Status status) 
        {
            return this.cannotRegisterParticipant; 
        }

        public override Fault SubordinateTMRegistrationFailed(Status status)
        { 
            return this.cannotCreateContext;
        } 
 
        public override Fault TMEnlistFailed(Status status)
        { 
            return this.cannotCreateContext;
        }

        // WS-AT 
        public override Fault UnknownTransaction
        { 
            get 
            {
                return this.unknownTransaction; 
            }
        }
    }
 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK