| | | 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.Threading; |
| | | 6 | | using CoreWCF.Channels; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Dispatcher |
| | | 9 | | { |
| | | 10 | | internal class TerminatingOperationBehavior |
| | | 11 | | { |
| | | 12 | | private static void AbortChannel(object state) |
| | | 13 | | { |
| | 0 | 14 | | ((IChannel)state).Abort(); |
| | 0 | 15 | | } |
| | | 16 | | |
| | | 17 | | public static TerminatingOperationBehavior CreateIfNecessary(DispatchRuntime dispatch) |
| | | 18 | | { |
| | 661 | 19 | | if (IsTerminatingOperationBehaviorNeeded(dispatch)) |
| | | 20 | | { |
| | 4 | 21 | | return new TerminatingOperationBehavior(); |
| | | 22 | | } |
| | | 23 | | else |
| | | 24 | | { |
| | 657 | 25 | | return null; |
| | | 26 | | } |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | private static bool IsTerminatingOperationBehaviorNeeded(DispatchRuntime dispatch) |
| | | 30 | | { |
| | 7340 | 31 | | for (int i = 0; i < dispatch.Operations.Count; i++) |
| | | 32 | | { |
| | 3013 | 33 | | DispatchOperation operation = dispatch.Operations[i]; |
| | | 34 | | |
| | 3013 | 35 | | if (operation.IsTerminating) |
| | | 36 | | { |
| | 4 | 37 | | return true; |
| | | 38 | | } |
| | | 39 | | } |
| | | 40 | | |
| | 657 | 41 | | return false; |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | internal void AfterReply(ref MessageRpc rpc) |
| | | 45 | | { |
| | 11 | 46 | | if (rpc.Operation.IsTerminating && rpc.Channel.HasSession) |
| | | 47 | | { |
| | 4 | 48 | | Timer timer = new Timer(new TimerCallback(AbortChannel), rpc.Channel.Binder.Channel, rpc.Channel.CloseTi |
| | | 49 | | } |
| | 11 | 50 | | } |
| | | 51 | | |
| | | 52 | | internal static void AfterReply(ref ProxyRpc rpc) |
| | | 53 | | { |
| | 0 | 54 | | if (rpc.Operation.IsTerminating && rpc.Channel.HasSession) |
| | | 55 | | { |
| | 0 | 56 | | IChannel sessionChannel = rpc.Channel.Binder.Channel; |
| | 0 | 57 | | rpc.Channel.CloseAsync(rpc.CancellationToken).GetAwaiter().GetResult(); |
| | | 58 | | } |
| | 0 | 59 | | } |
| | | 60 | | } |
| | | 61 | | } |