Ejemplo n.º 1
0
        public static void LogRequest(HttpContext context, NameValueCollection requestForm)
        {
            var           logType       = LogType.OnHandlerRequestReceived;
            RequestParams requestParams = WebHelper.BuildRequestParams(context, requestForm);

            var newLogElement = new LogElementDTO(
                guid: LoggingHelper.GetInstanceGUID(context, () => new Guid(), requestForm).GetValueOrDefault(),
                sessionGUID: LoggingHelper.GetSessionGUID(context, null, () => new Guid(), requestForm).GetValueOrDefault(),
                pageGUID: LoggingHelper.GetPageGUID(context, null, () => new Guid(), requestForm).GetValueOrDefault(),
                bundleGUID: LoggingHelper.GetBundleGUID(context, () => new Guid(), requestForm).GetValueOrDefault(),
                progressGUID: null,
                unixTimestamp: TimeHelper.UnixTimestamp(),
                logType: logType,
                element: LoggingHelper.StripUrlForLRAP(context.Request.RawUrl),
                element2: null,
                value: SerializationHelper.Serialize(requestParams, SerializationType.Json),
                times: 1,
                unixTimestampEnd: null,
                instanceTime: DateTime.Now,
                stackTrace: null
                );

            if (LoggingHelper.IsPlaying(context, requestForm))
            {
                var serverGUID  = LoggingHelper.GetServerGUID(context, () => { throw new Exception(); }, requestForm).Value;
                var sessionGUID = LoggingHelper.GetSessionGUID(context, null, null, requestForm);
                var pageGUID    = LoggingHelper.GetPageGUID(context, null, null, requestForm);

                if (LoggingHelper.FetchAndExecuteLogElement(serverGUID, sessionGUID, pageGUID, logType, (logElement) =>
                {
                    TimeHelper.SetNow(context, logElement.InstanceTime);

                    //                    var requestFormValues = SerializationHelper.DeserializeNameValueCollection(logElement.Value, SerializationType.Json);
                    requestParams = SerializationHelper.Deserialize <RequestParams>(logElement.Value, SerializationType.Json);

                    var headers = context?.Request?.Headers;
                    if (headers != null)
                    {
                        var json1 = SerializationHelper.Serialize(newLogElement, SerializationType.Json);
                        var xxx = SerializationHelper.Deserialize <LogElementDTO>(json1, SerializationType.Json);
                        var what = TimeHelper.UnixTimestamp(xxx.InstanceTime).ToString(CultureInfo.InvariantCulture);

                        headers[Consts.NowTimestampTag] = TimeHelper.UnixTimestamp(logElement.InstanceTime).ToString(CultureInfo.InvariantCulture);
                    }
                    //LoggingHelper.SetRequestValues(context, requestParams.Form, requestForm);

                    PlayerCommunicationHelper.SetLogElementAsDone(serverGUID, sessionGUID, pageGUID, logElement.GUID, new JobStatus()
                    {
                        Success = true
                    });                                                                                                                                    //, async: false);
                }))
                {
                    return;
                }
            }

            LoggingHelper.LogElement(newLogElement);
        }
Ejemplo n.º 2
0
        public static string LogResponse(HttpContext context, string response)
        {
            var logType = LogType.OnHandlerResponseSend;

            //Need to parse info from request to response... in this case where ashx is called from a external website
            var requestContainsInstanceGuid = context.Request.Params[Consts.GUIDTag] != null;

            var newLogElement = new LogElementDTO(
                guid: LoggingHelper.GetInstanceGUID(context, () => new Guid()).GetValueOrDefault(),
                sessionGUID: LoggingHelper.GetSessionGUID(context, null, () => new Guid()).GetValueOrDefault(),
                pageGUID: LoggingHelper.GetPageGUID(context, null, () => new Guid()).GetValueOrDefault(),
                bundleGUID: LoggingHelper.GetBundleGUID(context, () => new Guid()).GetValueOrDefault(),
                progressGUID: null,
                unixTimestamp: TimeHelper.UnixTimestamp(),
                logType: logType,
                element: LoggingHelper.StripUrlForLRAP(context.Request.RawUrl),
                element2: !requestContainsInstanceGuid ? SerializationHelper.SerializeNameValueCollection(context.Request.Form, SerializationType.Json) : null,
                value: response,
                times: 1,
                unixTimestampEnd: null,
                instanceTime: DateTime.Now,
                stackTrace: null
                );

            if (LoggingHelper.IsPlaying(context, requestForm: null))
            {
                var serverGUID  = LoggingHelper.GetServerGUID(context, () => { throw new Exception(); }).Value;
                var sessionGUID = LoggingHelper.GetSessionGUID(context, null, null);
                var pageGUID    = LoggingHelper.GetPageGUID(context, null, null);

                string newResponse = null;

                if (LoggingHelper.FetchAndExecuteLogElement(serverGUID, sessionGUID, pageGUID, logType, (logElement) =>
                {
                    TimeHelper.SetNow(context, logElement.InstanceTime);

                    newResponse = response;
                    //newResponse = logElement.Value;

                    //context.Response.Clear();
                    //context.Response.Write(newResponse);

                    PlayerCommunicationHelper.SetLogElementAsDone(serverGUID, sessionGUID, pageGUID, logElement.GUID, new JobStatus()
                    {
                        Success = true
                    });                                                                                                                                    //, async: false);
                }))
                {
                    return(newResponse);
                }
            }

            LoggingHelper.LogElement(newLogElement);

            return(response);
        }
