public override void OnActionExecuting(HttpActionContext actionContext)
        {
            //use with the attribute [SkipMyGlobalActionFilter]
            if (actionContext.ActionDescriptor.GetCustomAttributes <SkipMyGlobalActionFilterAttribute>(false).Any())
            {
                return;
            }

            //new Task(() => { ).Start(); //this will execute in its own thread allowing the request to continue processing independently of the 'Save'
            //var durationInMilli = (DateTime.Now - startTime).Milliseconds;
            //Debug.WriteLine("PreProcessQuoteRequestFilter hit...pre-process time: " + durationInMilli);

            var newRequest = new AApiRequest();

            actionContext.Request.Properties[Global.ARequestPropertyName] = newRequest;
            Task.Run(() =>
            {
                newRequest.LocalServerName = Global.LocalServerName;
                newRequest.ApiName         = Global.ApiObject.ApiName;
                newRequest.ApiEndPoint     = actionContext.Request.RequestUri.AbsolutePath.ToLower();
                newRequest.Url             = actionContext.Request.RequestUri.AbsoluteUri;
                newRequest.RemoteIP        = ClientInfo.GetIPAddress(actionContext.Request);
                try
                {
                    foreach (var key in actionContext.ActionArguments.Keys)
                    {
                        switch (key.ToLower())
                        {
                        case "authtoken": newRequest.AuthToken = actionContext.ActionArguments[key].ToString(); break;

                        case "clientid": newRequest.ClientId = NullSafe.NullSafeInteger(actionContext.ActionArguments[key]); break;

                        //case "request": (actionContext.ActionArguments[key] is string) ? newRequest.RawRequest = actionContext.ActionArguments[key].ToString() : ; break;
                        //case "loanpricerloanrequest": newRequest.RawRequest = JsonConvert.SerializeObject(actionContext.ActionArguments[key]); break;
                        case "commonparams": break;

                        default:
                            newRequest.RawRequest = (actionContext.ActionArguments[key] is string) ? newRequest.RawRequest = actionContext.ActionArguments[key].ToString() : JsonConvert.SerializeObject(actionContext.ActionArguments.FirstOrDefault()); break;
                        }
                    }
                }
                catch (Exception ex) { newRequest.RawRequest = "ERROR trying to read Content:" + ex.Message; }
                if (string.IsNullOrEmpty(newRequest.RawRequest))
                {
                    newRequest.RawRequest = actionContext.Request.RequestUri.Query;
                }
                newRequest.Save();
            });

            base.OnActionExecuting(actionContext);
        }
Пример #2
0
 public override void OnActionExecuted(HttpActionExecutedContext actionContext)
 {
     try
     {
         new Task(() =>
         {
             AApiResponse apiResponse = new AApiResponse();
             AApiRequest request      = actionContext.Request.Properties[Global.ARequestPropertyName] as AApiRequest;
             if (request != null)
             {
                 //if the request Id is zero, then the save to the data context may not have completed. Let's give it a little extra time...
                 int counter = 0;
                 while (request.Id == 0 && counter++ < 20)
                 {
                     Thread.Sleep(50);
                 }
                 apiResponse.Id = request.Id;
                 apiResponse.ClientDefinedIdentifier = request.ClientDefinedIdentifier;
             }
             var objContent             = (actionContext.ActionContext.Response.Content as ObjectContent);
             Requests.IResponse content = objContent?.Value as Requests.IResponse;
             if (content != null)
             {
                 apiResponse.ApiEndPoint             = content.ApiEndPoint;
                 apiResponse.Message                 = content.LoanTekDefinedIdentifier.ToString();
                 apiResponse.ExecutionTimeInMillisec = content.ExecutionTimeInMillisec;
                 apiResponse.HttpStatusCode          = actionContext.ActionContext.Response.StatusCode;
                 apiResponse.Save();
             }
         }).Start();
     }
     catch (Exception ex)
     {
         Global.OutPrint("ERROR: " + ex.Message, new SimpleLogger.LocationObject(this, "OnActionExecuted"), SimpleLogger.LogLevelType.ERROR);
     }
 }