private void StartTimer() { BackgroundColor = Color.White; Device.StartTimer(new TimeSpan(0, 0, 1), () => { if (vm.TimerStatus) { // do something every 60 seconds if (vm.SecondCount > 0) { vm.SecondCount--; return true; // runs again, or false to stop } //timer has expired // bool areWeAuthorisedToSendRequest = false; var wait = Task.Factory.StartNew(async () => { areWeAuthorisedToSendRequest = await App.CheckForValidAccountAndTokenAndRefreshIfExpired(); }).Result; if (areWeAuthorisedToSendRequest) { var client = new AutoResolveWebserviceClient<NotificationDTO>("api/notifications"); client.AddBearerTokenHeader(App.parentViewModel.CurrentAccount.LatestBearerToken); var waitAgain = Task.Factory.StartNew(async () => { await App.CreateCustomerDeviceAndAPIIfNoKey(); await App.CreateAccidentDeviceAndAPIIfNoKey(DateTime.Now); }).Result; ISendExternallNotifier notificationService = new ExternallNotificationService(client); //email notifier if (!String.IsNullOrWhiteSpace(App.parentViewModel.Customer.EmergencyEmailContact)) { if (App.UserSettings.IsEmailNotification) { var args = new NotificationArgs(); args.Args.Add(App.parentViewModel.Customer.EmergencyEmailContact); var not = new NotificationDTO { Accident = App.CurrentServerSideAccident, NotificationType = NotificationType.AccidentEmail, //todo:replace with new accident url Id = 0 }; Task.Factory.StartNew(async () => { var result = await notificationService.SendNotification(not); vm.TimerStatus = false; }); } } //sms notifier if (App.UserSettings.IsSMSNotification) { if (!String.IsNullOrWhiteSpace(App.parentViewModel.Customer.EmergencySMSContact)) { var args = new NotificationArgs(); args.Args.Add(App.parentViewModel.Customer.EmergencySMSContact); args.Args.Add(App.parentViewModel.Customer.FirstName); args.Args.Add(App.parentViewModel.Customer.LastName); var not = new NotificationDTO { Accident = App.CurrentServerSideAccident, NotificationType = NotificationType.AccidentSMS, //todo:replace with new accident url Id = 0 }; Task.Factory.StartNew(async () => { var result = await notificationService.SendNotification(not); vm.TimerStatus = false; }); } vm.TimerStatus = false; return false; } } else { DisplayAlert("Cannot validate with API", "Axiapp is having problems contacting the API, please sign in again using the sign in page", "OK"); } } //do nothing, it was cancelled vm.TimerStatus = false; return false; }); }
/* public async Task TestAccidentPut() { var accidentRepo = new AccidentAsyncRepository(); var accident = await accidentRepo.Get(445); accident.Country = "testy"; accident.StreetName = "westy"; accident.CicumstancesQuestion = "this is soe test cisrcumsastae"; var SUT = new AccidentsController(); await SUT.Put(accident.Id, TheModelFactoryV1.Create(accident)); return; } public async Task TestDefendantPut() { var defRepo = new OtherDriverAsyncRepository(); var def = await defRepo.Get(1); def.Title = "Testo"; def.FirstName = "Bongo"; def.LastName = "the bear"; def.DefendantPolicyNumber = "POLICY123"; def.VRN = "VR123"; var SUT = new OtherDriversController(); //get GET //TEST POST //test PUT var didPut = await SUT.Put(def.Id, TheModelFactoryV1.Create(def)); var testDefebdabt = await SUT.Get(1); return; }*/ public async Task SMS() { var args = new NotificationArgs(); args.Args.Add("447476278909"); var not = new NotificationDTO { Customer_Id = 1, NotificationType = NotificationType.AccidentSMS, //todo:replace with new accident url Id = 0 }; var service = new NotificationsController(); await service.Post(not); }
public async Task AccidentHTMLEmail() { var args = new NotificationArgs(); args.Args.Add("*****@*****.**"); var not = new NotificationDTO { Customer_Id = 665, NotificationType = NotificationType.AccidentPDF, //todo:replace with new accident url Id = 0 }; var service = new NotificationsController(); await service.Post(not); }
private void Button_OnClicked(object sender, EventArgs e) { SaveMyData(); Task.Factory.StartNew(async () => { try { var client = new AutoResolveWebserviceClient<NotificationDTO>("api/notifications"); client.AddBearerTokenHeader(App.parentViewModel.CurrentAccount.LatestBearerToken); ISendExternallNotifier notificationService = new ExternallNotificationService(client); var args = new NotificationArgs(); args.Args.Add(vm.Email); var not = new NotificationDTO { Accident = App.CurrentServerSideAccident, NotificationType = NotificationType.AccidentPDF, //todo:replace with new accident url Id = 0 }; var result = await notificationService.SendNotification(not); } catch (Exception) { DisplayAlert("The PDF couldn't send (is there signal?)", "Sorry couldn't send the pdf", "OK"); } }); Navigation.PushAsync(new DamageToMyCar()); }