Inheritance: ITriggeredConnectionStateChangedEventArgs
 void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
 {
     switch (args.State)
     {
         case TriggeredConnectState.Listening:
             Deployment.Current.Dispatcher.BeginInvoke(() =>
     state.Text = "Listening");
             // 作为主机正在监听等待连接
             break;
         case TriggeredConnectState.PeerFound:
             Deployment.Current.Dispatcher.BeginInvoke(() =>
    state.Text = "PeerFound");
             // 触碰完成
             break;
         case TriggeredConnectState.Connecting:
             // 正在连接
             break;
         case TriggeredConnectState.Completed:
             // 连接完成返回 StreamSocket对象可用于进行收发消息
             _streamSocket = args.Socket;
             break;
         case TriggeredConnectState.Canceled:
             //在完成之前,连接已停止
             break;
         case TriggeredConnectState.Failed:
             // 连接失败
             break;
     }
 }
 private void OnTriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
 {
     switch (args.State)
     {
         case TriggeredConnectState.Listening:
             // Conectando como host
             break;
         case TriggeredConnectState.PeerFound:
             // Conexão Proximity feita
             break;
         case TriggeredConnectState.Connecting:
             // Conectando como cliente
             break;
         case TriggeredConnectState.Completed:
             // Conexão completa
             _streamSocket = args.Socket;
             NavigationService.Navigate(new Uri("/PgeChat.xaml?nome=" + txtNome.Text, UriKind.Relative));
             break;
         case TriggeredConnectState.Canceled:
             MessageBox.Show("Conexão cancelada.");
             break;
         case TriggeredConnectState.Failed:
             MessageBox.Show("Erro ao tentar se conectar.");
             break;
     }
 }
        /// <summary>
        /// Connection state changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        async void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
        {
            if (args.State == TriggeredConnectState.PeerFound)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        txtStatus.Text = "Peer Found";
                    });
            }
            else if (args.State == TriggeredConnectState.Completed)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    txtStatus.Text = "Transferring";
                });

                //Stop broadcasting the connection
                PeerFinder.Stop();
                started = false;

                //Set the socket
                streamSocket = args.Socket;

                //Send the selected ringtone
                conn = new NFCConnection(Deployment.Current.Dispatcher, progressSend, txtStatus);
                await conn.SendSongOverSocket(streamSocket, Session.SharedFile.Name, Session.SharedFile.Name, Session.SharedFile.Size.ToString());

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    NavigationService.GoBack();
                });
            }
        }
        // Handles PeerFinder.TriggeredConnectionStateChanged event
        async private void TriggeredConnectionStateChangedEventHandler(object sender, TriggeredConnectionStateChangedEventArgs eventArgs)
        {
            rootPage.UpdateLog("TriggeredConnectionStateChangedEventHandler - " + Enum.GetName(typeof(ConnectState), (int)eventArgs.State), PeerFinderOutputText);

            if (eventArgs.State == TriggeredConnectState.PeerFound)
            {
                // Use this state to indicate to users that the tap is complete and
                // they can pull their devices away.
                rootPage.NotifyUser("Tap complete, socket connection starting!", NotifyType.StatusMessage);
            }

            if (eventArgs.State == TriggeredConnectState.Completed)
            {
                rootPage.NotifyUser("Socket connect success!", NotifyType.StatusMessage);
                // Start using the socket that just connected.
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    this.PeerFinder_StartSendReceive(eventArgs.Socket, null);
                });
            }

            if (eventArgs.State == TriggeredConnectState.Failed)
            {
                // The socket conenction failed
                rootPage.NotifyUser("Socket connect failed!", NotifyType.ErrorMessage);
            }
        }
 private void OnTriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
 {
     switch (args.State)
     {
         case TriggeredConnectState.Listening:
             // Connecting as host
             break;
         case TriggeredConnectState.PeerFound:
             // Proximity gesture is complete and user can pull their devices away. Remaining work is to
             // establish the connection using a different transport, like TCP/IP or Bluetooth
             break;
         case TriggeredConnectState.Connecting:
             // Connecting as a client
             break;
         case TriggeredConnectState.Completed:
             // Connection completed, retrieve the socket over which to communicate
             _streamSocket = args.Socket;
             NavigationService.Navigate(new Uri("/PgeChat.xaml?nome=" + txtNome.Text, UriKind.Relative));
             break;
         case TriggeredConnectState.Canceled:
             MessageBox.Show("Conexáo cancelada.");
             break;
         case TriggeredConnectState.Failed:
             MessageBox.Show("Erro ao tentar se conectar.");
             break;
     }
 }
