private void EndGetAllMappingsInternal(IAsyncResult result) { EndMessageInternal(result); GetAllMappingsAsyncResult mappingResult = result.AsyncState as GetAllMappingsAsyncResult; GetGenericPortMappingEntryResponseMessage message = mappingResult.SavedMessage as GetGenericPortMappingEntryResponseMessage; if (message != null) { Mapping mapping = new Mapping(message.Protocol, message.InternalPort, message.ExternalPort, message.LeaseDuration); mapping.Description = message.PortMappingDescription; mappingResult.Mappings.Add(mapping); GetGenericPortMappingEntry next = new GetGenericPortMappingEntry(mappingResult.Mappings.Count, this); // It's ok to do this synchronously because we should already be on anther thread // and this won't block the user. byte[] body; WebRequest request = next.Encode(out body); if (body.Length > 0) { request.ContentLength = body.Length; request.GetRequestStream().Write(body, 0, body.Length); } mappingResult.Request = request; request.BeginGetResponse(EndGetAllMappingsInternal, mappingResult); return; } CompleteMessage(result); }
public override IAsyncResult BeginGetAllMappings(AsyncCallback callback, object asyncState) { GetGenericPortMappingEntry message = new GetGenericPortMappingEntry(0, this); return(BeginMessageInternal(message, callback, asyncState, EndGetAllMappingsInternal)); }