Example #1
0
 void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     try
     {
         this.Dispatcher.BeginInvoke(() =>
         {
             // Ask the user if they want to accept the incoming request.
             var result = MessageBox.Show(String.Format(AppResources.Msg_ChatPrompt, args.PeerInformation.DisplayName)
                                          , AppResources.Msg_ChatPromptTitle, MessageBoxButton.OKCancel);
             if (result == MessageBoxResult.OK)
             {
                 ConnectToPeer(args.PeerInformation);
             }
             else
             {
                 // Currently no method to tell the sender that the connection was rejected.
             }
         });
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         CloseConnection(true);
     }
 }
Example #2
0
        void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
        {

            Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                  var result =  MessageBox.Show("是否接收" + args.PeerInformation.DisplayName + "连接请求", "蓝牙连接",
                         MessageBoxButton.OKCancel);

                  if (result== MessageBoxResult.OK)
                  {


                  }
                });
        }
 void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     try
     {
         if (ShouldConnect(args.PeerInformation))
         {
             // Go ahead and connect
             ConnectToPeer(args.PeerInformation);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     
 }
Example #4
0
 /// <summary>
 /// 连接请求事件处理
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private  async void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     //使用UI线程弹出连接请求的接收和拒绝弹窗
     await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
         {
             MessageDialog md = new MessageDialog("是否接收" + args.PeerInformation.DisplayName + "连接请求", "蓝牙连接");
             UICommand yes = new UICommand("接收");
             UICommand no = new UICommand("拒绝");
             md.Commands.Add(yes);
             md.Commands.Add(no);
             var result = await md.ShowAsync();
             if (result == yes)
             {
                 ConnectToPeer(args.PeerInformation);
             }
         });
 }
Example #5
0
            void ConnectionRequested(
                object sender,
                Windows.Networking.Proximity.ConnectionRequestedEventArgs e)
            {
                Console.WriteLine(
                    "Connection requested by " + e.PeerInformation.DisplayName + ". " +
                    "Will be accepted automatically.");

                try
                {
                    Receiver(e.PeerInformation);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error in receiver: {0}", ex.Message + Environment.NewLine + ex.StackTrace);
                }
            }
 private void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     // Zurück auf UI Thread wechseln
     Dispatcher.BeginInvoke(() => AskUserToAcceptPeerRequest(args.PeerInformation));
 }
 private void PeerFinderConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
   if (connectMode == ConnectMethod.Browse)
   {
     DoConnect(args.PeerInformation);
   }
 }
 void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     Connect(args.PeerInformation);
 }
Example #9
0
 /// <summary>
 /// Connects to incoming request.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private async void OnConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     try
     {
         connectionSocket = await PeerFinder.ConnectAsync(args.PeerInformation);
     }
     catch (Exception)
     {
         this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Error occurred while processing incoming request"));
     }            
 }
 /// <summary>
 /// A proximity connection was requested
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
    
 }
        private async void PeerConnectionRequested(object sender, ConnectionRequestedEventArgs e) {
            try {
                // Log
                await ProximityMapEnvironment.Default.Log(string.Format("Connecting to: {0}", e.PeerInformation.DisplayName), true);

                // Get socket
                StreamSocket socket = null;
                try {
                    socket = await PeerFinder.ConnectAsync(e.PeerInformation);
                }
                catch (Exception ex) {
                    Debug.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
                }

                if (socket == null) {
                    await Task.Delay(TimeSpan.FromSeconds(1d));
                    await ProximityMapEnvironment.Default.Log("Search for peers...", true);
                    return;
                }

                // Accept connection
                await this.PeerConnect(e.PeerInformation, socket);
            }
            catch (Exception ex) {
                Debug.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
Example #12
0
 // This gets called when we receive a connect request from a Peer
 private void PeerConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     _requestingPeer = args.PeerInformation;
     var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         rootPage.NotifyUser("Connection requested from peer " + args.PeerInformation.DisplayName, NotifyType.StatusMessage);
         this.PeerFinder_AdvertiseGrid.Visibility = Visibility.Collapsed;
         this.PeerFinder_BrowseGrid.Visibility = Visibility.Collapsed;
         this.PeerFinder_ConnectionGrid.Visibility = Visibility.Visible;
         this.PeerFinder_AcceptButton.Visibility = Visibility.Visible;
         this.PeerFinder_SendButton.Visibility = Visibility.Collapsed;
         this.PeerFinder_MessageBox.Visibility = Visibility.Collapsed;
         this.PeerFinder_SendToPeerList.Visibility = Visibility.Collapsed;
     });
 }
Example #13
0
        private async void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
        {


            try
            {
                // we will need two cases. of course the initial connection is what happens below. if it's not the initial connection, then we skip the accept and just go straight into it.
                if (is_initial_connect)
                {
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
                    {
                        ContentDialog diag_connection_requested = new ContentDialog();
                        diag_connection_requested.Title = "Connection requested!";
                        string prompt = args.PeerInformation.DisplayName.Substring(6) + " requests you to join the group!";
                        diag_connection_requested.PrimaryButtonText = "Accept";
                        diag_connection_requested.SecondaryButtonText = "Reject";
                        diag_connection_requested.Content = prompt;

                        ContentDialogResult connection_requested_result = await diag_connection_requested.ShowAsync();

                        if (connection_requested_result == ContentDialogResult.Primary)
                        {
                            grid_Loading.Visibility = Windows.UI.Xaml.Visibility.Visible;
                            await connection_helper(args.PeerInformation);

                        }
                    });
                }
                else
                {
                    // we've connected before, user program now expects to receive the userlist with phone numbers

                    await connection_helper(args.PeerInformation);
                    finalizing_connection = false;

                }



            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);

            }
           
        }