Beispiel #6
0
            void TriggeredConnectionStateChanged(
                object sender,
                Windows.Networking.Proximity.TriggeredConnectionStateChangedEventArgs e)
            {
                // THIS METHOD IS NEVER INVOKED, I don't know why yet

                Console.WriteLine("Peer found! " + e.Id);

                if (e.State == Windows.Networking.Proximity.TriggeredConnectState.PeerFound)
                {
                    Console.WriteLine("Peer found. You may now pull your devices out of proximity.\n");
                }
                if (e.State == Windows.Networking.Proximity.TriggeredConnectState.Completed)
                {
                    Console.WriteLine("Connected. You may now send a message.\n");
                }
            }
        private void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
        {
            if (args.State == TriggeredConnectState.PeerFound)
            {
                UpdateStatus("Gerät gefunden! Halte die Geräte noch zusammen, bis die Verbindung aufgebaut wurde.");
            }

            if (args.State == TriggeredConnectState.Completed)
            {
                UpdateStatus("Verbunden!");
                ReceiveImage(args.Socket);
            }

            if (args.State == TriggeredConnectState.Failed || args.State == TriggeredConnectState.Canceled)
            {
                UpdateStatus("Verbindung fehlgeschlagen. Versuche es erneut.");
            }
        }
        private void TriggeredConnectionStateChanged(object sender, Windows.Networking.Proximity.TriggeredConnectionStateChangedEventArgs e)
        {
            if (e.State == Windows.Networking.Proximity.TriggeredConnectState.PeerFound)
            {
                WriteMessageText("Peer found. Keep your devices together until the connection is established.\n");
            }

            if (e.State == Windows.Networking.Proximity.TriggeredConnectState.Completed)
            {
                WriteMessageText("Connected!\n");
                //Note you could cache the socket information for reconnection (making it so you don't have to tap again).
                SendOrReceiveSong(e.Socket);
            }

            //failure to connect
            if (e.State == Windows.Networking.Proximity.TriggeredConnectState.Failed && e.State == Windows.Networking.Proximity.TriggeredConnectState.Canceled)
            {
                WriteMessageText("Failed to connect!  Please try to pair the devices again\n");
            }
        }
        // Used to display state of the connection (i.e. connecting, connected, disconnected) when two PCs are tapped.
        private async void TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs e)
        {
            await messageDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                bool tapIsProcessed = false;
                switch (e.State)
                {
                    case TriggeredConnectState.PeerFound:
                        directions.Visibility = Visibility.Collapsed;
                        nfcStatusText.Visibility = Visibility.Visible;
                        foundPeers.IsEnabled = false;

                        progressBar.Visibility = Visibility.Visible;
                        backButton.Visibility = Visibility.Collapsed;

                        break;
                    case TriggeredConnectState.Completed:
                        // Associate socket handed back by TriggeredConnectionStateChanged event with player connectedPeers.
                        socket = new SocketReaderWriter(e.Socket, this);
                        socket.ReadMessage();
                        socket.WriteMessage(string.Format("{0} {1}", Constants.OpCodeSendDisplayName, PeerFinder.DisplayName));
                        startGameButton.Visibility = Visibility.Visible;
                        tapIsProcessed = true;

                        break;
                    case TriggeredConnectState.Failed:
                        tapIsProcessed = true;
                        
                        break;
                }

                // Reset UI
                if (tapIsProcessed)
                {
                    nfcStatusText.Visibility = Visibility.Collapsed;
                    foundPeers.IsEnabled = true;

                    lock (availablePeers)
                    {
                        if (availablePeers.Count > 0)
                        {
                            directions.Visibility = Visibility.Visible;
                        }
                    }

                    // Progress bar should be visible as long as PeerWatcher is running
                    progressBar.Visibility = Visibility.Collapsed;
                    if (peerWatcher != null)
                    {
                        PeerWatcherStatus status = peerWatcher.Status;
                        if (status == PeerWatcherStatus.EnumerationCompleted || status == PeerWatcherStatus.Started)
                        {
                            progressBar.Visibility = Visibility.Visible;
                        }
                    }
                }
            });
        }
        void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
        {

            if (args.State == TriggeredConnectState.Failed)
            {
                txtBTStatus.Text = "Failed to Connect... Try again!";
                BTStatus = "no"; 
                return;
            }

            if (args.State == TriggeredConnectState.Completed)
            {
                txtBTStatus.Text = "Connected!";
                BTStatus = "yes";
                MessageBox.Show("hi");
            }
        }
 private void PeerFinderTriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
 {
   if (connectMode == ConnectMethod.Tap)
   {
     switch (args.State)
     {
       case TriggeredConnectState.Completed: // Connection completed, get the socket
         DoConnect(args.Socket);
         break;
       default:
         FireConnectionStatusChanged(args.State);
         break;
     }
   }
 }
