add filter pid medhod to stringmanager

This commit is contained in:
stubbfel
2013-09-19 10:55:07 +02:00
parent e1b6a2d279
commit 04ff3ad80b
5 changed files with 100 additions and 18 deletions

View File

@@ -95,8 +95,13 @@ namespace CampusAppWP8.Pages.PlaceNews
qrScan = false;
string qrResult = App.LoadFromIsolatedStorage<string>("PlaceNewsQCCode");
App.SaveToIsolatedStorage<string>("PlaceNewsQCCode", null);
this.searchPidList = new List<string>() { qrResult.Split('\n')[0].Trim() };
this.SendGetPisPssForPlacenews(this.searchPidList);
string searchPid = Wp8StringManager.FilterPlaceIdinQRResultString(qrResult);
if (searchPid != null)
{
this.searchPidList = new List<string>() { searchPid };
this.SendGetPisPssForPlacenews(this.searchPidList);
}
}
else
{
@@ -280,6 +285,9 @@ namespace CampusAppWP8.Pages.PlaceNews
// load from pis api
this.SendGetPlaceService(this.searchPidList, serviceNames);
this.CheckedSetupResultBox();
}
/// <summary>
/// Method send get for PlaceInformation of certain places
@@ -351,7 +359,7 @@ namespace CampusAppWP8.Pages.PlaceNews
private void ApplicationBarMenuItem_Click(object sender, EventArgs e)
{
this.qrScan = true;
string urlString = "/Pages/Dev/QRScanner.xaml";
string urlString = Constants.PathQR_QRPage;
urlString += "?" + Constants.ParamQRResultKey + "=" + "PlaceNewsQCCode";
Uri url = new Uri(urlString as string, UriKind.Relative);
this.NavigationService.Navigate(url);
@@ -363,6 +371,7 @@ namespace CampusAppWP8.Pages.PlaceNews
/// <param name="e"> Event information.</param>
private void ApplicationBarMenuItem_Click_1(object sender, EventArgs e)
{
this.ProgressBar.Visibility = Visibility.Visible;
this.device.SubscribeForMessage("NDEF", this.NDEFHandler);
}
@@ -421,22 +430,12 @@ namespace CampusAppWP8.Pages.PlaceNews
NDEFMessage ndef = new NDEFMessage(data);
string nfcContent = ndef.GetContent();
nfcContent = nfcContent.Trim('{');
nfcContent = nfcContent.Trim('}');
string[] items = nfcContent.Split(',');
string pid = "0";
foreach (string item in items)
string pid = Wp8StringManager.FilterPlaceIdinNFCResultString(nfcContent.Trim());
if (pid != null)
{
if (item.StartsWith("\"pid\":\""))
{
pid = item;
pid = pid.TrimStart("\"pid\":\"".ToCharArray());
pid = pid.TrimEnd('\"');
break;
}
this.searchPidList = new List<string>() { pid };
this.SendGetPisPssForPlacenews(this.searchPidList);
}
this.searchPidList = new List<string>() { pid };
this.SendGetPisPssForPlacenews(this.searchPidList);
// this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(ndef.GetContent())));
}
#endregion

View File

@@ -861,6 +861,15 @@ namespace CampusAppWP8.Resources {
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die /Pages/Dev/QRScanner.xaml ähnelt.
/// </summary>
public static string PathQR_QRPage {
get {
return ResourceManager.GetString("PathQR_QRPage", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die /Pages/Setting/AppSettingPage.xaml ähnelt.
/// </summary>

View File

@@ -516,4 +516,7 @@
<data name="ParamQRResultKey" xml:space="preserve">
<value>QRResultKey</value>
</data>
<data name="PathQR_QRPage" xml:space="preserve">
<value>/Pages/Dev/QRScanner.xaml</value>
</data>
</root>

View File

@@ -1,7 +1,9 @@
<StyleCopSettings Version="105">
<GlobalSettings>
<CollectionProperty Name="RecognizedWords">
<Value>nfc</Value>
<Value>param</Value>
<Value>qr</Value>
<Value>str</Value>
<Value>stubbfel</Value>
<Value>telefon</Value>

View File

@@ -6,7 +6,7 @@
// <sience>06.06.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWPortalLib8.Utility
{
{
using System;
using System.Text.RegularExpressions;
using CampusAppWPortalLib8.Resources;
@@ -118,6 +118,75 @@ namespace CampusAppWPortalLib8.Utility
return shortStr;
}
/// <summary>
/// Method gets the placeId of the result string for an qrCode string
/// </summary>
/// <param name="qrCodeResult">input qrCode string</param>
/// <returns>the id if it was found it in the string otherwise null</returns>
public static string FilterPlaceIdinQRResultString(string qrCodeResult)
{
string[] lines = qrCodeResult.Split('\n');
string tmpLineTrim;
foreach (string line in lines)
{
tmpLineTrim = line.Trim();
if (DefaultStringManager.IsDigitsOnly(tmpLineTrim))
{
return tmpLineTrim;
}
}
return null;
}
/// <summary>
/// Method check if the string contains only digit
/// </summary>
/// <param name="str">input string</param>
/// <returns>true if the string contains only digit, otherwise false</returns>
public static bool IsDigitsOnly(string str)
{
foreach (char c in str)
{
if (c < '0' || c > '9')
{
return false;
}
}
return true;
}
/// <summary>
/// Method gets the placeId of the result string for an nfc string
/// </summary>
/// <param name="nfcResult">input nfc string</param>
/// <returns>the id if it was found it in the string otherwise null</returns>
public static string FilterPlaceIdinNFCResultString(string nfcResult)
{
string nfcResultTrim = nfcResult.Trim('{');
nfcResultTrim = nfcResultTrim.Trim('}');
string[] items = nfcResultTrim.Split(',');
string[] tmpStringPair;
foreach (string item in items)
{
tmpStringPair = item.Trim().Split(':');
if (tmpStringPair.Length == 2)
{
string pairKey = tmpStringPair[0].Trim('\"').Trim();
if (pairKey.Equals("pid"))
{
return tmpStringPair[1].Trim('\"').Trim();
}
}
}
return null;
}
#endregion
}
}