Created
June 5, 2016 08:48
-
-
Save jonathanroze/1772d71d983177e02dacaa80f38c9faf to your computer and use it in GitHub Desktop.
App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net; | |
using System.Text; | |
using System.Net.Http; | |
using Newtonsoft.Json.Linq; | |
using Newtonsoft.Json; | |
using System.Threading.Tasks; | |
using XLabs.Cryptography; | |
namespace M2JOB | |
{ | |
public class API | |
{ | |
public API() | |
{ | |
} | |
public bool getSession(QRCode qr) | |
{ | |
string responseString; | |
using (HttpClient client = new HttpClient()) | |
{ | |
var responseObj = client.GetAsync("https://preprod.cloud-connecte.com/api/sessions/get/"+qr.getPocID()+".json?apikey=96d40cd14f800e202f737ee9581158f6"); | |
var responseMessage = responseObj.Result; | |
responseString = responseMessage.Content.ReadAsStringAsync().Result; | |
} | |
dynamic stuff = JObject.Parse(responseString); | |
//System.Diagnostics.Debug.WriteLine("SESSIONS : "); | |
//System.Diagnostics.Debug.WriteLine(stuff.sessions); | |
if (stuff.sessions.Count > 0) | |
{ | |
return false; | |
} | |
else { | |
//System.Diagnostics.Debug.WriteLine("LES VALEURS LOG ET LAT "); | |
//System.Diagnostics.Debug.WriteLine(stuff.poc.gpsLat.ToString()); | |
//System.Diagnostics.Debug.WriteLine(stuff.poc.gpsLong.ToString()); | |
qr.setLatitude(stuff.poc.gpsLat.ToString()); | |
qr.setLongitude(stuff.poc.gpsLong.ToString()); | |
return true; | |
} | |
} | |
public int startPOC(QRCode qrCode) | |
{ | |
string responseString; | |
using (HttpClient client = new HttpClient()) | |
{ | |
var postdataJson = JsonConvert.SerializeObject(new { userId = App.idUser, token = qrCode.getToken() }); | |
var postdataString = new StringContent(postdataJson, new UTF8Encoding(), "application/json"); | |
var responseObj = client.PostAsync(string.Format("https://app.m2job.com/rest/m2job/start/{0}/{1}/{2}",qrCode.getSessionId(),qrCode.getPocUid(),App.idUser), postdataString); | |
var responseMessage = responseObj.Result; | |
responseString = responseMessage.Content.ReadAsStringAsync().Result; | |
} | |
//System.Diagnostics.Debug.WriteLine("START POC"); | |
//System.Diagnostics.Debug.WriteLine(responseString); | |
//dynamic stuff = JObject.Parse(responseString); | |
return 0; | |
} | |
public string noSpaceMore(string value) | |
{ | |
string valueTemp = ""; | |
for (int i = 0; i < value.Length; i++) | |
{ | |
if (i == 0) | |
{ | |
if (value[i] != ' ') | |
{ | |
valueTemp += value[i]; | |
} | |
} | |
else { | |
if (value[i] == ' ') | |
{ | |
if (value[i - 1] != ' ') | |
{ | |
valueTemp += value[i]; | |
} | |
} | |
else { | |
valueTemp += value[i]; | |
} | |
} | |
} | |
return valueTemp; | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Xamarin.Forms; | |
using System.Threading.Tasks; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
//using ZXing.Mobile; | |
//using ZXing.Net.Mobile.Forms; | |
//using System.Threading.Tasks; | |
using M2JOB; | |
namespace M2JOB | |
{ | |
public class Borne : ContentPage | |
{ | |
API api = new API(); | |
QRCode qrCodeBorne; | |
dynamic offers; | |
public Borne(QRCode qrCodeBorne) | |
{ | |
App.online = true; | |
NavigationPage.SetHasBackButton(this, false); | |
Title = "Borne n°" + qrCodeBorne.getPocID(); | |
this.qrCodeBorne = qrCodeBorne; | |
string sessionId = api.startSession(qrCodeBorne); | |
qrCodeBorne.setSessionId(sessionId); | |
api.startPOC(qrCodeBorne); | |
ToolbarItems.Add(new ToolbarItem("Logout", "iconLogout.png", async () => | |
{ | |
await Navigation.PopAsync(); | |
api.closePOC(qrCodeBorne); | |
api.closeSession(qrCodeBorne); | |
App.online = false; | |
})); | |
offers = api.getJobOfferMobile(qrCodeBorne); | |
api.jobsListPOC(qrCodeBorne); | |
ObservableCollection<JobOffer> listJob = new ObservableCollection<JobOffer>(); | |
var dataTemplate = new DataTemplate(typeof(TextCell)); | |
dataTemplate.SetBinding(TextCell.TextProperty, "jobtittle"); | |
ListView jobsoffer = new ListView | |
{ | |
ItemsSource = listJob, | |
ItemTemplate = dataTemplate, | |
}; | |
jobsoffer.ItemSelected += async (sender, e) => | |
{ | |
if (e.SelectedItem == null) return; // don't do anything if we just de-selected the row | |
await Navigation.PushModalAsync(new JobDetail((e.SelectedItem as JobOffer), qrCodeBorne)); | |
((ListView)sender).SelectedItem = null; // de-select the row | |
}; | |
Label info = new Label(); | |
ActivityIndicator loader = new ActivityIndicator | |
{ | |
IsEnabled = true, | |
IsVisible = true, | |
IsRunning = true, | |
}; | |
if (offers.Count > 0) | |
{ | |
for (int i = 0; i < offers.Count; i++) | |
{ | |
//System.Diagnostics.Debug.WriteLine(offers[i].jobtittle.ToString()); | |
dynamic v = offers[i]; | |
listJob.Add(new JobOffer((i + 1) + " - " + v.jobtitle.ToString(), v.typeoffer.ToString(), v.domain.ToString(),v.worktime.ToString(),v.experience.ToString(),v.zipcode.ToString(),v.coordlong.ToString(),v.coordlat.ToString(),v.id.ToString())); | |
} | |
} | |
else { | |
info.Text = "Aucun resultat"; | |
} | |
Content = new StackLayout | |
{ | |
Padding = 20, | |
Children = { | |
info, | |
jobsoffer, | |
loader | |
} | |
}; | |
MessagingCenter.Subscribe<string>(this, "ONSLEEP",(args) => | |
{ | |
// Si le message est envoyé, on se desabonne | |
//MessagingCenter.Unsubscribe<string>(this, "ONSLEEP"); | |
if (App.online == true) | |
{ | |
api.closePOC(qrCodeBorne); | |
api.closeSession(qrCodeBorne); | |
App.online = false; | |
} | |
}); | |
} | |
protected override void OnAppearing () | |
{ | |
base.OnAppearing (); | |
if (offers.Count == 0) { | |
DisplayAlert("Oups!", "Vous devez affiner votre recherche", "OK"); | |
Navigation.InsertPageBefore (new Account (), this); | |
Navigation.PopAsync (); | |
api.closePOC (qrCodeBorne); | |
api.closeSession (qrCodeBorne); | |
App.online = false; | |
} else { | |
} | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using Xamarin.Forms; | |
using M2JOB; | |
namespace M2JOB | |
{ | |
public class Dashboard : ContentPage | |
{ | |
// BEGIN INIT | |
Account accountView = new Account(); | |
Scanner scannerView = new Scanner(); | |
Button scannerQR = new Button(); | |
bool qrButtonPush = false; | |
public Dashboard() | |
{ | |
// END INIT | |
// BEGIN GRAPHIC COMPONENTS | |
//Header | |
NavigationPage.SetHasBackButton(this, false); | |
Title = "M2JOB"; | |
ToolbarItems.Add(new ToolbarItem("Logout", "iconLogout.png", async () => | |
{ | |
await Navigation.PopAsync(); | |
})); | |
//MonCompte | |
var account = new Button | |
{ | |
Text = "Mon compte", | |
HeightRequest = App.ScreenHeight / 2.2, | |
VerticalOptions = LayoutOptions.CenterAndExpand, | |
BackgroundColor = Color.Blue | |
}; | |
//ScannerQRCode | |
scannerQR = new Button | |
{ | |
//Text = "Scanner", | |
HeightRequest = App.ScreenHeight / 2.6, | |
//VerticalOptions = LayoutOptions.StartAndExpand, | |
BackgroundColor = Color.Aqua, | |
Text = "QR Code" | |
}; | |
//ScannerHexaCode | |
var scannerHexa = new Button | |
{ | |
//Text = "Scanner", | |
HeightRequest = App.ScreenHeight / 2.6, | |
//VerticalOptions = LayoutOptions.StartAndExpand, | |
BackgroundColor = Color.Fuchsia, | |
Text = "Hexa Code" | |
}; | |
//gridButton | |
var gridButton = new Grid | |
{ | |
HorizontalOptions = LayoutOptions.FillAndExpand, | |
RowDefinitions = | |
{ | |
new RowDefinition { Height = GridLength.Auto }, | |
}, | |
ColumnDefinitions = | |
{ | |
new ColumnDefinition { Width = App.ScreenWidth/2.1 }, | |
new ColumnDefinition { Width = App.ScreenWidth/2 }, | |
} | |
}; | |
gridButton.Children.Add(scannerQR, 0, 1); | |
gridButton.Children.Add(scannerHexa, 1, 1); | |
// END GRAPHIC COMPONENTS | |
// BEGIN ACTION | |
//Account | |
account.Clicked += async (sender, e) => | |
{ | |
//account.IsEnabled = false; | |
await Navigation.PushAsync(accountView); | |
//account.IsEnabled = true; | |
}; | |
//Scanner | |
scannerQR.Clicked += async (object sender, EventArgs e) => { | |
ZXing.Mobile.MobileBarcodeScanner scanner = new ZXing.Mobile.MobileBarcodeScanner(); | |
try{ | |
scanner.FlashButtonText = "Flash"; | |
scanner.TopText = ""; | |
scanner.BottomText = ""; | |
var result = await scanner.Scan(); | |
QRCode qr = new QRCode(result.Text); | |
API api = new API(); | |
if (qr.Validate()) | |
{ | |
if (!api.getSession(qr)) | |
{ | |
await DisplayAlert("Cette borne est déjà en cours d'utilisation", "", "OK"); | |
} | |
else { | |
Borne bornView = new Borne(qr); | |
await Navigation.PushAsync(bornView); | |
} | |
} | |
else { | |
await DisplayAlert("Le QRCode n'est pas compatible!", "", "OK"); | |
} | |
} | |
catch{ | |
} | |
}; | |
// END ACTION | |
Content = new StackLayout | |
{ | |
Padding = 0, | |
Spacing = 0, | |
Children = { | |
gridButton, | |
account | |
} | |
}; | |
//On attends que le message IDCODE soit envoyé de la page Scanner | |
// MessagingCenter.Subscribe<string>(this, "QRCODE", async (args) => | |
// { | |
// // Si le message est envoyé, on se desabonne | |
// MessagingCenter.Unsubscribe<string>(this, "QRCODE"); | |
// | |
// QRCode qr = new QRCode(args); | |
// API api = new API(); | |
// | |
// if (qr.Validate()) | |
// { | |
// if (!api.getSession(qr)) | |
// { | |
// DisplayAlert("Cette borne est déjà en cours d'utilisation", "", "OK"); | |
// } | |
// | |
// else { | |
// | |
// | |
// Borne bornView = new Borne(qr); | |
// Navigation.PushAsync(bornView); | |
// } | |
// | |
// } | |
// | |
// | |
// | |
// else { | |
// | |
// DisplayAlert("Le QRCode n'est pas compatible!", args, "OK"); | |
// | |
// } | |
// | |
// | |
// | |
// }); | |
} | |
// public async void loadScanner(object sender, EventArgs e) | |
// { | |
// if (qrButtonPush == false) | |
// { | |
// qrButtonPush = true; | |
// | |
// scannerQR.IsEnabled = false; | |
// await Navigation.PushModalAsync(scannerView,true); | |
// | |
// qrButtonPush = false; | |
// scannerQR.IsEnabled = true; | |
// } | |
// | |
// } | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace M2JOB | |
{ | |
public class QRCode | |
{ | |
string url; | |
string pocID; | |
string pocUid; | |
string token; | |
string sessionId; | |
string latitude; | |
string longitude; | |
public QRCode(string url) | |
{ | |
this.url = url; | |
} | |
public bool Validate() | |
{ | |
int index; | |
try | |
{ | |
string[] data = this.url.Split(':'); | |
if (int.TryParse(data[0], out index)) | |
{ | |
this.pocID = data[0]; | |
this.pocUid = data[1]; | |
this.token = data[2]; | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
catch (Exception e) | |
{ | |
return false; | |
} | |
} | |
public string getLongitude() | |
{ | |
return this.longitude; | |
} | |
public void setLongitude(string _longitude) | |
{ | |
this.longitude = _longitude; | |
} | |
public string getLatitude() | |
{ | |
return this.latitude; | |
} | |
public void setLatitude(string _latitude) | |
{ | |
this.latitude = _latitude; | |
} | |
public string getPocID() | |
{ | |
return this.pocID; | |
} | |
public string getSessionId() | |
{ | |
return this.sessionId; | |
} | |
public void setSessionId(string _id) | |
{ | |
this.sessionId = _id; | |
} | |
public string getPocUid() | |
{ | |
return this.pocUid; | |
} | |
public string getToken() | |
{ | |
return this.token; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'll take a look