示例#1
0
        public Task <bool> UpdateConfirmationsAsync()
        {
            return(Task.Run(async() =>
            {
                try
                {
                    _updateSemaphore.Wait();
                    _isUpdateInProcess = true;
                    App.Logger.Trace($"Authenticator.UpdateConfirmations");
                    State = AuthenticatorState.ConfimationUpdating;
                    int beforeCount = ConfirmationsSource.Count;
                    if (await GetConfitmations())
                    {
                        App.Logger.Info($"Authenticator.UpdateConfirmationsAsync Success. Confirmations: ({ConfirmationsSource.Count}) Added: [{ConfirmationsSource.Count - beforeCount}]");
                        State = AuthenticatorState.ConfimationUpdated;
                        _lastUpdate = DateTime.Now;
                        ConfirmationsEvent.Invoke(this, new AuthenticatorConfirmationsEventArgs(ConfirmationActionResult.Added, ConfirmationsSource.Count - beforeCount));

                        return true;
                    }
                    else
                    {
                        App.Logger.Error($"Authenticator.UpdateConfirmationsAsync Error");
                        State = AuthenticatorState.ConfimationError;

                        return false;
                    }
                }
                finally
                {
                    _isUpdateInProcess = false;
                    _updateSemaphore.Release();
                }
            }));
        }
示例#2
0
        public Task <bool> ProcessConfirmationsAsync(IEnumerable <ConfirmationItem> confirmations, ConfirmationAction action, CancellationToken cancellationToken)
        {
            return(Task.Run(async() => {
                _confirmationSemaphore.Wait();
                _isConirmationInProcess = true;
                bool success = true;
                try
                {
                    App.Logger.Info($"Authenticator.ProcessConfirmationsAsync Action: {action}");
                    State = AuthenticatorState.ConfirmationProcessing;
                    if (confirmations == null || confirmations.Count() == 0)
                    {
                        App.Logger.Trace($"Authenticator.ProcessConfirmationsAsync [Empty]");
                        return success;
                    }

                    App.Logger.Info($"Authenticator.ProcessConfirmationsAsync Confirmations for process: {confirmations.Count()}");
                    int counter = 0;
                    foreach (ConfirmationItem confirmation in confirmations)
                    {
                        try
                        {
                            cancellationToken.ThrowIfCancellationRequested();
                            await ProcessConfirmationAsync(confirmation, action);
                            counter++;
                        }
                        catch (OperationCanceledException)
                        {
                            App.Logger.Info($"Authenticator.ProcessConfirmationsAsync Canceled");
                            break;
                        }
                    }

                    ConfirmationActionResult confirmationActionResult = action == ConfirmationAction.Accept ? ConfirmationActionResult.Accept : ConfirmationActionResult.Decline;
                    ConfirmationsEvent.Invoke(this, new AuthenticatorConfirmationsEventArgs(confirmationActionResult, counter));

                    return success;
                }
                finally
                {
                    State = AuthenticatorState.ConfirmationProcessed;
                    _isConirmationInProcess = false;
                    _confirmationSemaphore.Release();
                }
            }));
        }