Exemple #1
0
        /// <summary>
        /// Starts listening for broadcast notifications of service availability.
        /// </summary>
        /// <remarks>
        /// <para>When called the system will listen for 'alive' and 'byebye' notifications. This can speed up searching, as well as provide dynamic notification of new devices appearing on the network, and previously discovered devices disappearing.</para>
        /// </remarks>
        /// <seealso cref="StopListeningForNotifications"/>
        /// <seealso cref="DeviceAvailable"/>
        /// <seealso cref="DeviceUnavailable"/>
        /// <exception cref="System.ObjectDisposedException">Throw if the <see cref="DisposableManagedObjectBase.IsDisposed"/>  ty is true.</exception>
        public void StartListeningForNotifications()
        {
            ThrowIfDisposed();

            _CommunicationsServer.RequestReceived -= CommsServer_RequestReceived;
            _CommunicationsServer.RequestReceived += CommsServer_RequestReceived;
            _CommunicationsServer.BeginListeningForBroadcasts();
        }
Exemple #2
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer, INetworkManager networkManager,
                                   string osName, string osVersion, bool sendOnlyMatchedHost)
        {
            if (communicationsServer == null)
            {
                throw new ArgumentNullException(nameof(communicationsServer));
            }

            if (networkManager == null)
            {
                throw new ArgumentNullException(nameof(networkManager));
            }

            if (osName == null)
            {
                throw new ArgumentNullException(nameof(osName));
            }

            if (osName.Length == 0)
            {
                throw new ArgumentException("osName cannot be an empty string.", nameof(osName));
            }

            if (osVersion == null)
            {
                throw new ArgumentNullException(nameof(osVersion));
            }

            if (osVersion.Length == 0)
            {
                throw new ArgumentException("osVersion cannot be an empty string.", nameof(osName));
            }

            _SupportPnpRootDevice = true;
            _Devices              = new List <SsdpRootDevice>();
            _ReadOnlyDevices      = new ReadOnlyCollection <SsdpRootDevice>(_Devices);
            _RecentSearchRequests = new Dictionary <string, SearchRequest>(StringComparer.OrdinalIgnoreCase);
            _Random = new Random();

            _networkManager = networkManager;
            _CommsServer    = communicationsServer;
            _CommsServer.RequestReceived += CommsServer_RequestReceived;
            _OSName              = osName;
            _OSVersion           = osVersion;
            _sendOnlyMatchedHost = sendOnlyMatchedHost;

            _CommsServer.BeginListeningForBroadcasts();
        }
Exemple #3
0
        /// <summary>
        /// Full constructor.
        /// </summary>
        /// <param name="communicationsServer">The <see cref="ISsdpCommunicationsServer"/> implementation, used to send and receive SSDP network messages.</param>
        /// <param name="osName">Then name of the operating system running the server.</param>
        /// <param name="osVersion">The version of the operating system running the server.</param>
        /// <param name="log">An implementation of <see cref="ISsdpLogger"/> to be used for logging activity. May be null, in which case no logging is performed.</param>
        protected SsdpDevicePublisherBase(ISsdpCommunicationsServer communicationsServer, string osName, string osVersion, ISsdpLogger log)
        {
            if (communicationsServer == null)
            {
                throw new ArgumentNullException("communicationsServer");
            }
            if (osName == null)
            {
                throw new ArgumentNullException("osName");
            }
            if (osName.Length == 0)
            {
                throw new ArgumentException("osName cannot be an empty string.", "osName");
            }
            if (osVersion == null)
            {
                throw new ArgumentNullException("osVersion");
            }
            if (osVersion.Length == 0)
            {
                throw new ArgumentException("osVersion cannot be an empty string.", "osName");
            }

            _Log = log ?? NullLogger.Instance;
            _SupportPnpRootDevice = true;
            _Devices              = new List <SsdpRootDevice>();
            _ReadOnlyDevices      = new ReadOnlyEnumerable <SsdpRootDevice>(_Devices);
            _RecentSearchRequests = new Dictionary <string, SearchRequest>(StringComparer.OrdinalIgnoreCase);
            _Random          = new Random();
            _DeviceValidator = new Upnp10DeviceValidator();             //Should probably inject this later, but for now we only support 1.0.

            _CommsServer = communicationsServer;
            _CommsServer.RequestReceived += CommsServer_RequestReceived;
            _OSName    = osName;
            _OSVersion = osVersion;

            _Log.LogInfo("Publisher started.");
            _CommsServer.BeginListeningForBroadcasts();
            _Log.LogInfo("Publisher started listening for broadcasts.");
        }
Exemple #4
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer, ITimerFactory timerFactory, string osName, string osVersion, Func <int> deviceCacheSeconds)
        {
            if (communicationsServer == null)
            {
                throw new ArgumentNullException("communicationsServer");
            }
            if (osName == null)
            {
                throw new ArgumentNullException("osName");
            }
            if (osName.Length == 0)
            {
                throw new ArgumentException("osName cannot be an empty string.", "osName");
            }
            if (osVersion == null)
            {
                throw new ArgumentNullException("osVersion");
            }
            if (osVersion.Length == 0)
            {
                throw new ArgumentException("osVersion cannot be an empty string.", "osName");
            }

            _SupportPnpRootDevice = true;
            _timerFactory         = timerFactory;
            _Devices              = new List <SsdpRootDevice>();
            _ReadOnlyDevices      = new ReadOnlyCollection <SsdpRootDevice>(_Devices);
            _RecentSearchRequests = new Dictionary <string, SearchRequest>(StringComparer.OrdinalIgnoreCase);
            _Random = new Random();

            _CommsServer = communicationsServer;
            _CommsServer.RequestReceived += CommsServer_RequestReceived;
            _OSName               = osName;
            _OSVersion            = osVersion;
            _deviceCacheSecondsFn = deviceCacheSeconds;

            _CommsServer.BeginListeningForBroadcasts();
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="communicationsServer">The <see cref="ISsdpCommunicationsServer"/> implementation, used to send and receive SSDP network messages.</param>
        /// <param name="osName">Then name of the operating system running the server.</param>
        /// <param name="osVersion">The version of the operating system running the server.</param>
        protected SsdpDevicePublisherBase(ISsdpCommunicationsServer communicationsServer, string osName, string osVersion)
        {
            if (communicationsServer == null) throw new ArgumentNullException("communicationsServer");
            if (osName == null) throw new ArgumentNullException("osName");
            if (osName.Length == 0) throw new ArgumentException("osName cannot be an empty string.", "osName");
            if (osVersion == null) throw new ArgumentNullException("osVersion");
            if (osVersion.Length == 0) throw new ArgumentException("osVersion cannot be an empty string.", "osName");

            _SupportPnpRootDevice = true;
            _Devices = new List<SsdpRootDevice>();
            _ReadOnlyDevices = new ReadOnlyEnumerable<SsdpRootDevice>(_Devices);
            _RecentSearchRequests = new Dictionary<string, SearchRequest>(StringComparer.OrdinalIgnoreCase);
            _Random = new Random();
            _DeviceValidator = new Upnp10DeviceValidator(); //Should probably inject this later, but for now we only support 1.0.

            _CommsServer = communicationsServer;
            _CommsServer.RequestReceived += CommsServer_RequestReceived;
            _OSName = osName;
            _OSVersion = osVersion;

            _CommsServer.BeginListeningForBroadcasts();
        }