| | | 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 System.Collections.ObjectModel; |
| | | 8 | | using System.Reflection; |
| | | 9 | | using CoreWCF.Collections.Generic; |
| | | 10 | | using CoreWCF.Runtime.Collections; |
| | | 11 | | using Microsoft.AspNetCore.Authorization; |
| | | 12 | | |
| | | 13 | | namespace CoreWCF.Description |
| | | 14 | | { |
| | | 15 | | public class OperationDescription |
| | | 16 | | { |
| | | 17 | | internal const string SessionOpenedAction = "http://schemas.microsoft.com/2011/02/session/onopen"; //Channels.We |
| | | 18 | | private ContractDescription _declaringContract; |
| | | 19 | | private bool _hasNoDisposableParameters; |
| | | 20 | | |
| | 2692 | 21 | | public OperationDescription(string name, ContractDescription declaringContract) |
| | | 22 | | { |
| | 2692 | 23 | | if (name == null) |
| | | 24 | | { |
| | 0 | 25 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(name)); |
| | | 26 | | } |
| | | 27 | | |
| | 2692 | 28 | | if (name.Length == 0) |
| | | 29 | | { |
| | 0 | 30 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( |
| | 0 | 31 | | new ArgumentOutOfRangeException(nameof(name), SR.SFxOperationDescriptionNameCannotBeEmpty)); |
| | | 32 | | } |
| | | 33 | | |
| | 2692 | 34 | | XmlName = new XmlName(name, true /*isEncoded*/); |
| | 2692 | 35 | | _declaringContract = declaringContract ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(n |
| | 2692 | 36 | | IsInitiating = true; |
| | 2692 | 37 | | IsTerminating = false; |
| | 2692 | 38 | | Faults = new FaultDescriptionCollection(); |
| | 2692 | 39 | | Messages = new MessageDescriptionCollection(); |
| | 2692 | 40 | | Behaviors = new KeyedByTypeCollection<IOperationBehavior>(); |
| | 2692 | 41 | | KnownTypes = new Collection<Type>(); |
| | 2692 | 42 | | AuthorizeOperation = new KeyedByTypeCollection<IAuthorizeOperation>(); |
| | 2692 | 43 | | } |
| | | 44 | | |
| | 0 | 45 | | internal OperationDescription(string name, ContractDescription declaringContract, bool validateRpcWrapperName) : |
| | | 46 | | { |
| | 0 | 47 | | IsValidateRpcWrapperName = validateRpcWrapperName; |
| | 0 | 48 | | } |
| | | 49 | | |
| | | 50 | | internal bool HasNoDisposableParameters |
| | | 51 | | { |
| | 3026 | 52 | | get { return _hasNoDisposableParameters; } |
| | 5372 | 53 | | set { _hasNoDisposableParameters = value; } |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | // Not serializable on purpose, metadata import/export cannot |
| | | 57 | | // produce it, only available when binding to runtime |
| | 47409 | 58 | | public MethodInfo SyncMethod { get; set; } |
| | | 59 | | |
| | | 60 | | // Not serializable on purpose, metadata import/export cannot |
| | | 61 | | // produce it, only available when binding to runtime |
| | 8830 | 62 | | public MethodInfo BeginMethod { get; set; } |
| | | 63 | | |
| | | 64 | | // Not serializable on purpose, metadata import/export cannot |
| | | 65 | | // produce it, only available when binding to runtime |
| | 2 | 66 | | public MethodInfo EndMethod { get; set; } |
| | | 67 | | |
| | | 68 | | // Not serializable on purpose, metadata import/export cannot |
| | | 69 | | // produce it, only available when binding to runtime |
| | 23600 | 70 | | public MethodInfo TaskMethod { get; set; } |
| | | 71 | | |
| | | 72 | | internal MethodInfo OperationMethod |
| | | 73 | | { |
| | | 74 | | get |
| | | 75 | | { |
| | 12098 | 76 | | if (SyncMethod == null) |
| | | 77 | | { |
| | 1534 | 78 | | return TaskMethod ?? BeginMethod; |
| | | 79 | | } |
| | | 80 | | else |
| | | 81 | | { |
| | 10564 | 82 | | return SyncMethod; |
| | | 83 | | } |
| | | 84 | | } |
| | | 85 | | } |
| | | 86 | | |
| | 251 | 87 | | internal bool HasProtectionLevel => false; |
| | | 88 | | |
| | | 89 | | public ContractDescription DeclaringContract |
| | | 90 | | { |
| | 26448 | 91 | | get { return _declaringContract; } |
| | | 92 | | set |
| | | 93 | | { |
| | 0 | 94 | | if (value == null) |
| | | 95 | | { |
| | 0 | 96 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(DeclaringContract)); |
| | | 97 | | } |
| | | 98 | | else |
| | | 99 | | { |
| | 0 | 100 | | _declaringContract = value; |
| | | 101 | | } |
| | 0 | 102 | | } |
| | | 103 | | } |
| | | 104 | | |
| | 4903 | 105 | | public FaultDescriptionCollection Faults { get; } |
| | | 106 | | |
| | | 107 | | public bool IsOneWay |
| | | 108 | | { |
| | 9014 | 109 | | get { return Messages.Count == 1; } |
| | | 110 | | } |
| | | 111 | | |
| | 1812 | 112 | | public Collection<Type> KnownTypes { get; } |
| | | 113 | | |
| | | 114 | | // Messages[0] is the 'request' (first of MEP), and for non-oneway MEPs, Messages[1] is the 'response' (second o |
| | 113966 | 115 | | public MessageDescriptionCollection Messages { get; } |
| | | 116 | | |
| | | 117 | | internal string CodeName |
| | | 118 | | { |
| | 5372 | 119 | | get { return XmlName.DecodedName; } |
| | | 120 | | } |
| | | 121 | | |
| | | 122 | | public string Name |
| | | 123 | | { |
| | 23090 | 124 | | get { return XmlName.EncodedName; } |
| | | 125 | | } |
| | | 126 | | |
| | 2752 | 127 | | internal bool IsValidateRpcWrapperName { private set; get; } = true; |
| | | 128 | | |
| | 6148 | 129 | | internal KeyedByTypeCollection<IAuthorizeOperation> AuthorizeOperation { get; } |
| | | 130 | | |
| | 2794 | 131 | | internal GenericHashtable<Type, ReadOnlyCollection<IAuthorizeData>> AuthorizeData { get; set; } |
| | | 132 | | |
| | | 133 | | public KeyedCollection<Type, IOperationBehavior> OperationBehaviors |
| | | 134 | | { |
| | 26571 | 135 | | get { return Behaviors; } |
| | | 136 | | } |
| | | 137 | | |
| | 67962 | 138 | | internal KeyedByTypeCollection<IOperationBehavior> Behaviors { get; } |
| | | 139 | | |
| | 28624 | 140 | | internal XmlName XmlName { get; } |
| | | 141 | | |
| | 14462 | 142 | | public bool IsInitiating { get; set; } |
| | | 143 | | |
| | | 144 | | internal bool IsServerInitiated() |
| | | 145 | | { |
| | 9962 | 146 | | EnsureInvariants(); |
| | 9962 | 147 | | return Messages[0].Direction == MessageDirection.Output; |
| | | 148 | | } |
| | | 149 | | |
| | 11426 | 150 | | public bool IsTerminating { get; set; } |
| | | 151 | | |
| | | 152 | | internal void EnsureInvariants() |
| | | 153 | | { |
| | 12990 | 154 | | if (Messages.Count != 1 && Messages.Count != 2) |
| | | 155 | | { |
| | 0 | 156 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFx |
| | | 157 | | } |
| | 12990 | 158 | | } |
| | | 159 | | |
| | | 160 | | internal Type TaskTResult |
| | | 161 | | { |
| | 10 | 162 | | get; |
| | 329 | 163 | | set; |
| | | 164 | | } |
| | | 165 | | |
| | 6429 | 166 | | internal bool IsSessionOpenNotificationEnabled { get; set; } |
| | | 167 | | } |
| | | 168 | | } |