コード例 #1
0
        /// <summary>
        /// Keep track of all UPnP devices on the network. The user can expect the OnAddedDeviceSink or OnAddedServiceSink
        /// delegate to immidiatly be called for each device that is already known.
        /// <para>
        /// if multiple filters are supplied, the results will be that of the parent device which satisfies all the search criteria.
        /// </para>
        /// </summary>
        /// <param name="OnAddedDeviceSink"></param>
        /// <param name="OnAddedServiceSink"></param>
        /// <param name="Filters">Array of strings, which represent the search criteria</param>
        public UPnPSmartControlPoint(DeviceHandler OnAddedDeviceSink, ServiceHandler OnAddedServiceSink, string[] Filters)
        {
            //MultiFilter = true;
            PartialMatchFilters = new String[Filters.Length];
            MinimumVersion      = new double[Filters.Length];
            for (int i = 0; i < PartialMatchFilters.Length; ++i)
            {
                if (Filters[i].Length > 15 && Filters[i].Length > UPnPStringFormatter.GetURNPrefix(Filters[i]).Length)
                {
                    PartialMatchFilters[i] = UPnPStringFormatter.GetURNPrefix(Filters[i]);
                    try
                    {
                        MinimumVersion[i] = double.Parse(Filters[i].Substring(PartialMatchFilters[i].Length), new CultureInfo("en-US").NumberFormat);
                    }
                    catch
                    {
                        MinimumVersion[i] = 1.0;
                    }
                }
                else
                {
                    PartialMatchFilters[i] = Filters[i];
                    MinimumVersion[i]      = 1.0;
                }
            }

            if (OnAddedDeviceSink != null)
            {
                OnAddedDevice += OnAddedDeviceSink;
            }
            if (OnAddedServiceSink != null)
            {
                OnAddedService += OnAddedServiceSink;
            }

            iSCP.OnAddedDevice   += HandleAddedDevice;
            iSCP.OnDeviceExpired += HandleExpiredDevice;
            iSCP.OnRemovedDevice += HandleRemovedDevice;
            iSCP.OnUpdatedDevice += HandleUpdatedDevice;

            IEnumerator cdEN = iSCP.GetCurrentDevices().GetEnumerator();

            if ((OnAddedDeviceSink != null || OnAddedServiceSink != null))
            {
                while (cdEN.MoveNext())
                {
                    HandleAddedDevice(null, (UPnPDevice)cdEN.Current);
                }
            }
        }