<commit_before>﻿using Microsoft.Owin.Hosting;
using System;
using System.Collections.Generic;
using System.IO;

namespace Tulpep.InternetSimulator
{
    class Program
    {
        static void Main(string[] args)
        {
            var options = new Options();
            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                if (options.Verbose) Console.WriteLine("Filename: {0}", options.InputFile);
            }


            string hostFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"drivers\etc\hosts");
            string hostFileBackup = hostFile + "_Backup_Internet_Simulator";

            List<string> hostModifications = new List<string>();
            hostModifications.Add("microsoft.com");
            hostModifications.Add("google.com");

            bool backupSuccess = BackupHostFile(options, hostFile, hostFileBackup);
            if (!backupSuccess)
            {
                Console.WriteLine("Cannot modify HOSTS file. Run this program as Admininistrator");
                return;
            }

            ModifyHostFile(options, hostFile, hostModifications);
            StartWebServer(options);
            RestoreHostFile(options, hostFile, hostFileBackup);
        }

        static void StartWebServer(Options options)
        {
            if (options.Verbose) Console.WriteLine("Starting web Server...");
            const string baseUri = "http://*:8080";
            WebApp.Start<WebServerStartup>(baseUri);
            Console.WriteLine("Server running at {0} - press Enter to quit. ", baseUri);
            Console.ReadLine();
        }

        static bool BackupHostFile(Options options, string originalPath, string backupPath)
        {
            if (options.Verbose) Console.WriteLine("Creating backup of HOSTS file in " + originalPath);
            try<commit_msg>Exception handling<commit_after>﻿using Microsoft.Owin.Hosting;
using System;
using System.Collections.Generic;
using System.IO;

namespace Tulpep.InternetSimulator
{
    class Program
    {
        static void Main(string[] args)
        {
            var options = new Options();
            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                if (options.Verbose) Console.WriteLine("Filename: {0}", options.InputFile);
            }


            string hostFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"drivers\etc\hosts");
            string hostFileBackup = hostFile + "_Backup_Internet_Simulator";

            List<string> hostModifications = new List<string>();
            hostModifications.Add("microsoft.com");
            hostModifications.Add("go.microsoft.com");
            hostModifications.Add("google.com");

            bool backupSuccess = BackupHostFile(options, hostFile, hostFileBackup);
            if (!backupSuccess)
            {
                Console.WriteLine("Cannot modify HOSTS file. Run this program as Admininistrator");
                return;
            }

            ModifyHostFile(options, hostFile, hostModifications);
            StartWebServer(options);
            RestoreHostFile(options, hostFile, hostFileBackup);
        }

        static void StartWebServer(Options options)
        {
            if (options.Verbose) Console.WriteLine("Starting web Server...");
            const string baseUri = "https://*:80";
            try
            {
                WebApp.Start<WebServerStartup>(baseUri);
                Console.WriteLine("Server running at {0} - press Enter to quit. ", baseUri);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }

        }

        static bool BackupHostFile(Options options, string originalPath, string backupPath)
        {
            if (options.Verbose) Console.WriteLine("Creating backup of HOSTS file in " + originalPath);
            try
{'fraction_non_alphanumeric': 0.09758526263380632, 'fraction_numerical': 0.0024894199651481204, 'mean_word_length': 2.1563236449332286, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, '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': '4638978', 'n_tokens_mistral': 1021, 'n_tokens_neox': 980, 'n_words': 222}