示例#1
0
        public bool MayBeDevice(string advertName, List <Guid> advertGUIDs)
        {
            if (_deviceInfo.NamePrefixes.Any())
            {
                foreach (var deviceInfoNamePrefix in _deviceInfo.NamePrefixes)
                {
                    if (advertName.IndexOf(deviceInfoNamePrefix) != 0)
                    {
                        continue;
                    }

                    _bpLogger.Debug($"Found {advertName} via NamePrefix {deviceInfoNamePrefix}");
                    return(true);
                }
            }

            if ((_deviceInfo.Names.Any() && !_deviceInfo.Names.Contains(advertName)) || !_deviceInfo.Names.Any())
            {
                _bpLogger.Trace($"Dropping query for {advertName}.");
                return(false);
            }

            if (_deviceInfo.Names.Any() && !advertGUIDs.Any())
            {
                _bpLogger.Debug("Found " + advertName + " for " + _deviceInfo.GetType());
                return(true);
            }

            _bpLogger.Trace("Found " + advertName + " for " + _deviceInfo.GetType() + " with services " + advertGUIDs);
            foreach (var s in _deviceInfo.Services)
            {
                _bpLogger.Trace("Expecting " + s);
            }

            foreach (var s in advertGUIDs)
            {
                _bpLogger.Trace("Got " + s);
            }

            // Intersect doesn't intersect until the enumerator is called
            var sv = _deviceInfo.Services.Intersect(advertGUIDs);

            foreach (var s in sv)
            {
                _bpLogger.Trace("Matched " + s);
                return(true);
            }

            return(false);
        }
        public bool MayBeDevice(string advertName, List <Guid> advertGUIDs)
        {
            if (_deviceInfo.Names.Any() && !_deviceInfo.Names.Contains(advertName))
            {
                return(false);
            }

            if (_deviceInfo.Names.Any() && !advertGUIDs.Any())
            {
                _bpLogger.Debug("Found " + advertName + " for " + _deviceInfo.GetType().ToString());
                _bpLogger.Debug("No advertised services?");
                return(true);
            }

            _bpLogger.Debug("Found " + advertName + " for " + _deviceInfo.GetType().ToString());
            foreach (var s in _deviceInfo.Services)
            {
                _bpLogger.Debug("Expecting " + s.ToString());
            }

            foreach (var s in advertGUIDs)
            {
                _bpLogger.Debug("Got " + s.ToString());
            }

            // Intersect doesn't intersect until the enumerator is called
            var sv = _deviceInfo.Services.Intersect(advertGUIDs);

            foreach (var s in sv)
            {
                _bpLogger.Debug("Matched " + s.ToString());
                return(true);
            }

            return(false);
        }
        private IBluetoothDeviceGeneralTestUtils GetInterfaceObj(IBluetoothDeviceInfo aInfo)
        {
            // Tests for IBluetoothDeviceInfo objects would normally be of the format
            //
            // BluetoothDeviceTestUtils.TestDeviceInfo<T>()
            //
            // However, since we have all of the types already listed in BluetoothSubtypeManager,
            // we can use reflection to build the dynamic type around those classes and
            // automatically test any new objects that show up in the array.
            //
            // If only the code wasn't so horribly ugly.
            var bdtu    = typeof(BluetoothDeviceTestUtils <>);
            var objType = bdtu.MakeGenericType(aInfo.GetType());
            var obj     = Activator.CreateInstance(objType) as IBluetoothDeviceGeneralTestUtils;

            obj.SetupTest(aInfo.Names.Length > 0 ? aInfo.Names[0] : aInfo.NamePrefixes[0]);
            return(obj);
        }