/// <summary> /// Retrieve the in progress uploads for a username and perform business logic to check existence. /// Retries operation when there is an exception and logs all actions. /// </summary> /// <param name="username">Username of profile score to fetch.</param> /// <param name="pagination">Pagination for the operation. Starts at 0.</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>List of UploadResult</returns> public async Task <List <UploadResult> > GetInProgressUploadsAsync(string username, int pagination, string ipAddress, int failureCount, Exception ex) { // Escape condition for recursive call if exception is thrown. if (failureCount >= Constants.OperationRetry) { throw ex; } // List of uploads to return. var inProgessUploads = new List <UploadResult>(); try { // Check that the user exists. var userExists = await _userManagementService.CheckUserExistenceAsync(username).ConfigureAwait(false); if (!userExists) { throw new ArgumentException(Constants.UsernameDNE); } // Perform operation. inProgessUploads = await _uploadService.GetInProgressUploadsByUploaderAsync(username, pagination).ConfigureAwait(false); } catch (Exception e) { // Log everytime we catch an exception. await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString), Constants.GetInProgressUploadsOperation, username, ipAddress, e.ToString()).ConfigureAwait(false); // Retry operation Constant.OperationRetry amount of times when there is exception. await GetInProgressUploadsAsync(username, pagination, ipAddress, ++failureCount, e).ConfigureAwait(false); } // Operation successfull, log that operation. await _loggingManager.LogAsync(DateTime.UtcNow.ToString(Constants.LoggingFormatString), Constants.GetInProgressUploadsOperation, username, ipAddress).ConfigureAwait(false); return(inProgessUploads); }