Example #1
0
        /// <summary>
        ///     Removes a port mapping from the UPnP enabled device.
        /// </summary>
        /// <param name="port">The port to remove.</param>
        /// <param name="protocol">The protocol of the port [TCP/UDP]</param>
        /// <exception cref="ApplicationException">This exception is thrown when UPnP is disabled.</exception>
        /// <exception cref="ObjectDisposedException">This exception is thrown when this class has been disposed.</exception>
        /// <exception cref="ArgumentException">This exception is thrown when the port [or protocol] is invalid.</exception>
        /// <remarks></remarks>
        public static void Remove(int port, Protocol protocol)
        {
            if (_lastInstance == null)
            {
                _lastInstance = new UPnP();
            }


            if (!UpnpEnabled)
            {
                throw new ApplicationException("UPnP is not enabled, or there was an error with UPnP Initialization.");
            }

            // Begin utilizing
            if (!_lastInstance.Exists(port, protocol))
            {
                throw new ArgumentException("This mapping doesn't exist!", port + " : " + protocol);
            }

            // Okay, continue on
            _lastInstance._staticMapping.Remove(port, protocol.ToString());
            GetMapping(); //refresh
        }