private void SendRegistrationToServer(string token) { ILoginViewModel login = ServiceLocator.Current.GetInstance <ILoginViewModel>(); hub = new NotificationHub(AppConfigurations.NotificationHubName, AppConfigurations.NotificationHubConnectionString, this); var tags = new List <string> { //"ucm" }; if (login != null && login.User != null && string.IsNullOrEmpty(login.User.UserName) == false) { //tags.Add(login.User.UserName); tags.Add(ServiceLocator.Current.GetInstance <ILoginViewModel>().User.UserName); } try { Task.Run(() => { hub.Unregister(); var regID = hub.Register(token, tags.ToArray()); }); } catch (Exception ex) { exceptionService = ServiceLocator.Current.GetInstance <IExceptionService>(); exceptionService.RegisterException(ex); } }
public void RegisterNotifications() { try { var refreshedToken = FirebaseInstanceId.Instance.Token; SendRegistrationToServer(refreshedToken); } catch (Exception ex) { exceptionService = ServiceLocator.Current.GetInstance <IExceptionService>(); exceptionService.RegisterException(ex); } }
public void UnregisterNotifications() { try { hub = new NotificationHub(AppConfigurations.NotificationHubName, AppConfigurations.NotificationHubConnectionString, this); Task.Run(() => { hub.Unregister(); }); } catch (Exception ex) { exceptionService = ServiceLocator.Current.GetInstance <IExceptionService>(); exceptionService.RegisterException(ex); } }
public async Task Start(string id, string message, string code, string url) { try { dialogService.ShowProgress(); await ReviewVersion(); if (await fileService.FileExists(string.Format("{0} User", AppConfigurations.Brand))) { ResponseLogin userSaved = await fileService.LoadAsync <ResponseLogin>(string.Format("{0} User", AppConfigurations.Brand)); if (userSaved != null && userSaved.Expires != null && userSaved.Expires_in > 0) { dialogService.ShowProgress(); loginViewModel.User = new ResponseLogin(); ViewModelHelper.CloneUser(loginViewModel, userSaved); apiService.Token = loginViewModel.User.Access_token; var req = new RequestEnabledSession { Code = loginViewModel.User.SessionCode, Document = loginViewModel.User.Document, DocumentType = loginViewModel.User.DocumentType, Controller = "Account", Action = "EnabledSession" }; RequestSoftwareVersion request = new RequestSoftwareVersion(); ResponseSoftwareVersion response = await apiService.GetSoftwareVersion(request); IMenuPageViewModel menuPageViewModel = ServiceLocator.Current.GetInstance <IMenuPageViewModel>(); if (response.Success && response.StatusCode == 0) { menuPageViewModel.Version = response.Value; } menuPageViewModel.LoadMenu(); await navigationService.Navigate(AppPages.MenuPage); ICallViewModel callViewModel = ServiceLocator.Current.GetInstance <ICallViewModel>(); await callViewModel.Init(); INotificationService notificationService = ServiceLocator.Current.GetInstance <INotificationService>(); notificationService.RegisterNotifications(); //if (id != null) //{ // switch (id) // { // case "1": // await navigationService.Navigate(AppPages.MedicalCenterCoordinationPage); // break; // case "2": // await navigationService.Navigate(AppPages.QualifyServicesPage, false, code); // break; // case "3": // await navigationService.Navigate(AppPages.ScheduledServicesPage); // break; // } // return; //} await navigationService.Navigate(AppPages.LandingPage); dialogService.HideProgress(); if (!string.IsNullOrWhiteSpace(url)) { await Launcher.OpenAsync(url); } IContingencyMessagePageViewModel contingencyMessage = ServiceLocator.Current.GetInstance <IContingencyMessagePageViewModel>(); contingencyMessage.LoadData(); return; } } await navigationService.Navigate(AppPages.LoginPage); } catch (Exception ex) { exceptionService.RegisterException(ex); INotificationService notificationsService = ServiceLocator.Current.GetInstance <INotificationService>(); ILoginPageViewModel loginPageViewModel = ServiceLocator.Current.GetInstance <ILoginPageViewModel>(); INotificationService notificationService = ServiceLocator.Current.GetInstance <INotificationService>(); loginViewModel.User = null; loginPageViewModel.Email = string.Empty; loginPageViewModel.Password = string.Empty; notificationsService.UnregisterNotifications(); await fileService.SaveAsync(string.Format("{0} User", AppConfigurations.Brand), loginViewModel.User); await navigationService.Navigate(AppPages.LoginPage); } finally { dialogService.HideProgress(); } }
private async Task ValidateResponde(ResponseLogin responseLogin) { ErrorEmail = string.Empty; ErrorPassword = string.Empty; if (responseLogin.Success == false || (responseLogin.StatusCode != null && responseLogin.StatusCode != "0")) { if (responseLogin.StatusCode == CodeResponse.UserDisableAccount || responseLogin.StatusCode == CodeResponse.UserInactive) { await dialogService.ShowUserInactive(responseLogin.Tittle, responseLogin.Message, Email, responseLogin.StatusCode == CodeResponse.UserDisableAccount? "Reactivar Usuario" : "Enviar Correo", responseLogin.StatusCode); return; } await dialogService.ShowMessage(responseLogin.Tittle, responseLogin.Message); return; } if (responseLogin.Success) { ViewModelHelper.SetResponseLoginToLoginViewModel(this, responseLogin); ILoginViewModel loginViewModel = ServiceLocator.Current.GetInstance <ILoginViewModel>(); ILandingPageViewModel landingPageViewModel = ServiceLocator.Current.GetInstance <ILandingPageViewModel>(); landingPageViewModel.UserName = loginViewModel.User.NameOne; apiService.Token = loginViewModel.User.Access_token; try { await fileService.SaveAsync(string.Format("{0} User", AppConfigurations.Brand), loginViewModel.User); } catch (Exception ex) { exceptionService.RegisterException(ex); } ICallViewModel callViewModel = ServiceLocator.Current.GetInstance <ICallViewModel>(); await callViewModel.Init(); notificationsService.RegisterNotifications(); RequestSoftwareVersion request = new RequestSoftwareVersion(); ResponseSoftwareVersion response = await apiService.GetSoftwareVersion(request); IMenuPageViewModel menuPageViewModel = ServiceLocator.Current.GetInstance <IMenuPageViewModel>(); if (response.Success && response.StatusCode == 0) { menuPageViewModel.Version = response.Value; } menuPageViewModel.LoadMenu(); await navigationService.Navigate(AppPages.MenuPage); IContingencyMessagePageViewModel contingencyMessage = ServiceLocator.Current.GetInstance <IContingencyMessagePageViewModel>(); contingencyMessage.LoadData(); } //else //{ // if (responseLogin.StatusCode == "401") // { // await dialogService.ShowUserInactive(responseLogin.Tittle, responseLogin.Message, Email); // return; // } // if (responseLogin.StatusCode == "18") // { // if (await dialogService.ShowConfirm("Usuario inactivo", string.Format("{0} {1}", responseLogin.Message, AppResources.SendActivationEmail))) // { // dialogService.ShowProgress(); // RequestSendActivationEmail request = new RequestSendActivationEmail() { User = Email }; // ResponseSendActivationEmail response = await apiService.SendActivationEmail(request); // dialogService.HideProgress(); // await dialogService.ShowMessage(response.Title, response.Message); // } // return; // } // await dialogService.ShowMessage(responseLogin.Tittle, responseLogin.Message); //} }