Exemplo n.º 1
0
        public override async Task DeletePortMapAsync(Mapping mapping)
        {
            Guard.IsNotNull(mapping, "mapping");

            if (mapping.PrivateIP.Equals(IPAddress.None))
            {
                mapping.PrivateIP = DeviceInfo.LocalAddress;
            }

            NatDiscoverer.TraceSource.LogInfo("DeletePortMapAsync - Deleteing port mapping {0}", mapping);

            try
            {
                var message = new DeletePortMappingRequestMessage(mapping);
                await _soapClient
                .InvokeAsync("DeletePortMapping", message.ToXml())
                .TimeoutAfter(TimeSpan.FromSeconds(4));

                UnregisterMapping(mapping);
            }
            catch (MappingException e)
            {
                if (e.ErrorCode != UpnpConstants.NoSuchEntryInArray)
                {
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        public override Task DeletePortMapAsync(Mapping mapping)
        {
            Guard.IsNotNull(mapping, "mapping");

            if (mapping.PrivateIP.Equals(IPAddress.None))
            {
                mapping.PrivateIP = DeviceInfo.LocalAddress;
            }

            NatDiscoverer.TraceSource.LogInfo("DeletePortMapAsync - Deleteing port mapping {0}", mapping);

            var message = new DeletePortMappingRequestMessage(mapping);

            return(_soapClient
                   .InvokeAsync("DeletePortMapping", message.ToXml())
                   .TimeoutAfter(TimeSpan.FromSeconds(4))
                   .ContinueWith(task =>
            {
                if (!task.IsFaulted)
                {
                    UnregisterMapping(mapping);
                }
                else
                {
                    MappingException e = task.Exception.InnerException as MappingException;
                    if (e != null && e.ErrorCode != UpnpConstants.NoSuchEntryInArray)
                    {
                        throw e;
                    }
                }
            }));
        }