<commit_before>﻿using System;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Windows.Forms;
using FEClient.NotMyCode;

namespace FEClient.Forms
{
    public partial class SendOptions : Form
    {
        private readonly int _rounds;
        public SendOptions()
        {
            InitializeComponent();
            _rounds = Rng.NextInt(500, 1500); //TODO: does this reprisent a problem because as convergence happens on 1500 it COULD get more rewarding to terminate
            roundsBox.Text = _rounds.ToString();
        }

        private bool AddressBoxIsIp
        {
            get
            {
                var ipText = destinationBox.Text;
                if (ipText.Contains(":"))
                {
                    var index = ipText.LastIndexOf(":");
                    ipText = ipText.Remove(index, ipText.Length - index);
                }
                IPAddress ipObj;
                return IPAddress.TryParse(ipText, out ipObj);
            }
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            fileBox.Text = openFileDialog.FileName;
        }

        private void browseButton_Click(object sender, EventArgs e)
        {
            openFileDialog.ShowDialog();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            if (!ValidateAll())
            {
                return;
            }

            var ip = ""; //TODO: does not need to be used?!
            /*if (addressBoxIsEmail)
            {
                var url = settings.TTP + "/rest/sessions/";

                url = url + destinationBox.Text;
                try
                {
                    var content = new WebClient().DownloadString(url);
                    ip = content;
                }
                catch (WebException ex)
                {
                    MessageBox.Show("Could not find. " + ex.Message);
                    return;
                }
            } else*/
            if (AddressBoxIsIp)
            {
                ip = destinationBox.Text;
            }

            if (!ip.Contains(":"))
            {
                ip += ":6555";
            }


            var sendDialog = new SendDialog(ip, fileBox.Text, int.Parse(roundsBox.Text), int.Parse(complexityBox.Text),
                int.Parse(timeoutBox.Text));
            sendDialog.Show(); //TODO: validate
            Close();
        }

        private bool ValidateAll()
        {
            if (!AddressBoxIsIp)
            {
                errorProvider.SetError(destinationBox, "Wrong format, should be an email or IP");
                return false;
            }
            if (string.IsNullOrWhiteSpace(fileBox.Text))
                return false;

            var fileInfo = new FileInfo(fileBox.Text);
            if (fileInfo.Exists && fileInfo.Length > 0)
            {
                return true;
            }
            return false;
        }

        //private bool addressBoxIsEmail
        //{
        //    get { return new RegexUtilities().IsValidEmail(destinationBox.Text); }
        //}

        private void textBox2_Validated(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(fileBox.Text))
                return;

            var fileInfo = new FileInfo(fileBox.Text);
            if (!fileInfo.Exists || fileInfo.Length <= 0)
            {
                errorProvider.SetError(fileBox, "File does not exist or is blank");
            }
            else
            {
                errorProvider.SetError(fileBox, string.Empty);
            }
        }

        private void textBox1_Validated(object sender, EventArgs e)
        {
            errorProvider.SetError(destinationBox,
                !AddressBoxIsIp ? "Wrong format, should be an IP address" : string.Empty);
        }

        private void label2_Click(object sender, EventArgs e)<commit_msg>SendOptions now uses non culture specific string comparisons<commit_after>﻿using System;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Windows.Forms;
using FEClient.NotMyCode;

namespace FEClient.Forms
{
    public partial class SendOptions : Form
    {
        private readonly int _rounds;
        public SendOptions()
        {
            InitializeComponent();
            _rounds = Rng.NextInt(500, 1500); //TODO: does this reprisent a problem because as convergence happens on 1500 it COULD get more rewarding to terminate
            roundsBox.Text = _rounds.ToString();
        }

        private bool AddressBoxIsIp
        {
            get
            {
                var ipText = destinationBox.Text;
                if (ipText.Contains(":"))
                {
                    var index = ipText.LastIndexOf(":", StringComparison.Ordinal);
                    ipText = ipText.Remove(index, ipText.Length - index);
                }
                IPAddress ipObj;
                return IPAddress.TryParse(ipText, out ipObj);
            }
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            fileBox.Text = openFileDialog.FileName;
        }

        private void browseButton_Click(object sender, EventArgs e)
        {
            openFileDialog.ShowDialog();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            if (!ValidateAll())
            {
                return;
            }

            var ip = ""; //TODO: does not need to be used?!
            /*if (addressBoxIsEmail)
            {
                var url = settings.TTP + "/rest/sessions/";

                url = url + destinationBox.Text;
                try
                {
                    var content = new WebClient().DownloadString(url);
                    ip = content;
                }
                catch (WebException ex)
                {
                    MessageBox.Show("Could not find. " + ex.Message);
                    return;
                }
            } else*/
            if (AddressBoxIsIp)
            {
                ip = destinationBox.Text;
            }

            if (!ip.Contains(":"))
            {
                ip += ":6555";
            }


            var sendDialog = new SendDialog(ip, fileBox.Text, int.Parse(roundsBox.Text), int.Parse(complexityBox.Text),
                int.Parse(timeoutBox.Text));
            sendDialog.Show(); //TODO: validate
            Close();
        }

        private bool ValidateAll()
        {
            if (!AddressBoxIsIp)
            {
                errorProvider.SetError(destinationBox, "Wrong format, should be an email or IP");
                return false;
            }
            if (string.IsNullOrWhiteSpace(fileBox.Text))
                return false;

            var fileInfo = new FileInfo(fileBox.Text);
            return fileInfo.Exists && fileInfo.Length > 0;
        }

        //private bool addressBoxIsEmail
        //{
        //    get { return new RegexUtilities().IsValidEmail(destinationBox.Text); }
        //}

        private void textBox2_Validated(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(fileBox.Text))
                return;

            var fileInfo = new FileInfo(fileBox.Text);
            if (!fileInfo.Exists || fileInfo.Length <= 0)
            {
                errorProvider.SetError(fileBox, "File does not exist or is blank");
            }
            else
            {
                errorProvider.SetError(fileBox, string.Empty);
            }
        }

        private void textBox1_Validated(object sender, EventArgs e)
        {
            errorProvider.SetError(destinationBox,
                !AddressBoxIsIp ? "Wrong format, should be an IP address" : string.Empty);
        }

        private void label2_Click(object sender, EventArgs e)
{'fraction_non_alphanumeric': 0.08659869794865496, 'fraction_numerical': 0.005159071367153913, 'mean_word_length': 1.370995923121724, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6512898', 'n_tokens_mistral': 2117, 'n_tokens_neox': 1984, 'n_words': 495}