Example #1
0
 /// <summary>
 /// Called when a new device is discovered.
 /// </summary>
 /// <param name="findData">The search for which the UPnP framework is returning results.</param>
 /// <param name="device">The new device which was added.</param>
 /// <param name="guidInterface">The network interface Guid from which the device came.</param>
 void IUPnPDeviceFinderAddCallbackWithInterface.DeviceAddedWithInterface(
     int findData, UPnPDevice device, ref Guid guidInterface)
 {
     if (Discovery != null)
     {
         Discovery.OnDeviceAdded(new DeviceAddedEventArgs(device, guidInterface));
     }
 }
Example #2
0
 /// <summary>
 /// Internal dispose method.
 /// </summary>
 /// <param name="disposeManaged">True to dispose managed objects.</param>
 protected virtual void Dispose(bool disposeManaged)
 {
     if (disposeManaged)
     {
         if (mdDiscovery != null)
         {
             mdDiscovery.Dispose();
             mdDiscovery = null;
         }
     }
 }
Example #3
0
 /// <summary>
 /// Stops the current async search if running.
 /// </summary>
 public void StopAsync()
 {
     if (AsyncRunning)
     {
         mdDiscovery.Stop();
         mdDiscovery.DeviceAdded    -= new DeviceAddedEventHandler(mdDiscovery_DeviceAdded);
         mdDiscovery.DeviceRemoved  -= new DeviceRemovedEventHandler(mdDiscovery_DeviceRemoved);
         mdDiscovery.SearchComplete -= new SearchCompleteEventHandler(mdDiscovery_SearchComplete);
         mdDiscovery.Dispose();
         mdDiscovery = null;
     }
 }
Example #4
0
        /// <summary>
        /// Starts or restarts the current async search.
        /// </summary>
        public void ReStartAsync()
        {
            if (AsyncRunning)
            {
                StopAsync();
            }

            if (!AsyncRunning)
            {
                mdDiscovery                 = new Discovery(DiscoveryServiceType, AddressFamily, ResolveNetworkInterfaces);
                mdDiscovery.DeviceAdded    += new DeviceAddedEventHandler(mdDiscovery_DeviceAdded);
                mdDiscovery.DeviceRemoved  += new DeviceRemovedEventHandler(mdDiscovery_DeviceRemoved);
                mdDiscovery.SearchComplete += new SearchCompleteEventHandler(mdDiscovery_SearchComplete);
                mdDiscovery.Start();
            }
        }
Example #5
0
        /// <summary>
        /// Finds devices by device or service type asynchronously using a timeout period.
        /// </summary>
        /// <param name="uriString">The URI string to search for or null for all devices.</param>
        /// <param name="timeoutMS">The maximum timeout time in milliseconds to wait.</param>
        /// <param name="maxDevices">The maximum number of devices to find before returning.</param>
        /// <param name="devicesFound">
        /// The delegate to call when async operation is complete. <para /> NOTE: this delegate is executed
        /// in a different to the calling thread.</param>
        /// <param name="addressFamily">The address family to search in. (Vista or above only).</param>
        /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param>
        /// <returns>A Devices list containing the found devices.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when devicesFound delegate is null.</exception>
        public static void FindDevicesAsync(
            string uriString,
            int timeoutMS,
            int maxDevices,
            DevicesFoundDelegate devicesFound,
            AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth,
            bool resolveNetworkInterfaces    = false)
        {
            if (devicesFound == null)
            {
                throw new ArgumentNullException("devicesFound");
            }

            Object[] loParams = new object[]
            {
                uriString, timeoutMS, maxDevices,
                addressFamily, resolveNetworkInterfaces,
                devicesFound
            };

            Devices ldDevices         = null;
            bool    lbSearchCompleted = false;
            Thread  ltCurrent         = Thread.CurrentThread;

            Thread ltThread = new Thread(
                (object args) =>
            {
                try
                {
                    object[] loArgs = (object[])args;

                    ldDevices = Discovery.FindDevices(
                        (string)loArgs[0], (int)loArgs[1], (int)loArgs[2],
                        out lbSearchCompleted, (AddressFamilyFlags)loArgs[3],
                        (bool)loArgs[4]);
                }
                finally
                {
                    devicesFound(ldDevices, lbSearchCompleted);
                }
            }
                );

            ltThread.Start(loParams);
        }
