| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using CoreWCF.Channels; |
| | | 6 | | using CoreWCF.Description; |
| | | 7 | | using CoreWCF.Dispatcher; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF |
| | | 10 | | { |
| | | 11 | | [AttributeUsage(CoreWCFAttributeTargets.OperationBehavior)] |
| | | 12 | | public sealed class OperationBehaviorAttribute : Attribute, IOperationBehavior |
| | | 13 | | { |
| | | 14 | | internal const ImpersonationOption DefaultImpersonationOption = ImpersonationOption.NotAllowed; |
| | | 15 | | private ImpersonationOption _impersonation = ImpersonationOption.NotAllowed; |
| | | 16 | | private ReleaseInstanceMode _releaseInstance = ReleaseInstanceMode.None; |
| | | 17 | | |
| | 6082 | 18 | | public bool AutoDisposeParameters { get; set; } = true; |
| | | 19 | | |
| | | 20 | | public ImpersonationOption Impersonation |
| | | 21 | | { |
| | | 22 | | get |
| | | 23 | | { |
| | 3026 | 24 | | return _impersonation; |
| | | 25 | | } |
| | | 26 | | set |
| | | 27 | | { |
| | 493 | 28 | | if (!ImpersonationOptionHelper.IsDefined(value)) |
| | | 29 | | { |
| | 0 | 30 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 31 | | } |
| | 493 | 32 | | _impersonation = value; |
| | 493 | 33 | | } |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | public ReleaseInstanceMode ReleaseInstanceMode |
| | | 37 | | { |
| | 0 | 38 | | get { return _releaseInstance; } |
| | | 39 | | set |
| | | 40 | | { |
| | 0 | 41 | | if (!ReleaseInstanceModeHelper.IsDefined(value)) |
| | | 42 | | { |
| | 0 | 43 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | | 44 | | } |
| | | 45 | | |
| | 0 | 46 | | _releaseInstance = value; |
| | 0 | 47 | | } |
| | | 48 | | } |
| | | 49 | | |
| | 3187 | 50 | | void IOperationBehavior.AddBindingParameters(OperationDescription operationDescription, BindingParameterCollecti |
| | 2645 | 51 | | void IOperationBehavior.Validate(OperationDescription operationDescription) { } |
| | | 52 | | |
| | | 53 | | void IOperationBehavior.ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch) |
| | | 54 | | { |
| | 3026 | 55 | | if (description == null) |
| | | 56 | | { |
| | 0 | 57 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(description)); |
| | | 58 | | } |
| | | 59 | | |
| | 3026 | 60 | | if (dispatch == null) |
| | | 61 | | { |
| | 0 | 62 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(dispatch)); |
| | | 63 | | } |
| | | 64 | | |
| | 3026 | 65 | | if (description.IsServerInitiated() && _releaseInstance != ReleaseInstanceMode.None) |
| | | 66 | | { |
| | 0 | 67 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( |
| | 0 | 68 | | SR.Format(SR.SFxOperationBehaviorAttributeReleaseInstanceModeDoesNotApplyToCallback, |
| | 0 | 69 | | description.Name))); |
| | | 70 | | } |
| | | 71 | | |
| | 3026 | 72 | | dispatch.AutoDisposeParameters = AutoDisposeParameters; |
| | 3026 | 73 | | dispatch.ReleaseInstanceBeforeCall = (_releaseInstance & ReleaseInstanceMode.BeforeCall) != 0; |
| | 3026 | 74 | | dispatch.ReleaseInstanceAfterCall = (_releaseInstance & ReleaseInstanceMode.AfterCall) != 0; |
| | 3026 | 75 | | dispatch.Impersonation = Impersonation; |
| | 3026 | 76 | | } |
| | | 77 | | |
| | | 78 | | void IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy) |
| | | 79 | | { |
| | 2 | 80 | | } |
| | | 81 | | } |
| | | 82 | | } |