private static void OnSsdpDiscovery(object Sender, SsdpDiscoveryEventArgs e)
        {
            int  i, c = 0;
            bool ReportDevice  = false;
            bool ReportService = false;

            if (e.ReportInterface(SsdpClient.UpnpRootDevice) || e.ReportInterface("urn:clayster:device:learningIotCamera:1"))
            {
                ReportDevice = true;
                c++;
            }

            if (e.ReportInterface("urn:schemas-upnp-org:service:DigitalSecurityCameraStillImage:1"))
            {
                ReportService = true;
                c++;
            }

            double[] k = new double[c];

            lock (lastAccessBySessionId)
            {
                for (i = 0; i < c; i++)
                {
                    k [i] = gen.NextDouble();
                }
            }

            Array.Sort(k);
            i = 0;

            if (ReportDevice)
            {
                System.Timers.Timer t = new System.Timers.Timer(e.MaximumWaitTime * 1000 * k[i++] + 1);
                t.AutoReset = false;
                t.Elapsed  += (o2, e2) =>
                {
                    e.SendResponse(DateTime.Now.AddMinutes(30), "/CameraDevice.xml", SsdpClient.UpnpRootDevice,
                                   "uuid:" + defaultSettings.UDN + "::upnp:rootdevice");
                };
                t.Start();
            }

            if (ReportService)
            {
                System.Timers.Timer t = new System.Timers.Timer(e.MaximumWaitTime * 1000 * k[i++] + 1);
                t.AutoReset = false;
                t.Elapsed  += (o2, e2) =>
                {
                    e.SendResponse(DateTime.Now.AddMinutes(30), "/StillImageService.xml",
                                   "urn:schemas-upnp-org:service:DigitalSecurityCameraStillImage:1",
                                   "uuid:" + defaultSettings.UDN + ":service:DigitalSecurityCameraStillImage:1");
                };
                t.Start();
            }
        }
Exemplo n.º 2
0
		private static void OnSsdpDiscovery(object Sender, SsdpDiscoveryEventArgs e)
		{
			int i, c = 0;
			bool ReportDevice = false;
			bool ReportService = false;

			if (e.ReportInterface (SsdpClient.UpnpRootDevice) || e.ReportInterface ("urn:clayster:device:learningIotCamera:1"))
			{
				ReportDevice = true;
				c++;
			}

			if (e.ReportInterface ("urn:schemas-upnp-org:service:DigitalSecurityCameraStillImage:1"))
			{
				ReportService = true;
				c++;
			}

			double[] k = new double[c];

			lock (lastAccessBySessionId)
			{
				for (i = 0; i < c; i++)
					k [i] = gen.NextDouble ();
			}

			Array.Sort (k);
			i = 0;

			if (ReportDevice)
			{
				System.Timers.Timer t = new System.Timers.Timer (e.MaximumWaitTime * 1000 * k[i++] + 1);
				t.AutoReset = false;
				t.Elapsed += (o2, e2) =>
					{
						e.SendResponse (DateTime.Now.AddMinutes (30), "/CameraDevice.xml", SsdpClient.UpnpRootDevice, 
							"uuid:" + defaultSettings.UDN + "::upnp:rootdevice");
					};
				t.Start ();
			}

			if (ReportService)
			{
				System.Timers.Timer t = new System.Timers.Timer (e.MaximumWaitTime * 1000 * k[i++] + 1);
				t.AutoReset = false;
				t.Elapsed += (o2, e2) =>
					{
						e.SendResponse (DateTime.Now.AddMinutes (30), "/StillImageService.xml", 
							"urn:schemas-upnp-org:service:DigitalSecurityCameraStillImage:1", 
							"uuid:" + defaultSettings.UDN + ":service:DigitalSecurityCameraStillImage:1");
					};
				t.Start ();
			}
		}