Example #1
0
        private void PublishLaunchApp()
        {
            proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

            if (proximityDevice != null)
            {
                // The format of the app launch string is: "<args>\tWindows\t<AppName>".
                // The string is tab or null delimited.

                // The <args> string must have at least one character.
                string launchArgs = "user=default";

                // The format of the AppName is: PackageFamilyName!PRAID.
                string praid = "MyAppId"; // The Application Id value from your package.appxmanifest.

                string appName = Windows.ApplicationModel.Package.Current.Id.FamilyName + "!" + praid;

                string launchAppMessage = launchArgs + "\tWindows\t" + appName;

                var dataWriter = new Windows.Storage.Streams.DataWriter();
                dataWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE;
                dataWriter.WriteString(launchAppMessage);
                var launchAppPubId =
                    proximityDevice.PublishBinaryMessage(
                        "LaunchApp:WriteTag", dataWriter.DetachBuffer());
            }
        }
        private async void CompleteFriendshipNFC(Windows.Networking.Proximity.ProximityDevice sender, Windows.Networking.Proximity.ProximityMessage message)
        {
            // Stop subscribing to the message. This means the other user finished sending a friend request
            AppServices.myProximityDevice.StopSubscribingForMessage(this.subscribedMessageID);
            this.subscribedMessageID = -1;

            // Stop publishing friend request sent message as the user has already processed it
            AppServices.myProximityDevice.StopPublishingMessage(this.publishedMessageID);
            this.publishedMessageID = -1;

            // Other user accepted our friend request successfully so we add them to our list and save the encryption key
            if (message.DataAsString.Equals("true"))
            {
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    AppServices.friendsData.friendsList.Add(new Tap_Chat.ViewModel.FriendsListEntry()
                    {
                        encryptedUsername = this.nfcFriendName, isOnline = true, encryptionKey = AppServices.encryptionAlgorithim.CreateSymmetricKey(keyBuff)
                    });
                    this.EndAsyncOperationsSuccess();
                    this.PrintMessage("Added Friend Successfully!");
                });
            }
            // Other user failed to accept our friend request so we print out a message and end
            else
            {
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // Even though the add failed we call success to remove the progress indicator and enable input
                    this.EndAsyncOperationsSuccess();
                    this.PrintMessage("Other user had an error. Add friend failed");
                });
            }
        }
Example #3
0
        private void ReceiveEncryptionKey(Windows.Networking.Proximity.ProximityDevice sender, Windows.Networking.Proximity.ProximityMessage message)
        {
            string keyString = message.DataAsString;

            this.keyBuff = CryptographicBuffer.DecodeFromHexString(keyString);
            lastSelected.encryptionKey = AppServices.encryptionAlgorithim.CreateSymmetricKey(this.keyBuff);
            this.PrintMessageAsync("Secure connection established! You may now separate your devices.");
        }
        private void initializeProximitySample()
        {
            proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

            if (proximityDevice == null)
            {
                WriteMessageText("Failed to initialized proximity device.\n" +
                                 "Your device may not have proximity hardware.");
            }
        }
        private void ProximityDeviceArrived(Windows.Networking.Proximity.ProximityDevice device)
        {
            string strCmdText;

            strCmdText = "/k python ";
            Debug.WriteLine("Proximity device arrived.\n");
            //System.Diagnostics.Process.Start("CMD.exe", strCmdText);
            //Button_Click(null,null);
            //var result = task.WaitAndUnwrapException();
            //DefaultLaunch("http://172.20.10.4:12345/");
            DefaultLaunch("http://google.com");
        }
Example #6
0
        public MainPage()
        {
            InitializeComponent();

            proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

            if (proximityDevice != null)
            {
                proximityDevice.DeviceArrived  += ProximityDeviceArrived;
                proximityDevice.DeviceDeparted += ProximityDeviceDeparted;
            }
            else
            {
                MessageTextBlock.Text += "Failed to initialize proximity device.\n";
            }
        }
Example #7
0
        private void InitializeProximityDevice()
        {
            proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

            if (proximityDevice != null)
            {
                proximityDevice.DeviceArrived  += ProximityDeviceArrived;
                proximityDevice.DeviceDeparted += ProximityDeviceDeparted;

                WriteMessageText("Proximity device initialized.\n");
            }
            else
            {
                WriteMessageText("Failed to initialized proximity device.\n");
            }
        }