Example #14
0
 // This gets called when we receive a connect request from a Peer
 private void PeerConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     _requestingPeer = args.PeerInformation;
     var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         rootPage.NotifyUser("Connection requested from peer " + args.PeerInformation.DisplayName, NotifyType.StatusMessage);
         HideAllControlGroups();
         ShowSendOrAcceptControls(false);
     });
 }
        // This gets called when we receive a connect request from a Peer
        private void PeerConnectionRequested(object sender, ConnectionRequestedEventArgs args)
        {
            _requestingPeer = args.PeerInformation;
            var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                rootPage.NotifyUser("Connection requested from peer " + args.PeerInformation.DisplayName, NotifyType.StatusMessage);

                HideAllControls();
                this.PeerFinder_AcceptButton.Visibility = Visibility.Visible;
            });
        }
Example #16
0
        private async void PeerConnectionRequested(object sender, ConnectionRequestedEventArgs e)
        {
            _requestingPeer = e.PeerInformation;

            await proximityDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                this.NotifyUser("Connection requested from peer " + e.PeerInformation.DisplayName, NotifyType.PeerMessage);
                AccepPeer();
                //this.PeerFinder_SendButton.Visibility = Visibility.Collapsed;
            });
        }
Example #17
0
        private async void ConnectionRequested(object sender, ConnectionRequestedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {            
                // handles case where you have no existing invitation
                List<string> existingInvitations = new List<string>();
                existingInvitations.Add(e.PeerInformation.DisplayName);

                // put the display name and peer information in a dictionary
                invitations[e.PeerInformation.DisplayName] = e.PeerInformation;

                receivedInvitations.SelectionMode = ListViewSelectionMode.Single;
                receivedInvitations.ItemsSource = existingInvitations;

                ReceivedInvitationsHeader.Text = "STOMP invitations :-)";
                progressBar.Visibility = Visibility.Collapsed;
                directions.Visibility = Visibility.Visible;
            });
        }
        private async void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
        {
            try
            {
                await this.textboxDebug.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                    async () =>
                    {
                        this.textboxDebug.Text += "Connection Requested\n";
                        await this.connect(args.PeerInformation);
                        if (_streamsocket != null)
                        {
                            while (true)
                            {
                                // nếu đã tồn tại một thể hiện của lớp DataReader thì đối tượng đó tự động được giải phóng.
                                DataReader datareader = new DataReader(_streamsocket.InputStream);
                                try
                                {
                                    uint size = await datareader.LoadAsync(sizeof(uint));
                                    if (size != sizeof(uint))
                                    {
                                        return;
                                    }
                                    uint lenght = datareader.ReadUInt32();
                                    uint exactlylenght = await datareader.LoadAsync(lenght);
                                    if (lenght != exactlylenght)
                                    {
                                        return;
                                    }
                                    string msg = datareader.ReadString(exactlylenght);
                                    this.textboxDebug.Text += "Receive from " + _streamsocket.Information.RemoteAddress + ": " + msg + "\n";
                                }
                                catch (Exception ex)
                                {
                                    this.textboxDebug.Text += ex.Message + "\n";
                                }
                            }

                        }
                    });
            }
            catch (Exception ex)
            {
                this.textboxDebug.Text += ex.Message + "\n";
            }


            //await PeerFinder.ConnectAsync(args.PeerInformation);
            // throw new NotImplementedException();
        }
Example #19
0
        /// <summary>
        /// Event handler to be executed when PeerFinder's ConnectionRequested fires.
        /// </summary>
        private async void ConnectionRequested(object sender, ConnectionRequestedEventArgs e)
        {
            try
            {
                if (Connecting != null)
                {
                    Connecting();
                }

                _socket = await PeerFinder.ConnectAsync(e.PeerInformation);

                PeerFinder.TriggeredConnectionStateChanged -= TriggeredConnectionStateChanged;
                PeerFinder.ConnectionRequested -= ConnectionRequested;

                _writer = new DataWriter(_socket.OutputStream);
                _writer.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
                _writer.ByteOrder = Windows.Storage.Streams.ByteOrder.LittleEndian;

                _reader = new DataReader(_socket.InputStream);
                _reader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
                _reader.ByteOrder = Windows.Storage.Streams.ByteOrder.LittleEndian;

                _status = ConnectionStatusValue.Connected;

                ListenAsync();

                SendNameAsync(NFCTalk.DataContext.Singleton.Settings.Name);

                if (Connected != null)
                {
                    Connected();
                }
            }
            catch (Exception ex)
            {
                if (ConnectivityProblem != null)
                {
                    ConnectivityProblem();
                }
            }
        }
Example #20
0
        async void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
        {
            try
            {
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                {
                    MessageDialog msg = new MessageDialog("Accept connection request?");

                    //Došao je zahtjev -> prihvati ili nemoj
                    msg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(CommandHandlers)));
                    msg.Commands.Add(new UICommand("No", new UICommandInvokedHandler(CommandHandlers)));
                    await msg.ShowAsync();

                    if (result_accept == true)
                    {
                        ConnectToPeer(args.PeerInformation);
                    }
                    else
                    {
                        // Odbijena komunikacija
                    }
                });
            }
            catch (Exception ex)
            {
                /*MessageDialog msg = new MessageDialog(ex.Message);
                await msg.ShowAsync();
                MessageBox.Show(ex.Message);*/
                CloseConnection(true);
            }
        }