예제 #1
0
        public async Task <IHttpActionResult> LeadEventListenerInsert(PayloadParent peLeadDataForUpdate)
        {
            //UserGuid = GetUserGuidFromHttpContextBase(_httpContextBase);
            //if (UserGuid == Guid.Empty) return new HttpActionResult(HttpStatusCode.Unauthorized, "User Validation Error");

            //Log the request
            var logCommand = new LogCommand
            {
                User            = User,
                LoggingInstance = _loggingInstance,
                LogMessage      = $"LeadController.LeadEventListenerInsert Starting input parameter CDCLeadDataForUpdate = {peLeadDataForUpdate}"
            };

            _logHandler.ReplayId = LoggingHelper.GetReplayId(JsonConvert.SerializeObject(peLeadDataForUpdate));

            _logHandler.HandleLog(logCommand);

            //Await the response
            //ToDo: This needs to be handled correctly.
            //Await the response
            var results = await _leadService.UpsertLeadFromInsertEvent(peLeadDataForUpdate, logCommand);

            //Log the response
            logCommand.LogMessage =
                $"LeadController.LeadEventListenerCreate completed. Output value End Of Controller";
            _logHandler.HandleLog(logCommand);

            //Return the results
            return(ReturnFormattedResults(results));
        }
예제 #2
0
        public IHttpActionResult AccountEventListenerUpdate(PayloadParent payloadParent)
        {
            //UserGuid = GetUserGuidFromHttpContextBase(_httpContextBase);
            //if (UserGuid == Guid.Empty) return new HttpActionResult(HttpStatusCode.Unauthorized, "User Validation Error");

            //Log the request
            var logCommand = new LogCommand
            {
                User            = User,
                LoggingInstance = _loggingInstance,
                LogMessage      = $"CustomerController.AccountAppointmentEventListenerUpdate Starting input parameter CDCCustomerDataForUpdate = {payloadParent}"
            };

            _logHandler.ReplayId = LoggingHelper.GetReplayId(JsonConvert.SerializeObject(payloadParent));
            _logHandler.HandleLog(logCommand);

            //Await the response
            //ToDo: This needs to be handled correctly.
            //Await the response
            //Await the response
            var results = new GenericServiceResponse
            {
                Entity             = "Account Place Holder - Nothing is Happening!",
                Success            = true,
                RestResponseStatus = GenericServiceResponse.RestStatus.Success
            };

            //Log the response
            logCommand.LogMessage =
                $"CustomerController.AccountAppointmentEventListenerUpdate completed. Output value End Of Controller";
            _logHandler.HandleLog(logCommand);

            //Return the results
            return(ReturnFormattedResults(results));
        }
예제 #3
0
        public async Task <IHttpActionResult> AccountEventListenerInsert(PayloadParent payloadParent)
        {
            //UserGuid = GetUserGuidFromHttpContextBase(_httpContextBase);
            //if (UserGuid == Guid.Empty) return new HttpActionResult(HttpStatusCode.Unauthorized, "User Validation Error");

            //Log the request
            var logCommand = new LogCommand
            {
                User            = User,
                LoggingInstance = _loggingInstance,
                LogMessage      = $"CustomerController.AccountAppointmentEventListenerInsert Starting input parameter payloadParent = {payloadParent}"
            };

            _logHandler.ReplayId = LoggingHelper.GetReplayId(JsonConvert.SerializeObject(payloadParent));

            _logHandler.HandleLog(logCommand);

            //Await the response
            var results = await _leadService.ConvertLeadToAccount(payloadParent, logCommand);

            //Log the response
            logCommand.LogMessage =
                $"CustomerController.AccountAppointmentEventListenerInsert completed. Output value End of controller";
            _logHandler.HandleLog(logCommand);

            //Return the results
            return(ReturnFormattedResults(results));
        }
예제 #4
0
        public async Task <IHttpActionResult> ServiceAppointmentEventListenerUpdate(PayloadParent payloadResponse)
        {
            string ActionName = "ServiceAppointmentEventListenerUpdate";
            //Log the request
            var logCommand = new LogCommand
            {
                User            = User,
                LoggingInstance = _loggingInstance,
                LogMessage      = $"{Controller}.{ActionName} Starting input parameter PayloadParent = {JsonConvert.SerializeObject(payloadResponse)}"
            };

            _logHandler.ReplayId = LoggingHelper.GetReplayId(JsonConvert.SerializeObject(payloadResponse));

            _logHandler.HandleLog(logCommand);

            //Await the response
            var results = await _SchedulingService.SimpleServiceAppointmentHandler(payloadResponse, logCommand);

            //Log the response
            logCommand.LogMessage =
                $"CustomerController.TaskEventListenerInsert completed. Output value End of controller";
            _logHandler.HandleLog(logCommand);

            //Return the results
            return(ReturnFormattedResults(results));
        }