Example #8
0
        private void initializeProximityDevice()
        {
            proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

            if (proximityDevice != null)
            {
                PublishMessageButton.Click            += PublishMessage;
                SubscribeForMessageButton.Click       += SubscribeForMessage;
                StopSubscribingForMessageButton.Click += StopSubscribingForMessage;
                StopPublishingMessageButton.Click     += StopPublishingMessage;
            }
            else
            {
                WriteMessageText("Failed to initialized proximity device.\n");
            }
        }
        private void InitializeProximityDevice()
        {
            proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

            if (proximityDevice != null)
            {
                proximityDevice.DeviceArrived  += ProximityDeviceArrived;
                proximityDevice.DeviceDeparted += ProximityDeviceDeparted;
                wv.Navigate(new Uri("about:blank"));

                Debug.WriteLine("Proximity device initialized.\n");
            }
            else
            {
                Debug.WriteLine("Failed to initialized proximity device.\n");
            }
        }
Example #10
0
        private async void InitializeProximity()
        {
            string selectorString = Windows.Networking.Proximity.ProximityDevice.GetDeviceSelector();

            var deviceInfoCollection =
                await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(selectorString, null);

            if (deviceInfoCollection.Count == 0)
            {
                StatusTextBlock.Text = "No proximity devices found.";
            }
            else
            {
                StatusTextBlock.Text = "Proximity Device id = " + deviceInfoCollection[0].Id;
                proximityDevice      =
                    Windows.Networking.Proximity.ProximityDevice.FromId(deviceInfoCollection[0].Id);
            }
        }
        private async void AcceptFriendRequestNFC(Windows.Networking.Proximity.ProximityDevice sender, Windows.Networking.Proximity.ProximityMessage message)
        {
            // Stop subscribing to the message. This means the other user finished sending a friend request
            AppServices.myProximityDevice.StopSubscribingForMessage(this.subscribedMessageID);
            this.subscribedMessageID = -1;

            // Other user successfully sent friend request (message is not "false"), so we receive the generated encryption key
            if (message.DataAsString.Equals("false") == false)
            {
                // Accept the friend request
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    this.StartAsyncOperations("Accepting friend request...");
                });

                AppServices.operationComplete = false;
                AppServices.buddyService.AcceptFriendRequest(AppServices.localUsernameEncrypted, this.nfcFriendName, new AcceptRequestCallback());

                //await Task.Run(() =>
                //{
                while (AppServices.operationComplete == false)
                {
                    ;
                }
                //});

                // Unable to accept friend request. Error out and tell the other user
                if (AppServices.operationSuccessful == false)
                {
                    this.publishedMessageID = AppServices.myProximityDevice.PublishMessage(this.friendRequestCompleteNFCMessageType, "false");
                    await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        this.EndAsyncOperationsError();
                    });

                    return;
                }

                // Accepted friend request successfully. Tell the other user and add them to our friends list
                this.publishedMessageID = AppServices.myProximityDevice.PublishMessage(this.friendRequestCompleteNFCMessageType, "true");
                this.newEncryptionKey   = message.DataAsString;
                IBuffer keyBuff = CryptographicBuffer.DecodeFromHexString(this.newEncryptionKey);
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    AppServices.friendsData.friendsList.Add(new Tap_Chat.ViewModel.FriendsListEntry()
                    {
                        encryptedUsername = this.nfcFriendName, isOnline = true, encryptionKey = AppServices.encryptionAlgorithim.CreateSymmetricKey(keyBuff)
                    });
                    this.EndAsyncOperationsSuccess();
                    this.PrintMessage("Added Friend Successfully!");
                });
            }
            // Other user had an issue sending a request so we print a message and end
            else
            {
                // We ended in success but the other user had an error so we hide the progress indicator and print a different message
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    this.EndAsyncOperationsSuccess();
                });

                this.PrintMessageAsync("Other user had an error. Unable to add friend.");
                return;
            }
        }
        private async void ReceiveUsernameNFC(Windows.Networking.Proximity.ProximityDevice device, Windows.Networking.Proximity.ProximityMessage message)
        {
            // Once a message is received stop subscribing for it
            AppServices.myProximityDevice.StopSubscribingForMessage(this.subscribedMessageID);
            this.subscribedMessageID = -1;

            // Check to see who's username is greater. The one with the greater username sends the request and generates a key
            int compareResult = string.Compare(AppServices.localUsernameEncrypted, message.DataAsString);

            this.nfcFriendName = message.DataAsString;

            // I must send friend request using the App42 API
            if (compareResult > 0)
            {
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    this.StartAsyncOperations("Establishing friendship...");
                });

                AppServices.operationComplete = false;
                AppServices.buddyService.SendFriendRequest(AppServices.localUsernameEncrypted, message.DataAsString, "Friend Request", new FriendRequestCallback());

                //await Task.Run(() =>
                //{
                while (AppServices.operationComplete == false)
                {
                    ;
                }
                //});

                // Once the friend request is sent completely we stop publishing our name
                AppServices.myProximityDevice.StopPublishingMessage(this.publishedMessageID);
                this.publishedMessageID = -1;

                // If sending the request failed we notify the other user
                if (AppServices.operationSuccessful == false)
                {
                    this.publishedMessageID = AppServices.myProximityDevice.PublishMessage(this.friendRequestSentNFCMessageType, "false");
                    await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        this.EndAsyncOperationsError();
                    });

                    return;
                }
                // The send was successful so we tell the other user our encryption key and now wait for them to accept and notify us
                keyBuff = CryptographicBuffer.GenerateRandom(256);
                this.newEncryptionKey    = CryptographicBuffer.EncodeToHexString(keyBuff);
                this.publishedMessageID  = AppServices.myProximityDevice.PublishMessage(this.friendRequestSentNFCMessageType, this.newEncryptionKey);
                this.subscribedMessageID = AppServices.myProximityDevice.SubscribeForMessage(this.friendRequestCompleteNFCMessageType, CompleteFriendshipNFC);
            }
            // I must wait for a friend request from the other user using the App42 API
            else
            {
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    this.StartAsyncOperations("Waiting for friendship data...");
                });

                this.subscribedMessageID = AppServices.myProximityDevice.SubscribeForMessage(this.friendRequestSentNFCMessageType, AcceptFriendRequestNFC);
                AppServices.myProximityDevice.StopPublishingMessage(this.publishedMessageID);
                this.publishedMessageID = -1;
            }
        }