Beispiel #12
0
 private async void TriggeredConnectionStateChangedEventHandler(object sender, TriggeredConnectionStateChangedEventArgs e)
 {
     switch (e.State)
     {
         case TriggeredConnectState.PeerFound:
             // Use this state to indicate to users that the tap is complete and
             // they can pull their devices away.
             //this.NotifyUser("Tap complete, socket connection starting!", NotifyType.StatusMessage);
             break;
         case TriggeredConnectState.Completed:
             this.NotifyUser("Socket connect success!", NotifyType.StatusMessage);
             // Start using the socket that just connected.
             await proximityDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
                 this.PeerFinder_StartSendReceive(e.Socket);
             });
             break;
         case TriggeredConnectState.Failed:
             this.NotifyUser("Socket connect failed!", NotifyType.ErrorMessage);
             break;
         default:
             this.NotifyUser("TriggeredConnectionStateChangedEventHandler - " + rgConnectState[(int)e.State], NotifyType.PeerMessage);
             break;
     }
 }
        /// <summary>
        /// Connection state changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        async void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
        {
            try
            {
                if (args.State == TriggeredConnectState.PeerFound)
                {
                    //Display a status message
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        txtStatus.Text = "Peer Found!";
                    });
                }
                else if (args.State == TriggeredConnectState.Completed)
                {
                    //Display a status message
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        txtStatus.Text = "Receiving File...";
                    });

                    //Set the socket
                    streamSocket = args.Socket;

                    //Start receiving the song
                    conn = new NFCConnection(Deployment.Current.Dispatcher, progressReceive, txtFile);
                    await conn.ReceiveSongFromSocket(streamSocket);


                    //Navigate to the home page
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        NavigationService.Navigate(new Uri("/BrowsePage.xaml", UriKind.Relative));
                    });
                }
            }
            catch (Exception ex)
            {
                string error = ex.Message;
                MessageBox.Show(ex.Message);
            }

        }
        private void OnTriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
        {
            switch (args.State)
            {
                //listening as host
                case TriggeredConnectState.Listening:
                    {
                        UpdateInformation("Waiting...\n");
                        break;
                    }
                // Proximity gesture is complete and user can pull their devices away. Remaining work is to 
                // establish the connection using a different transport, like TCP/IP or Bluetooth
                case TriggeredConnectState.PeerFound:
                    {
                        UpdateInformation("Compatible device found!\n");
                        break;
                    }
                // Connecting as a client
                case TriggeredConnectState.Connecting:
                    {
                        UpdateInformation("Connecting...\n");
                        break;
                    }
                // Connection completed, retrieve the socket over which to communicate
                case TriggeredConnectState.Completed:
                    {
                        //PeerFinder.Stop();
                        UpdateInformation("Connection complete!  Transferring item now...  \nWhen your friend sees the item on their device you may press the Back button and end the share.");
                        streamSocket = args.Socket;
                        storedRemoteHostRawName = args.Socket.Information.RemoteHostName.RawName;
                        storedRemoteServiceName = args.Socket.Information.RemoteServiceName;

                        //If the device is the host, send over data
                        if (IsHost)
                        {
                            //now share the actual data
                            SendData();
                        }
                        else //otherwise, don't push any data and wait to receive it
                        {
                            long ID = Device.SubscribeForMessage("Windows.DnD35", MessageReceived);
#if DEBUG
                            Debug.WriteLine("message ID: " + ID);
#endif
                        }
                        UpdateInformation("Transfer completed.  You can go back to your Entry now by pressing the Back button.");
                        break;
                    }
                case TriggeredConnectState.Canceled:
                    {
                        break;
                    }
                //Connection was unsuccessful
                case TriggeredConnectState.Failed:
                    {
                        UpdateInformation("Failed to connect to another device. \n");
                        //if the user wants to, try again
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {

                            CustomMessageBox messageBox = new CustomMessageBox()
                            {
                                Caption = "NFC Error.",
                                Message = "There was an issue connecting to another Device.  Try again?",
                                LeftButtonContent = "Yes",
                                RightButtonContent = "Nope",
                            };
                            messageBox.Dismissed += (s1, e1) =>
                            {
                                switch (e1.Result)
                                {
                                    case CustomMessageBoxResult.LeftButton:
                                        {
                                            if (streamSocket != null)
                                            {
                                                RetryConnection(streamSocket);
                                            }
                                            else
                                            {
                                                Share();
                                            }
                                            break;
                                        }
                                    case CustomMessageBoxResult.RightButton:
                                        {
                                            PeerFinder.Stop();
                                            this.Dispose();
                                            break;
                                        }
                                    case CustomMessageBoxResult.None:
                                        {
                                            PeerFinder.Stop();
                                            this.Dispose();
                                            break;
                                        }
                                    default:
                                        {
                                            PeerFinder.Stop();
                                            this.Dispose();
                                            break;
                                        }
                                }
                            };
                        });
                        break;
                    }
            }
        }
