<commit_before>﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Common.Logging;
using Dragon.Core;
using Dragon.Core.Configuration;

namespace Dragon.SQL.Repositories
{
    public class ConnectionHelper
    {
        private static readonly ILog s_log = LogManager.GetCurrentClassLogger();

        public static Func<string,DbConnection> ConnectionFactory;
        public static Func<string, DbConnection> DefaultConnectionFactory;
        public static string ConnectionString = null;

        static ConnectionHelper()
        {
            DefaultConnectionFactory = (s) => new SqlConnection(s);
            ConnectionFactory = DefaultConnectionFactory;
            ConnectionString = ConnectionStringManager.Value;
        }

        public static DbConnection Open()
        {
            var conn = ConnectionFactory(ConnectionString);

            try
            {
                conn.Open();
                s_log.Trace(x => x("Database connection successfull"));
            }
            catch (Exception ex)
            {
                s_log.Error(x => x("Database connection failed"), ex);
                throw new Exception(Strings.SqlStores_Exception_ConnectFailed);
            }

            return conn;
        }
    }
}<commit_msg>ConnecionHelper now has helper factory for ConnectionString<commit_after>﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Common.Logging;
using Dragon.Core;
using Dragon.Core.Configuration;

namespace Dragon.SQL.Repositories
{
    public class ConnectionHelper
    {
        private static readonly ILog s_log = LogManager.GetCurrentClassLogger();

        public static Func<string, DbConnection> ConnectionFactory;
        public static Func<string, DbConnection> DefaultConnectionFactory;
        public static Func<string> DefaultConnectionString = null;
        public static Func<string> ConnectionString = null;

        static ConnectionHelper()
        {
            DefaultConnectionFactory = (s) => new SqlConnection(s);
            ConnectionFactory = DefaultConnectionFactory;
            DefaultConnectionString = () => ConnectionStringManager.Value;
            ConnectionString = DefaultConnectionString;
        }

        public static DbConnection Open()
        {
            var conn = ConnectionFactory(ConnectionString());

            try
            {
                conn.Open();
                s_log.Trace(x => x("Database connection successfull"));
            }
            catch (Exception ex)
            {
                s_log.Error(x => x("Database connection failed"), ex);
                throw new Exception(Strings.SqlStores_Exception_ConnectFailed);
            }

            return conn;
        }
    }
}
{'fraction_non_alphanumeric': 0.07859358841778696, 'fraction_numerical': 0.0, 'mean_word_length': 2.354913294797688, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 16, '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': '7137254', 'n_tokens_mistral': 695, 'n_tokens_neox': 669, 'n_words': 172}