async Task ExecuteCancelAsync() { Logger.Track(EvolveLoggerKeys.LoginCancel); if (Settings.FirstRun) { AccountResponse result = await client.LoginAnonymously(); if (result?.Success ?? false) { try { Message = "Updating schedule..."; IsBusy = true; Settings.UserId = result.User?.Id; MessagingService.Current.SendMessage(MessageKeys.LoggedIn); await StoreManager.SyncAllAsync(false); Settings.Current.LastSync = DateTime.UtcNow; Settings.Current.HasSyncedData = true; } catch (Exception ex) { //if sync doesn't work don't worry it is alright we can recover later Logger.Report(ex); } finally { Message = string.Empty; IsBusy = false; } Settings.FirstRun = false; await Finish(); } else { Logger.Track(EvolveLoggerKeys.LoginFailure, "Reason", result.Error); MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert { Title = "Anonymous Sign In Failed", Message = result.Error, Cancel = "OK" }); } } else { await Finish(); } }
async Task LoginForProvider(string providerName, Func <Task <AccountResponse> > providerLogin) { if (IsBusy) { return; } try { IsBusy = true; Message = "Signing in..."; AccountResponse result = await providerLogin(); if (result?.Success ?? false) { Message = "Updating schedule..."; Settings.FirstName = result.User?.FirstName ?? string.Empty; Settings.LastName = result.User?.LastName ?? string.Empty; Settings.Email = result.User?.Email?.ToLowerInvariant(); Settings.UserId = result.User?.Id; Settings.UserAvatar = result.User?.AvatarUrl; Logger.Track(EvolveLoggerKeys.LoginSuccess); try { await StoreManager.SyncAllAsync(true); Settings.Current.LastSync = DateTime.UtcNow; Settings.Current.HasSyncedData = true; } catch (Exception ex) { //if sync doesn't work don't worry it is alright we can recover later Logger.Report(ex); } Settings.FirstRun = false; Finish(); } else { Logger.Track(EvolveLoggerKeys.LoginFailure, "Reason", result.Error); MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert { Title = "Unable to Log In", Message = result.Error, Cancel = "OK" }); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); Logger.Track(EvolveLoggerKeys.LoginFailure, "Reason", ex?.Message ?? string.Empty); MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert { Title = "Unable to Log In", Message = $"{providerName} Log In Failed", Cancel = "OK" }); } finally { Message = string.Empty; IsBusy = false; } }