Beispiel #1
0
        private void PeerFinderTriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
        {
            switch (args.State)
            {
            case TriggeredConnectState.Connecting:
            case TriggeredConnectState.PeerFound:
                this.RouteToUiThread(
                    () =>
                {
                    this.IsConnecting  = true;
                    this.ConnectedPeer = "Tap complete, opening socket.";
                });
                break;

            case TriggeredConnectState.Completed:
                this.RouteToUiThread(
                    () =>
                {
                    this.IsConnecting = false;
                });
                this.InitializeSocket(args.Socket);
                break;

            default:
                if (args.State != TriggeredConnectState.Listening)
                {
                    this.RouteToUiThread(
                        () =>
                    {
                        this.ErrorMessage = string.Format("Issue connecting to tap socket: {0}", args.State);
                    });
                }
                break;
            }
        }
        void TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs e)
        {
            switch (e.State)
            {
            case TriggeredConnectState.PeerFound:
                UpdateConnectionStatus(ConnectionStatus.PeerFound);
                break;

            case TriggeredConnectState.Canceled:
                UpdateConnectionStatus(ConnectionStatus.Canceled);
                break;

            case TriggeredConnectState.Failed:
                UpdateConnectionStatus(ConnectionStatus.Failed);
                break;

            case TriggeredConnectState.Completed:
                StartSendReceive(e.Socket);
                UpdateConnectionStatus(ConnectionStatus.Completed);

                // Stop advertising since we have connected
                PeerFinder.Stop();
                _peerFinderStarted = false;
                break;
            }
        }
Beispiel #3
0
        private void TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
        {
            switch (args.State)
            {
            case TriggeredConnectState.PeerFound:       // Tapped another phone
                LogMessage("Peer found");
                break;

            case TriggeredConnectState.Connecting:
                LogMessage("Connecting to peer");
                break;

            case TriggeredConnectState.Failed:
                LogMessage("Connection failed");
                break;

            case TriggeredConnectState.Completed:       // Connection ready to use
                // Save socket to fields
                socket     = args.Socket;
                dataWriter = new DataWriter(socket.OutputStream);
                dataReader = new DataReader(socket.InputStream);
                // Listen to incoming socket
                LogMessage("Connected, ready to play!");
                HandShake();
                break;
            }
        }
Beispiel #4
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)
        {
            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;
                        }
                    }
                }
            });
        }
 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";
     });
 }
Beispiel #6
0
 private void TriggeredConnectionStateChanged(
     object sender,
     TriggeredConnectionStateChangedEventArgs e)
 {
     if (e.State == TriggeredConnectState.PeerFound)
     {
         WriteMessageText("Gerät in Reichweite gefunden.\n");
     }
     if (e.State == TriggeredConnectState.Completed)
     {
         Connected(e.Socket);
     }
 }
Beispiel #7
0
 private void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
 {
     if (args.State == TriggeredConnectState.PeerFound)
     {
         proximityDevice = ProximityDevice.GetDefault();
         var message = new NdefMessage {
             new NdefUriRecord {
                 Uri = "tracktimer:addFriend?" + App.MobileService.CurrentUser.UserId
             }
         };
         proximityDevice.PublishBinaryMessage("NDEF", message.ToByteArray().AsBuffer(), MessageWrittenHandler);
     }
 }
        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 #9
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 #10
0
        private void TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
        {
            switch (args.State)
            {
            case TriggeredConnectState.PeerFound:       // Tapped another phone
                break;

            case TriggeredConnectState.Connecting:
                break;

            case TriggeredConnectState.Completed:       // Connection ready to use
                // Save socket to fields
                socket = args.Socket;
                nfcService.PublishTextMessage(NFC_IBCS_ACK, (string)settingsService.Get("email"));
                // Listen to incoming socket
                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");
            }
        }
Beispiel #12
0
        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!");
                TransferImage(args.Socket);
            }

            if (args.State == TriggeredConnectState.Failed || args.State == TriggeredConnectState.Canceled)
            {
                UpdateStatus("Verbindung fehlgeschlagen. Versuche es erneut.");
            }
        }
        private void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
        {
            switch (args.State)
            {
            case TriggeredConnectState.Completed:
                ReceiveData(args.Socket).Wait();
                break;

            case TriggeredConnectState.Canceled:
                PeerFinder.Stop();
                PeerFinder.Start();
                break;

            case TriggeredConnectState.Failed:
                PeerFinder.Stop();
                PeerFinder.Start();
                break;

            default:
                break;
            }
        }
Beispiel #14
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;
            }
        }
Beispiel #15
0
        void PeerFinder_TriggeredConnectionStateChanged(object sender, TriggeredConnectionStateChangedEventArgs args)
        {
            switch (args.State)
            {
            case TriggeredConnectState.Connecting:
                break;

            case TriggeredConnectState.Completed:
                writer = new DataWriter(args.Socket.OutputStream);
                SendInfo(pInformation);
                break;

            case TriggeredConnectState.Canceled:
                PeerFinder.Stop();
                PeerFinder.Start();
                break;

            case TriggeredConnectState.Failed:
                PeerFinder.Stop();
                PeerFinder.Start();
                break;
            }
        }
Beispiel #16
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;
            }
        }
        // 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);
            }
        }
Beispiel #18
0
 private static void PeerFinder_TriggeredConnectionStateChanged(object sender,
                                                                TriggeredConnectionStateChangedEventArgs args)
 {
     var s = args;
 }