Esempio n. 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();
        }
Esempio n. 2
0
        private void MakeDiscoverable(string name)
        {
            if (_ssdpServer == null)
            {
                var _configuration = new UPNPConfiguration()
                {
                    UdpListnerPort  = _uPnPListenerPort,
                    FriendlyName    = name,
                    Manufacture     = "Tampa IoT Dev",
                    ModelName       = Constants.TankBotModelName,
                    DefaultPageHtml = @"<html>
<head>
<title>SoccerBot</title>
<link rel=""stylesheet"" href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"" integrity=""sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"" crossorigin=""anonymous"">
</head>
<body>
<h1>Tampa IoT TankBot SSDP (uPnP) Listener Page</h1>
</body>
</html>"
                };

                try
                {
                    _ssdpServer = NetworkServices.GetSSDPServer();
                    _ssdpServer.MakeDiscoverable(9500, _configuration);
                }
                catch (Exception ex)
                {
                    _logger.NotifyUserError("ConnectionManager_MakeDiscoverable", ex.Message);
                }
            }
        }
        /// <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();
        }
Esempio n. 4
0
        public void StartSSDPServer()
        {
            _server = SLWIOC.Get <ISSDPServer>();

            //_server = Core.Networking.Services.NetworkServices.GetSSDPServer();
            _server.MakeDiscoverable(9050, _configuration);
            _server.ShowDiagnostics = true;
        }
Esempio n. 5
0
        /// <summary>
        ///     Gets a singletone instance of the <see cref="SSDPServer"/>.
        /// </summary>
        /// <param name="loggerFactory">
        ///     The <see cref="ILoggerFactory"/> to use for logging the debug information.
        /// </param>
        /// <returns>
        ///     A singletone instance of the <see cref="SSDPServer"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="logManager"/> is <c>null</c>.
        /// </exception>
        public static ISSDPServer GetInstance(ILoggerFactory loggerFactory, string[] localIps = null)
        {
            lock (instanceSyncObject)
            {
                if (instance == null)
                {
                    instance = new SSDPServer(loggerFactory, localIps);
                }
            }

            return(instance);
        }
Esempio n. 6
0
        /// <summary>
        ///     Gets a singletone instance of the <see cref="SSDPServer"/>.
        /// </summary>
        /// <returns>
        ///     A singletone instance of the <see cref="SSDPServer"/>.
        /// </returns>
        public static ISSDPServer GetInstance()
        {
            lock (instanceSyncObject)
            {
                if (instance == null)
                {
                    instance = new SSDPServer();
                }
            }

            return(instance);
        }
Esempio n. 7
0
        /// <summary>
        ///     Gets a singletone instance of the <see cref="SSDPServer"/>.
        /// </summary>
        /// <param name="logManager">
        ///     The <see cref="ILogManager"/> to use for logging the debug information.
        /// </param>
        /// <returns>
        ///     A singletone instance of the <see cref="SSDPServer"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="logManager"/> is <c>null</c>.
        /// </exception>
        public static ISSDPServer GetInstance(ILogManager logManager)
        {
            lock (instanceSyncObject)
            {
                if (instance == null)
                {
                    instance = new SSDPServer(logManager);
                }
            }

            return(instance);
        }
Esempio n. 8
0
        public void MakeDiscoverable(string name)
        {
            var _configuration = new UPNPConfiguration()
            {
                UdpListnerPort  = 1900,
                FriendlyName    = name,
                Manufacture     = "Tampa IoT Dev",
                ModelName       = "SoccerBot-mBot",
                DefaultPageHtml = @"<html>
<head>
<title>SoccerBot</title>
<link rel=""stylesheet"" href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"" integrity=""sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"" crossorigin=""anonymous"">
</head>
<body>
<h1>Soccer Bot SSDP (uPnP) Listener Page</h1>
</body>
</html>"
            };


            _ssdpServer = NetworkServices.GetSSDPServer();
            _ssdpServer.MakeDiscoverable(9500, _configuration);
        }
Esempio n. 9
0
		/// <summary>
		///     Gets a singletone instance of the <see cref="SSDPServer"/>.
		/// </summary>
		/// <returns>
		///     A singletone instance of the <see cref="SSDPServer"/>.
		/// </returns>
		public static ISSDPServer GetInstance()
		{
			lock (instanceSyncObject)
			{
				if (instance == null)
				{
					instance = new SSDPServer();
				}
			}

			return instance;
		}
Esempio n. 10
0
		/// <summary>
		///     Gets a singletone instance of the <see cref="SSDPServer"/>.
		/// </summary>
		/// <param name="logManager">
		///     The <see cref="ILogManager"/> to use for logging the debug information.
		/// </param>
		/// <returns>
		///     A singletone instance of the <see cref="SSDPServer"/>.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		///     <paramref name="logManager"/> is <c>null</c>.
		/// </exception>
		public static ISSDPServer GetInstance(ILogManager logManager)
		{
			lock (instanceSyncObject)
			{
				if (instance == null)
				{
					instance = new SSDPServer(logManager);
				}
			}

			return instance;
		}