Exemple #1
0
        public static void SetupPage(HttpContext context, Page page, LogType logType, NameValueCollection requestForm = null)
        {
            var pageGUID = GetPageGUID(context, page, defaultValue: null, requestForm: requestForm);

            if (pageGUID == null)
            {
                if (IsPlaying(context, requestForm))
                {
                    var serverGUID = GetServerGUID(context, null, requestForm).Value;

                    if (FetchAndExecuteLogElement(serverGUID, null, new Guid(), logType, (logElement) =>
                    {
                        TimeHelper.SetNow(context, logElement.InstanceTime);
                        SetPageGUID(page, logElement.PageGUID);
                    }))
                    {
                        ;
                    }
                }
                else
                {
                    SetPageGUID(page, Guid.NewGuid());
                }
            }
        }
        public static void LogRequest(HttpContext context, Page page, NameValueCollection requestForm)
        {
            var logType = LogType.OnPageRequest;

            var           postBackControlClientId = GetPostBackControlClientId(context, page, requestForm);
            RequestParams requestParams           = WebHelper.BuildRequestParams(context, requestForm);

            var newLogElement = new LogElementDTO(
                guid: Guid.NewGuid(),
                sessionGUID: LoggingHelper.GetSessionGUID(context, page, () => new Guid(), requestForm).Value,
                pageGUID: LoggingHelper.GetPageGUID(context, page, () => new Guid(), requestForm).Value,
                bundleGUID: null,
                progressGUID: null,
                unixTimestamp: TimeHelper.UnixTimestamp(),
                logType: logType,
                element: LoggingHelper.StripUrlForLRAP(context.Request.RawUrl),
                element2: postBackControlClientId,
                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, page, null, requestForm);
                var pageGUID    = LoggingHelper.GetPageGUID(context, page, null, requestForm);

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

                    if (LoggingHelper.SolutionLoggingPlayer?.StoreLogElementHistory(logElement, newLogElement) ?? false)
                    {
                        PlayerCommunicationHelper.SendLogElementHistory(serverGUID, logElement, newLogElement, LoggingHelper.SolutionLoggingPlayer?.BuildAdditionalData(context.ApplicationInstance));
                    }

                    //var requestFormValues = SerializationHelper.DeserializeNameValueCollection(logElement.Value, SerializationType.Json);
                    requestParams = DeserializeRequestValue(logElement);

                    //Kan jo ikke bare overskrive... uden at spørge brugeren om det er det der ønskes, det kan ihf ikke være default behavior
                    //LoggingHelper.SetRequestValues(context, requestParams.Form, requestForm);

                    //var requestParams = requestForm != null ? WebHelper.ParamsWithSpecialRequestForm(context, requestForm) : context.Request?.Params;

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

            LoggingHelper.LogElement(newLogElement);
        }
