<commit_before>﻿using System;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Web;
using Gibraltar.Agent;
using Loupe.Agent.Web.Module.DetailBuilders;
using Loupe.Agent.Web.Module.Models;
using Newtonsoft.Json;
using Exception = System.Exception;

namespace Loupe.Agent.Web.Module
{
    public class MessageHandler
    {
        private const string LogSystem = "Loupe";
        private const string Category = "Loupe.Internal";
        private readonly Regex _urlRegex = new Regex("/[Ll]oupe/[Ll]og(?!/.)", RegexOptions.Compiled);
        private JavaScriptLogger _javaScriptLogger;

        public JavaScriptLogger JavaScriptLogger
        {
            get { return _javaScriptLogger ?? (_javaScriptLogger = new JavaScriptLogger()); }
            set { _javaScriptLogger = value; }
        }

        public void HandleRequest(HttpContextBase context)
        {
            if (UrlMatch(context) && RequestIsValid(context))
            {
                LogMessage(context);
            }
        }

        private bool UrlMatch(HttpContextBase context)
        {
            try
            {
                var urlMatch = _urlRegex.Match(context.Request.Url.LocalPath);

                return urlMatch.Success;
            }<commit_msg>Add a top level exception handler in case, for whatever reason, the specific exception handlers do not deal with an error<commit_after>﻿using System;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Web;
using Gibraltar.Agent;
using Loupe.Agent.Web.Module.DetailBuilders;
using Loupe.Agent.Web.Module.Models;
using Newtonsoft.Json;
using Exception = System.Exception;

namespace Loupe.Agent.Web.Module
{
    public class MessageHandler
    {
        private const string LogSystem = "Loupe";
        private const string Category = "Loupe.Internal";
        private readonly Regex _urlRegex = new Regex("/[Ll]oupe/[Ll]og(?!/.)", RegexOptions.Compiled);
        private JavaScriptLogger _javaScriptLogger;

        public JavaScriptLogger JavaScriptLogger
        {
            get { return _javaScriptLogger ?? (_javaScriptLogger = new JavaScriptLogger()); }
            set { _javaScriptLogger = value; }
        }

        public void HandleRequest(HttpContextBase context)
        {
            try
            {
                if (UrlMatch(context) && RequestIsValid(context))
                {
                    LogMessage(context);
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                Log.Write(LogMessageSeverity.Critical, LogSystem, 0, ex, LogWriteMode.Queued,
                    CreateStandardRequestDetailXml(context), Category, "Exception attempting to process message",
                    "Exception caught in top level catch block, this should have be caught by error handler specific to the part of the request processing that failed.");
#endif
            }
        }

        private bool UrlMatch(HttpContextBase context)
        {
            try
            {
                var urlMatch = _urlRegex.Match(context.Request.Url.LocalPath);

                return urlMatch.Success;
            }
{'fraction_non_alphanumeric': 0.08153026026967701, 'fraction_numerical': 0.00031357792411414236, 'mean_word_length': 2.2517838939857286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4929185', 'n_tokens_mistral': 819, 'n_tokens_neox': 783, 'n_words': 216}