<commit_before>﻿using System;
using System.Data;
using System.Diagnostics;
using System.Reflection;
using System.Text.RegularExpressions;
using Insight.Database.Mapping;

namespace SqlServer.Management.IntegrationServices.Data.Catalog.Parameters
{
    /// <summary>
    /// A parameter mapper which changes the SSIS style parameters to CamelCase.
    /// </summary>
    internal class SsisParameterMapper : IParameterMapper
    {
        private static Regex RenameRegex =
            new Regex(@"(?<id>[A-Z,a-z,0-9]+)(?<underscore>_)+");
        public string MapParameter(Type type, IDbCommand command, IDataParameter parameter)
        {
            var connectionString = command.Connection.ConnectionString;
            var commandText = command.CommandText ?? string.Empty;
            if (ConnectionStrings.IsSsisConnectionString(connectionString) 
                // don't change casing of the ReturnValue parameter since Insight.Database makes use of it
                && parameter.Direction != ParameterDirection.ReturnValue
                )
            {
                Console.WriteLine(command.CommandText);
                var member = RenameRegex.Replace(parameter.ParameterName, match =>
                {                    
                    var id = match.Groups["id"].Value;
                    return System.Globalization.CultureInfo.InvariantCulture.TextInfo.ToTitleCase(id);
                });
                
                Debug.WriteLine("Mapping ParameterName={0}; to Member={1};", parameter.ParameterName, member);
                return member;
            }
            return null;<commit_msg>Make Regex readonly<commit_after>﻿using System;
using System.Data;
using System.Diagnostics;
using System.Reflection;
using System.Text.RegularExpressions;
using Insight.Database.Mapping;

namespace SqlServer.Management.IntegrationServices.Data.Catalog.Parameters
{
    /// <summary>
    /// A parameter mapper which changes the SSIS style parameters to CamelCase.
    /// </summary>
    internal class SsisParameterMapper : IParameterMapper
    {
        private static readonly Regex RenameRegex =
            new Regex(@"(?<id>[A-Z,a-z,0-9]+)(?<underscore>_)+");
        public string MapParameter(Type type, IDbCommand command, IDataParameter parameter)
        {
            var connectionString = command.Connection.ConnectionString;
            var commandText = command.CommandText ?? string.Empty;
            if (ConnectionStrings.IsSsisConnectionString(connectionString) 
                // don't change casing of the ReturnValue parameter since Insight.Database makes use of it
                && parameter.Direction != ParameterDirection.ReturnValue
                )
            {
                Console.WriteLine(command.CommandText);
                var member = RenameRegex.Replace(parameter.ParameterName, match =>
                {                    
                    var id = match.Groups["id"].Value;
                    return System.Globalization.CultureInfo.InvariantCulture.TextInfo.ToTitleCase(id);
                });
                
                Debug.WriteLine("Mapping ParameterName={0}; to Member={1};", parameter.ParameterName, member);
                return member;
            }
            return null;
{'fraction_non_alphanumeric': 0.09088136627020434, 'fraction_numerical': 0.002439768222018908, 'mean_word_length': 2.203125, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5217215', 'n_tokens_mistral': 793, 'n_tokens_neox': 755, 'n_words': 180}