Пример #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="UPnPDevicesDiscovery{TDevice}" /> class.
        /// </summary>
        /// <param name="targetDeviceType">
        ///     The type of the devices to discover.
        /// </param>
        /// <param name="ssdpServer">
        ///     The implementation of the SSDP protocol to use for discovering the UPnP devices.
        /// </param>
        /// <param name="logManager">
        ///     The <see cref="ILogManager"/> to use for logging the debug information.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="targetDeviceType"/> is <c>null</c> or <see cref="string.Empty"/> -OR-
        ///     <paramref name="ssdpServer"/> is <c>null</c> -OR-
        ///     <paramref name="logManager"/> is <c>null</c>.
        /// </exception>
        internal UPnPDevicesDiscovery(string targetDeviceType, ISSDPServer ssdpServer, ILogManager logManager = null)
        {
            targetDeviceType.EnsureNotNull("targetDevices");
            ssdpServer.EnsureNotNull("ssdpServer");

            this.targetDeviceType = targetDeviceType;
            this.ssdpServer       = ssdpServer;
            this.logManager       = logManager;

            if (this.logManager != null)
            {
                this.logger = this.logManager.GetLogger(this.GetType());
                this.logger.Instance().Info("Started listening for upnp devices", "TargetDevices".As(targetDeviceType));
            }

            var targetDevicesNotifications = from notification in this.ssdpServer.NotifyMessages
                                             where string.Compare(notification.NotificationType, targetDeviceType, StringComparison.OrdinalIgnoreCase) == 0
                                             select notification;

            targetDevicesNotifications.Where(m => m.NotificationSubtype == NotifyMessageType.Alive).Subscribe(this.TryAddDevice);
            targetDevicesNotifications.Where(m => m.NotificationSubtype == NotifyMessageType.Update).Subscribe(this.TryUpdateDevice);
            targetDevicesNotifications.Where(m => m.NotificationSubtype == NotifyMessageType.ByeBye).Subscribe(m => this.TryRemoveDevice(m.UDN));

            this.ScanAsync();
        }
Пример #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="UPnPDevicesDiscovery{TDevice}" /> class.
        /// </summary>
        /// <param name="targetDeviceType">
        ///     The type of the devices to discover.
        /// </param>
        /// <param name="ssdpServer">
        ///     The implementation of the SSDP protocol to use for discovering the UPnP devices.
        /// </param>
        /// <param name="loggerFactory">
        ///     The <see cref="ILogManager"/> to use for logging the debug information.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="targetDeviceType"/> is <c>null</c> or <see cref="string.Empty"/> -OR-
        ///     <paramref name="ssdpServer"/> is <c>null</c> -OR-
        ///     <paramref name="logManager"/> is <c>null</c>.
        /// </exception>
        internal UPnPDevicesDiscovery(string targetDeviceType, ISSDPServer ssdpServer, ILoggerFactory loggerFactory)
        {
            targetDeviceType.EnsureNotNull("targetDevices");
            ssdpServer.EnsureNotNull("ssdpServer");

            System.Text.Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);


            this.targetDeviceType = targetDeviceType;
            this.ssdpServer       = ssdpServer;
            this.loggerFactory    = loggerFactory;

            this.logger = loggerFactory.CreateLogger(this.GetType());
            this.logger.LogInformation("Started listening for upnp devices", "TargetDevices".As(targetDeviceType));

            var targetDevicesNotifications = from notification in this.ssdpServer.NotifyMessages
                                             where string.Compare(notification.NotificationType, targetDeviceType, StringComparison.OrdinalIgnoreCase) == 0
                                             select notification;

            targetDevicesNotifications.Where(m => m.NotificationSubtype == NotifyMessageType.Alive).Subscribe(this.TryAddDevice);
            targetDevicesNotifications.Where(m => m.NotificationSubtype == NotifyMessageType.Update).Subscribe(this.TryUpdateDevice);
            targetDevicesNotifications.Where(m => m.NotificationSubtype == NotifyMessageType.ByeBye).Subscribe(m => this.TryRemoveDevice(m.UDN));

            this.ScanAsync();
        }