| | | 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 System.Collections.Concurrent; |
| | | 6 | | using System.Collections.Generic; |
| | | 7 | | using CoreWCF.Collections.Generic; |
| | | 8 | | using CoreWCF.IdentityModel.Claims; |
| | | 9 | | using Microsoft.AspNetCore.Authorization; |
| | | 10 | | |
| | | 11 | | namespace CoreWCF.Dispatcher |
| | | 12 | | { |
| | | 13 | | public sealed class DispatchOperation |
| | | 14 | | { |
| | | 15 | | private IDispatchFaultFormatter _faultFormatter; |
| | | 16 | | private ImpersonationOption _impersonation; |
| | | 17 | | private bool _isTerminating; |
| | | 18 | | private bool _isSessionOpenNotificationEnabled; |
| | | 19 | | private bool _releaseInstanceAfterCall; |
| | | 20 | | private bool _releaseInstanceBeforeCall; |
| | 3750 | 21 | | private bool _deserializeRequest = true; |
| | 3750 | 22 | | private bool _serializeReply = true; |
| | 3750 | 23 | | private bool _autoDisposeParameters = true; |
| | | 24 | | private ConcurrentDictionary<string, List<Claim>> _authorizeClaims; |
| | | 25 | | |
| | 3750 | 26 | | public DispatchOperation(DispatchRuntime parent, string name, string action) |
| | | 27 | | { |
| | 3750 | 28 | | Parent = parent ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(parent)); |
| | 3750 | 29 | | Name = name ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(name)); |
| | 3750 | 30 | | Action = action; |
| | 3750 | 31 | | _impersonation = OperationBehaviorAttribute.DefaultImpersonationOption; |
| | | 32 | | // Not necessary for basic functionality |
| | 3750 | 33 | | CallContextInitializers = parent.NewBehaviorCollection<ICallContextInitializer>(); |
| | 3750 | 34 | | FaultContractInfos = parent.NewBehaviorCollection<FaultContractInfo>(); |
| | 3750 | 35 | | ParameterInspectors = parent.NewBehaviorCollection<IParameterInspector>(); |
| | 3750 | 36 | | IsOneWay = true; |
| | 3750 | 37 | | _authorizeClaims = new ConcurrentDictionary<string, List<Claim>>(); |
| | 3750 | 38 | | } |
| | | 39 | | |
| | 3426 | 40 | | public DispatchOperation(DispatchRuntime parent, string name, string action, string replyAction) : this(parent, |
| | | 41 | | { |
| | 3426 | 42 | | ReplyAction = replyAction; |
| | 3426 | 43 | | IsOneWay = false; |
| | 3426 | 44 | | } |
| | | 45 | | |
| | 6518 | 46 | | public string Action { get; } |
| | | 47 | | |
| | 7351 | 48 | | public SynchronizedCollection<ICallContextInitializer> CallContextInitializers { get; } |
| | | 49 | | |
| | 3837 | 50 | | public SynchronizedCollection<FaultContractInfo> FaultContractInfos { get; } |
| | | 51 | | |
| | | 52 | | public IDispatchMessageFormatter Formatter |
| | | 53 | | { |
| | 6700 | 54 | | get { return InternalFormatter; } |
| | | 55 | | set |
| | | 56 | | { |
| | 3049 | 57 | | lock (Parent.ThisLock) |
| | | 58 | | { |
| | 3049 | 59 | | Parent.InvalidateRuntime(); |
| | 3049 | 60 | | InternalFormatter = value; |
| | 3049 | 61 | | } |
| | 3049 | 62 | | } |
| | | 63 | | } |
| | | 64 | | |
| | | 65 | | public IDispatchFaultFormatter FaultFormatter |
| | | 66 | | { |
| | | 67 | | get |
| | | 68 | | { |
| | 3837 | 69 | | if (_faultFormatter == null) |
| | | 70 | | { |
| | 3669 | 71 | | _faultFormatter = new DataContractSerializerFaultFormatter(FaultContractInfos); |
| | | 72 | | } |
| | 3837 | 73 | | return _faultFormatter; |
| | | 74 | | } |
| | | 75 | | set |
| | | 76 | | { |
| | 168 | 77 | | lock (Parent.ThisLock) |
| | | 78 | | { |
| | 168 | 79 | | Parent.InvalidateRuntime(); |
| | 168 | 80 | | _faultFormatter = value; |
| | 168 | 81 | | IsFaultFormatterSetExplicit = true; |
| | 168 | 82 | | } |
| | 168 | 83 | | } |
| | | 84 | | } |
| | | 85 | | |
| | 173 | 86 | | internal bool IsFaultFormatterSetExplicit { get; private set; } = false; |
| | | 87 | | |
| | | 88 | | public bool AutoDisposeParameters |
| | | 89 | | { |
| | 3674 | 90 | | get { return _autoDisposeParameters; } |
| | | 91 | | |
| | | 92 | | set |
| | | 93 | | { |
| | 3026 | 94 | | lock (Parent.ThisLock) |
| | | 95 | | { |
| | 3026 | 96 | | Parent.InvalidateRuntime(); |
| | 3026 | 97 | | _autoDisposeParameters = value; |
| | 3026 | 98 | | } |
| | 3026 | 99 | | } |
| | | 100 | | } |
| | | 101 | | |
| | | 102 | | public bool DeserializeRequest |
| | | 103 | | { |
| | 3674 | 104 | | get { return _deserializeRequest; } |
| | | 105 | | set |
| | | 106 | | { |
| | 3063 | 107 | | lock (Parent.ThisLock) |
| | | 108 | | { |
| | 3063 | 109 | | Parent.InvalidateRuntime(); |
| | 3063 | 110 | | _deserializeRequest = value; |
| | 3063 | 111 | | } |
| | 3063 | 112 | | } |
| | | 113 | | } |
| | | 114 | | |
| | 3674 | 115 | | public bool IsOneWay { get; } |
| | | 116 | | |
| | | 117 | | public ImpersonationOption Impersonation |
| | | 118 | | { |
| | 3682 | 119 | | get { return _impersonation; } |
| | | 120 | | set |
| | | 121 | | { |
| | 3026 | 122 | | lock (Parent.ThisLock) |
| | | 123 | | { |
| | 3026 | 124 | | Parent.InvalidateRuntime(); |
| | 3026 | 125 | | _impersonation = value; |
| | 3026 | 126 | | } |
| | 3026 | 127 | | } |
| | | 128 | | } |
| | | 129 | | |
| | | 130 | | public ConcurrentDictionary<string,List<Claim>> AuthorizeClaims |
| | | 131 | | { |
| | 3868 | 132 | | get { return _authorizeClaims; } |
| | | 133 | | set |
| | | 134 | | { |
| | 0 | 135 | | lock (Parent.ThisLock) |
| | | 136 | | { |
| | 0 | 137 | | Parent.InvalidateRuntime(); |
| | 0 | 138 | | _authorizeClaims = value; |
| | 0 | 139 | | } |
| | 0 | 140 | | } |
| | | 141 | | } |
| | | 142 | | |
| | 6700 | 143 | | internal bool HasNoDisposableParameters { get; set; } |
| | | 144 | | |
| | 10413 | 145 | | internal IDispatchMessageFormatter InternalFormatter { get; set; } |
| | | 146 | | |
| | 11112 | 147 | | internal IOperationInvoker InternalInvoker { get; set; } |
| | | 148 | | |
| | | 149 | | public IOperationInvoker Invoker |
| | | 150 | | { |
| | 7360 | 151 | | get { return InternalInvoker; } |
| | | 152 | | set |
| | | 153 | | { |
| | 3088 | 154 | | lock (Parent.ThisLock) |
| | | 155 | | { |
| | 3088 | 156 | | Parent.InvalidateRuntime(); |
| | 3088 | 157 | | InternalInvoker = value; |
| | 3088 | 158 | | } |
| | 3088 | 159 | | } |
| | | 160 | | } |
| | | 161 | | |
| | | 162 | | internal bool IsTerminating |
| | | 163 | | { |
| | 6687 | 164 | | get { return _isTerminating; } |
| | | 165 | | set |
| | | 166 | | { |
| | 3026 | 167 | | lock (Parent.ThisLock) |
| | | 168 | | { |
| | 3026 | 169 | | Parent.InvalidateRuntime(); |
| | 3026 | 170 | | _isTerminating = value; |
| | 3026 | 171 | | } |
| | 3026 | 172 | | } |
| | | 173 | | } |
| | | 174 | | |
| | | 175 | | internal bool IsSessionOpenNotificationEnabled |
| | | 176 | | { |
| | 3674 | 177 | | get { return _isSessionOpenNotificationEnabled; } |
| | | 178 | | set |
| | | 179 | | { |
| | 3026 | 180 | | lock (Parent.ThisLock) |
| | | 181 | | { |
| | 3026 | 182 | | Parent.InvalidateRuntime(); |
| | 3026 | 183 | | _isSessionOpenNotificationEnabled = value; |
| | 3026 | 184 | | } |
| | 3026 | 185 | | } |
| | | 186 | | } |
| | | 187 | | |
| | 46584 | 188 | | public string Name { get; } |
| | | 189 | | |
| | 7348 | 190 | | public ICollection<IParameterInspector> ParameterInspectors { get; } |
| | | 191 | | |
| | 68856 | 192 | | public DispatchRuntime Parent { get; } |
| | | 193 | | |
| | 3953 | 194 | | internal Lazy<AuthorizationPolicy> AuthorizationPolicy { get; set; } |
| | | 195 | | |
| | 3674 | 196 | | internal ReceiveContextAcknowledgementMode ReceiveContextAcknowledgementMode { get; set; } |
| | | 197 | | |
| | | 198 | | internal bool ReleaseInstanceAfterCall |
| | | 199 | | { |
| | 3674 | 200 | | get { return _releaseInstanceAfterCall; } |
| | | 201 | | set |
| | | 202 | | { |
| | 3026 | 203 | | lock (Parent.ThisLock) |
| | | 204 | | { |
| | 3026 | 205 | | Parent.InvalidateRuntime(); |
| | 3026 | 206 | | _releaseInstanceAfterCall = value; |
| | 3026 | 207 | | } |
| | 3026 | 208 | | } |
| | | 209 | | } |
| | | 210 | | |
| | | 211 | | internal bool ReleaseInstanceBeforeCall |
| | | 212 | | { |
| | 3674 | 213 | | get { return _releaseInstanceBeforeCall; } |
| | | 214 | | set |
| | | 215 | | { |
| | 3026 | 216 | | lock (Parent.ThisLock) |
| | | 217 | | { |
| | 3026 | 218 | | Parent.InvalidateRuntime(); |
| | 3026 | 219 | | _releaseInstanceBeforeCall = value; |
| | 3026 | 220 | | } |
| | 3026 | 221 | | } |
| | | 222 | | } |
| | | 223 | | |
| | 3674 | 224 | | public string ReplyAction { get; } |
| | | 225 | | |
| | | 226 | | public bool SerializeReply |
| | | 227 | | { |
| | 3674 | 228 | | get { return _serializeReply; } |
| | | 229 | | set |
| | | 230 | | { |
| | 3063 | 231 | | lock (Parent.ThisLock) |
| | | 232 | | { |
| | 3063 | 233 | | Parent.InvalidateRuntime(); |
| | 3063 | 234 | | _serializeReply = value; |
| | 3063 | 235 | | } |
| | 3063 | 236 | | } |
| | | 237 | | } |
| | | 238 | | } |
| | | 239 | | } |