<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace CupCake.Debug
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                string command = args[0].ToLower();

                if (command == "deploy")
                {
                    Deploy(args.Skip(1));
                }
                else if (command == "debug")
                {
                    Debug();
                }
                else
                {
                    Console.WriteLine("Invalid command specified.");
                }
            }
            else
            {
                Console.WriteLine("Please specify a command to run");
            }
        }

        private static void Deploy(IEnumerable<string> args)
        {
            string cupCakePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\CupCake";
            if (!Directory.Exists(cupCakePath))
                Directory.CreateDirectory(cupCakePath);

            string profilesPath = cupCakePath + "\\Profiles";
            if (!Directory.Exists(profilesPath))
                Directory.CreateDirectory(profilesPath);

            string debugProfilePath = profilesPath + "\\Debug";
            if (Directory.Exists(debugProfilePath))
                Directory.Delete(debugProfilePath, true);

            Directory.CreateDirectory(debugProfilePath);

            string sourcePath = String.Join(" ", args);

            string[] files = Directory.GetFiles(sourcePath);

            foreach (string s in files)
            {
                string fileName = Path.GetFileName(s);
                if (fileName != null)
                {
                    string destFile = Path.Combine(debugProfilePath, fileName);
                    File.Copy(s, destFile, true);
                }
            }
        }

        private static void Debug()
        {
            string path;
            try
            {
                using (var client = new TcpClient())
                {
                    client.Connect(IPAddress.Loopback, 4570);

                    using (NetworkStream stream = client.GetStream())
                    using (var reader = new StreamReader(stream, Encoding.Unicode))
                    {
                        // Request Debug
                        stream.WriteByte(0xE1);

                        // Skip one byte
                        stream.ReadByte();
                        // Wait until the connection is closed by cupcake
                        path = reader.ReadToEnd();
                    }
                }
            }
            catch (SocketException)
            {
                Console.WriteLine("Problem communicating with the client, make sure it is running.");
                return;
            }

            AppDomain.CurrentDomain.ExecuteAssembly(path + "\\CupCake.Server.exe", new[] { "--envpath", path, "--debug" });
        }<commit_msg>[CupCake.Debug] Throw an exception if something wrong happens<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace CupCake.Debug
{
    internal class Program
    {
        private static int Main(string[] args)
        {
            if (args.Length > 0)
            {
                string command = args[0].ToLower();

                if (command == "deploy")
                {
                    Deploy(args.Skip(1));
                }
                else if (command == "debug")
                {
                    Debug();
                }
                else
                {
                    Console.WriteLine("Invalid command specified.");
                    return 1;
                }
            }
            else
            {
                Console.WriteLine("Please specify a command to run");
                return 1;
            }
            return 0;
        }

        private static void Deploy(IEnumerable<string> args)
        {
            string cupCakePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\CupCake";
            if (!Directory.Exists(cupCakePath))
                Directory.CreateDirectory(cupCakePath);

            string profilesPath = cupCakePath + "\\Profiles";
            if (!Directory.Exists(profilesPath))
                Directory.CreateDirectory(profilesPath);

            string debugProfilePath = profilesPath + "\\Debug";
            if (Directory.Exists(debugProfilePath))
                Directory.Delete(debugProfilePath, true);

            Directory.CreateDirectory(debugProfilePath);

            string sourcePath = String.Join(" ", args);

            string[] files = Directory.GetFiles(sourcePath);

            foreach (string s in files)
            {
                string fileName = Path.GetFileName(s);
                if (fileName != null)
                {
                    string destFile = Path.Combine(debugProfilePath, fileName);
                    File.Copy(s, destFile, true);
                }
            }
        }

        private static void Debug()
        {
            string path;
            try
            {
                using (var client = new TcpClient())
                {
                    client.Connect(IPAddress.Loopback, 4570);

                    using (NetworkStream stream = client.GetStream())
                    using (var reader = new StreamReader(stream, Encoding.Unicode))
                    {
                        // Request Debug
                        stream.WriteByte(0xE1);

                        // Skip one byte
                        stream.ReadByte();
                        // Wait until the connection is closed by cupcake
                        path = reader.ReadToEnd();
                    }
                }
            }
            catch (SocketException ex)
            {
                throw new Exception("Problem communicating with the client, make sure it is running.", ex);
            }

            AppDomain.CurrentDomain.ExecuteAssembly(path + "\\CupCake.Server.exe", new[] { "--envpath", path, "--debug" });
        }
{'fraction_non_alphanumeric': 0.09043724441648317, 'fraction_numerical': 0.003302925448254168, 'mean_word_length': 1.2382963745160156, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6780156', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1398, 'n_words': 342}