Exemplo n.º 1
0
        private async Task AuthenticateAsync()
        {
            AuthenticationResult result;
            LogMessage           exceptionMsg = null;

            ProgressTitle   = _progressTitleForPasscode;
            ProgressMessage = _progressMessageForPasscode;

            this.IsBusy = true;

            try
            {
                result = await _authenticationService.AuthenticateAsync(this.Passcode);

                if (result.Success)
                {
                    _infoService.SetCurrentDriver(result.Driver);

                    if (await _currentDriverRepository.GetByIDAsync(_infoService.CurrentDriverID.Value) == null)
                    {
                        var newDriver = new CurrentDriver {
                            ID = _infoService.CurrentDriverID.Value
                        };

                        try
                        {
                            await _currentDriverRepository.InsertAsync(newDriver);
                        }
                        catch (Exception ex)
                        {
                            MvxTrace.Error("\"{0}\" in {1}.{2}\n{3}", ex.Message, "CurrentDriverRepository", "InsertAsync", ex.StackTrace);
                            throw;
                        }
                    }

                    // Start the gateway queue timer which will cause submission of any queued data to the MWF Mobile gateway service on a repeat basis
                    _gatewayQueuedService.StartQueueTimer();

                    await _navigationService.MoveToNextAsync();
                }
            }
            catch (Exception ex)
            {
                exceptionMsg = _loggingService.GetExceptionLogMessage(ex);
                result       = new AuthenticationResult()
                {
                    AuthenticationFailedMessage = "Unable to check your passcode.", Success = false
                };
            }
            finally
            {
                // clear the passcode
                this.Passcode = string.Empty;
                this.IsBusy   = false;
            }

            if (exceptionMsg != null)
            {
                await _loggingService.LogEventAsync(exceptionMsg);
            }

            // Let the user know
            if (!result.Success)
            {
                await Mvx.Resolve <ICustomUserInteraction>().AlertAsync(result.AuthenticationFailedMessage);
            }
        }