<commit_before>﻿using System;
using System.Data;
using YAF.Classes.Data;

namespace YAF.Classes.Core
{
  using YAF.Classes.Utils;

  /// <summary>
  /// The yaf load board settings.
  /// </summary>
  public class YafLoadBoardSettings : YafBoardSettings
  {
    /// <summary>
    /// Initializes a new instance of the <see cref="YafLoadBoardSettings"/> class.
    /// </summary>
    /// <param name="boardID">
    /// The board id.
    /// </param>
    /// <exception cref="Exception">
    /// </exception>
    public YafLoadBoardSettings(object boardID)
    {
      _boardID = boardID;

      // get the board table
      DataTable dataTable = DB.board_list(_boardID);

      if (dataTable.Rows.Count == 0)
      {
        throw new Exception("No data for board with id: " + _boardID);
      }

      // setup legacy board settings...
      SetupLegacyBoardSettings(dataTable.Rows[0]);

      // get all the registry values for the forum
      LoadBoardSettingsFromDB();
    }

    /// <summary>
    /// The setup legacy board settings.
    /// </summary>
    /// <param name="board">
    /// The board.
    /// </param>
    private void SetupLegacyBoardSettings(DataRow board)
    {
      _membershipAppName = board["MembershipAppName"].ToString().IsNotSet()
                             ? YafContext.Current.CurrentMembership.ApplicationName
                             : board["MembershipAppName"].ToString();

      _rolesAppName = board["RolesAppName"].ToString().IsNotSet()
                        ? YafContext.Current.CurrentRoles.ApplicationName
                        : board["RolesAppName"].ToString();

      _legacyBoardSettings = new YafLegacyBoardSettings(
        board["Name"].ToString(), 
        Convert.ToString(board["SQLVersion"]), 
        SqlDataLayerConverter.VerifyBool(board["AllowThreaded"].ToString()), 
        _membershipAppName, 
        _rolesAppName);
    }

    /// <summary>
    /// The load board settings from db.
    /// </summary>
    /// <exception cref="Exception">
    /// </exception>
    protected void LoadBoardSettingsFromDB()
    {
      // verify DB is initialized...
      if (!YafContext.Current.Get<YafInitializeDb>().Initialized)
      {
        throw new Exception("Database is not initialized.");
      }

      DataTable dataTable;
      using (dataTable = DB.registry_list())
      {
        // get all the registry settings into our hash table
        foreach (DataRow dr in dataTable.Rows)
        {
          if (dr["Value"] == DBNull.Value)
          {
            _reg.Add(dr["Name"].ToString().ToLower(), null);
          }
          else
          {
            _reg.Add(dr["Name"].ToString().ToLower(), dr["Value"]);
          }
        }
      }
<commit_msg>Now BoardSettings just automatically initalizes the database if it's not initalized.<commit_after>﻿using System;
using System.Data;
using YAF.Classes.Data;

namespace YAF.Classes.Core
{
  using YAF.Classes.Utils;

  /// <summary>
  /// The yaf load board settings.
  /// </summary>
  public class YafLoadBoardSettings : YafBoardSettings
  {
    /// <summary>
    /// Initializes a new instance of the <see cref="YafLoadBoardSettings"/> class.
    /// </summary>
    /// <param name="boardID">
    /// The board id.
    /// </param>
    /// <exception cref="Exception">
    /// </exception>
    public YafLoadBoardSettings(object boardID)
    {
      _boardID = boardID;

      // get the board table
      DataTable dataTable = DB.board_list(_boardID);

      if (dataTable.Rows.Count == 0)
      {
        throw new Exception("No data for board with id: " + _boardID);
      }

      // setup legacy board settings...
      SetupLegacyBoardSettings(dataTable.Rows[0]);

      // get all the registry values for the forum
      LoadBoardSettingsFromDB();
    }

    /// <summary>
    /// The setup legacy board settings.
    /// </summary>
    /// <param name="board">
    /// The board.
    /// </param>
    private void SetupLegacyBoardSettings(DataRow board)
    {
      _membershipAppName = board["MembershipAppName"].ToString().IsNotSet()
                             ? YafContext.Current.CurrentMembership.ApplicationName
                             : board["MembershipAppName"].ToString();

      _rolesAppName = board["RolesAppName"].ToString().IsNotSet()
                        ? YafContext.Current.CurrentRoles.ApplicationName
                        : board["RolesAppName"].ToString();

      _legacyBoardSettings = new YafLegacyBoardSettings(
        board["Name"].ToString(), 
        Convert.ToString(board["SQLVersion"]), 
        SqlDataLayerConverter.VerifyBool(board["AllowThreaded"].ToString()), 
        _membershipAppName, 
        _rolesAppName);
    }

    /// <summary>
    /// The load board settings from db.
    /// </summary>
    /// <exception cref="Exception">
    /// </exception>
    protected void LoadBoardSettingsFromDB()
    {
      // verify DB is initialized...
      if (!YafContext.Current.Get<YafInitializeDb>().Initialized)
      {
        YafContext.Current.Get<YafInitializeDb>().Run();
      }

      DataTable dataTable;
      using (dataTable = DB.registry_list())
      {
        // get all the registry settings into our hash table
        foreach (DataRow dr in dataTable.Rows)
        {
          if (dr["Value"] == DBNull.Value)
          {
            _reg.Add(dr["Name"].ToString().ToLower(), null);
          }
          else
          {
            _reg.Add(dr["Name"].ToString().ToLower(), dr["Value"]);
          }
        }
      }

{'fraction_non_alphanumeric': 0.13335749229932958, 'fraction_numerical': 0.0007247689798876608, 'mean_word_length': 2.0480397570403093, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, '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': '1465748', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1512, 'n_words': 333}