public Task Handle(IPAddress localAddress, UpnpDeviceInfo deviceInfo, IPEndPoint endpoint, NatProtocol protocol) { switch (protocol) { case NatProtocol.Upnp: var searcher = new UpnpSearcher(Logger, HttpClient); searcher.DeviceFound += Searcher_DeviceFound; return(searcher.Handle(localAddress, deviceInfo, endpoint)); default: throw new ArgumentException("Unexpected protocol: " + protocol); } }
public static async Task Handle(IPAddress localAddress, UpnpDeviceInfo deviceInfo, IPEndPoint endpoint, NatProtocol protocol) { switch (protocol) { case NatProtocol.Upnp: var searcher = new UpnpSearcher(Logger, HttpClient); searcher.DeviceFound += Searcher_DeviceFound; await searcher.Handle(localAddress, deviceInfo, endpoint).ConfigureAwait(false); break; default: throw new ArgumentException("Unexpected protocol: " + protocol); } }
private static INatDevice GetDevice(CancellationToken cancellation) { UpnpSearcher searcher = new UpnpSearcher(); var device = searcher.SearchAndReceive(cancellation); if(device == null) { NodeServerTrace.Information("No UPnP device found"); return null; } return device; }
static ISearcher GetOrCreate(NatProtocol protocol) { if (!Searchers.TryGetValue(protocol, out ISearcher searcher)) { searcher = protocol == NatProtocol.Pmp ? (ISearcher)PmpSearcher.Create() : UpnpSearcher.Create(); searcher.DeviceFound += HandleDeviceFound; searcher.UnknownDeviceFound += HandleUnknownDeviceFound; Searchers[protocol] = searcher; } return(searcher); }