Example #13
0
 private void ProximityDeviceDeparted(Windows.Networking.Proximity.ProximityDevice device)
 {
     WriteMessageText("Proximate device departed. id = " + device.DeviceId + "\n");
 }
 private void messageReceived(Windows.Networking.Proximity.ProximityDevice device,
                              Windows.Networking.Proximity.ProximityMessage message)
 {
     WriteMessageText("Message received: " + message.DataAsString + "\n");
 }
 private bool NFCIsSupportedOnDevice()
 {
     Device = Windows.Networking.Proximity.ProximityDevice.GetDefault();
     if (Device != null)
     {
         return true;
     }
     else
     {
         System.Windows.MessageBox.Show("Uh-oh!  NFC does not seem to be supported or turned on for this device!  \n\n You can turn it on in Settings if your phone supports it.");
         return false;
     }
 }
Example #16
0
 private void proximityWriteTagLaunchAppMessageTransmitCallback(
     Windows.Networking.Proximity.ProximityDevice sender,
     long messageId)
 {
     // The LaunchApp message has been successfully written to a tag.
 }
 private void UriTransmitted(
     Windows.Networking.Proximity.ProximityDevice sender,
     long messageId)
 {
     // The Uri has been successfully transmitted.
 }
Example #18
0
 private void MessagePublished(
     Windows.Networking.Proximity.ProximityDevice sender,
     long messageId)
 {
     // The message has been successfully published.
 }
Example #19
0
 private void messageReceived(
     Windows.Networking.Proximity.ProximityDevice device,
     Windows.Networking.Proximity.ProximityMessage message)
 {
     MessageBlock.Text += "Message received: " + message.DataAsString + "\n";
 }
Example #20
0
 private void ProximityDeviceDeparted(Windows.Networking.Proximity.ProximityDevice device)
 {
     Debug.WriteLine("Proximate device departed. id = " + device.DeviceId + "\n");
 }