<commit_before>﻿using System;
using Fuzziverse.Properties;

namespace Fuzziverse.Databases
{
  public class DatabaseController
  {
    private readonly IEditDatabaseSettings databaseSettingsEditor;
    private bool databaseIsConnected;

    public DatabaseController(IEditDatabaseSettings databaseSettingsEditor)
    {
      this.databaseSettingsEditor = databaseSettingsEditor;
    }

    public void Initialize()
    {
      this.databaseSettingsEditor.AddSqlInstanceTextBoxChangedHandler(this.OnSqlInstanceTextBoxValueChanged);
      this.databaseSettingsEditor.AddSaveSqlInstanceClickedHandler(this.OnSaveSqlInstanceButtonClicked);
      this.databaseSettingsEditor.AddConnectSqlClickedHandler(this.OnConnectSqlButtonClicked);
      this.databaseSettingsEditor.AddAutoconnectCheckBoxCheckedChangedHandler(this.OnAutoconnectCheckBoxCheckedChanged);

      this.databaseSettingsEditor.SetSqlInstanceTextBoxValue(Settings.Default.SqlInstance);
      if (Settings.Default.Autoconnect) {
        this.databaseSettingsEditor.SetAutoconnectCheckBox();
      } else {
        this.databaseSettingsEditor.ClearAutoconnectCheckBox();
      }
    }

    public void OnSqlInstanceTextBoxValueChanged(object sender, EventArgs eventArgs)
    {
      this.EnableOrDisableComponents();
    }

    private void EnableOrDisableComponents()
    {
      if (this.databaseIsConnected) {
        this.databaseSettingsEditor.DisableSqlInstanceTextBox();
        this.databaseSettingsEditor.DisableSaveSqlInstanceButton();
        this.databaseSettingsEditor.DisableConnectSqlButton();
        this.databaseSettingsEditor.DisableAutoconnectCheckBox();
        return;
      }

      if (this.databaseSettingsEditor.GetSqlInstanceTextBoxValue() != Settings.Default.SqlInstance) {
        this.databaseSettingsEditor.EnableSaveSqlInstanceButton();
        this.databaseSettingsEditor.DisableAutoconnectCheckBox();
      } else {
        this.databaseSettingsEditor.DisableSaveSqlInstanceButton();
        this.databaseSettingsEditor.EnableAutoconnectCheckBox();
      }

      if (this.databaseSettingsEditor.GetSqlInstanceTextBoxValue() != "") {
        this.databaseSettingsEditor.EnableConnectSqlButton();
      } else {
        this.databaseSettingsEditor.DisableConnectSqlButton();
      }
    }

    public void OnSaveSqlInstanceButtonClicked(object sender, EventArgs eventArgs)
    {
      Settings.Default.SqlInstance = this.databaseSettingsEditor.GetSqlInstanceTextBoxValue();
      Settings.Default.Save();
      this.EnableOrDisableComponents();
    }

    public void OnConnectSqlButtonClicked(object sender, EventArgs eventArgs)
    {
      this.databaseIsConnected = true;
      this.EnableOrDisableComponents();
    }

    public void OnAutoconnectCheckBoxCheckedChanged(object sender, EventArgs eventArgs)
    {
      Settings.Default.Autoconnect = this.databaseSettingsEditor.GetAutoconnectCheckBoxValue();
      Settings.Default.Save();
    }
  }<commit_msg>minor<commit_after>﻿using System;
using Fuzziverse.Properties;

namespace Fuzziverse.Databases
{
  public class DatabaseController
  {
    private const string connectionStringPattern = "Data Source={0};Initial Catalog=Fuzziverse;Integrated Security=True";

    private readonly IEditDatabaseSettings databaseSettingsEditor;
    private bool databaseIsConnected;

    public DatabaseController(IEditDatabaseSettings databaseSettingsEditor)
    {
      this.databaseSettingsEditor = databaseSettingsEditor;
    }

    public void Initialize()
    {
      this.SubscribeToUserInput();
      this.LoadSettings();
    }

    private void SubscribeToUserInput()
    {
      this.databaseSettingsEditor.AddSqlInstanceTextBoxChangedHandler(this.OnSqlInstanceTextBoxValueChanged);
      this.databaseSettingsEditor.AddSaveSqlInstanceClickedHandler(this.OnSaveSqlInstanceButtonClicked);
      this.databaseSettingsEditor.AddConnectSqlClickedHandler(this.OnConnectSqlButtonClicked);
      this.databaseSettingsEditor.AddAutoconnectCheckBoxCheckedChangedHandler(this.OnAutoconnectCheckBoxCheckedChanged);
    }

    private void LoadSettings()
    {
      this.databaseSettingsEditor.SetSqlInstanceTextBoxValue(Settings.Default.SqlInstance);
      if (Settings.Default.Autoconnect) {
        this.databaseSettingsEditor.SetAutoconnectCheckBox();
      } else {
        this.databaseSettingsEditor.ClearAutoconnectCheckBox();
      }
    }

    public void OnSqlInstanceTextBoxValueChanged(object sender, EventArgs eventArgs)
    {
      this.EnableOrDisableComponents();
    }

    public void OnSaveSqlInstanceButtonClicked(object sender, EventArgs eventArgs)
    {
      Settings.Default.SqlInstance = this.databaseSettingsEditor.GetSqlInstanceTextBoxValue();
      Settings.Default.Save();
      this.EnableOrDisableComponents();
    }

    public void OnConnectSqlButtonClicked(object sender, EventArgs eventArgs)
    {
      this.databaseIsConnected = true;
      this.EnableOrDisableComponents();
    }

    public void OnAutoconnectCheckBoxCheckedChanged(object sender, EventArgs eventArgs)
    {
      Settings.Default.Autoconnect = this.databaseSettingsEditor.GetAutoconnectCheckBoxValue();
      Settings.Default.Save();
    }

    private void EnableOrDisableComponents()
    {
      if (this.databaseIsConnected) {
        this.databaseSettingsEditor.DisableSqlInstanceTextBox();
        this.databaseSettingsEditor.DisableSaveSqlInstanceButton();
        this.databaseSettingsEditor.DisableConnectSqlButton();
        this.databaseSettingsEditor.DisableAutoconnectCheckBox();
        return;
      }

      if (this.databaseSettingsEditor.GetSqlInstanceTextBoxValue() != Settings.Default.SqlInstance) {
        this.databaseSettingsEditor.EnableSaveSqlInstanceButton();
        this.databaseSettingsEditor.DisableAutoconnectCheckBox();
      } else {
        this.databaseSettingsEditor.DisableSaveSqlInstanceButton();
        this.databaseSettingsEditor.EnableAutoconnectCheckBox();
      }

      if (this.databaseSettingsEditor.GetSqlInstanceTextBoxValue() != "") {
        this.databaseSettingsEditor.EnableConnectSqlButton();
      } else {
        this.databaseSettingsEditor.DisableConnectSqlButton();
      }
    }
  }
{'fraction_non_alphanumeric': 0.0761889356195406, 'fraction_numerical': 0.00016175994823681658, 'mean_word_length': 4.213322091062395, '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': '240228', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1530, 'n_words': 200}