| | | 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 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | internal abstract class OutputChannel : ServiceChannelBase, IOutputChannel |
| | | 11 | | { |
| | 22 | 12 | | protected OutputChannel(IDefaultCommunicationTimeouts timeouts) : base(timeouts) { } |
| | | 13 | | |
| | | 14 | | public abstract EndpointAddress RemoteAddress { get; } |
| | | 15 | | |
| | | 16 | | public abstract Uri Via { get; } |
| | | 17 | | |
| | | 18 | | public override T GetProperty<T>() |
| | | 19 | | { |
| | 12 | 20 | | if (typeof(T) == typeof(IOutputChannel)) |
| | | 21 | | { |
| | 0 | 22 | | return (T)(object)this; |
| | | 23 | | } |
| | | 24 | | |
| | 12 | 25 | | T baseProperty = base.GetProperty<T>(); |
| | 12 | 26 | | if (baseProperty != null) |
| | | 27 | | { |
| | 0 | 28 | | return baseProperty; |
| | | 29 | | } |
| | | 30 | | |
| | 12 | 31 | | return default; |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | protected abstract Task OnSendAsync(Message message, CancellationToken token); |
| | | 35 | | |
| | | 36 | | public Task SendAsync(Message message) |
| | | 37 | | { |
| | 0 | 38 | | return SendAsync(message, CancellationToken.None); |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | public Task SendAsync(Message message, CancellationToken token) |
| | | 42 | | { |
| | 15 | 43 | | if (message == null) |
| | | 44 | | { |
| | 0 | 45 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message)); |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | // TODO: Fix exception message as a negative timeout wasn't passed, a cancelled token was |
| | 15 | 49 | | if (token.IsCancellationRequested) |
| | | 50 | | { |
| | 0 | 51 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( |
| | 0 | 52 | | new ArgumentException(SRCommon.SFxTimeoutOutOfRange0, nameof(token))); |
| | | 53 | | } |
| | | 54 | | |
| | 15 | 55 | | ThrowIfDisposedOrNotOpen(); |
| | | 56 | | |
| | 15 | 57 | | AddHeadersTo(message); |
| | 15 | 58 | | EmitTrace(message); |
| | 15 | 59 | | return OnSendAsync(message, token); |
| | | 60 | | } |
| | | 61 | | |
| | | 62 | | private void EmitTrace(Message message) |
| | | 63 | | { |
| | 15 | 64 | | } |
| | | 65 | | |
| | | 66 | | protected virtual void AddHeadersTo(Message message) |
| | | 67 | | { |
| | 15 | 68 | | } |
| | | 69 | | } |
| | | 70 | | } |