예제 #1
0
        async Task ExecuteLoginAsync()
        {
            if (IsBusy)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(email))
            {
                MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                {
                    Title   = "Sign in Information",
                    Message = "We do need your email address :-)",
                    Cancel  = "OK"
                });
                return;
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                {
                    Title   = "Sign in Information",
                    Message = "Password is empty!",
                    Cancel  = "OK"
                });
                return;
            }

            try
            {
                IsBusy  = true;
                Message = "Signing in...";
                #if DEBUG
                await Task.Delay(1000);
                #endif
                AccountResponse result = null;

                #if ENABLE_TEST_CLOUD
                if (email == "*****@*****.**")
                {
                    result = new AccountResponse
                    {
                        Success = true,
                        User    = new User
                        {
                            Email     = "*****@*****.**",
                            FirstName = "XTC",
                            LastName  = "User"
                        }
                    };
                }
                #endif
                if (result == null)
                {
                    result = await client.LoginAsync(email, password);
                }

                if (result?.Success ?? false)
                {
                    Message                 = "Updating schedule...";
                    Settings.FirstName      = result.User?.FirstName ?? string.Empty;
                    Settings.LastName       = result.User?.LastName ?? string.Empty;
                    Settings.Email          = email.ToLowerInvariant();
                    Settings.UserIdentifier = email.ToLowerInvariant();
                    MessagingService.Current.SendMessage(MessageKeys.LoggedIn);
                    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);
                    }
                    await Finish();

                    Settings.FirstRun = false;
                }
                else
                {
                    Logger.Track(EvolveLoggerKeys.LoginFailure, "Reason", result.Error);
                    MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                    {
                        Title   = "Unable to Sign in",
                        Message = result.Error,
                        Cancel  = "OK"
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Track(EvolveLoggerKeys.LoginFailure, "Reason", ex?.Message ?? string.Empty);

                MessagingService.Current.SendMessage <MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                {
                    Title   = "Unable to Sign in",
                    Message = "The email or password provided is incorrect.",
                    Cancel  = "OK"
                });
            }
            finally
            {
                Message = string.Empty;
                IsBusy  = false;
            }
        }
예제 #2
0
        async Task ExecuteLoginAsync()
        {
            if(IsBusy)
                return;

            if(string.IsNullOrWhiteSpace(email))
            {
                MessagingService.Current.SendMessage<MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                    {
                        Title="Sign in Information",
                        Message="We do need your email address :-)",
                        Cancel ="OK"
                    });
                return;
            }

            if(string.IsNullOrWhiteSpace(password))
            {
                MessagingService.Current.SendMessage<MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                    {
                        Title="Sign in Information",
                        Message="Password is empty!",
                        Cancel ="OK"
                    });
                return;
            }

            try 
            {
                IsBusy = true;
                Message = "Signing in...";
                #if DEBUG
                await Task.Delay(1000);
                #endif
                AccountResponse result = null;

                #if ENABLE_TEST_CLOUD
                if(email == "*****@*****.**")
                {
                    result = new AccountResponse
                        {
                            Success = true,
                            User = new User 
                                {
                                    Email = "*****@*****.**",
                                    FirstName = "XTC",
                                    LastName = "User"
                                }
                        };
                }
                #endif
                if(result == null)
                    result = await client.LoginAsync(email, password);
                
                if(result?.Success ?? false)
                {
                    Message = "Updating schedule...";
                    Settings.FirstName = result.User?.FirstName ?? string.Empty;
                    Settings.LastName = result.User?.LastName ?? string.Empty;
                    Settings.Email = email.ToLowerInvariant();
                    MessagingService.Current.SendMessage(MessageKeys.LoggedIn);
                    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);
                    }
                    await Finish();
                    Settings.FirstRun = false;
                }
                else
                {
                    Logger.Track(EvolveLoggerKeys.LoginFailure, "Reason", result.Error); 
                    MessagingService.Current.SendMessage<MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                        {
                            Title="Unable to Sign in",
                            Message=result.Error,
                            Cancel ="OK"
                        });
                }
            } 
            catch (Exception ex) 
            {
                Logger.Track(EvolveLoggerKeys.LoginFailure, "Reason", ex?.Message ?? string.Empty);

                MessagingService.Current.SendMessage<MessagingServiceAlert>(MessageKeys.Message, new MessagingServiceAlert
                    {
                        Title="Unable to Sign in",
                        Message="The email or password provided is incorrect.",
                        Cancel ="OK"
                    });
            }
            finally
            {
                Message = string.Empty;
                IsBusy = false;
            }
        }