<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
using CefSharp;
using CefSharp.OffScreen;

namespace SaltyBet_Desktop
{
	public partial class MainWindow : Form
	{
		private ChromiumWebBrowser browser;

		private DataExtractor dataExtractor;
		private MatchTracker matchTracker;
		private Util util;
		private DatabaseConnection dbConn;

		private Thread refreshThread;

		public MainWindow()
		{
			InitializeComponent();

			var settings = new CefSettings();

			settings.WindowlessRenderingEnabled = true;

			Cef.Initialize(settings);
			browser = new ChromiumWebBrowser("http://saltybet.com");
			// this.pMain.Controls.Add(browser);
			// browser.Dock = DockStyle.Fill;

			dataExtractor = new DataExtractor(browser);
			matchTracker = new MatchTracker();
			util = new Util();
			dbConn = new DatabaseConnection();

			refreshThread = new Thread(refreshLoop);
			refreshThread.Start();
		}

		/// <summary>
		/// Updates the textboxes with new data from saltybet site.
		/// </summary>
		private void refresh()
		{
			// Don't update if browser is on the wrong page. Or the browser isn't initialized. 
			if (!browser.IsBrowserInitialized || browser.Address != "http://www.saltybet.com/" || browser.IsLoading)
				return;

			// Update match tracker with new info, if new info is available. 
			matchTracker.Update(dataExtractor);

			// Update database
			if (matchTracker.IsNewMatch())
			{
				// If last match wasn't a team match update add a new row
				if (!matchTracker.WasTeamMatch())
				{
					// row layout
					// TimeStamp | RedName | RedPot | Red Odds | BlueName | BluePot | BlueOdds | Winner | Match Time
					dgwMatchHistory.Rows.Add(
						util.GetLongDate(),
						matchTracker.LastPlayer1, matchTracker.LastPotPlayer1, matchTracker.LastOddsPlayer1,
						matchTracker.LastPlayer2, matchTracker.LastPotPlayer2, matchTracker.LastOddsPlayer2,<commit_msg>Moved database init above cef init to prevent cef processes to not terminate correctly<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
using CefSharp;
using CefSharp.OffScreen;

namespace SaltyBet_Desktop
{
	public partial class MainWindow : Form
	{
		private ChromiumWebBrowser browser;

		private DataExtractor dataExtractor;
		private MatchTracker matchTracker;
		private Util util;
		private DatabaseConnection dbConn;

		private Thread refreshThread;

		public MainWindow()
		{
			InitializeComponent();

			dbConn = new DatabaseConnection();

			var settings = new CefSettings();

			settings.WindowlessRenderingEnabled = true;

			Cef.Initialize(settings);
			browser = new ChromiumWebBrowser("http://saltybet.com");
			// this.pMain.Controls.Add(browser);
			// browser.Dock = DockStyle.Fill;

			dataExtractor = new DataExtractor(browser);
			matchTracker = new MatchTracker();
			util = new Util();

			refreshThread = new Thread(refreshLoop);
			refreshThread.Start();
		}

		/// <summary>
		/// Updates the textboxes with new data from saltybet site.
		/// </summary>
		private void refresh()
		{
			// Don't update if browser is on the wrong page. Or the browser isn't initialized. 
			if (!browser.IsBrowserInitialized || browser.Address != "http://www.saltybet.com/" || browser.IsLoading)
				return;

			// Update match tracker with new info, if new info is available. 
			matchTracker.Update(dataExtractor);

			// Update database
			if (matchTracker.IsNewMatch())
			{
				// If last match wasn't a team match update add a new row
				if (!matchTracker.WasTeamMatch())
				{
					// row layout
					// TimeStamp | RedName | RedPot | Red Odds | BlueName | BluePot | BlueOdds | Winner | Match Time
					dgwMatchHistory.Rows.Add(
						util.GetLongDate(),
						matchTracker.LastPlayer1, matchTracker.LastPotPlayer1, matchTracker.LastOddsPlayer1,
						matchTracker.LastPlayer2, matchTracker.LastPotPlayer2, matchTracker.LastOddsPlayer2,
{'fraction_non_alphanumeric': 0.09721566776781501, 'fraction_numerical': 0.002831524303916942, 'mean_word_length': 3.8335233751425313, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '336766', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1202, 'n_words': 344}