NFC.xaml.cs CampusAppWP8::Pages::Dev::NFC CampusAppWP8::Pages::Dev System::Runtime::InteropServices::WindowsRuntime Windows::Networking::Proximity //----------------------------------------------------------------------- //<copyrightfile="NFC.xaml.cs"company="BTU/IIT"> //Companycopyrighttag. //</copyright> //<author>stubbfel</author> //<sience>08.08.2013</sience> //---------------------------------------------------------------------- namespaceCampusAppWP8.Pages.Dev { usingSystem; usingSystem.Collections.Generic; usingSystem.Runtime.InteropServices.WindowsRuntime; usingSystem.Windows; usingSystem.Windows.Navigation; usingCampusAppWP8.Model.Campusmap; usingCampusAppWP8.Model.GeoDb; usingCampusAppWP8.Utility.NDEF; usingMicrosoft.Phone.Controls; usingWindows.Networking.Proximity; publicpartialclassNFC:PhoneApplicationPage { #regionMember privatereadonlyProximityDevicedevice=ProximityDevice.GetDefault(); privateintactNDEFIndex; privateList<NDEFMessage>ndefList; #endregion #regionConstructor publicNFC() { this.InitializeComponent(); this.ndefList=newList<NDEFMessage>(); MapModelmap=newCBMainMapModel(); foreach(PlaceModelplaceinmap.Spatial.Places) { this.ndefList.Add(newNDEFMessage(place.ToNfcString(),NDEFMessage.TYPEVAL.TEXT)); } this.actNDEFIndex=0; } #endregion #regionMethod #regionprotected protectedoverridevoidOnNavigatedTo(NavigationEventArgse) { base.OnNavigatedTo(e); this.Writecontent.Text=this.ndefList[this.actNDEFIndex].GetContent(); } #endregion #regionprivate privatevoidPublishHandler(ProximityDevicesender,longmessageId) { this.device.StopPublishingMessage(messageId); this.Dispatcher.BeginInvoke(newAction(()=>MessageBox.Show("Writed:"+this.actNDEFIndex))); } privatevoidNDEFHandler(ProximityDevicesender,ProximityMessagemessage) { this.device.StopSubscribingForMessage(message.SubscriptionId); varndefMessage=message.Data; byte[]testa=ndefMessage.ToArray(); NDEFMessagendef=newNDEFMessage(testa); this.Dispatcher.BeginInvoke(newAction(()=>MessageBox.Show(ndef.GetContent()))); } privatevoidRead_Click(objectsender,RoutedEventArgse) { this.device.SubscribeForMessage("NDEF",this.NDEFHandler); } privatevoidNext_Click(objectsender,RoutedEventArgse) { if(this.actNDEFIndex<this.ndefList.Count-1) { this.actNDEFIndex++; this.Writecontent.Text=this.ndefList[this.actNDEFIndex].GetContent(); } } privatevoidPrev_Click(objectsender,RoutedEventArgse) { if(this.actNDEFIndex>0) { this.actNDEFIndex--; this.Writecontent.Text=this.ndefList[this.actNDEFIndex].GetContent(); } } privatevoidWrite_Click(objectsender,RoutedEventArgse) { this.device.PublishBinaryMessage("NDEF:WriteTag",this.ndefList[this.actNDEFIndex].ToByteArray().AsBuffer(),this.PublishHandler); } #endregion #endregion } }