コード例 #1
0
        /// <summary>
        /// Get the in progress upload pagination length for a user and performs business logic to check for user existence.
        /// Retries operation when there is an exception and logs all actions.
        /// </summary>
        /// <param name="username">User to retrieve pagination length from.</param>
        /// <param name="ipAddress">Ipaddress for logging.</param>
        /// <param name="failureCount">Current failure count of the operation.</param>
        /// <param name="ex">Exception that is thrown.</param>
        /// <returns>int that represents pagination size.</returns>
        public async Task <int> GetInProgressUploadPaginationSizeAsync(string username, string ipAddress, int failureCount, Exception ex)
        {
            // Escape condition for recursive call if exception is thrown.
            if (failureCount >= Constants.OperationRetry)
            {
                throw ex;
            }

            // Pagination size to return.
            int paginationSize = 0;

            try
            {
                // Check that the user exists.
                var userExists = await _userManagementService.CheckUserExistenceAsync(username).ConfigureAwait(false);

                if (!userExists)
                {
                    throw new ArgumentException(Constants.UsernameDNE);
                }

                // Perform operation.
                paginationSize = await _uploadService.GetInProgressPaginationSizeAsync(username).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                // Log everytime we catch an exception.
                await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString),
                                               Constants.GetInProgressUploadPagination, username, ipAddress, e.ToString()).ConfigureAwait(false);

                // Retry operation Constant.OperationRetry amount of times when there is exception.
                await GetInProgressUploadPaginationSizeAsync(username, ipAddress, ++failureCount, e).ConfigureAwait(false);
            }

            // Operation successfull, log that operation.
            await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString),
                                           Constants.GetInProgressUploadPagination, username, ipAddress).ConfigureAwait(false);

            return(paginationSize);
        }