예제 #5
0
        public override async Task Invoke(IOwinContext context)
        {
            //Don't log if the isLoggingEnabled = false or Swagger requests.
            if (!_isLoggingEnabled || context.Request.Uri.AbsoluteUri.ToLower().Contains("localhost"))
            {
                //skip the middleware logger
                await _next.Invoke(context);

                return;
            }
            //public async Task Invoke(IDictionary<string, object> environment)
            //{
            //    IOwinContext context = new OwinContext(environment);


            // Get the identity
            var identity = (context.Request.User != null && context.Request.User.Identity.IsAuthenticated)
                ? context.Request.User.Identity.Name
                : "(anonymous)";


            // Buffer the request (body is a string, we can use this to log the request later
            var requestBody = new StreamReader(context.Request.Body).ReadToEnd();
            var requestData = Encoding.UTF8.GetBytes(requestBody);

            context.Request.Body = new MemoryStream(requestData);

            var apiPacket = new ApiPacket
            {
                CallerIdentity   = identity,
                RequestBody      = requestBody,
                RequestLength    = context.Request.Body.Length,
                RequestTimestamp = DateTime.Now // HttpContext.Current.Timestamp
            };

            var replayId = LoggingHelper.GetReplayId(requestBody);

            if (replayId != 0)
            {
                apiPacket.ReplayId = replayId;
            }
            apiPacket.CallerIdentity = SplitRequestBody(requestBody, "username");


            // Buffer the response
            var responseBuffer = new MemoryStream();
            var responseStream = context.Response.Body;

            context.Response.Body = responseBuffer;

            // add the "http-correlation-id" response header so the user can correlate back to this entry
            var responseHeaders = (IDictionary <string, string[]>)context.Environment["owin.ResponseHeaders"];
            //responseHeaders["http-correlation-id"] = new[] { apiPacket.CorrelationId.ToString("d") };

            await _next.Invoke(context);

            responseBuffer.Seek(0, SeekOrigin.Begin);
            var reader = new StreamReader(responseBuffer);

            apiPacket.Response = await reader.ReadToEndAsync();

            //If you need code to check for a specific request and modify the associated response
            //if (context.Request.Path.Value == @"/token")
            //{
            //    responseBuffer.Seek(0, SeekOrigin.Begin);
            //    var reader = new StreamReader(responseBuffer);
            //    apiPacket.Response = await reader.ReadToEndAsync();

            //    JObject jResp = JObject.Parse(apiPacket.Response);
            //    JObject jUserGuid = JObject.Parse(@"{'UserGuid':'PutUseGuidValueHere'}");
            //    jResp.Add("UserGuid", JToken.FromObject("UserGuidValue"));
            //    apiPacket.Response = jResp.ToString();


            //    var writeStream = new MemoryStream();
            //    StreamWriter writer = new StreamWriter(writeStream);
            //    writer.Write(apiPacket.Response);
            //    writer.Flush();
            //    writeStream.Position = 0;

            //    responseBuffer.Seek(0, SeekOrigin.Begin);
            //    writeStream.CopyTo(responseBuffer);
            //}

            //context.Response.Body = responseBuffer;
            apiPacket.ResponseLength = context.Response.ContentLength ?? 0;
            apiPacket.Duration       = (DateTime.Now - apiPacket.RequestTimestamp).TotalSeconds;

            //Make sure that user and the user identity is not null and that claims is not null before you look for the CorrelationId and AdUserName
            //or you will get a null ref error
            string trackingId;

            if (((ClaimsIdentity)context.Authentication.User?.Identity)?.Claims.FirstOrDefault() != null)
            {
                if (context.Authentication.User != null)
                {
                    trackingId = ((ClaimsIdentity)context.Authentication.User.Identity).Claims.FirstOrDefault(x => x.Type.ToUpper() == "SFCORRELATIONID")?.Value;
                    Guid.TryParse(trackingId, out Guid trackGuid);
                    apiPacket.CorrelationId  = trackGuid;
                    apiPacket.CallerIdentity = ((ClaimsIdentity)context.Authentication.User.Identity).Claims.FirstOrDefault(x => x.Type.ToUpper() == "SFADUSERNAME")?.Value;
                }

                context.Environment.TryGetValue("owin.CallCancelled", out var cancellation);
                if (cancellation != null)
                {
                    var token = (CancellationToken)cancellation;
                    if (token.IsCancellationRequested == false)
                    {
                        responseHeaders["http-correlation-id"] = new[] { apiPacket.CorrelationId.ToString("d") }
                    }
                    ;
                }
            }

            else if (responseHeaders != null && responseHeaders.ContainsKey("http-correlation-id") && responseHeaders["http-correlation-id"].FirstOrDefault() != Guid.Empty.ToString())
            {
                trackingId = responseHeaders["http-correlation-id"].FirstOrDefault();
                Guid.TryParse(trackingId, out Guid trackGuid);
                apiPacket.CorrelationId = trackGuid;
            }

            WriteRequestHeaders(context.Request, apiPacket);
            WriteResponseHeaders(context.Response, apiPacket);

            _logThisError = apiPacket.StatusCode != (int)HttpStatusCode.OK;
            try
            {
                //Persist the ApiPacket in the database ignore any logging errors ex: (System.Web.HttpException (0x80004005): Server cannot append header after HTTP headers have been sent.
                await _httpLoggerRepository.InsertApiPacketAsync(_isLoggingEnabled, apiPacket, _logThisError);
            }

            finally
            {
                // You need to do the following so that the buffered response is flushed out to the client application.
                responseBuffer.Seek(0, SeekOrigin.Begin);
                await responseBuffer.CopyToAsync(responseStream);
            }
        }