Beispiel #15
0
 private void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
 {
     switch (args.State)
     {
         case TriggeredConnectState.Listening:
             // Connecting as host
             this.viewModel.Status = "Eröffne Session...";
             break;
         case TriggeredConnectState.Connecting:
             // Connecting as a client
             this.viewModel.Status = "Verbindungsaufbau...";
             break;
         case TriggeredConnectState.PeerFound:
             // Proximity gesture is complete and user can pull their devices away. Remaining work is to 
             // establish the connection using a different transport, like TCP/IP or Bluetooth
             this.viewModel.Status = "Session gefunden, versuche zu verbinden...";
             break;
         case TriggeredConnectState.Completed:
             // Connection completed, retrieve the socket over which to communicate
             this.viewModel.Status = "Verbunden";
             this.HandleConnection(args.Socket);
             break;
         case TriggeredConnectState.Canceled:
             this.viewModel.Status = "Verbindung abgebrochen";
             this.viewModel.Connected = false;
             break;
         case TriggeredConnectState.Failed:
             // Connection was unsuccessful
             this.viewModel.Status = "Fehler bei der Verbindung";
             this.viewModel.Connected = false;
             break;
     }
 }
        void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
        {
            // This will be used to Get Data from our Hardware soon

            if (args.State == TriggeredConnectState.Failed)
            {
                txtBTStatus.Text = "Failed to Connect... Try again!";
                BTStatus = "no"; // Not connected
                return;
            }

            if (args.State == TriggeredConnectState.Completed)
            {
                txtBTStatus.Text = "Connected!";
                BTStatus = "yes"; // Means we are connected
                MessageBox.Show("hi");
            }
        }
        void TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs e)
        {
            switch (e.State)
            {
                case TriggeredConnectState.Canceled:
                    UpdateConnectionStatus(ConnectionStatus.Canceled);
                    break;
                case TriggeredConnectState.Completed:
                    StartSendReceive(e.Socket);
                    UpdateConnectionStatus(ConnectionStatus.Completed);

                    // Stop advertising since we have connected
                    PeerFinder.Stop();
                    _peerFinderStarted = false;
                    break;
                case TriggeredConnectState.Connecting:
                    UpdateConnectionStatus(ConnectionStatus.Connecting);
                    break;
                case TriggeredConnectState.Failed:
                    UpdateConnectionStatus(ConnectionStatus.Failed);
                    break;
                case TriggeredConnectState.Listening:
                    break;
                case TriggeredConnectState.PeerFound:
                    UpdateConnectionStatus(ConnectionStatus.PeerFound);
                    break;
                default:
                    break;
            }

        }
