public override void OnActionExecuting(HttpActionContext actionContext) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); var request = actionContext.ActionArguments[RequestArgumentName]; bool enableValidation = false; if (Utils.Configuration.HasSetting(Constants.ValidateWSDLocation)) { enableValidation = Utils.Configuration[Constants.ValidateWSDLocation].ToBool(); } if (request == null || !enableValidation) { return; } HttpRequestMessage httpRequest = (HttpRequestMessage)request; Request requestparam = new Request(); this.PawsAuditor.UserId = this.PawsLogger.UserId; this.PawsAuditor.TransactionId = this.PawsLogger.TransactionId; this.PawsAuditor.RegionCode = Utils.Configuration.CurrentRegionId; try { requestparam = JsonSerialization.DeserializeString <Request>(httpRequest.Content.ReadAsStringAsync().Result); GeoLocation geolocation = requestparam.Params.Location; GeoLocation[] geolocations = requestparam.Params.Locations; List <RegionPolygonsCache> subregions = (List <RegionPolygonsCache>)DatabaseCache.ServiceCacheHelper.GetServiceCacheObjects(ServiceCacheObjectType.RegionPolygons, null); bool isValidRequest = false; bool isBatchRequest = false; if (geolocation != null) { isValidRequest = ValidateRequestedLocation(geolocation, subregions); } else if (geolocations != null && geolocations.Length > 0) { isBatchRequest = true; isValidRequest = ValidateBatchRequestLocations(geolocations, subregions); } stopWatch.Stop(); if (!isValidRequest) { PawsResponse errorResponse = null; if (isBatchRequest) { errorResponse = ErrorHelper.CreateErrorResponse(requestparam.Method, geolocations, Constants.ErrorMessageOutsideCoverage); } else { errorResponse = ErrorHelper.CreateErrorResponse(requestparam.Method, geolocation, Constants.ErrorMessageOutsideCoverage); } this.PawsLogger.Log(TraceEventType.Error, LoggingMessageId.PAWSGenericMessage, errorResponse.Error.Message); string auditMethod; AuditId auditId = PawsUtil.GetAuditId(requestparam.Method, out auditMethod); this.PawsAuditor.Audit(auditId, AuditStatus.Failure, stopWatch.ElapsedMilliseconds, auditMethod + " failed"); actionContext.Response = actionContext.Request.CreateResponse <PawsResponse>(errorResponse); } } catch (Exception ex) { stopWatch.Stop(); this.PawsLogger.Log(TraceEventType.Error, LoggingMessageId.PAWSGenericMessage, ex.ToString()); string auditMethod; AuditId auditId = PawsUtil.GetAuditId(requestparam.Method, out auditMethod); this.PawsAuditor.Audit(auditId, AuditStatus.Failure, stopWatch.ElapsedMilliseconds, auditMethod + " failed"); PawsResponse errorResponse = ErrorHelper.CreateExceptionResponse(requestparam.Method, ex.Message); actionContext.Response = actionContext.Request.CreateResponse <PawsResponse>(errorResponse); } }
public PawsResponse Post(HttpRequestMessage httpRequest) { PawsResponse postResponse = new PawsResponse(); string methodId = string.Empty; Request requestparam = new Request(); try { // Begin Log transaction this.PawsLogger.Log(TraceEventType.Information, LoggingMessageId.PAWSGenericMessage, "Enter " + this.methodName); // Begin elapsed time calculation this.stopWatch = new Stopwatch(); this.stopWatch.Start(); try { requestparam = JsonSerialization.DeserializeString <Request>(httpRequest.Content.ReadAsStringAsync().Result); } catch (Exception) { return(new PawsResponse { JsonRpc = "2.0", Error = new Result { Code = "-201", Message = Constants.InvalidRequest } }); } postResponse = this.Router(requestparam); if (postResponse.Error != null) { postResponse.Error.Version = requestparam.Params.Version; } // Populate audit id based on method in the request string auditMethod; this.auditId = PawsUtil.GetAuditId(requestparam.Method, out auditMethod); this.auditMethodName = auditMethod; // End Audit transaction this.PawsAuditor.UserId = this.PawsLogger.UserId; this.PawsAuditor.TransactionId = this.PawsLogger.TransactionId; this.PawsAuditor.RegionCode = Utils.Configuration.CurrentRegionId; // End Elapsed Time Calculation this.stopWatch.Stop(); this.elapsedTime = this.stopWatch.ElapsedMilliseconds; if (postResponse.Result == null && postResponse.Error.Code != null) { this.PawsAuditor.Audit(this.auditId, AuditStatus.Failure, this.elapsedTime, this.auditMethodName + " failed"); } else if (postResponse.Error == null && postResponse.Result.Type != null) { this.PawsAuditor.Audit(this.auditId, AuditStatus.Success, this.elapsedTime, this.auditMethodName + " passed"); } // End Log transaction this.PawsLogger.Log(TraceEventType.Information, LoggingMessageId.PAWSGenericMessage, "Exit " + this.methodName); return(postResponse); } catch (Exception exception) { // Log transaction Failure this.PawsLogger.Log(TraceEventType.Error, LoggingMessageId.PAWSGenericMessage, exception.ToString()); // Audit transaction Failure this.PawsAuditor.UserId = this.PawsLogger.UserId; this.PawsAuditor.TransactionId = this.PawsLogger.TransactionId; this.PawsAuditor.RegionCode = Utils.Configuration.CurrentRegionId; string auditMethod; this.auditId = PawsUtil.GetAuditId(requestparam.Method, out auditMethod); this.auditMethodName = auditMethod; // End Elapsed Time Calculation this.stopWatch.Stop(); this.elapsedTime = this.stopWatch.ElapsedMilliseconds; this.PawsAuditor.Audit(this.auditId, AuditStatus.Failure, this.elapsedTime, this.auditMethodName + " failed"); return(new PawsResponse { JsonRpc = "2.0", Error = new Result { Code = "-201", Message = exception.Message } }); } }