private Tuple <TestAssociationHandle, TestAssociationHandle> CreateHandlePair(TestTransport remoteTransport, Address remoteAddress) { var localHandle = new TestAssociationHandle(LocalAddress, remoteAddress, this, false); var remoteHandle = new TestAssociationHandle(remoteAddress, LocalAddress, remoteTransport, true); return(new Tuple <TestAssociationHandle, TestAssociationHandle>(localHandle, remoteHandle)); }
/// <summary> /// Returns the remote endpoint for a pair of endpoints relative to the owner of the supplied <see cref="TestAssociationHandle"/>. /// </summary> /// <param name="handle">The reference handle to determine the remote endpoint relative to</param> /// <param name="listenerPair">pair of listeners in initiator, receiver order</param> /// <returns></returns> public IHandleEventListener RemoteListenerRelativeTo(TestAssociationHandle handle, Tuple <IHandleEventListener, IHandleEventListener> listenerPair) { if (handle.Inbound) { return(listenerPair.Item1); //initiator } return(listenerPair.Item2); //receiver }
public Task DefaultDisassociate(TestAssociationHandle handle) { var handlers = _registry.DeregisterAssociation(handle.Key); handlers.Item1.Notify(new Disassociated(DisassociateInfo.Unknown)); handlers.Item2.Notify(new Disassociated(DisassociateInfo.Unknown)); return(Task.Run(() => { })); }
/// <summary> /// Returns the event handler corresponding to the remote endpoint of the given local handle. In other words /// it returns the listener that will receive <see cref="InboundPayload" /> events when /// <seealso cref="AssociationHandle.Write" /> is called. /// </summary> /// <param name="localHandle">The handle</param> /// <returns>The option that contains the listener if it exists.</returns> public IHandleEventListener GetRemoteReadHandlerFor(TestAssociationHandle localHandle) { if (_listenersTable.TryGetValue(localHandle.Key, out var listeners)) { return(RemoteListenerRelativeTo(localHandle, listeners)); } return(null); }
/// <summary> /// TBD /// </summary> /// <param name="handle">TBD</param> /// <returns>TBD</returns> public Task <bool> DefaultDisassociate(TestAssociationHandle handle) { var handlers = _registry.DeregisterAssociation(handle.Key); if (handlers != null) { handlers.Item1.Notify(new Disassociated(DisassociateInfo.Unknown)); handlers.Item2.Notify(new Disassociated(DisassociateInfo.Unknown)); } return(Task.FromResult(true)); }
private Task <bool> DefaultWriteBehavior(TestAssociationHandle handle, ByteString payload) { var remoteReadHandler = _registry.GetRemoteReadHandlerFor(handle); if (remoteReadHandler != null) { remoteReadHandler.Notify(new InboundPayload(payload)); return(Task.Run(() => true)); } return(Task.Run(() => { throw new ArgumentException("No association present"); #pragma warning disable 162 return true; #pragma warning restore 162 })); }
public Task <bool> Write(TestAssociationHandle handle, ByteString payload) { return(WriteBehavior.Apply(new Tuple <TestAssociationHandle, ByteString>(handle, payload))); }
public Task Disassociate(TestAssociationHandle handle) { return(DisassociateBehavior.Apply(handle)); }