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); }
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); }
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); }
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); }
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(); }
public static void SetNow(HttpContext context, DateTime dt) { if (context == null) { return; } if (context.Session != null) { context.Session[Consts.NowSetTimestampTag] = TimeHelper.UnixTimestamp(DateTime.Now).ToString(CultureInfo.InvariantCulture); context.Session[Consts.NowTimestampTag] = TimeHelper.UnixTimestamp(dt).ToString(CultureInfo.InvariantCulture); } if (context.Request?.Headers != null) { context.Request.Headers[Consts.NowSetTimestampTag] = TimeHelper.UnixTimestamp(DateTime.Now).ToString(CultureInfo.InvariantCulture); context.Request.Headers[Consts.NowTimestampTag] = TimeHelper.UnixTimestamp(dt).ToString(CultureInfo.InvariantCulture); } }
public static LogHandlerResponse LogHandlerRequest(string requestJSON) { var request = SerializationHelper.Deserialize <LogHandlerDTO>(requestJSON, SerializationType.Json); var now = DateTime.Now; var logHandlerResponse = new LogHandlerResponse() { ServerTimeStart = TimeHelper.UnixTimestamp() }; var logElementResponse = new LogElementResponse(); if (request.LogElements.Length > 0) { var maxClientUnixTimestamp = request.LogElements.Max(x => x.UnixTimestamp); var serverUnixTimestamp = TimeHelper.UnixTimestamp(); var diffUnixTimestamp = maxClientUnixTimestamp - serverUnixTimestamp; if (diffUnixTimestamp > 0) { request.LogElements.ToList().ForEach(x => x.UnixTimestamp -= diffUnixTimestamp); } foreach (var logElement in request.LogElements) { logElement.Element = HttpUtility.HtmlDecode(logElement.Element); //Has to be encoded when sending from client to server, due to asp.net default security logElement.Value = logElement.Value != null?HttpUtility.HtmlDecode(logElement.Value) : null; //Has to be encoded when sending from client to server, due to asp.net default security logElementResponse += LogElement(logElement); } } logHandlerResponse.Success = logElementResponse.Success; logHandlerResponse.Message = logElementResponse.Message; logHandlerResponse.ServerTimeEnd = TimeHelper.UnixTimestamp(); return(logHandlerResponse); }
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); }
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 LogElement(LogElementDTO logElement) { lock (logElementLock) { try { var config = ConfigurationHelper.GetConfigurationSection(); if (!config.Enabled) { return new LogElementResponse() { Success = true } } ; var unixNow = TimeHelper.UnixTimestamp(); LogElementDTO lastLogElement = null; //Cleanup old entries in dictionary dictLastLogElementPerPage.Where(x => x.Value.UnixTimestamp < unixNow - cleanupAfterLastLogElementsAfterSeconds).Select(x => x.Key).ToList().ForEach(x => dictLastLogElementPerPage.Remove(x)); if (dictLastLogElementPerPage.TryGetValue(logElement.PageGUID, out lastLogElement)) { if (lastLogElement.UnixTimestamp >= logElement.UnixTimestamp) { //Correct logElement, it must be placed after lastLogElement var diffAdjust = (lastLogElement.UnixTimestamp + unixTimestampForwardAdjuster) - logElement.UnixTimestamp; logElement.UnixTimestamp += diffAdjust; if (logElement.UnixTimestampEnd.HasValue) { logElement.UnixTimestampEnd += diffAdjust; } } } else { //This is the first registered logElement for this pageGUID, nothing to correct against } if (unixNow < logElement.UnixTimestamp) //Get server back on right track if the logElement.UnixTimestamp is ahead of time, which it could be if the logElement was transfered from e.g. the clientside(browser) { var diffSeconds = logElement.UnixTimestamp - unixNow; var diffMS = (int)Math.Ceiling(diffSeconds * 1000.0); System.Threading.Thread.Sleep(diffMS); } dictLastLogElementPerPage[logElement.PageGUID] = logElement; GetLoggingPersister(config.LogType).LogElement(config.FilePath, logElement); return(new LogElementResponse() { Success = true }); } catch (Exception ex) { return(new LogElementResponse() { Success = false, Message = ex.Message + " ::: " + ex.StackTrace }); } } }
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); }