private void btnSendFiles_Click(object sender, EventArgs e)
        {
            try
            {
                var sbdd = new InTheHand.Windows.Forms.SelectBluetoothDeviceDialog();
                sbdd.ShowAuthenticated = true;
                sbdd.ShowRemembered    = true;
                sbdd.ShowUnknown       = true;

                InTheHand.Net.Sockets.BluetoothDeviceInfo deviceInfo = null;

                OpenFileDialog openFileDialog = new OpenFileDialog();

                if (sbdd.ShowDialog() == DialogResult.OK)
                {
                    deviceInfo = sbdd.SelectedDevice;

                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        var file    = openFileDialog.FileName;
                        var uri     = new Uri("obex://" + deviceInfo.DeviceAddress + "/" + file);
                        var request = new InTheHand.Net.ObexWebRequest(uri);
                        request.ReadFile(file);
                        var response = (InTheHand.Net.ObexWebResponse)request.GetResponse();
                        MessageBox.Show(response.StatusCode.ToString());
                        response.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #2
0
        /// <summary>
        /// Ends an asynchronous Service Record lookup query.
        /// </summary>
        /// -
        /// <param name="asyncResult">An <see cref="T:System.IAsyncResult"/> returned
        /// by <see cref="M:InTheHand.Net.Sockets.BluetoothClient.BeginDiscoverDevices(System.Int32,System.Boolean,System.Boolean,System.Boolean,System.Boolean,System.AsyncCallback,System.Object)"/>.
        /// </param>
        /// -
        /// <returns>See <see cref="M:InTheHand.Net.Sockets.BluetoothClient.DiscoverDevices(System.Int32,System.Boolean,System.Boolean,System.Boolean,System.Boolean)"/>.
        /// </returns>
        public BluetoothDeviceInfo[] EndDiscoverDevices(IAsyncResult asyncResult)
        {
#if !V1
            return(BluetoothDeviceInfo.Wrap(m_impl.EndDiscoverDevices(asyncResult)));
#else
            throw new NotSupportedException();
#endif
        }
Exemple #3
0
        /// <summary>
        /// Gets the name of a device by a specified socket.
        /// </summary>
        /// <param name="s"> A <see cref="Socket"/>.</param>
        /// <returns>Returns a string value of the computer or device name.</returns>
        public static string GetRemoteMachineName(Socket s)
        {
#if WinCE
            return(InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.GetRemoteMachineName(s));
#else
            var bdi = new BluetoothDeviceInfo(((BluetoothEndPoint)s.RemoteEndPoint).Address);
            return(bdi.DeviceName);
#endif
        }
Exemple #4
0
 //----
 internal static BluetoothDeviceInfo[] Wrap(IBluetoothDeviceInfo[] orig)
 {
     // Bah no Array.ConvertAll method in NETCF.
     BluetoothDeviceInfo[] wrapped = new BluetoothDeviceInfo[orig.Length];
     for (int i = 0; i < orig.Length; ++i)
     {
         wrapped[i] = new BluetoothDeviceInfo(orig[i]);
     }
     return(wrapped);
 }
Exemple #5
0
        int IComparable.CompareTo(object obj)
        {
            //objects are equal if device address matches
            BluetoothDeviceInfo bdi = obj as BluetoothDeviceInfo;

            if (bdi != null)
            {
                return(((IComparable)this.DeviceAddress).CompareTo(bdi));
            }
            return(-1);
        }
Exemple #6
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());
        }
Exemple #7
0
        //--------

        #region Equals
        /// <summary>
        /// Compares two <see cref="BluetoothDeviceInfo"/> instances for equality.
        /// </summary>
        /// -
        /// <param name="obj">The <see cref="BluetoothDeviceInfo"/>
        /// to compare with the current instance.
        /// </param>
        /// -
        /// <returns><c>true</c> if <paramref name="obj"/>
        /// is a <see cref="BluetoothDeviceInfo"/> and equal to the current instance;
        /// otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            //objects are equal if device address matches
            BluetoothDeviceInfo bdi = obj as BluetoothDeviceInfo;

            if (bdi != null)
            {
                return(this.DeviceAddress.Equals(bdi.DeviceAddress));
            }
            if (!IsAMsftInternalType(obj))
            {
                Debug.Fail("Who's comparing "
                           + (obj == null ? "<null>" : "'" + obj.GetType().FullName + "'")
                           + " to BDI!");
            }
            return(base.Equals(obj));
        }
Exemple #8
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);
        }
Exemple #9
0
 public BluetoothDeviceInfo[] DiscoverDevices(int maxDevices,
                                              bool authenticated, bool remembered, bool unknown, bool discoverableOnly)
 {
     return(BluetoothDeviceInfo.Wrap(m_impl.DiscoverDevices(maxDevices, authenticated, remembered, unknown, discoverableOnly)));
 }
Exemple #10
0
 void AuthHandler(object sender, InTheHand.Net.Bluetooth.BluetoothWin32AuthenticationEventArgs e)
 {
     InTheHand.Net.Sockets.BluetoothDeviceInfo bdi = e.Device;
 }