Ejemplo n.º 3
0
        public static void SetupClientBase <T>(System.ServiceModel.ClientBase <T> client, HttpContext httpContext) where T : class
        {
            var guid        = LoggingHelper.GetInstanceGUID(httpContext, () => new Guid()).GetValueOrDefault();
            var sessionGUID = LoggingHelper.GetSessionGUID(httpContext, httpContext?.Handler as Page, () => new Guid()).GetValueOrDefault();
            var pageGUID    = LoggingHelper.GetPageGUID(httpContext, httpContext?.Handler as Page, () => new Guid()).GetValueOrDefault();
            var bundleGUID  = LoggingHelper.GetBundleGUID(httpContext, () => new Guid()).GetValueOrDefault();

            var newLogElement = new LogElementDTO(
                guid: guid,
                sessionGUID: sessionGUID,
                pageGUID: pageGUID,
                bundleGUID: bundleGUID,
                progressGUID: null,
                unixTimestamp: TimeHelper.UnixTimestamp(),
                logType: LogType.OnSetup,
                element: $"SetupClientBase_{client.Endpoint.Address.Uri}", //LoggingHelper.StripUrlForLRAP(context.Request.RawUrl),
                element2: null,
                value: "",                                                 //SerializationHelper.Serialize(requestParams, SerializationType.Json),
                times: 1,
                unixTimestampEnd: null,
                instanceTime: DateTime.Now,
                stackTrace: null
                );

            var eab = new EndpointAddressBuilder(client.Endpoint.Address);

            eab.Headers.Add(AddressHeader.CreateAddressHeader(Consts.GUIDTag,
                                                              string.Empty,
                                                              guid.ToString()));

            eab.Headers.Add(AddressHeader.CreateAddressHeader(Consts.SessionGUIDTag,
                                                              string.Empty,
                                                              sessionGUID.ToString()));

            eab.Headers.Add(AddressHeader.CreateAddressHeader(Consts.PageGUIDTag,
                                                              string.Empty,
                                                              pageGUID.ToString()));

            eab.Headers.Add(AddressHeader.CreateAddressHeader(Consts.BundleGUIDTag,
                                                              string.Empty,
                                                              bundleGUID.ToString()));

            eab.Headers.Add(AddressHeader.CreateAddressHeader(Consts.ServerGUIDTag,
                                                              string.Empty,
                                                              LoggingHelper.GetServerGUID(httpContext, () => new Guid()).GetValueOrDefault().ToString()));

            client.Endpoint.Address = eab.ToEndpointAddress();
        }
Ejemplo n.º 4
0
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
        {
            if (!Configuration.Enabled)
            {
                return(null);
            }

            //var via = channel.Via;
            //var inputSession = channel.InputSession;
            //var outputSession = channel.OutputSession;
            //var SessionId = channel.SessionId;
            //var LocalAddress = channel.LocalAddress;
            //var state = channel.State;

            var context = HttpContext.Current;
            var page    = HttpContext.Current?.Handler as Page;

            var loggingState = new LoggingState()
            {
                Context     = context,
                Page        = page,
                GUID        = LoggingHelper.GetInstanceGUID(context, () => Guid.NewGuid()).GetValueOrDefault(),
                SessionGUID = LoggingHelper.GetSessionGUID(context, page, () => new Guid()).GetValueOrDefault(),
                PageGUID    = LoggingHelper.GetPageGUID(context, page, null).GetValueOrDefault(),
                BundleGUID  = LoggingHelper.GetBundleGUID(context, () => Guid.NewGuid()).GetValueOrDefault(),
                Url         = LoggingHelper.StripUrlForLRAP(channel.Via.ToString()),
                Action      = request.Headers.Action,
                ServerGUID  = LoggingHelper.GetServerGUID(HttpContext.Current, null, page?.Request?.Params)
            };

            var logType = LogType.OnWCFServiceRequest;

            //OperationContext.Current.SessionId

            string messageBody   = GetMessageBody(request);
            var    newLogElement = new LogElementDTO(
                guid: loggingState.GUID,
                sessionGUID: loggingState.SessionGUID,
                pageGUID: loggingState.PageGUID,
                bundleGUID: loggingState.BundleGUID,
                progressGUID: null,
                unixTimestamp: TimeHelper.UnixTimestamp(),
                logType: logType,
                element: Path.GetFileName(loggingState.Action),
                element2: null,
                value: messageBody,
                times: 1,
                unixTimestampEnd: null,
                instanceTime: DateTime.Now,
                stackTrace: null
                );

            if (LoggingHelper.IsPlaying(context, page?.Request.Params))
            {
                if (LoggingHelper.FetchAndExecuteLogElement(loggingState.ServerGUID.Value, loggingState.SessionGUID, loggingState.PageGUID, logType, (logElement) =>
                {
                    TimeHelper.SetNow(context, logElement.InstanceTime);

                    var loggedMessageBody = logElement.Value;
                    if (loggedMessageBody != null && messageBody != null && loggedMessageBody != messageBody)
                    {
                        var useLoggedElement = PlayerCommunicationHelper.ReportDifference(loggingState.ServerGUID.Value, logElement, newLogElement);
                        if (useLoggedElement)
                        {
                            messageBody = loggedMessageBody;
                        }
                    }

                    PlayerCommunicationHelper.SetLogElementAsDone(loggingState.ServerGUID.Value, loggingState.SessionGUID, loggingState.PageGUID, logElement.GUID, new JobStatus()
                    {
                        Success = true
                    });                                                                                                                                                                                 //, async: false);
                }))
                {
                }
            }
            else
            {
                LoggingHelper.LogElement(newLogElement);
            }

            request = BuildMessage(messageBody, request);

            return(loggingState);
        }