diff --git a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj
index f705103d..c40749c8 100644
--- a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj
+++ b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj
@@ -116,9 +116,15 @@
+
+
+
+
+ NFC.xaml
+
AppSettingPage.xaml
@@ -282,6 +288,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
@@ -435,7 +445,9 @@
-
+
+ Designer
+
diff --git a/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceModel.cs b/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceModel.cs
index 876a7701..0a2ed4c2 100644
--- a/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceModel.cs
+++ b/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceModel.cs
@@ -83,5 +83,14 @@ namespace CampusAppWP8.Model.GeoDb
/// The services.
[XmlElement("placeService")]
public ObservableCollection Services { get; set; }
+
+ /// Converts this object to a nfc string.
+ /// Stubbfel, 21.08.2013.
+ /// This object as a string.
+ public string ToNfcString()
+ {
+ string nfcStr = "{\"pid\":\"" + this.PlaceId + "\",\"parent\":\"" + this.ParentId + "\"}";
+ return nfcStr;
+ }
}
}
diff --git a/CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml b/CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml
new file mode 100644
index 00000000..9f7e46cd
--- /dev/null
+++ b/CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml.cs
new file mode 100644
index 00000000..463f2f11
--- /dev/null
+++ b/CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml.cs
@@ -0,0 +1,127 @@
+//-----------------------------------------------------------------------
+//
+// Company copyright tag.
+//
+// stubbfel
+// 08.08.2013
+//----------------------------------------------------------------------
+
+namespace CampusAppWP8.Pages.Dev
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Runtime.InteropServices.WindowsRuntime;
+ using System.Windows;
+ using System.Windows.Navigation;
+ using CampusAppWP8.Model.Campusmap;
+ using CampusAppWP8.Model.GeoDb;
+ using CampusAppWP8.Utility.NDEF;
+ using Microsoft.Phone.Controls;
+ using Windows.Networking.Proximity;
+
+ /// Nfc page.
+ /// Stubbfel, 22.08.2013.
+ public partial class NFC : PhoneApplicationPage
+ {
+ /// The device.
+ private readonly ProximityDevice device = ProximityDevice.GetDefault();
+
+ /// Zero-based index of the act ndef.
+ private int actNDEFIndex;
+
+ /// List of ndefs.
+ private List ndefList;
+
+ /// Initializes a new instance of the NFC class.
+ /// Stubbfel, 22.08.2013.
+ public NFC()
+ {
+ this.InitializeComponent();
+ this.ndefList = new List();
+ MapModel map = new CBMainMapModel();
+ foreach (PlaceModel place in map.Spatial.Places)
+ {
+ this.ndefList.Add(new NDEFMessage(place.ToNfcString(), NDEFMessage.TYPEVAL.TEXT));
+ }
+
+ this.actNDEFIndex = 0;
+ }
+
+ /// Override the OnNavigatedTo method.
+ /// Stubbfel, 22.08.2013.
+ /// Arguments of navigation.
+ protected override void OnNavigatedTo(NavigationEventArgs e)
+ {
+ base.OnNavigatedTo(e);
+ this.Writecontent.Text = this.ndefList[this.actNDEFIndex].GetContent();
+ }
+
+ /// Handler, called when the publish.
+ /// Stubbfel, 22.08.2013.
+ /// The sender.
+ /// Identifier for the message.
+ private void PublishHandler(ProximityDevice sender, long messageId)
+ {
+ this.device.StopPublishingMessage(messageId);
+ this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show("Writed:" + this.actNDEFIndex)));
+ }
+
+ /// Handler, called when the ndef.
+ /// Stubbfel, 22.08.2013.
+ /// The sender.
+ /// The message.
+ private void NDEFHandler(ProximityDevice sender, ProximityMessage message)
+ {
+ this.device.StopSubscribingForMessage(message.SubscriptionId);
+ var ndefMessage = message.Data;
+ byte[] testa = ndefMessage.ToArray();
+
+ NDEFMessage ndef = new NDEFMessage(testa);
+ this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(ndef.GetContent())));
+ }
+
+ /// Event handler. Called by Read for click events.
+ /// Stubbfel, 22.08.2013.
+ /// The sender.
+ /// Routed event information.
+ private void Read_Click(object sender, RoutedEventArgs e)
+ {
+ this.device.SubscribeForMessage("NDEF", this.NDEFHandler);
+ }
+
+ /// Event handler. Called by Next for click events.
+ /// Stubbfel, 22.08.2013.
+ /// The sender.
+ /// Routed event information.
+ private void Next_Click(object sender, RoutedEventArgs e)
+ {
+ if (this.actNDEFIndex < this.ndefList.Count - 1)
+ {
+ this.actNDEFIndex++;
+ this.Writecontent.Text = this.ndefList[this.actNDEFIndex].GetContent();
+ }
+ }
+
+ /// Event handler. Called by Prev for click events.
+ /// Stubbfel, 22.08.2013.
+ /// The sender.
+ /// Routed event information.
+ private void Prev_Click(object sender, RoutedEventArgs e)
+ {
+ if (this.actNDEFIndex > 0)
+ {
+ this.actNDEFIndex--;
+ this.Writecontent.Text = this.ndefList[this.actNDEFIndex].GetContent();
+ }
+ }
+
+ /// Event handler. Called by Write for click events.
+ /// Stubbfel, 22.08.2013.
+ /// The sender.
+ /// Routed event information.
+ private void Write_Click(object sender, RoutedEventArgs e)
+ {
+ this.device.PublishBinaryMessage("NDEF:WriteTag", this.ndefList[this.actNDEFIndex].ToByteArray().AsBuffer(), this.PublishHandler);
+ }
+ }
+}
\ No newline at end of file
diff --git a/CampusAppWP8/CampusAppWP8/Pages/StartPage.xaml b/CampusAppWP8/CampusAppWP8/Pages/StartPage.xaml
index ca2c2d80..ab7c5c3c 100644
--- a/CampusAppWP8/CampusAppWP8/Pages/StartPage.xaml
+++ b/CampusAppWP8/CampusAppWP8/Pages/StartPage.xaml
@@ -142,6 +142,7 @@
+
diff --git a/CampusAppWP8/CampusAppWP8/Pages/StartPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/StartPage.xaml.cs
index 6c3d516d..5562226d 100644
--- a/CampusAppWP8/CampusAppWP8/Pages/StartPage.xaml.cs
+++ b/CampusAppWP8/CampusAppWP8/Pages/StartPage.xaml.cs
@@ -31,6 +31,7 @@ namespace CampusAppWP8.Pages
this.InitializeComponent();
ApplicationBarMenuItem menuItem1 = ApplicationBar.MenuItems[0] as ApplicationBarMenuItem;
ApplicationBarMenuItem menuItem2 = ApplicationBar.MenuItems[1] as ApplicationBarMenuItem;
+ ApplicationBarMenuItem menuItem3 = ApplicationBar.MenuItems[2] as ApplicationBarMenuItem;
if (menuItem1 != null)
{
menuItem1.Text = AppResources.Setting_UserProfilAppBarTitle;
@@ -41,6 +42,11 @@ namespace CampusAppWP8.Pages
menuItem2.Text = AppResources.Setting_ApplAppBarTitle;
}
+ if (menuItem3 != null)
+ {
+ menuItem3.Text = "Nfc";
+ }
+
if (!Settings.AppSetting.InitApp)
{
this.ShowOptIns();
@@ -126,6 +132,17 @@ namespace CampusAppWP8.Pages
NavigationService.Navigate(url);
}
+ ///
+ /// Method Navigate to
+ ///
+ /// Caller of the function
+ /// some EventArgs
+ private void ApplicationBarMenuItem3_Click(object sender, EventArgs e)
+ {
+ Uri url = new Uri("/Pages/Dev/NFC.xaml", UriKind.Relative);
+ NavigationService.Navigate(url);
+ }
+
///
/// Method change the Opacity of the ApplicationBar
///
diff --git a/CampusAppWP8/CampusAppWP8/Utility/NDEF/NDEFMessage.cs b/CampusAppWP8/CampusAppWP8/Utility/NDEF/NDEFMessage.cs
new file mode 100644
index 00000000..f4038e46
--- /dev/null
+++ b/CampusAppWP8/CampusAppWP8/Utility/NDEF/NDEFMessage.cs
@@ -0,0 +1,154 @@
+//-----------------------------------------------------------------------
+//
+// Company copyright tag.
+//
+// stubbfel
+// 21.08.2013
+//----------------------------------------------------------------------
+namespace CampusAppWP8.Utility.NDEF
+{
+ using System.Collections.Generic;
+ using System.IO;
+
+ /// Ndef message.
+ /// Stubbfel, 21.08.2013.
+ public class NDEFMessage
+ {
+ #region Members
+
+ /// The records.
+ private List records;
+
+ #endregion
+
+ #region constructors
+
+ /// Initializes a new instance of the NDEFMessage class.
+ /// Stubbfel, 21.08.2013.
+ /// The content.
+ /// The type.
+ /// (Optional) the tnf.
+ public NDEFMessage(string content, TYPEVAL type, NDEFRecord.TNFVAL tnf = NDEFRecord.TNFVAL.WKT)
+ {
+ this.records = new List();
+ float recordsCount = (float)content.Length / NDEFRecord.MaxRecordPayLoad;
+ NDEFRecord tmpRecord = null;
+ string praefix = NDEFMessage.GetPraefix(type);
+
+ for (int i = 0; recordsCount > 0; i++)
+ {
+ tmpRecord = new NDEFShortRecord();
+ tmpRecord.Type = type;
+ tmpRecord.TNF = tnf;
+ tmpRecord.PayloadPraefix = praefix;
+ int recordsize = 255;
+ if (content.Length < (i + 1) * recordsize)
+ {
+ recordsize = content.Length - (i * recordsize);
+ }
+
+ tmpRecord.Payload = content.Substring(i * 255, recordsize);
+ if (i == 0)
+ {
+ tmpRecord.MB = NDEFRecord.NDEFFlags.MBSET;
+ }
+
+ this.records.Add(tmpRecord);
+ recordsCount--;
+ }
+
+ this.records[this.records.IndexOf(tmpRecord)].ME = NDEFRecord.NDEFFlags.MESET;
+ }
+
+ /// Initializes a new instance of the NDEFMessage class.
+ /// Stubbfel, 21.08.2013.
+ /// The array.
+ public NDEFMessage(byte[] array)
+ {
+ this.records = new List();
+
+ NDEFRecord tmpRecord = null;
+ for (int i = 0; i < array.Length; i += tmpRecord.RecordSize)
+ {
+ tmpRecord = new NDEFShortRecord(array, i);
+
+ this.records.Add(tmpRecord);
+ }
+ }
+
+ #endregion
+
+ #region enum
+
+ /// Values that represent TYPEVAL.
+ /// Stubbfel, 21.08.2013.
+ public enum TYPEVAL
+ {
+ /// An enum constant representing the empty option.
+ EMPTY = 0x00,
+
+ /// An enum constant representing the URL option.
+ URL = 0x55,
+
+ /// An enum constant representing the text option.
+ TEXT = 0x54,
+ }
+
+ #endregion
+
+ #region Methods
+ /// Gets a praefix.
+ /// Stubbfel, 21.08.2013.
+ /// The type.
+ /// The praefix.
+ public static string GetPraefix(TYPEVAL type)
+ {
+ string praefix = string.Empty;
+
+ switch (type)
+ {
+ case TYPEVAL.TEXT:
+ praefix = "\x02" + "de";
+ break;
+ case TYPEVAL.URL:
+ praefix = "\x01";
+ break;
+ default:
+ break;
+ }
+
+ return praefix;
+ }
+
+ /// Gets the content.
+ /// Stubbfel, 21.08.2013.
+ /// The content.
+ public string GetContent()
+ {
+ string result = string.Empty;
+
+ foreach (NDEFRecord record in this.records)
+ {
+ result += record.Payload;
+ }
+
+ return result;
+ }
+
+ /// Converts this object to a byte array.
+ /// Stubbfel, 21.08.2013.
+ /// This object as a byte[].
+ public byte[] ToByteArray()
+ {
+ MemoryStream ms = new MemoryStream();
+ foreach (NDEFRecord record in this.records)
+ {
+ ms.Write(record.ToByteArray(), 0, record.RecordSize);
+ }
+
+ return ms.ToArray();
+ }
+
+ #endregion
+ }
+}
diff --git a/CampusAppWP8/CampusAppWP8/Utility/NDEF/NDEFRecord.cs b/CampusAppWP8/CampusAppWP8/Utility/NDEF/NDEFRecord.cs
new file mode 100644
index 00000000..8d3a0c7e
--- /dev/null
+++ b/CampusAppWP8/CampusAppWP8/Utility/NDEF/NDEFRecord.cs
@@ -0,0 +1,188 @@
+//-----------------------------------------------------------------------
+//
+// Company copyright tag.
+//
+// stubbfel
+// 21.08.2013
+//----------------------------------------------------------------------
+namespace CampusAppWP8.Utility.NDEF
+{
+ using System.IO;
+ using System.Text;
+
+ /// Ndef record of a NDEFMessage.
+ /// Stubbfel, 21.08.2013.
+ public abstract class NDEFRecord
+ {
+ #region Members
+
+ /// The maximum record pay load.
+ public const int MaxRecordPayLoad = 255;
+
+ /// Size of the type.
+ protected const byte TypeSize = 0x01;
+
+ #endregion
+
+ #region Constructors
+ /// Initializes a new instance of the NDEFRecord class.
+ /// Stubbfel, 21.08.2013.
+ public NDEFRecord()
+ {
+ }
+
+ /// Initializes a new instance of the NDEFRecord class.
+ /// Stubbfel, 21.08.2013.
+ /// The array.
+ /// (Optional) zero-based index of the.
+ public NDEFRecord(byte[] array, int index = 0)
+ {
+ this.FormatFlags = array[index];
+ }
+
+ #endregion
+
+ #region enum
+
+ /// Values that represent NDEFFlags.
+ /// Stubbfel, 21.08.2013.
+ public enum NDEFFlags
+ {
+ /// An Enum constant representing the UNSET option.
+ UNSET = 0x00,
+
+ /// An Enum constant representing the Message begin option.
+ MBSET = 0x80,
+
+ /// An Enum constant representing the Message end option.
+ MESET = 0x40,
+
+ /// An Enum constant representing the CHUNK FLAG option.
+ CFSET = 0x20,
+
+ /// An Enum constant representing the Short Record set option.
+ SRSET = 0x10,
+
+ /// An Enum constant representing the ID length option.
+ ILSET = 0x08,
+
+ /// An enum constant representing the tnfset option.
+ TNFSET = 0x03
+ }
+
+ /// Values that represent TNFVAL.
+ /// Stubbfel, 21.08.2013.
+ public enum TNFVAL
+ {
+ /// An enum constant representing the empty option.
+ EMPTY = 0x00,
+
+ /// An enum constant representing the Well-Know-Type option.
+ WKT = 0x01,
+
+ /// An enum constant representing the MediaType option.
+ MEDIATYPE = 0x02,
+
+ /// An enum constant representing the URI option.
+ URI = 0x03,
+
+ /// An enum constant representing the NFCE option.
+ NFCE = 0x04,
+
+ /// An enum constant representing the unknow option.
+ unknow = 0x05,
+
+ /// An enum constant representing the unchanged option.
+ UNCHANGED = 0x06,
+
+ /// An enum constant representing the reserved option.
+ RESERVED = 0x07
+ }
+
+ #endregion
+
+ #region Properties
+ /// Gets or sets the MBFlag.
+ /// The MBFlag.
+ public NDEFFlags MB { get; set; }
+
+ /// Gets or sets MEFlag.
+ /// The MEFlag .
+ public NDEFFlags ME { get; set; }
+
+ /// Gets or sets the CFFlag.
+ /// The CFFlag.
+ public NDEFFlags CF { get; set; }
+
+ /// Gets or sets the SRFlag.
+ /// The SRFlag.
+ public NDEFFlags SR { get; set; }
+
+ /// Gets or sets the ILFlag.
+ /// The ILFlag.
+ public NDEFFlags IL { get; set; }
+
+ /// Gets or sets the TNFField.
+ /// The TNFField.
+ public TNFVAL TNF { get; set; }
+
+ /// Gets or sets the type.
+ /// The type.
+ public NDEFMessage.TYPEVAL Type { get; set; }
+
+ /// Gets or sets the format flags.
+ /// The format flags.
+ public byte FormatFlags
+ {
+ get
+ {
+ return (byte)((byte)this.TNF | ((byte)this.MB) | ((byte)this.ME) | ((byte)this.CF) | ((byte)this.SR) | ((byte)this.IL));
+ }
+
+ protected set
+ {
+ this.TNF = (TNFVAL)(value & (byte)NDEFFlags.TNFSET);
+ this.MB = (NDEFFlags)(value & (byte)NDEFFlags.MBSET);
+ this.ME = (NDEFFlags)(value & (byte)NDEFFlags.MESET);
+ this.CF = (NDEFFlags)(value & (byte)NDEFFlags.CFSET);
+ this.SR = (NDEFFlags)(value & (byte)NDEFFlags.SRSET);
+ this.IL = (NDEFFlags)(value & (byte)NDEFFlags.ILSET);
+ }
+ }
+
+ /// Gets or sets the payload.
+ /// The payload.
+ public string Payload { get; set; }
+
+ /// Gets the size of the record.
+ /// The size of the record.
+ public int RecordSize
+ {
+ get
+ {
+ return this.HeaderSize + this.Payload.Length + this.PayloadPraefix.Length;
+ }
+ }
+
+ /// Gets or sets the payload praefix.
+ /// The payload praefix.
+ public string PayloadPraefix { get; set; }
+
+ /// Gets or sets the size of the header.
+ /// The size of the header.
+ protected int HeaderSize { get; set; }
+
+ #endregion
+
+ #region Methods
+
+ /// Converts the record to a byte array.
+ /// Stubbfel, 21.08.2013.
+ /// This object as a byte[].
+ public abstract byte[] ToByteArray();
+
+ #endregion
+ }
+}
+
+// End of Utility\NDEF\NDEFRecord.cs
diff --git a/CampusAppWP8/CampusAppWP8/Utility/NDEF/NDEFShortRecord.cs b/CampusAppWP8/CampusAppWP8/Utility/NDEF/NDEFShortRecord.cs
new file mode 100644
index 00000000..06927893
--- /dev/null
+++ b/CampusAppWP8/CampusAppWP8/Utility/NDEF/NDEFShortRecord.cs
@@ -0,0 +1,63 @@
+//-----------------------------------------------------------------------
+//
+// Company copyright tag.
+//
+// stubbfel
+// 21.08.2013
+//----------------------------------------------------------------------
+namespace CampusAppWP8.Utility.NDEF
+{
+ using System.Text;
+
+ /// Ndef short record.
+ /// Stubbfel, 21.08.2013.
+ public class NDEFShortRecord : NDEFRecord
+ {
+ /// Initializes a new instance of the NDEFShortRecord class.
+ /// Stubbfel, 21.08.2013.
+ public NDEFShortRecord()
+ {
+ this.HeaderSize = 4;
+ this.SR = NDEFFlags.SRSET;
+ this.IL = NDEFFlags.UNSET;
+ this.CF = NDEFFlags.UNSET;
+ }
+
+ /// Initializes a new instance of the NDEFShortRecord class.
+ /// Stubbfel, 21.08.2013.
+ /// The array.
+ /// (Optional) zero-based index of the.
+ public NDEFShortRecord(byte[] array, int index = 0)
+ : base(array)
+ {
+ this.HeaderSize = 4;
+ this.Type = (NDEFMessage.TYPEVAL)array[index + 3];
+ this.PayloadPraefix = NDEFMessage.GetPraefix(this.Type);
+ int payLoadSize = array[index + 2] - this.PayloadPraefix.Length;
+ this.Payload = Encoding.UTF8.GetString(array, index + this.HeaderSize + this.PayloadPraefix.Length, payLoadSize);
+ }
+
+ /// Converts this NDEFShortRecord to a byte array.
+ /// Stubbfel, 21.08.2013.
+ /// This object as a byte[].
+ public override byte[] ToByteArray()
+ {
+ byte[] payloadAr = Encoding.UTF8.GetBytes(this.PayloadPraefix + this.Payload);
+ byte[] array = new byte[payloadAr.Length + this.HeaderSize];
+
+ array[0] = this.FormatFlags;
+ array[1] = NDEFRecord.TypeSize;
+ array[2] = (byte)(Payload.Length + this.PayloadPraefix.Length);
+ array[3] = (byte)this.Type;
+
+ int i = this.HeaderSize;
+ foreach (byte b in payloadAr)
+ {
+ array[i] = b;
+ i++;
+ }
+
+ return array;
+ }
+ }
+}
diff --git a/CampusAppWP8/CampusAppWP8/Utility/Utilities.cs b/CampusAppWP8/CampusAppWP8/Utility/Utilities.cs
index bacf89c4..f138e4e6 100644
--- a/CampusAppWP8/CampusAppWP8/Utility/Utilities.cs
+++ b/CampusAppWP8/CampusAppWP8/Utility/Utilities.cs
@@ -12,11 +12,14 @@ namespace CampusAppWP8.Utility
using System.Device.Location;
using System.Globalization;
using System.Linq;
+ using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using CampusAppWP8.Resources;
+ using CampusAppWP8.Utility.NDEF;
+ using Windows.Networking.Proximity;
///
/// Collection of utility functions.
@@ -224,6 +227,7 @@ namespace CampusAppWP8.Utility
// set to 0 point, if access to device is not allow
geoposition = new GeoPosition();
geoposition.Location = new GeoCoordinate(0, 0);
+ geoposition.Timestamp = DateTime.Now;
}
watcher.Stop();
@@ -242,9 +246,16 @@ namespace CampusAppWP8.Utility
string lat = geoposition.Location.Latitude.ToString(CultureInfo.InvariantCulture);
string log = geoposition.Location.Longitude.ToString(CultureInfo.InvariantCulture);
string time = geoposition.Timestamp.Ticks.ToString();
- App.SaveToAppState(Constants.GeoWatch_CurrentPosition_Lat, lat);
- App.SaveToAppState(Constants.GeoWatch_CurrentPosition_Long, log);
- App.SaveToAppState(Constants.GeoWatch_CurrentPosition_Time, time);
+ try
+ {
+ App.SaveToAppState(Constants.GeoWatch_CurrentPosition_Lat, lat);
+ App.SaveToAppState(Constants.GeoWatch_CurrentPosition_Long, log);
+ App.SaveToAppState(Constants.GeoWatch_CurrentPosition_Time, time);
+ }
+ catch (Exception ex)
+ {
+ Logger.LogException(ex);
+ }
}
}