Ejemplo n.º 1
0
        internal static bool AddUniqueDevice(List <IBluetoothDeviceInfo> list,
                                             IBluetoothDeviceInfo bdi)
        {
            int idx = BluetoothDeviceInfo.ListIndexOf(list, bdi);

            AssertManualExistsIf(idx, list, bdi);
            if (idx == -1)
            {
                list.Add(bdi);
                return(true);
            }
            else
            {
                Debug.WriteLine("Replace device");
                // Check the new info versus the previously discovered device.
                IBluetoothDeviceInfo bdiOld = list[idx];
                Debug.Assert(bdiOld.DeviceAddress.Equals(bdi.DeviceAddress));
                //Debug.Assert(deviceName != null);
                //Debug.Assert(deviceName.Length != 0);
                //Debug.Assert(bdiOld.ClassOfDevice.Equals(bdi.ClassOfDevice));
                // Replace
                list[idx] = bdi;
                return(false);
            }
        }
Ejemplo n.º 2
0
        internal static IBluetoothDeviceInfo[] Intersect(IBluetoothDeviceInfo[] list, List <IBluetoothDeviceInfo> seenDevices)
        {
            var copy = new List <IBluetoothDeviceInfo>(list.Length);

            foreach (var cur in list)
            {
                if (-1 != BluetoothDeviceInfo.ListIndexOf(seenDevices, cur))
                {
                    copy.Add(cur);
                }
            }//for
            return(copy.ToArray());
        }
Ejemplo n.º 3
0
        internal static List_IBluetoothDeviceInfo DiscoverDevicesMerge(
            bool authenticated, bool remembered, bool unknown,
            List_IBluetoothDeviceInfo knownDevices,
            List_IBluetoothDeviceInfo discoverableDevices,
            bool discoverableOnly, DateTime discoTime)
        {
            // Check args
            if (unknown || discoverableOnly)
            {
                if (discoverableDevices == null)
                {
                    throw new ArgumentNullException("discoverableDevices");
                }
            }
            else
            {
                bool nunit = TestUtilities.IsUnderTestHarness(); // Don't warn then.
                Debug.Assert(nunit || discoverableDevices == null, "No need to run SLOW Inquiry when not wanting 'unknown'.");
            }
            if (knownDevices == null)
            {
                throw new ArgumentNullException("knownDevices");
            }
            AssertNoDuplicates(knownDevices, "knownDevices");
            AssertNoDuplicates(discoverableDevices, "discoverableDevices");
            //
            bool addFromKnown_General;

            if (discoverableOnly)
            {
                addFromKnown_General = false;
            }
            else
            {
                addFromKnown_General = authenticated || remembered;
                if (!addFromKnown_General && !unknown)
                {
                    return(new List_IBluetoothDeviceInfo());
                }
            }
            List_IBluetoothDeviceInfo merged;

            if (unknown || discoverableOnly)
            {
                merged = new List_IBluetoothDeviceInfo(discoverableDevices);
            }
            else
            {
                merged = new List_IBluetoothDeviceInfo();
            }
            //
            foreach (IBluetoothDeviceInfo cur in knownDevices)
            {
                bool debug_contains = false;
                //TODO #if DEBUG
                foreach (IBluetoothDeviceInfo curMerged in merged)
                {
                    if (BluetoothDeviceInfo.EqualsIBDI(curMerged, cur))
                    {
                        debug_contains = true;
                        break;
                    }
                }
                //#endif
                //--
                int idx = BluetoothDeviceInfo.ListIndexOf(merged, cur);
                if (idx != -1)
                {
                    // The device is both in the inquiry result and the remembered list.
                    // Does the called want "already known" devices?  If so, update
                    // to the correct flags, otherwise remove it.
                    Debug.Assert(debug_contains);
                    if (addFromKnown_General || discoverableOnly)
                    {
                        ((IBluetoothDeviceInfo)merged[idx]).Merge(cur);
                        // (The casts are for the NETCFv1 build).
                    }
                    else
                    {
                        merged.RemoveAt(idx);
                    }
                }
                else
                {
                    // The device is not in inquiry result, do we add it from the known list?
                    Debug.Assert(!debug_contains);
                    bool addFromKnown_Specific
                        = (remembered && cur.Remembered) ||
                          (authenticated && cur.Authenticated);
                    if (addFromKnown_General && addFromKnown_Specific)
                    {
                        merged.Add(cur);
                    }
                }
            }//for
            AssertNoDuplicates(merged, "merged");
            return(merged);
        }