Exemple #3
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);
        }
        public static void LogResponse(SqlCommandDTO cmdDTO, object value)
        {
            var context = HttpContext.Current;

            var page        = HttpContext.Current.Handler as Page;
            var logType     = LogType.OnPersistenceResponse;
            var sessionGUID = LoggingHelper.GetSessionGUID(HttpContext.Current, HttpContext.Current.Handler as Page, () => new Guid()).Value;
            var pageGUID    = LoggingHelper.GetPageGUID(HttpContext.Current, HttpContext.Current.Handler as Page, () => new Guid()).Value;

            var newLogElement = new LogElementDTO(
                guid: Guid.NewGuid(),
                sessionGUID: sessionGUID,
                pageGUID: pageGUID,
                bundleGUID: cmdDTO.BundleGUID,
                progressGUID: null,
                unixTimestamp: TimeHelper.UnixTimestamp(),
                logType: logType,
                element: cmdDTO.CommandText,
                element2: null,
                value: value != null ? SerializationHelper.Serialize(value, SerializationType.Json) : null,
                times: 1,
                unixTimestampEnd: null,
                instanceTime: DateTime.Now,
                stackTrace: null
                );

            if (LoggingHelper.IsPlaying(context, page?.Request.Params))
            {
                var serverGUID = LoggingHelper.GetServerGUID(HttpContext.Current, null, page?.Request.Params).Value;

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

                    var loggedValue = logElement.Value != null ? SerializationHelper.Deserialize <object>(logElement.Value, SerializationType.Json) : null;

                    if (loggedValue != null && value != null && !loggedValue.Equals(value))
                    {
                        //Show UI-warning.. something in the response differs
                    }

                    //Kan jo ikke bare overskrive... uden at spørge brugeren om det er det der ønskes, det kan ihf ikke være default behavior
                    //LoggingHelper.SetRequestValues(context, requestParams.Form, requestForm);

                    //var requestParams = requestForm != null ? WebHelper.ParamsWithSpecialRequestForm(context, requestForm) : context.Request?.Params;

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

            LoggingHelper.LogElement(newLogElement);
        }
        public static string LogResponse(HttpContext context, Page page, string response)
        {
            var logType = LogType.OnPageResponse;

            var postBackControlClientId = GetPostBackControlClientId(context, page, requestForm: null);

            var newLogElement = new LogElementDTO(
                guid: Guid.NewGuid(),
                sessionGUID: LoggingHelper.GetSessionGUID(context, page, () => new Guid()).Value,
                pageGUID: LoggingHelper.GetPageGUID(context, page, () => new Guid()).Value,
                bundleGUID: null,
                progressGUID: null,
                unixTimestamp: TimeHelper.UnixTimestamp(),
                logType: logType,
                element: LoggingHelper.StripUrlForLRAP(context.Request.RawUrl),
                element2: postBackControlClientId,
                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, page, null);
                var pageGUID    = LoggingHelper.GetPageGUID(context, page, null);

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

                    //Skal vel bare replace viewstate med den fra response... oooog... hmm, ja burde jo være fint nok at diverse lrap-værdier er i response
                    var responseViewState = WebHelper.GetResponseViewState(response);
                    //Kan jo ikke bare overskrive... uden at spørge brugeren om det er det der ønskes, det kan ihf ikke være default behavior

                    //newResponse = WebHelper.SetResponseViewState(logElement.Value, responseViewState);
                    //context.Response.Clear();
                    //context.Response.Write(newResponse);
                    newResponse = response;

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

            LoggingHelper.LogElement(newLogElement);

            return(response);
        }
        public static void LogSession(HttpContext context, Page page, NameValueCollection requestForm, bool before)
        {
            var logType = before ? LogType.OnPageSessionBefore : LogType.OnPageSessionAfter;
            NameValueCollection sessionValues = LoggingHelper.GetSessionValues(page);

            var postBackControlClientId = GetPostBackControlClientId(context, page, requestForm);

            var newLogElement = new LogElementDTO(
                guid: Guid.NewGuid(),
                sessionGUID: LoggingHelper.GetSessionGUID(context, page, () => new Guid(), requestForm).Value,
                pageGUID: LoggingHelper.GetPageGUID(context, page, () => new Guid(), requestForm).Value,
                bundleGUID: null,
                progressGUID: null,
                unixTimestamp: TimeHelper.UnixTimestamp(),
                logType: logType,
                element: LoggingHelper.StripUrlForLRAP(context.Request.RawUrl),
                element2: postBackControlClientId,
                value: sessionValues != null ? SerializationHelper.SerializeNameValueCollection(sessionValues, SerializationType.Json) : null,
                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, page, null, requestForm);
                var pageGUID    = LoggingHelper.GetPageGUID(context, page, null, requestForm);

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

                    if (logElement.Value != null)
                    {
                        NameValueCollection loggedSessionValues = SerializationHelper.DeserializeNameValueCollection(logElement.Value, SerializationType.Json);
                        //Kan jo ikke bare overskrive... uden at spørge brugeren om det er det der ønskes, det kan ihf ikke være default behavior
                        //LoggingHelper.SetSessionValues(page, loggedSessionValues);
                    }
                    else if (sessionValues != null)
                    {
                        throw new Exception("Session difference");
                    }

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

            LoggingHelper.LogElement(newLogElement);
        }
Exemple #7
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);
        }
        public static void LogViewState(HttpContext context, Page page, bool before)
        {
            var logType = before ? LogType.OnPageViewStateBefore : LogType.OnPageViewStateAfter;
            NameValueCollection viewStateValues = LoggingHelper.GetViewStateValues(page);

            var postBackControlClientId = GetPostBackControlClientId(context, page, requestForm: null);

            var newLogElement = new LogElementDTO(
                guid: Guid.NewGuid(),
                sessionGUID: LoggingHelper.GetSessionGUID(context, page, () => new Guid()).Value,
                pageGUID: LoggingHelper.GetPageGUID(context, page, () => new Guid()).Value,
                bundleGUID: null,
                progressGUID: null,
                unixTimestamp: TimeHelper.UnixTimestamp(),
                logType: logType,
                element: LoggingHelper.StripUrlForLRAP(context.Request.RawUrl),
                element2: postBackControlClientId,
                value: viewStateValues != null ? SerializationHelper.SerializeNameValueCollection(viewStateValues, SerializationType.Json) : null,
                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, page, null);
                var pageGUID    = LoggingHelper.GetPageGUID(context, page, null);

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

                    if (logElement.Value != null)
                    {
                        NameValueCollection loggedViewStateValues = SerializationHelper.DeserializeNameValueCollection(logElement.Value, SerializationType.Json);
                        LoggingHelper.SetViewStateValues(page, loggedViewStateValues);
                    }
                    else if (viewStateValues != null)
                    {
                        throw new Exception("ViewState difference");
                    }

                    PlayerCommunicationHelper.SetLogElementAsDone(serverGUID, sessionGUID, pageGUID, logElement.GUID, jobStatus: new JobStatus()
                    {
                        Success = true
                    });                                                                                                                                               //, async: false); //Non deadlock, because we would never call the webserver via namedpipe back again
                }))
                {
                    return;
                }
            }

            LoggingHelper.LogElement(newLogElement);
        }
