<commit_before>﻿using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using ActiLifeAPILibrary;
using Newtonsoft.Json;

namespace WorkflowApp
{
    public partial class WorkFlowForm : Form
    {
        private readonly WorkFlowWorker _workFlowWorker;
        private FilterExport _lastFilter;

        public WorkFlowForm()
        {
            InitializeComponent();
            _lastFilter = null;
            _workFlowWorker = new WorkFlowWorker();

            

            HandleCreated += (o, e) =>
            {
                comboBoxWtvAlgorith.SelectedIndex = 0;
                comboBoxExportType.SelectedIndex = 0;
                foreach (var filterExport in _workFlowWorker.FilterExports)
                    listBoxFilterExports.Items.Add(filterExport);

                listBoxFilterExports.SelectedIndex = 0;
            };

            buttonAddFiles.Click += (sender, args) => AddFilesMenuClick();
            buttonClear.Click += (sender, args) =>
            {
                DialogResult result = MessageBox.Show(this,
                    "Are you sure you want to clear all files? This cannot be undone.",
                    "Remove All Files", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    _workFlowWorker.ClearFiles();
                    listBoxFiles.Items.Clear();
                }
            };
            buttonClearFilters.Click += (sender, args) =>
            {
                DialogResult result = MessageBox.Show(this,
                    "Are you sure you want to clear all filters? This cannot be undone.",
                    "Remove All Filters", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    _workFlowWorker.ClearFilters();
                    checkedListBoxFilters.Items.Clear();
                }
            };

            toolStripMenuAddFiles.Click += (o, e) => AddFilesMenuClick();
            toolStripMenuAddDirectory.Click += (o, e) => AddDirectoryMenuClick();
            buttonSelectFolder.Click += (sender, args) =>
            {
                string currentDirectory = Helpers.SelectFolder();
                if (!string.IsNullOrEmpty(currentDirectory))
                    textBoxDirectory.Text = currentDirectory;
            };

            listBoxFilterExports.SelectedIndexChanged += (sender, args) => SaveFiltersAndUpdateUI();

            buttonOpenFilters.Click += (sender, args) => OpenFilters();

            buttonCalculate.Click += async (sender, args) => CalculateRunExport();
        }

        private async void CalculateRunExport()
        {
            using (var api = new ActiLifeAPILibrary.ActiLifeAPIConnection())
            {
                try
                {
                    await api.Connect(5000);
                }
                catch (Exceptions.APIConnectionException ex)
                {
                    MessageBox.Show(this, "Unable to connect to ActiLife via the API.", "Can't connect to ActiLife!",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                
                //calculate WTV
                foreach (var file in _workFlowWorker.Files)
                {
                    
                }

                //loop through filter exports
                    //calculate data scoring and export

                //FINISH!
            }
        }

        private void SaveFiltersAndUpdateUI()
        {
            if (_lastFilter == null)
            {
                checkedListBoxFilters.ClearSelected();
                _lastFilter = (FilterExport)listBoxFilterExports.SelectedItem;
                return;
            }

            var selectedItems = checkedListBoxFilters.CheckedItems;
            foreach (var scoringFilter in _lastFilter.ScoringFilters)
                scoringFilter.Use = false;<commit_msg>get the API version from the library for testing<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using ActiLifeAPILibrary;
using Newtonsoft.Json;

namespace WorkflowApp
{
    public partial class WorkFlowForm : Form
    {
        private readonly WorkFlowWorker _workFlowWorker;
        private FilterExport _lastFilter;

        public WorkFlowForm()
        {
            InitializeComponent();
            _lastFilter = null;
            _workFlowWorker = new WorkFlowWorker();

            

            HandleCreated += (o, e) =>
            {
                comboBoxWtvAlgorith.SelectedIndex = 0;
                comboBoxExportType.SelectedIndex = 0;
                foreach (var filterExport in _workFlowWorker.FilterExports)
                    listBoxFilterExports.Items.Add(filterExport);

                listBoxFilterExports.SelectedIndex = 0;
            };

            buttonAddFiles.Click += (sender, args) => AddFilesMenuClick();
            buttonClear.Click += (sender, args) =>
            {
                DialogResult result = MessageBox.Show(this,
                    "Are you sure you want to clear all files? This cannot be undone.",
                    "Remove All Files", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    _workFlowWorker.ClearFiles();
                    listBoxFiles.Items.Clear();
                }
            };
            buttonClearFilters.Click += (sender, args) =>
            {
                DialogResult result = MessageBox.Show(this,
                    "Are you sure you want to clear all filters? This cannot be undone.",
                    "Remove All Filters", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    _workFlowWorker.ClearFilters();
                    checkedListBoxFilters.Items.Clear();
                }
            };

            toolStripMenuAddFiles.Click += (o, e) => AddFilesMenuClick();
            toolStripMenuAddDirectory.Click += (o, e) => AddDirectoryMenuClick();
            buttonSelectFolder.Click += (sender, args) =>
            {
                string currentDirectory = Helpers.SelectFolder();
                if (!string.IsNullOrEmpty(currentDirectory))
                    textBoxDirectory.Text = currentDirectory;
            };

            listBoxFilterExports.SelectedIndexChanged += (sender, args) => SaveFiltersAndUpdateUI();

            buttonOpenFilters.Click += (sender, args) => OpenFilters();

            buttonCalculate.Click += (sender, args) => CalculateRunExport();
        }

        private async void CalculateRunExport()
        {
            using (var api = new ActiLifeAPIConnection())
            {
                try
                {
                    await api.Connect(5000);
                }
                catch (Exceptions.APIConnectionException ex)
                {
                    MessageBox.Show(this, ex.Message, "Can't connect to ActiLife!",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                
                /*
                {
                    "Action": "APIVersion"
                }
                 * */

                var apiVersion = await api.APIVersion();
                Console.WriteLine(apiVersion);

                //calculate WTV
                //foreach (var file in _workFlowWorker.Files)
                //{
                    
                //}

                //loop through filter exports
                    //calculate data scoring and export

                //FINISH!
            }
        }

        private void SaveFiltersAndUpdateUI()
        {
            if (_lastFilter == null)
            {
                checkedListBoxFilters.ClearSelected();
                _lastFilter = (FilterExport)listBoxFilterExports.SelectedItem;
                return;
            }

            var selectedItems = checkedListBoxFilters.CheckedItems;
            foreach (var scoringFilter in _lastFilter.ScoringFilters)
                scoringFilter.Use = false;
{'fraction_non_alphanumeric': 0.08088942307692308, 'fraction_numerical': 0.0016826923076923078, 'mean_word_length': 1.4516794342958161, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 23, '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': '4596242', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1877, 'n_words': 432}