async Task ExecuteTapQueueMessageCommandAsync(CloudQueueMessage queueMessage) { if (queueMessage == null) { return; } MessagingService.Current.Subscribe <MessageArgsDeleteQueueMessage>(MessageKeys.DeleteQueueMessage, async(m, argsDeleteQueueMessage) => { Navigation.PopAsync(); IProgressDialog deletingDialog = UserDialogs.Loading("Deleting Queue Message"); deletingDialog.Show(); try { var message = QueueMessages.Where(qm => qm.Id == argsDeleteQueueMessage.QueueId).FirstOrDefault(); if (message == null) { return; } await Queue.BaseQueue.DeleteMessageAsync(message); App.Logger.Track(AppEvent.DeleteQueueMessage.ToString()); QueueMessages.Remove(message); QueueMessageCount--; SortQueueMessages(); } catch (Exception ex) { Logger.Report(ex, "Method", "HandleMessageArgsDeleteQueueMessage"); MessagingService.Current.SendMessage(MessageKeys.Error, ex); } finally { if (deletingDialog != null) { if (deletingDialog.IsShowing) { deletingDialog.Hide(); } deletingDialog.Dispose(); } } }); try { var queueMessageDetailsPage = new QueueMessageDetailsPage(queueMessage, queue); App.Logger.TrackPage(AppPage.QueueMessageDetails.ToString()); await NavigationService.PushAsync(Navigation, queueMessageDetailsPage); } catch (Exception ex) { Console.WriteLine("Ex: " + ex.Message); } }
protected override async Task OnSaveAsync(NoteModel note) { using (UserDialogs.Loading()) { await _notesHub.UpdateNoteAsync(note); } }
private async Task PlayNewGame() { try { NavigationParameters parameters; using (UserDialogs.Loading()) { var questions = await _triviaService.GetQuestions(); if (questions == null) { await PageDialogService.DisplayAlertAsync("Sorry!", "There are no questions available, please try again later.", "OK"); } parameters = new NavigationParameters() { { "Questions", questions } }; } await NavigationService.NavigateAsync("TriviaPage", parameters); } catch (Exception ex) { await PageDialogService.DisplayAlertAsync("Error", ex.Message, "OK"); } }
async Task ExecuteTapFileShareCommandAsync(ASECloudFileShare fileShare) { if (fileShare == null) { return; } MessagingService.Current.Subscribe <MessageArgsDeleteFileShare>(MessageKeys.DeleteFileShare, async(m, argsDeleteFileShare) => { Navigation.PopAsync(); IProgressDialog deletingDialog = UserDialogs.Loading("Deleting FileShare"); deletingDialog.Show(); try { var aseFileShare = FileShares.Where(fs => fs.FileShareName == argsDeleteFileShare.FileShareName && fs.StorageAccountName == argsDeleteFileShare.StorageAccountName).FirstOrDefault(); if (aseFileShare == null) { return; } await aseFileShare.BaseFileShare.DeleteAsync(); App.Logger.Track(AppEvent.DeleteFileShare.ToString()); FileShares.Remove(aseFileShare); SortFileShares(); var realm = App.GetRealm(); await realm.WriteAsync(temprealm => { temprealm.Remove(temprealm.All <RealmCloudFileShare>() .Where(fs => fs.FileShareName == argsDeleteFileShare.FileShareName && fs.StorageAccountName == argsDeleteFileShare.StorageAccountName).First()); }); } catch (Exception ex) { Logger.Report(ex, "Method", "HandleMessageArgsDeleteFileShare"); MessagingService.Current.SendMessage(MessageKeys.Error, ex); } finally { if (deletingDialog != null) { if (deletingDialog.IsShowing) { deletingDialog.Hide(); } deletingDialog.Dispose(); } } }); var filesPage = new FilesPage(fileShare); App.Logger.TrackPage(AppPage.Files.ToString()); await NavigationService.PushAsync(Navigation, filesPage); }
async Task ExecuteTapContainerCommandAsync(ASECloudBlobContainer container) { if (container == null) { return; } MessagingService.Current.Subscribe <MessageArgsDeleteContainer>(MessageKeys.DeleteContainer, async(m, argsDeleteContainer) => { Console.WriteLine("Delete containerX: " + argsDeleteContainer.ContainerName); Navigation.PopAsync(); IProgressDialog deletingDialog = UserDialogs.Loading("Deleting Container"); deletingDialog.Show(); try { var aseContainer = Containers.Where(c => c.ContainerName == argsDeleteContainer.ContainerName && c.StorageAccountName == argsDeleteContainer.StorageAccountName).FirstOrDefault(); if (aseContainer == null) { return; } await aseContainer.BaseContainer.DeleteAsync(); App.Logger.Track(AppEvent.DeleteContainer.ToString()); Containers.Remove(aseContainer); SortContainers(); var realm = App.GetRealm(); await realm.WriteAsync(temprealm => { temprealm.Remove(temprealm.All <RealmCloudBlobContainer>() .Where(c => c.ContainerName == argsDeleteContainer.ContainerName && c.StorageAccountName == argsDeleteContainer.StorageAccountName).First()); }); } catch (Exception ex) { Logger.Report(ex, "Method", "HandleMessageArgsDeleteContainer"); MessagingService.Current.SendMessage(MessageKeys.Error, ex); } finally { if (deletingDialog != null) { if (deletingDialog.IsShowing) { deletingDialog.Hide(); } deletingDialog.Dispose(); } } }); var blobsPage = new BlobsPage(container); App.Logger.TrackPage(AppPage.Blobs.ToString()); await NavigationService.PushAsync(Navigation, blobsPage); }
async void ExecuteAccionLogoutIC() { using (UserDialogs.Loading("")) { await Task.Delay(300); await NavigationService.NavigateAsync("app:///NavigationPage/MainPage"); } }
public async Task OnNavigatedAsync(NavigationData navigationData, CancellationToken token) { _userHub.UserDataUpdated += OnUserDataUpdated; using (UserDialogs.Loading()) { _user = await _userService.GetUserDataAsync(); LoadFieldsFromModel(_user); } }
async Task ExecuteTapContainerCommandAsync(ASECloudTable table) { if (table == null) { return; } MessagingService.Current.Subscribe <MessageArgsDeleteTable>(MessageKeys.DeleteTable, async(m, argsDeleteTable) => { Navigation.PopAsync(); IProgressDialog deletingDialog = UserDialogs.Loading("Deleting Table"); deletingDialog.Show(); try { var aseTable = Tables.Where(t => t.TableName == argsDeleteTable.TableName && t.StorageAccountName == argsDeleteTable.StorageAccountName).FirstOrDefault(); if (aseTable == null) { return; } await aseTable.BaseTable.DeleteIfExistsAsync(); App.Logger.Track(AppEvent.DeleteTable.ToString()); Tables.Remove(aseTable); SortTables(); var realm = App.GetRealm(); await realm.WriteAsync(temprealm => { temprealm.Remove(temprealm.All <RealmCloudTable>() .Where(t => t.TableName == argsDeleteTable.TableName && t.StorageAccountName == argsDeleteTable.StorageAccountName).First()); }); } catch (Exception ex) { Logger.Report(ex, "Method", "HandleMessageArgsDeleteTable"); MessagingService.Current.SendMessage(MessageKeys.Error, ex); } finally { if (deletingDialog != null) { if (deletingDialog.IsShowing) { deletingDialog.Hide(); } deletingDialog.Dispose(); } } }); var tableRowsPage = new TableRowsPage(table); App.Logger.TrackPage(AppPage.TableRows.ToString()); await testPage.Navigation.PushAsync(tableRowsPage); }
private async Task OnSaveProfileAsync() { UpdateFieldsOfModel(_user); using (UserDialogs.Loading()) { await _userService.UpdateUserDataAsync(_user); } await NavigationService.NavigateBackAsync(CancellationToken.None); }
private async Task GotoList(string userSignInName, Page loginPage, bool emailSignIn) { using (UserDialogs.Loading("Loading List...")) { await Task.Delay(10); await Task.Run(async() => { await PageService.PopToRootAsync(); await PageService.PushAsync(new LoadsPage(UserDialogs, userSignInName, emailSignIn)); }); } }
async Task ExecuteTapFileCommandAsync(IListFileItem fileItem) { if (fileItem == null) { return; } MessagingService.Current.Subscribe <MessageArgsDeleteFile>(MessageKeys.DeleteFile, async(m, argsDeleteFile) => { Navigation.PopAsync(); IProgressDialog deletingDialog = UserDialogs.Loading("Deleting File"); deletingDialog.Show(); try { var file = Files.Where(f => f.Share.Name == argsDeleteFile.FileName).FirstOrDefault(); if (file == null) { return; } await FileShare.BaseFileShare.GetRootDirectoryReference().GetFileReference(file.Share.Name).DeleteAsync(); App.Logger.Track(AppEvent.DeleteFile.ToString()); Files.Remove(file); FileAndDirectoryCount--; SortFiles(); } catch (Exception ex) { Logger.Report(ex, "Method", "HandleMessageArgsDeleteFile"); MessagingService.Current.SendMessage(MessageKeys.Error, ex); } finally { if (deletingDialog != null) { if (deletingDialog.IsShowing) { deletingDialog.Hide(); } deletingDialog.Dispose(); } } }); }
async Task EditGroupNameAsync(ToDoGroupDto group) { var editResult = await UserDialogs.PromptAsync(new PromptConfig() { InputType = InputType.Name, CancelText = Strings.Cancel, OkText = Strings.Edit, Placeholder = group.Title, }); if (editResult.Ok) { using (UserDialogs.Loading(Strings.Login, out CancellationToken cancellationToken)) { group.Title = editResult.Text; await ToDoService.UpdateGroup(group, cancellationToken); } } }
public LoadsViewModel(IUserDialogs dialogs, string userSignInValue, bool emailSignIn) : base(dialogs) { if (emailSignIn) { _userEmail = userSignInValue; } else { _userPhoneNumber = userSignInValue; } PageService = new PageService(); Loads = new ObservableRangeCollection <Shippingorder_Mobilesearch>(); RefreshCommand = new Command(async() => { using (UserDialogs.Loading("Loading List...")) { await Task.Delay(10); await ExecuteRefreshCommand(false); await Task.Delay(10); } }); ForceRefreshCommand = new Command(async() => { using (UserDialogs.Loading("Loading List...")) { await Task.Delay(10); await ExecuteRefreshCommand(false); await Task.Delay(10); } }); LogoutCommand = new Command(async() => { using (UserDialogs.Loading("Logging Out...")) { await Task.Delay(10); await ExecuteLogoutCommand(); await Task.Delay(10); } }); }
async Task Login() { try { UserName = UserName ?? ""; Password = Password ?? ""; if (UserName_HasError || Password_HasError) { return; } using (UserDialogs.Loading(Strings.Login, out CancellationToken cancellationToken)) { await Task.Run(async() => { await SecurityService.LoginWithCredentials(UserName, Password, "ToDoLineApp", "secret", cancellationToken: cancellationToken); }, cancellationToken); } await NavigationService.NavigateAsync("/Master/Nav/ToDoItems"); } catch (Exception ex) { if (ex.Message.StartsWith("invalid_grant ")) { string error_description = JToken.Parse(ex.Message.Replace("invalid_grant ", ""))["error_description"].Value <string>(); if (error_description == "InvalidUserNameAndOrPassword") { await UserDialogs.AlertAsync(Strings.InvalidUserNameAndOrPassword, Strings.Error); return; // don't throw it. } } throw; } }
async Task ExecuteCreateContainerAsync() { if (IsBusy) { return; } if (!ReadyToSave) { //This should never happen as the save button should be disabled Logger.Report(new Exception("Create container called when ReadyToSave was false"), "Method", "ExecuteCreateContainerAsync"); return; } if (containerName.Length < 3 || containerName.Length > 63 || !Regex.IsMatch(containerName, @"^[a-z0-9]+(-[a-z0-9]+)*$")) { MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert { Title = "Container name is invalid", Message = "Container names must be between 3 and 63 chars, only contain lowercase letters, numbers, and hyphens, must begin with a number or letter, must not contain consecutive hyphens, or end with a hyphen.", Cancel = "OK" }); return; } IProgressDialog savingDialog = UserDialogs.Loading("Saving Container"); savingDialog.Show(); try { IsBusy = true; string connectionString = Constants.StorageConnectionString; connectionString = connectionString.Replace("<ACCOUNTNAME>", SelectedStorageAccount.Name); connectionString = connectionString.Replace("<ACCOUNTKEY>", SelectedStorageAccount.PrimaryKey); CloudStorageAccount sa = CloudStorageAccount.Parse(connectionString); var blobClient = sa.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(ContainerName); if (container == null) { Console.WriteLine("Container is null"); } if (await container.ExistsAsync()) { MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert { Title = "Container Exists", Message = "A container with the name \"" + ContainerName + "\" already exists in this storage account.", Cancel = "OK" }); return; } else { await container.CreateAsync(); if (SelectedAccessType != "Private") { if (SelectedAccessType == "Container") { await container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Container }); } else if (SelectedAccessType == "Blob") { await container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); } } var realm = App.GetRealm(); var storageAccountName = selectedStorageAccount.Name; realm.Write(() => { realm.Add(new RealmCloudBlobContainer(container.Name, selectedStorageAccount.Name, container.Uri.ToString())); }); if (containersVM != null) { containersVM.AddContainer(new ASECloudBlobContainer(container, selectedStorageAccount.Name)); App.Logger.Track(AppEvent.CreatedContainer.ToString()); } //This is here and in finally so we'll dismiss this before popping the page so the //Loader doesn't stay longer than the popup if (savingDialog != null) { if (savingDialog.IsShowing) { savingDialog.Hide(); } savingDialog.Dispose(); } await PopupNavigation.PopAsync(); } } catch (Exception ex) { Logger.Report(ex, "Method", "ExecuteCreateContainerAsync"); MessagingService.Current.SendMessage(MessageKeys.Error, ex); } finally { IsBusy = false; if (savingDialog != null) { if (savingDialog.IsShowing) { savingDialog.Hide(); } savingDialog.Dispose(); } } return; }
async Task ExecuteCreateTableAsync() { if (IsBusy) { return; } if (!ReadyToSave) { Logger.Report(new Exception("Create table called when ReadyToSave was false"), "Method", "ExecuteCreateTableAsync"); return; } if (tableName.Length < 3 || tableName.Length > 63 || !Regex.IsMatch(tableName, @"^[A-Za-z][A-Za-z0-9]*$")) { MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert { Title = "Table name is invalid", Message = "Table names must be between 3 and 63 chars, only contain letters and numbers, and start with a letter.", Cancel = "OK" }); return; } IProgressDialog savingDialog = UserDialogs.Loading("Saving Table"); savingDialog.Show(); try { IsBusy = true; string connectionString = Constants.StorageConnectionString; connectionString = connectionString.Replace("<ACCOUNTNAME>", SelectedStorageAccount.Name); connectionString = connectionString.Replace("<ACCOUNTKEY>", SelectedStorageAccount.PrimaryKey); CloudStorageAccount sa = CloudStorageAccount.Parse(connectionString); var tableClient = sa.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference(tableName); if (table == null) { Console.WriteLine("Table is null"); } if (await table.ExistsAsync()) { MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert { Title = "Table Exists", Message = "A table with the name \"" + TableName + "\" already exists in this storage account.", Cancel = "OK" }); return; } else { await table.CreateAsync(); var realm = App.GetRealm(); var storageAccountName = selectedStorageAccount.Name; realm.Write(() => { realm.Add(new RealmCloudTable(table.Name, selectedStorageAccount.Name, table.Uri.ToString())); }); if (tablesVM != null) { tablesVM.AddTable(new ASECloudTable(table, selectedStorageAccount.Name)); App.Logger.Track(AppEvent.CreatedTable.ToString()); } //This is here and in finally so we'll dismiss this before popping the page so the //Loader doesn't stay longer than the popup if (savingDialog != null) { if (savingDialog.IsShowing) { savingDialog.Hide(); } savingDialog.Dispose(); } await PopupNavigation.PopAsync(); } } catch (Exception ex) { Logger.Report(ex, "Method", "ExecuteCreateTableAsync"); MessagingService.Current.SendMessage(MessageKeys.Error, ex); } finally { IsBusy = false; if (savingDialog != null) { if (savingDialog.IsShowing) { savingDialog.Hide(); } savingDialog.Dispose(); } } return; }
async Task ExecuteCreateQueueMessageAsync() { if (IsBusy) { return; } if (!ReadyToSave) { //This should never happen as the save button should be disabled Logger.Report(new Exception("Create Queue Message called when ReadyToSave was false"), "Method", "ExecuteCreateQueueMessageAsync"); return; } //Messages must expire in 1 second to 7 days //Calculate time to live TimeSpan?messageTTL = null; switch (SelectedExpirationTimePeriod) { case "Days": messageTTL = new TimeSpan(ExpiresInTime, 0, 0, 0); break; case "Hours": messageTTL = new TimeSpan(0, ExpiresInTime, 0, 0); break; case "Minutes": messageTTL = new TimeSpan(0, 0, ExpiresInTime, 0); break; case "Seconds": messageTTL = new TimeSpan(0, 0, 0, ExpiresInTime); break; } if (messageTTL < MinimumExpirationtime || messageTTL > MaximumExpirationtime) { MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert { Title = "Expiration time is invalid", Message = "Messages must expire in no less than 1 second and no more than 7 days.", Cancel = "OK" }); return; } IProgressDialog savingDialog = UserDialogs.Loading("Saving Queue Message"); savingDialog.Show(); try { IsBusy = true; var newMessage = new CloudQueueMessage(MessageText); await queueMessagesViewModel.Queue.BaseQueue.AddMessageAsync(newMessage, messageTTL, null, null, null); if (queueMessagesViewModel != null) { queueMessagesViewModel.AddQueueMessage(newMessage); App.Logger.Track(AppEvent.CreatedQueueMessage.ToString()); } //This is here and in finally so we'll dismiss this before popping the page so the //Loader doesn't stay longer than the popup if (savingDialog != null) { if (savingDialog.IsShowing) { savingDialog.Hide(); } savingDialog.Dispose(); } await PopupNavigation.PopAsync(); } catch (Exception ex) { Logger.Report(ex, "Method", "ExecuteCreateQueueMessageAsync"); MessagingService.Current.SendMessage(MessageKeys.Error, ex); } finally { IsBusy = false; if (savingDialog != null) { if (savingDialog.IsShowing) { savingDialog.Hide(); } savingDialog.Dispose(); } } return; }
async Task ExecuteAddBlobCommandAsync() { if (IsBusy) { return; } IProgressDialog savingDialog = null; try { //Check for Storage Permissions var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage); if (status != PermissionStatus.Granted) { if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location)) { MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert { Title = "Need storage access", Message = "In order to upload new blobs, we need access to your phone's storage.", Cancel = "OK" }); } var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Storage }); status = results[Permission.Storage]; } if (status == PermissionStatus.Granted) { var result = await DependencyService.Get <IFilePicker>().PickFile(); if (result != null) { savingDialog = UserDialogs.Loading("Saving Blob"); savingDialog.Show(); var blob = Container.BaseContainer.GetBlockBlobReference(result.FileName); if (await blob.ExistsAsync()) { savingDialog.Hide(); MessagingService.Current.SendMessage <MessagingServiceQuestion>(MessageKeys.Question, new MessagingServiceQuestion { Negative = "No", Positive = "Yes", Question = "A blob with the same name already exists in this Container, would you like to overwrite?", Title = "Overwrite blob?", OnCompleted = (async(questionResult) => { if (questionResult) { try { savingDialog.Show(); await blob.FetchAttributesAsync(); byteCount -= blob.Properties.Length; await blob.UploadFromByteArrayAsync(result.DataArray, 0, result.DataArray.Length); byteCount += blob.Properties.Length; TotalBlobSize = FileSizeHelper.GetHumanizedSizeFromBytes(byteCount); App.Logger.Track(AppEvent.OverwriteBlob.ToString()); } catch (Exception ex) { Logger.Report(ex); MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert { Title = "Unable to Overwrite Blob", Message = "There was an issue trying to overwrite blob in storage. Please try again.", Cancel = "OK" }); } finally { if (savingDialog != null) { if (savingDialog.IsShowing) { savingDialog.Hide(); } savingDialog.Dispose(); } } } } ) }); } else { await blob.UploadFromByteArrayAsync(result.DataArray, 0, result.DataArray.Length); App.Logger.Track(AppEvent.CreatedBlob.ToString()); Blobs.Add((CloudBlob)blob); byteCount += blob.Properties.Length; BlobCount = Blobs.Count.ToString(); TotalBlobSize = FileSizeHelper.GetHumanizedSizeFromBytes(byteCount); SortBlobs(); } } } } catch (Exception ex) { Logger.Report(ex); MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert { Title = "Unable to Save Blob", Message = "There was an issue trying to save to blob storage. Please try again.", Cancel = "OK" }); } finally { if (savingDialog != null) { if (savingDialog.IsShowing) { savingDialog.Hide(); } savingDialog.Dispose(); } } }
async Task ExecuteTapBlobCommandAsync(CloudBlob blob) { if (blob == null) { return; } MessagingService.Current.Subscribe <MessageArgsDeleteBlob>(MessageKeys.DeleteBlob, async(m, argsDeleteBlob) => { Navigation.PopAsync(); IProgressDialog deletingDialog = UserDialogs.Loading("Deleting Blob"); deletingDialog.Show(); try { var aseBlob = Blobs.Where(b => b.Name == argsDeleteBlob.BlobName && b.Container.Name == argsDeleteBlob.ContainerName).FirstOrDefault(); if (aseBlob == null) { return; } await aseBlob.DeleteAsync(); App.Logger.Track(AppEvent.DeleteBlob.ToString()); Blobs.Remove(aseBlob); byteCount -= aseBlob.Properties.Length; BlobCount = Blobs.Count.ToString(); TotalBlobSize = FileSizeHelper.GetHumanizedSizeFromBytes(byteCount); SortBlobs(); } catch (Exception ex) { Logger.Report(ex, "Method", "HandleMessageArgsDeleteBlob"); MessagingService.Current.SendMessage(MessageKeys.Error, ex); } finally { if (deletingDialog != null) { if (deletingDialog.IsShowing) { deletingDialog.Hide(); } deletingDialog.Dispose(); } } }); try { var blobDetailsPage = new BlobDetailsPage(blob); App.Logger.TrackPage(AppPage.BlobDetails.ToString()); await NavigationService.PushAsync(Navigation, blobDetailsPage); } catch (Exception ex) { Console.WriteLine("Ex: " + ex.Message); } }
async Task ExecuteLoginCommand(Page loginPage) { if (IsBusy) { return; } if (!await CheckConnectivityAsync()) { return; } var check = await App.CheckLocationServices(); try { IsBusy = true; if (check != Plugin.Permissions.Abstractions.PermissionStatus.Granted) { if (check != Plugin.Permissions.Abstractions.PermissionStatus.Unknown) { Device.BeginInvokeOnMainThread(() => App.LocationServicesFailure()); } IsBusy = false; return; } Analytics.TrackEvent("Driver-Login"); AuthenticationResult result; try { result = await App.AuthenticationClient .AcquireTokenInteractive(CommonConstants.Scopes) .WithPrompt(Prompt.SelectAccount) .WithParentActivityOrWindow(App.UIParent) .WithUseEmbeddedWebView(true) .ExecuteAsync(); using (UserDialogs.Loading("Logging In...")) { string signInValue = ""; var token = new JwtSecurityToken(result.IdToken); bool emailSignIn = true; foreach (var claim in token.Claims) { if (claim.Type == "emails" || claim.Type == "signInNames.emailAddress") { signInValue = claim.Value; } else if (claim.Type == "signInNames.phoneNumber") { signInValue = claim.Value; emailSignIn = false; } } await GotoList(signInValue, loginPage, emailSignIn); } } catch (MsalException ex) { if (ex.Message != null && ex.Message.Contains("AADB2C90118")) { result = await ForgotPassword(); await App.GoLogin(); } else if (ex.Message != null && ex.Message.Contains("AADB2C90091")) { await PageService.DisplayAlert("User Cancelled", "Sign in was cancelled", "Dismiss"); } else if (ex.ErrorCode != "authentication_canceled") { await PageService.DisplayAlert("An error has occurred", "Exception message: " + ex.Message, "Dismiss"); } } } catch (Exception ex) { Crashes.TrackError(ex); } finally { if (check == Plugin.Permissions.Abstractions.PermissionStatus.Granted) { await App.soapService.StartListening(); } IsBusy = false; } }
async Task ExecuteOnAppearingLogin(Page loginPage) { if (IsBusy) { return; } IsBusy = true; try { using (UserDialogs.Loading("Checking connection...")) { //Check Location Services first var check = await App.CheckLocationServices(); if (check != Plugin.Permissions.Abstractions.PermissionStatus.Granted) { Device.BeginInvokeOnMainThread(() => { if (check != Plugin.Permissions.Abstractions.PermissionStatus.Unknown) { App.LocationServicesFailure(); } App.GoLogout(); }); IsBusy = false; return; } } } catch (Exception ex) { Console.WriteLine(ex.Message); Device.BeginInvokeOnMainThread(() => { App.LocationServicesFailure(); }); IsBusy = false; return; } try { _ = Task.Run(async() => { // Look for existing account IEnumerable <IAccount> accounts = await App.AuthenticationClient.GetAccountsAsync(); if (accounts.Count() > 0) { using (UserDialogs.Loading("Logging in automatically...")) { AuthenticationResult result = await App.AuthenticationClient .AcquireTokenSilent(CommonConstants.Scopes, accounts.FirstOrDefault()) .ExecuteAsync(); string signInValue = ""; var token = new JwtSecurityToken(result.IdToken); bool emailSignIn = true; foreach (var claim in token.Claims) { if (claim.Type == "emails" || claim.Type == "signInNames.emailAddress") { signInValue = claim.Value; } else if (claim.Type == "signInNames.phoneNumber") { signInValue = claim.Value; emailSignIn = false; } } if (!String.IsNullOrEmpty(signInValue)) { Console.WriteLine("User '" + signInValue + "' already logged in, showing LOADS page"); await GotoList(signInValue, loginPage, emailSignIn); await App.soapService.StartListening(); } else { Console.WriteLine("User not logged in, showing Login page"); } } } else { Console.WriteLine("User not logged in, showing Login page"); } }); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine("User not logged in, showing Login page"); } finally { IsBusy = false; } }
public LoadDetailViewModel(Shippingorder_Mobilesearch load, IUserDialogs dialogs, int loadId, string userSignInValue, bool emailSignIn) : base(dialogs) { OrderNumber = loadId; if (emailSignIn) { _userEmail = userSignInValue; } else { _userPhoneNumber = userSignInValue; } SingleLoad = new ObservableRangeCollection <Shippingorder_Mobilesearch>() { load }; RefreshCommand = new Command(async() => { using (UserDialogs.Loading($"Loading Details of Order # {OrderNumber}...")) { await Task.Delay(10); await ExecuteRefreshCommand(false); await Task.Delay(10); } }); ForceRefreshCommand = new Command(async() => { using (UserDialogs.Loading($"Loading Details of Order # {OrderNumber}...")) { await Task.Delay(10); await ExecuteRefreshCommand(true); await Task.Delay(10); } }); CheckInCommand = new Command(async() => { using (UserDialogs.Loading("Checking in...")) { await Task.Delay(10); await ExecuteCheckInCommand(); await Task.Delay(10); } }); UndoCheckInCommand = new Command(async() => { using (UserDialogs.Loading("Undoing checkin...")) { await Task.Delay(10); await ExecuteUndoCheckInCommand(); await Task.Delay(10); } }); PhotoCommand = new Command <string>(async(string arg) => { using (UserDialogs.Loading("Please wait...")) { await Task.Delay(10); await ExecutePhotoCommand(arg); await Task.Delay(10); } }); LastLocationCommand = new Command(async() => { using (UserDialogs.Loading("Please wait...")) { await Task.Delay(10); await ExecuteLastLocationCommand(); await Task.Delay(10); } }); PhotoListCommand = new Command(async() => { using (UserDialogs.Loading("Please wait...")) { await Task.Delay(10); await ExecutePhotoListCommand(); await Task.Delay(10); } }); }