Beispiel #18
0
 //Used to display state of the connection (i.e. connecting, connected, disconnected) when two PCs are tapped        
 private async void TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs e)
 {
     if (e.State == TriggeredConnectState.PeerFound)
     {
         await messageDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
         {
             progressBar.Visibility = Visibility.Collapsed;
             ReceivedInvitationsHeader.Visibility = Visibility.Collapsed;
             receivedInvitations.Visibility = Visibility.Collapsed;
             backButton.Visibility = Visibility.Collapsed;
             
             tapProgressBar.Visibility = Visibility.Visible;
             tapConnectStatus.Text = "Connecting to Host...";
         });
     }
     else if (e.State == TriggeredConnectState.Completed)
     {
         try
         {
             await messageDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
                 StreamSocket socket = e.Socket;
                 tapConnectStatus.Text = "Connected!";
                 tapProgressBar.Visibility = Visibility.Collapsed;
                 WaitForHost(socket);
             });
         }
         catch (Exception)
         {
             tapConnectStatus.Text = "Cannot connect";
             tapProgressBar.Visibility = Visibility.Collapsed;
             PeerFinder.Stop();
             backButton.Visibility = Visibility.Visible;
         }
     }
     else if (e.State == TriggeredConnectState.Failed)
     {
         await messageDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
         {
             tapConnectStatus.Text = "Cannot connect";
             PeerFinder.Stop();
             backButton.Visibility = Visibility.Visible;
             tapProgressBar.Visibility = Visibility.Collapsed;
         });
     }
     
 }
Beispiel #19
0
        /// <summary>
        /// Event handler to be executed when PeerFinder's TriggeredConnectionStateChanged fires.
        /// </summary>
        private void TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs e)
        {
            switch (e.State)
            {
                case TriggeredConnectState.PeerFound: System.Diagnostics.Debug.WriteLine("PeerFound");
                    {
                        if (Connecting != null)
                        {
                            Connecting();
                        }
                    }
                    break;

                case TriggeredConnectState.Connecting: System.Diagnostics.Debug.WriteLine("Connecting");
                    {
                        _status = ConnectionStatusValue.Connecting;
                    }
                    break;

                case TriggeredConnectState.Listening: System.Diagnostics.Debug.WriteLine("Listening");
                    {
                        _status = ConnectionStatusValue.Listening;
                    }
                    break;

                case TriggeredConnectState.Completed: System.Diagnostics.Debug.WriteLine("Completed");
                    {
                        PeerFinder.TriggeredConnectionStateChanged -= TriggeredConnectionStateChanged;
                        PeerFinder.ConnectionRequested -= ConnectionRequested;
                        
                        _socket = e.Socket;

                        _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();
                        }
                    }
                    break;

                case TriggeredConnectState.Canceled: System.Diagnostics.Debug.WriteLine("Canceled");
                    {
                        if (ConnectivityProblem != null)
                        {
                            ConnectivityProblem();
                        }
                    }
                    break;

                case TriggeredConnectState.Failed: System.Diagnostics.Debug.WriteLine("Failed");
                    {
                        if (ConnectivityProblem != null)
                        {
                            ConnectivityProblem();
                        }
                    }
                    break;
            }
        }
        private async void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
        {
            await this.textboxDebug.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
            () =>
            {
                this.textboxDebug.Text += "Connection State Changed\n";
            });

        }