public override async Task <Mapping> GetSpecificMappingAsync(Protocol protocol, int publicPort) { var message = new GetSpecificPortMappingEntryMessage(protocol, publicPort, this); var response = await SendMessageAsync(message).ConfigureAwait(false); if (!(response is GetSpecificPortMappingEntryResponseMessage msg)) { throw new MappingException(ErrorCode.Unknown, "Invalid response received when getting the specific mapping"); } return(new Mapping(protocol, msg.InternalPort, publicPort, msg.LeaseDuration, msg.PortMappingDescription)); }
internal static PortMapAsyncResult Create(MessageBase message, WebRequest request, AsyncCallback storedCallback, object asyncState) { if (message is GetGenericPortMappingEntry) { return(new GetAllMappingsAsyncResult(request, storedCallback, asyncState)); } if (message is GetSpecificPortMappingEntryMessage) { GetSpecificPortMappingEntryMessage mapMessage = (GetSpecificPortMappingEntryMessage)message; GetAllMappingsAsyncResult result = new GetAllMappingsAsyncResult(request, storedCallback, asyncState); result.SpecificMapping = new Mapping(mapMessage.protocol, 0, mapMessage.externalPort, 0); return(result); } return(new PortMapAsyncResult(request, storedCallback, asyncState)); }
public override IAsyncResult BeginGetSpecificMapping(Protocol protocol, int port, AsyncCallback callback, object asyncState) { GetSpecificPortMappingEntryMessage message = new GetSpecificPortMappingEntryMessage(protocol, port, this); return(this.BeginMessageInternal(message, callback, asyncState, new AsyncCallback(this.EndGetSpecificMappingInternal))); }