<commit_before>﻿using Sloong;
using Sloong.Interfaqce;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace servctrl
{
    public partial class FormTest : Form
    {
        private IPageHost pageHost;
        private Dictionary<string, string> testCaseMap = null;
        const string TestCastMapPath = "UI\\TestCase.bin";
        static int nSwift = 0;


        public Dictionary<string, ConnectInfo> SocketMap
        {
            get
            {
                return pageHost[ShareItem.SocketMap] as Dictionary<string, ConnectInfo>;
            }
            set { }
        }


        Socket sockCurrent
        {
            get
            {
                var cbox = pageHost[ShareItem.ConfigSelecter] as ComboBox;
                if (cbox != null)
                {
                    return SocketMap[cbox.Text].m_Socket;
                }
                return null;
            }

            set { }
        }

        string[] defTestCase = 
        {
            "Get all user info;60001|",
            "Get all user name;60001|name",
            "Get target user info:60001||name='test'",
            "Add new user;60002|testuser",
        };

        public FormTest( IPageHost _pageHost )
        {
            InitializeComponent();
            this.TopLevel = false;
            pageHost = _pageHost;

            pageHost.PageMessage += PageMessageHandler;

            // read the cache
            try
            {
                testCaseMap = (Dictionary<string, string>)Utility.Deserialize(TestCastMapPath);
            }
            catch (Exception)
            {
                testCaseMap = new Dictionary<string, string>();
            }
            if ( testCaseMap.Count == 0)
            {
                // add the default test case.
                foreach(var item in defTestCase)
                {
                    var list = item.Split(';');
                    testCaseMap[list[0]] = list[1];
                }
             }
        }

        void PageMessageHandler(object sender, PageMessage e)
        {
            var type = e.Type;
            switch (type)
            {
                case MessageType.ExitApp:
                    break;
            }
        }

        private void buttonSend_Click(object sender, EventArgs e)
        {
            int nMul = 0;
            if (checkBoxSingle.Checked)
                nMul = 1;
            else
                nMul = Convert.ToInt32(textBoxMulNum.Text);

           
            {
                try
                {
                   
                    sockCurrent.ReceiveTimeout = 5000;
                    // real message
                    var msg = textBoxMsg.Text;
                    var msgs = msg.Split('|');
                    for (int i = 0; i < nMul; i++)
                    {
                        nSwift++;
                        
                        string md5 = Utility.MD5_Encoding(msg, Encoding.UTF8);

                        var sendmsg = string.Format("{0}|{1}|{2}", md5, nSwift, msg);
                        listBoxLog.Items.Add(sendmsg);
                        var len = string.Format("{0:D8}", sendmsg.Length);
                        sendmsg = len + sendmsg;

                        byte[] sendByte = Encoding.ASCII.GetBytes(sendmsg);
                        lock (sockCurrent)
                        {

                            Utility.SendEx(sockCurrent, sendByte);
                        }
                        if (nMul > 1)
                        {
                            int nInt;
                            try
                            {
                                nInt = Convert.ToInt32(textBoxNumInterval.Text);
                            }
                            catch(Exception)
                            {
                                nInt = 0;
                            }
                            if( nInt > 0 )
                                System.Threading.Thread.Sleep(nInt);
                        }
                            
                   // }
                    

//                      for (int i = 0; i < nMul; i++)
//                      {
                         // send end, rece the return.
                         byte[] leng = Utility.RecvEx(sockCurrent, 8);
                         long nlen = 0;
                         byte[] data = null;
                         try
                         {
                             nlen = BitConverter.ToInt32(leng, 0);
                             data  = Utility.RecvEx(sockCurrent, nlen);
                         }
                         catch(Exception ex)
                         {
                             listBoxLog.SelectedIndex = listBoxLog.Items.Add(ex.ToString());
                         }
                        
                         
                         // check the return.
                         string strres = Encoding.ASCII.GetString(data);
                         var ress = strres.Split('|');
                         string log = strres;
                         if (ress[2] != "0")<commit_msg>modify encoding.<commit_after>﻿using Sloong;
using Sloong.Interfaqce;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace servctrl
{
    public partial class FormTest : Form
    {
        private IPageHost pageHost;
        private Dictionary<string, string> testCaseMap = null;
        const string TestCastMapPath = "UI\\TestCase.bin";
        static int nSwift = 0;


        public Dictionary<string, ConnectInfo> SocketMap
        {
            get
            {
                return pageHost[ShareItem.SocketMap] as Dictionary<string, ConnectInfo>;
            }
            set { }
        }


        Socket sockCurrent
        {
            get
            {
                var cbox = pageHost[ShareItem.ConfigSelecter] as ComboBox;
                if (cbox != null)
                {
                    return SocketMap[cbox.Text].m_Socket;
                }
                return null;
            }

            set { }
        }

        string[] defTestCase = 
        {
            "Get all user info;60001|",
            "Get all user name;60001|name",
            "Get target user info;60001||name='test'",
            "Add new user;60002|testuser",
        };

        public FormTest( IPageHost _pageHost )
        {
            InitializeComponent();
            this.TopLevel = false;
            pageHost = _pageHost;

            pageHost.PageMessage += PageMessageHandler;

            // read the cache
            try
            {
                testCaseMap = (Dictionary<string, string>)Utility.Deserialize(TestCastMapPath);
            }
            catch (Exception)
            {
                testCaseMap = new Dictionary<string, string>();
            }
            if ( testCaseMap.Count == 0)
            {
                // add the default test case.
                foreach(var item in defTestCase)
                {
                    var list = item.Split(';');
                    testCaseMap[list[0]] = list[1];
                }
             }
        }

        void PageMessageHandler(object sender, PageMessage e)
        {
            var type = e.Type;
            switch (type)
            {
                case MessageType.ExitApp:
                    break;
            }
        }

        private void buttonSend_Click(object sender, EventArgs e)
        {
            int nMul = 0;
            if (checkBoxSingle.Checked)
                nMul = 1;
            else
                nMul = Convert.ToInt32(textBoxMulNum.Text);

           
            {
                try
                {
                   
                    sockCurrent.ReceiveTimeout = 5000;
                    // real message
                    var msg = textBoxMsg.Text;
                    var msgs = msg.Split('|');
                    for (int i = 0; i < nMul; i++)
                    {
                        nSwift++;
                        
                        string md5 = Utility.MD5_Encoding(msg, Encoding.UTF8);

                        var sendmsg = string.Format("{0}|{1}|{2}", md5, nSwift, msg);
                        listBoxLog.Items.Add(sendmsg);
                        var len = string.Format("{0:D8}", sendmsg.Length);
                        sendmsg = len + sendmsg;

                        byte[] sendByte = Encoding.ASCII.GetBytes(sendmsg);
                        lock (sockCurrent)
                        {

                            Utility.SendEx(sockCurrent, sendByte);
                        }
                        if (nMul > 1)
                        {
                            int nInt;
                            try
                            {
                                nInt = Convert.ToInt32(textBoxNumInterval.Text);
                            }
                            catch(Exception)
                            {
                                nInt = 0;
                            }
                            if( nInt > 0 )
                                System.Threading.Thread.Sleep(nInt);
                        }
                            
                   // }
                    

//                      for (int i = 0; i < nMul; i++)
//                      {
                         // send end, rece the return.
                         byte[] leng = Utility.RecvEx(sockCurrent, 8);
                         long nlen = 0;
                         byte[] data = null;
                         try
                         {
                             nlen = BitConverter.ToInt32(leng, 0);
                             data  = Utility.RecvEx(sockCurrent, nlen);
                         }
                         catch(Exception ex)
                         {
                             listBoxLog.SelectedIndex = listBoxLog.Items.Add(ex.ToString());
                         }
                        
                         
                         // check the return.
                         string strres = Encoding.UTF8.GetString(data);
                         var ress = strres.Split('|');
                         string log = strres;
                         if (ress[2] != "0")
{'fraction_non_alphanumeric': 0.08101851851851852, 'fraction_numerical': 0.010277777777777778, 'mean_word_length': 0.8748481166464156, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '2865069', 'n_tokens_mistral': 2697, 'n_tokens_neox': 2450, 'n_words': 548}