| | | 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 CoreWCF.Diagnostics; |
| | | 6 | | using CoreWCF.Runtime; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | internal static class CommunicationObjectExtensions |
| | | 11 | | { |
| | | 12 | | internal static bool DoneReceivingInCurrentState(this CommunicationObject communicationObject) |
| | | 13 | | { |
| | 41 | 14 | | communicationObject.ThrowPending(); |
| | | 15 | | |
| | 41 | 16 | | switch (communicationObject.State) |
| | | 17 | | { |
| | | 18 | | case CommunicationState.Created: |
| | 0 | 19 | | throw TraceUtility.ThrowHelperError(CreateNotOpenException(communicationObject), Guid.Empty, communi |
| | | 20 | | |
| | | 21 | | case CommunicationState.Opening: |
| | 0 | 22 | | throw TraceUtility.ThrowHelperError(CreateNotOpenException(communicationObject), Guid.Empty, communi |
| | | 23 | | |
| | | 24 | | case CommunicationState.Opened: |
| | 41 | 25 | | return false; |
| | | 26 | | |
| | | 27 | | case CommunicationState.Closing: |
| | 0 | 28 | | return true; |
| | | 29 | | |
| | | 30 | | case CommunicationState.Closed: |
| | 0 | 31 | | return true; |
| | | 32 | | |
| | | 33 | | case CommunicationState.Faulted: |
| | 0 | 34 | | return true; |
| | | 35 | | |
| | | 36 | | default: |
| | 0 | 37 | | throw Fx.AssertAndThrow("DoneReceivingInCurrentState: Unknown CommunicationObject.state"); |
| | | 38 | | } |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | private static Exception CreateNotOpenException(CommunicationObject communicationObject) |
| | | 42 | | { |
| | 0 | 43 | | return new InvalidOperationException(SR.Format(SRCommon.CommunicationObjectCannotBeUsed, communicationObject |
| | | 44 | | } |
| | | 45 | | } |
| | | 46 | | } |