Example #6
0
        /// <summary>
        /// Finds devices by device or service type synchronously using a timeout period.
        /// </summary>
        /// <param name="uriString">The URI string to search for or null / empty for all.</param>
        /// <param name="timeoutMS">The maximum timeout time in milliseconds to wait or -1 for wait forever.</param>
        /// <param name="maxDevices">The maximum number of devices to find before returning or 0 for as many as possible.</param>
        /// <param name="searchCompleted">True if the search completed and all available devices were returned.</param>
        /// <param name="addressFamily">The address family to search in. (Vista or above only).</param>
        /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param>
        /// <returns>A Devices list containing the found devices.</returns>
        public static Devices FindDevices(
            string uriString,
            int timeoutMS,
            int maxDevices,
            out bool searchCompleted,
            AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth,
            bool resolveNetworkInterfaces    = false)
        {
            Discovery        ldDiscovery       = new Discovery(uriString, addressFamily, resolveNetworkInterfaces);
            Devices          ldDevices         = new Devices();
            bool             lbSearchCompleted = false;
            ManualResetEvent lmreComplete      = new ManualResetEvent(false);

            ldDiscovery.DeviceAdded +=
                (sender, args) =>
            {
                ldDevices.Add(args.Device);
                if (maxDevices > 0 && ldDevices.Count >= maxDevices)
                {
                    lmreComplete.Set();
                }
            };

            ldDiscovery.SearchComplete += (sender, args) =>
            {
                lbSearchCompleted = true;
                lmreComplete.Set();
            };

            ldDiscovery.Start();

            lmreComplete.WaitOne(timeoutMS);

            searchCompleted = lbSearchCompleted;
            ldDiscovery.Dispose();

            return(ldDevices);
        }
Example #7
0
 public DeviceFinderCallbackWithInterface(Discovery discovery)
     : base(discovery)
 {
 }
Example #8
0
 /// <summary>
 /// Ignores all events from this point forward.
 /// </summary>
 public void Ignore()
 {
     mdDiscovery = null;
 }
Example #9
0
 /// <summary>
 /// Creates a new device finder callback object.
 /// </summary>
 /// <param name="discovery">The discovery object for which the events should be raised.</param>
 public DeviceFinderCallback(Discovery discovery)
 {
     mdDiscovery = discovery;
 }
Example #10
0
        /// <summary>
        /// Finds devices by device or service type synchronously using a timeout period.
        /// </summary>
        /// <param name="uriString">The URI string to search for or null / empty for all.</param>
        /// <param name="timeoutMS">The maximum timeout time in milliseconds to wait or -1 for wait forever.</param>
        /// <param name="maxDevices">The maximum number of devices to find before returning or 0 for as many as possible.</param>
        /// <param name="searchCompleted">True if the search completed and all available devices were returned.</param>
        /// <param name="addressFamily">The address family to search in. (Vista or above only).</param>
        /// <param name="resolveNetworkInterfaces">True to resolve network interface Guids.</param>
        /// <returns>A Devices list containing the found devices.</returns>
        public static Devices FindDevices(
            string uriString,
            int timeoutMS,
            int maxDevices,
            out bool searchCompleted,
            AddressFamilyFlags addressFamily = AddressFamilyFlags.IPvBoth,
            bool resolveNetworkInterfaces = false)
        {
            Discovery ldDiscovery = new Discovery(uriString, addressFamily, resolveNetworkInterfaces);
            Devices ldDevices = new Devices();
            bool lbSearchCompleted = false;
            ManualResetEvent lmreComplete = new ManualResetEvent(false);

            ldDiscovery.DeviceAdded +=
                (sender, args) =>
                {
                    ldDevices.Add(args.Device);
                    if (maxDevices > 0 && ldDevices.Count >= maxDevices)
                        lmreComplete.Set();
                };

            ldDiscovery.SearchComplete += (sender, args) =>
                {
                    lbSearchCompleted = true;
                    lmreComplete.Set();
                };

            ldDiscovery.Start();

            lmreComplete.WaitOne(timeoutMS);

            searchCompleted = lbSearchCompleted;
            ldDiscovery.Dispose();

            return ldDevices;
        }
Example #11
0
        private void startEnum()
        {
            ManagedUPnP.Logging.LogLines += new LogLinesEventHandler(ManagedUPnPLog);
            ManagedUPnP.Logging.Enabled = true;

            mdDiscovery = new Discovery(null,AddressFamilyFlags.IPv4,true);

            mdDiscovery.DeviceAdded += new DeviceAddedEventHandler(mdDiscovery_DeviceAdded);
            mdDiscovery.SearchComplete += new SearchCompleteEventHandler(mdDiscovery_SearchComplete);
            mdDiscovery.Start();
        }
Example #12
0
 /// <summary>
 /// Adds all services for a device UDN syncrhonously.
 /// </summary>
 /// <param name="udn">The UDN of the device to add the services for.</param>
 public void AddAllFor(string udn)
 {
     AddAllFor(Discovery.FindServicesByUDN(udn, DiscoveryServiceType, AddressFamily));
 }
Example #13
0
 public DeviceFinderCallbackWithInterface(Discovery discovery)
     : base(discovery)
 {
 }
Example #14
0
 /// <summary>
 /// Ignores all events from this point forward.
 /// </summary>
 public void Ignore()
 {
     mdDiscovery = null;
 }
Example #15
0
 /// <summary>
 /// Creates a new device finder callback object.
 /// </summary>
 /// <param name="discovery">The discovery object for which the events should be raised.</param>
 public DeviceFinderCallback(Discovery discovery)
 {
     mdDiscovery = discovery;
 }