Esempio n. 1
0
 private void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     try {
         Deployment.Current.Dispatcher.BeginInvoke(async() =>
         {
             // Den Benutzer fragen ob die Verbindung aufgebaut werden soll.
             var result = MessageBox.Show(String.Format(AppResources.Msg_ChatPrompt, args.PeerInformation.DisplayName)
                                          , AppResources.Msg_ChatPromptTitle, MessageBoxButton.OKCancel);
             if (result == MessageBoxResult.OK)
             {
                 if (await ConnectToPeer(args.PeerInformation))
                 {
                     if (PeerConnected != null)
                     {
                         PeerConnected();
                     }
                 }
                 ;
             }
             else
             {
                 // die API hat keine Funktion, die aufgerufen werden kann, um eine Verbindung abzulehnen.
             }
         });
     } catch (Exception ex) {
         MessageBox.Show(ex.Message);
         Terminate();
     }
 }
 private void PeerFinderConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     if (connectMode == ConnectMethod.Browse)
     {
         DoConnect(args.PeerInformation);
     }
 }
Esempio n. 3
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);
     }
 }
Esempio n. 4
0
        async void OnConnectionRequested(object sender, ConnectionRequestedEventArgs args)
        {
            Window.IpInputBox.IsEnabled   = false;
            Window.PortInputBox.IsEnabled = false;
            Window.CancelButton.IsEnabled = false;
            Window.DoneButton.IsEnabled   = false;

            try
            {
                int    port = int.Parse(Window.PortInputBox.Text);
                string ip   = Window.IpInputBox.Text;
                await Client.Connect(ip, port);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error");
                Window.DoneButton.IsEnabled   = true;
                Window.CancelButton.IsEnabled = true;
                Window.IpInputBox.IsEnabled   = true;
                Window.PortInputBox.IsEnabled = true;
                return;
            }

            Window.Close();
        }
 // This gets called when we receive a connect request from a Peer
 void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     Verbose(string.Format("Do you accept to receive a file from {0} ?", args.PeerInformation.DisplayName));
     if (ConnectionRequested != null)
     {
         ConnectionRequested(this, args);
     }
 }
Esempio n. 6
0
        private void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
        {
            if (ShouldConnect())
            {
                // Go ahead and connect
                ConnectToPeer(args.PeerInformation);
            }

            return;
        }
Esempio n. 7
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;
            });
        }
Esempio n. 9
0
        private async void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
        {
            PeerInformation info = args.PeerInformation;

            socket = await PeerFinder.ConnectAsync(info);

            if (ConnectionReceived != null)
            {
                ConnectionReceived(this, new RfcommStreamSocketListenerConnectionReceivedEventArgs(socket));
            }
        }
Esempio n. 10
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"));
     }
 }
        private async void PeerConnectionRequested(object sender, ConnectionRequestedEventArgs args)
        {
            _requestingPeer = args.PeerInformation;
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                rootPage.NotifyUser("Connection requested from peer " + args.PeerInformation.DisplayName, NotifyType.StatusMessage);

                this.PeerFinder_AcceptButton.Visibility = Visibility.Visible;
                this.PeerFinder_SendButton.Visibility   = Visibility.Collapsed;
                this.PeerFinder_MessageBox.Visibility   = Visibility.Collapsed;
            });
        }
Esempio n. 12
0
 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);
     }
 }
Esempio n. 13
0
        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();
        }
 // 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_AdvertiseButton.Visibility   = Visibility.Collapsed;
         this.PeerFinder_BrowsePeersButton.Visibility = Visibility.Collapsed;
         this.PeerFinder_AcceptButton.Visibility      = Visibility.Visible;
         this.PeerFinder_SendButton.Visibility        = Visibility.Collapsed;
         this.PeerFinder_MessageBox.Visibility        = Visibility.Collapsed;
         this.PeerFinder_SelectRole.Visibility        = Visibility.Collapsed;
         this.PeerFinder_DiscoveryData.Visibility     = Visibility.Collapsed;
         this.PeerFinder_ConnectButton.Visibility     = Visibility.Collapsed;
         this.PeerFinder_FoundPeersList.Visibility    = Visibility.Collapsed;
     });
 }
Esempio n. 15
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);
         }
     });
 }
Esempio n. 16
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;
            });
        }
Esempio n. 17
0
        private async void PeerFinderConnectionRequested(object sender, ConnectionRequestedEventArgs args)
        {
            if (this.isConnecting)
            {
                return;
            }

            try
            {
                this.RouteToUiThread(
                    () =>
                {
                    this.IsConnecting  = true;
                    this.ConnectedPeer = string.Format(
                        "Incoming request from {0}...",
                        args.PeerInformation.DisplayName);
                });

                var socket = await PeerFinder.ConnectAsync(args.PeerInformation);

                this.InitializeSocket(socket);
                this.RouteToUiThread(
                    () =>
                {
                    this.IsConnecting = false;
                    var peer          =
                        this.Peers.FirstOrDefault(p => p.Information.Id == args.PeerInformation.Id);
                    if (peer == null)
                    {
                        peer = new FoundPeer(args.PeerInformation);
                        this.Peers.Add(peer);
                    }
                    this.SelectedPeer  = peer;
                    this.ConnectedPeer = peer.Name;
                });
            }
            catch (Exception ex)
            {
                this.RouteToUiThread(() => this.ErrorMessage = ex.Message);
            }
        }
Esempio n. 18
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();
                }
            }
        }
Esempio n. 19
0
 private void ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     try {
         Dispatcher.BeginInvoke(() => {
             Bluetooth.ConnectToPeer(args.PeerInformation);
             rivalName  = args.PeerInformation.DisplayName;
             var result = MessageBox.Show(String.Format("Пользователь {0} предлагает вам игру. Принять приглашение?",
                                                        rivalName), "Приглашение", MessageBoxButton.OKCancel);
             if (result == MessageBoxResult.OK)
             {
                 Bluetooth.SendCommand(BluetoothCommands.AcceptInvite);
             }
             else
             {
                 Bluetooth.SendCommand(BluetoothCommands.DiscardInvite);
                 Bluetooth.Disconnect();
             }
         });
     }
     catch (Exception ex) {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 20
0
 void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     Dispatcher.BeginInvoke(() => {
         MessageBox.Show("Connection:" + args.PeerInformation.DisplayName);
     });
 }
Esempio n. 21
0
 private void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     throw new NotImplementedException();
 }
 void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
 }
Esempio n. 23
0
 private void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     ConnectToPeer(args.PeerInformation);
 }
Esempio n. 24
0
 private void PeerFinder_ConnectionRequested(object sender, ConnectionRequestedEventArgs args)
 {
     // Zurück auf UI Thread wechseln
     Dispatcher.BeginInvoke(() => AskUserToAcceptPeerRequest(args.PeerInformation));
 }