Exemple #9
0
        public static void LogSession(HttpContext context, NameValueCollection requestForm, bool before)
        {
            var logType       = before ? LogType.OnHandlerSessionBefore : LogType.OnHandlerSessionAfter;
            var sessionValues = LoggingHelper.GetSessionValues(context);

            var newLogElement = new LogElementDTO(
                guid: Guid.NewGuid(),
                sessionGUID: LoggingHelper.GetSessionGUID(context, null, () => new Guid(), requestForm).Value,
                pageGUID: LoggingHelper.GetPageGUID(context, null, () => new Guid(), requestForm).Value,
                bundleGUID: null,
                progressGUID: null,
                unixTimestamp: TimeHelper.UnixTimestamp(),
                logType: logType,
                element: LoggingHelper.StripUrlForLRAP(context.Request.RawUrl),
                element2: null,
                value: sessionValues != null ? SerializationHelper.SerializeNameValueCollection(sessionValues, SerializationType.Json) : null,
                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);

                    if (logElement.Value != null)
                    {
                        var loggedSessionValues = SerializationHelper.DeserializeNameValueCollection(logElement.Value, SerializationType.Json);
                        LoggingHelper.SetSessionValues(context, loggedSessionValues);
                    }
                    else if (sessionValues != null)
                    {
                        throw new Exception("Session difference");
                    }

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

            LoggingHelper.LogElement(newLogElement);
        }
Exemple #10
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);
        }
Exemple #11
0
        public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            if (!Configuration.Enabled)
            {
                return;
            }

            var loggingState = correlationState as LoggingState;

            if (loggingState != null)
            {
                string messageBody = GetMessageBody(reply);

                var logType = LogType.OnWCFServiceResponse;

                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(loggingState.Context, loggingState.Page?.Request.Params))
                {
                    if (LoggingHelper.FetchAndExecuteLogElement(loggingState.ServerGUID.Value, loggingState.SessionGUID, loggingState.PageGUID, logType, (logElement) =>
                    {
                        TimeHelper.SetNow(loggingState.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);
                }

                reply = BuildMessage(messageBody, reply);
            }
        }
        public static LogElementResponse LogRequest(SqlCommandLRAP cmd, LoggingDBType type, CommandBehavior behavior = CommandBehavior.Default)
        {
            var context = HttpContext.Current;

            var page        = HttpContext.Current.Handler as Page;
            var logType     = LogType.OnPersistenceRequest;
            var sessionGUID = LoggingHelper.GetSessionGUID(HttpContext.Current, HttpContext.Current.Handler as Page, () => new Guid()).Value;
            var pageGUID    = LoggingHelper.GetPageGUID(HttpContext.Current, HttpContext.Current.Handler as Page, () => new Guid()).Value;

            var cmdDTO = MapSqlCommandLRAPToSqlCommandDTO(cmd, type, behavior);

            var newLogElement = new LogElementDTO(
                guid: Guid.NewGuid(),
                sessionGUID: sessionGUID,
                pageGUID: pageGUID,
                bundleGUID: cmdDTO.BundleGUID,
                progressGUID: null,
                unixTimestamp: TimeHelper.UnixTimestamp(),
                logType: logType,
                element: cmdDTO.CommandText,
                element2: null,
                value: SerializationHelper.Serialize(cmdDTO, SerializationType.Json),
                times: 1,
                unixTimestampEnd: null,
                instanceTime: DateTime.Now,
                stackTrace: ConfigurationHelper.GetConfigurationSection().LogStackTrace ? new StackTrace().ToString() : ""
                );

            if (LoggingHelper.IsPlaying(context, page?.Request.Params))
            {
                var serverGUID = LoggingHelper.GetServerGUID(HttpContext.Current, null, page?.Request.Params).Value;

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

                    var loggedCmdDTO = SerializationHelper.Deserialize <SqlCommandDTO>(logElement.Value, SerializationType.Json);

                    if (!cmdDTO.Equals(loggedCmdDTO))
                    {
                        //Show UI-warning.. something in the request differs
                    }

                    //Kan jo ikke bare overskrive... uden at spørge brugeren om det er det der ønskes, det kan ihf ikke være default behavior
                    //LoggingHelper.SetRequestValues(context, requestParams.Form, requestForm);

                    //var requestParams = requestForm != null ? WebHelper.ParamsWithSpecialRequestForm(context, requestForm) : context.Request?.Params;

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

            var result = LoggingHelper.LogElement(newLogElement);

            result.Object = cmdDTO;

            return(result);
        }