private async Task<SuppressionFilesRequest> UpdateRequest(SuppressionFilesRequest request) { using (var ctx = new SuppressionFilesContext()) using (var repository = new Repository<SuppressionFilesContext>(ctx)) { request = repository.Update(request); using (var uow = new UnitOfWork<SuppressionFilesContext>(ctx)) { await uow.CommitAsync(); } return request; } }
private HttpResponseException BuildErrorResponse(SuppressionFilesRequest request, string message) { Action<string> _logByLevel = Logger.Debug; var errorMessage = string.Format("Error Message: {0}", message); if (request != null) { if (SuppressionFilesRequest.RequestErrorCode.None == request.ErrorCode) { request.ErrorCode = SuppressionFilesRequest.RequestErrorCode.Other; _logByLevel += s => Logger.Fatal(s); } errorMessage = string.Format("{0}, {1}", string.Format(InvalidMessageFormat, request.SuppressionFilesRequestId, request.ErrorCode, request.ErrorCode.GetDescription()), errorMessage); Task.Run(async () => await UpdateRequest(request)); } _logByLevel(errorMessage); return new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage)); }
private void CheckParameters(SuppressionFilesRequest request, int requesterId, int storeKey, DateTime receivedDate, bool? hashed, string key, out string latestFile) { using (var ctx = new OenContext()) using (var repository = new Repository<OenContext>(ctx)) { Logger.Trace("Validating Requester"); if (!_validator.IsValidRequester(requesterId, _settings.RequesterId)) { request.ErrorCode = SuppressionFilesRequest.RequestErrorCode.InvalidRequesterId; throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Format(InvalidMessageFormat, request.SuppressionFilesRequestId, request.ErrorCode, request.ErrorCode.GetDescription()))); } Logger.Trace("Validating List"); var list = repository.Retrieve<SuppressionType>().FirstOrDefault(x => x.suptype_id == storeKey); if (!_validator.IsValidList(list)) { request.ErrorCode = SuppressionFilesRequest.RequestErrorCode.InvalidListId; throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Format(InvalidMessageFormat, request.SuppressionFilesRequestId, request.ErrorCode, request.ErrorCode.GetDescription()))); } Logger.Trace("Validating Key"); if (!_validator.IsValidKey(_settings.RequesterId, _settings.SecretKey, list, receivedDate, _settings.AuthorizedRequestsExpirationTimeInHours, key)) { request.ErrorCode = SuppressionFilesRequest.RequestErrorCode.InvalidKey; throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Format(InvalidMessageFormat, request.SuppressionFilesRequestId, request.ErrorCode, request.ErrorCode.GetDescription()))); } var availableFiles = new string [] { FindLatestSuppressionFile(string.Format(SuppressionFilesRequest.HashedFileNameFormat, list.suptype_id)), FindLatestSuppressionFile(string.Format(SuppressionFilesRequest.FileNameFormat, list.suptype_id)) }; latestFile = availableFiles.FirstOrDefault(); if (hashed.HasValue && !hashed.Value && (availableFiles.LastOrDefault() != null)) { latestFile = availableFiles.LastOrDefault(); } if (String.IsNullOrWhiteSpace(latestFile)) { request.ErrorCode = SuppressionFilesRequest.RequestErrorCode.FileNotFound; throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Format(InvalidMessageFormat, request.SuppressionFilesRequestId, request.ErrorCode, request.ErrorCode.GetDescription()))); } } }