コード例 #1
0
        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;

            });
        }
コード例 #2
0
        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());

        }