PublishBinaryMessage() private method

private PublishBinaryMessage ( [ messageType, [ message ) : long
messageType [
message [
return long
        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 can be an empty string ("").
                string launchArgs = "user=default";

                // The format of the AppName is: PackageFamilyName!PRAID.
                string praid = "{b8c21b6b-2f16-49f6-9ee9-b3a713c54500}"; // 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 void OnWriteableTagArrived(ProximityDevice sender, ProximityMessage message)
       {
    
           var dataWriter = new DataWriter();
           dataWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE;
           string appLauncher = string.Format(@"mywaiter:MainPage?source=3");
 
           dataWriter.WriteString(appLauncher);
           pubId = sender.PublishBinaryMessage("WindowsUri:WriteTag", dataWriter.DetachBuffer());
   
       }
        public void PingAdversary(ProximityDevice device, NotifyNfcReady notify)
        {
            if (subscribeId != -1)
            {
                proximityDevice.StopSubscribingForMessage(subscribeId);
                subscribeId = -1;
            }

            if (publishId != -1)
            {
                proximityDevice.StopPublishingMessage(publishId);
                publishId = -1;
            }

            if (state == NfcManager.ProtoState.Busy)
            {
                return;
            }

            state = NfcManager.ProtoState.NotReady;
            notifyReady = notify;
            initialMessage.devicetime = random.NextDouble();
            MemoryStream stream = new MemoryStream();
            DataContractSerializer serializer = new DataContractSerializer(initialMessage.GetType());
            serializer.WriteObject(stream, initialMessage);
            stream.Position = 0;
            var dataWriter = new DataWriter();
            dataWriter.WriteBytes(stream.GetBuffer());
            proximityDevice = device;
            publishId = proximityDevice.PublishBinaryMessage("Windows.CarTrumps", dataWriter.DetachBuffer());
            subscribeId = proximityDevice.SubscribeForMessage("Windows.CarTrumps", OnMessageReceived);
        }
        private void OnWriteableTagArrived(ProximityDevice sender, ProximityMessage message)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    try
                    {
                        if (
                            MessageBox.Show("Are you sure you want to write to this NFC Tag?", "Confirmation",
                                            MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                        {
                            var dataWriter = new DataWriter();
                            dataWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE;
                            string appLauncher = string.Format(@"zVirtualScenes:MainPage?action=scene&id={0}",
                                                               SelectedScene.id);
                            dataWriter.WriteString(appLauncher);
                            pubId = sender.PublishBinaryMessage("WindowsUri:WriteTag", dataWriter.DetachBuffer());
                            MessageBox.Show("Completed writing to the tag.");

                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Could not write to the tag.  Reason:" + e.Message);
                    }
                    finally
                    {
                        _proximityDevice.StopSubscribingForMessage(subid);
                    }

                });
        }
        /// <summary>
        /// Function to handle the chunk message and push the NFC message to proximity device.
        /// </summary>
        /// <param name="proximityDevice">ProximityDevice instance to be used.</param>
        /// <param name="chuckData">IBuffer to chunk message.</param>
        private static async Task NfcMessageHandlerAsync(ProximityDevice proximityDevice, IBuffer chuckData, CancellationToken ct)
        {
            using (var publishedEvent = new AutoResetEvent(false))
            {
                long publishedMessageId = INVALID_PUBLISHED_MESSAGE_ID;

                publishedMessageId = proximityDevice.PublishBinaryMessage(
                    NFC_PROV_MESSAGE_PROTOCOL_NAME,
                    chuckData, (
                        Windows.Networking.Proximity.ProximityDevice device,
                        long messageId
                    ) =>
                    {
                        publishedEvent.Set();
                    });

                if (INVALID_PUBLISHED_MESSAGE_ID == publishedMessageId)
                {
                    throw new System.ArgumentException("Published message ID returned was invalid.");
                }

                // Wait for the event to be signaled on a threadpool thread so we don't block the UI thread.
                await Task.Run(() =>
                {
                    // Wait for the message transmitted handler to ensure the NFC message has been processed internally.
                    WaitHandle.WaitAny(new WaitHandle[] { publishedEvent, ct.WaitHandle });
                    ct.ThrowIfCancellationRequested();
                });
            }
        }
        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);
                publishedUriId =
                    proximityDevice.PublishBinaryMessage(
                        "NDEF:WriteTag", dataWriter.DetachBuffer(), proximityWriteTagLaunchAppMessageTransmitCallback);
            }
        }
Beispiel #7
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 can be an empty string ("").
                string launchArgs = "user=default";

                // The format of the AppName is: PackageFamilyName!PRAID.
                string praid = "{b8c21b6b-2f16-49f6-9ee9-b3a713c54500}"; // 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());
            }
        }