| | | 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 System.Threading.Tasks; |
| | | 7 | | using CoreWCF.Channels; |
| | | 8 | | using CoreWCF.Configuration; |
| | | 9 | | using CoreWCF.Diagnostics; |
| | | 10 | | using CoreWCF.Runtime; |
| | | 11 | | |
| | | 12 | | namespace CoreWCF.Dispatcher |
| | | 13 | | { |
| | | 14 | | internal class InputChannelBinder : IChannelBinder |
| | | 15 | | { |
| | | 16 | | private IInputChannel _channel; |
| | | 17 | | private IServiceChannelDispatcher _next; |
| | | 18 | | |
| | 1718 | 19 | | public InputChannelBinder() |
| | | 20 | | { |
| | 1718 | 21 | | } |
| | | 22 | | |
| | | 23 | | internal void Init(IInputChannel channel, Uri listenUri) |
| | | 24 | | { |
| | 1718 | 25 | | if (!((channel != null))) |
| | | 26 | | { |
| | | 27 | | Fx.Assert("InputChannelBinder.InputChannelBinder: (channel != null)"); |
| | 0 | 28 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(channel)); |
| | | 29 | | } |
| | 1718 | 30 | | _channel = channel; |
| | 1718 | 31 | | ListenUri = listenUri; |
| | 1718 | 32 | | } |
| | | 33 | | |
| | | 34 | | public IChannel Channel |
| | | 35 | | { |
| | 1989 | 36 | | get { return _channel; } |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | public bool HasSession |
| | | 40 | | { |
| | 3530 | 41 | | get { return _channel is ISessionChannel<IInputSession>; } |
| | | 42 | | } |
| | | 43 | | |
| | 1718 | 44 | | public Uri ListenUri { get; private set; } |
| | | 45 | | |
| | | 46 | | public EndpointAddress LocalAddress |
| | | 47 | | { |
| | 0 | 48 | | get { return _channel.LocalAddress; } |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public EndpointAddress RemoteAddress |
| | | 52 | | { |
| | | 53 | | get |
| | | 54 | | { |
| | 0 | 55 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); |
| | | 56 | | } |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | public void Abort() |
| | | 60 | | { |
| | 0 | 61 | | _channel.Abort(); |
| | 0 | 62 | | } |
| | | 63 | | |
| | | 64 | | public void CloseAfterFault(TimeSpan timeout) |
| | | 65 | | { |
| | 0 | 66 | | var helper = new TimeoutHelper(timeout); |
| | 0 | 67 | | _channel.CloseAsync(helper.GetCancellationToken()).GetAwaiter().GetResult(); |
| | 0 | 68 | | } |
| | | 69 | | |
| | | 70 | | public RequestContext CreateRequestContext(Message message) |
| | | 71 | | { |
| | 0 | 72 | | return WrapMessage(message); |
| | | 73 | | } |
| | | 74 | | |
| | | 75 | | public Task SendAsync(Message message, CancellationToken token) |
| | | 76 | | { |
| | 0 | 77 | | throw TraceUtility.ThrowHelperError(new NotImplementedException(), message); |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | public Task<Message> RequestAsync(Message message, CancellationToken token) |
| | | 81 | | { |
| | 0 | 82 | | throw TraceUtility.ThrowHelperError(new NotImplementedException(), message); |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | private RequestContext WrapMessage(Message message) |
| | | 86 | | { |
| | 0 | 87 | | if (message == null) |
| | | 88 | | { |
| | 0 | 89 | | return null; |
| | | 90 | | } |
| | | 91 | | else |
| | | 92 | | { |
| | 0 | 93 | | return new InputRequestContext(message, this); |
| | | 94 | | } |
| | | 95 | | } |
| | | 96 | | |
| | | 97 | | public void SetNextDispatcher(IServiceChannelDispatcher dispatcher) |
| | | 98 | | { |
| | 1718 | 99 | | _next = dispatcher; |
| | 1718 | 100 | | } |
| | | 101 | | |
| | | 102 | | public Task DispatchAsync(RequestContext context) |
| | | 103 | | { |
| | 1718 | 104 | | return _next.DispatchAsync(context); |
| | | 105 | | } |
| | | 106 | | |
| | | 107 | | public Task DispatchAsync(Message message) |
| | | 108 | | { |
| | 0 | 109 | | RequestContext requestContext = WrapMessage(message); |
| | 0 | 110 | | return _next.DispatchAsync(requestContext); |
| | | 111 | | } |
| | | 112 | | |
| | | 113 | | private class InputRequestContext : RequestContextBase |
| | | 114 | | { |
| | | 115 | | private readonly InputChannelBinder _binder; |
| | | 116 | | |
| | | 117 | | internal InputRequestContext(Message request, InputChannelBinder binder) |
| | 0 | 118 | | : base(request, TimeSpan.Zero, TimeSpan.Zero) |
| | | 119 | | { |
| | 0 | 120 | | _binder = binder; |
| | 0 | 121 | | } |
| | | 122 | | |
| | | 123 | | protected override void OnAbort() |
| | | 124 | | { |
| | 0 | 125 | | } |
| | | 126 | | |
| | | 127 | | protected override Task OnCloseAsync(CancellationToken token) |
| | | 128 | | { |
| | 0 | 129 | | return Task.CompletedTask; |
| | | 130 | | } |
| | | 131 | | |
| | | 132 | | protected override Task OnReplyAsync(Message message, CancellationToken token) |
| | | 133 | | { |
| | 0 | 134 | | return Task.CompletedTask; |
| | | 135 | | } |
| | | 136 | | } |
| | | 137 | | } |
| | | 138 | | } |