<commit_before>﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;

namespace Platinum.VisualStudio.Command
{
    /// <summary />
    public class Program
    {
        /// <summary />
        public static void Main( string[] args )
        {
            /*
             * TODO
             */
            CommandLine cl = new CommandLine();
            cl.Solution = args[ 0 ];


            /*
             * Load referenced assemblies into domain, so that they are discoverable.
             * In this case, it is preferable to probing the entire directory -- since
             * these command-line tools tend to be put all together in a bin/ folder.
             */
            foreach ( string key in ConfigurationManager.AppSettings.Keys )
            {
                string assemblyName = ConfigurationManager.AppSettings[ key ];

                try
                {
                    AppDomain.CurrentDomain.Load( assemblyName );
                }
                catch ( Exception ex )
                {
                    Console.Error.WriteLine( "err: failed to load assembly '{0}'.", assemblyName );
                    Console.Error.WriteLine( ex.ToString() );
                    Environment.ExitCode = 1001;
                    return;
                }
            }


            /*
             *
             */
            Type interfaceType = typeof( ITool );
            Dictionary<string, Type> tools = new Dictionary<string, Type>();

            foreach ( var assembly in AppDomain.CurrentDomain.GetAssemblies() )
            {
                Console.WriteLine( assembly.FullName );

                if ( assembly.IsDynamic == true )
                    continue;

                if ( assembly.FullName.StartsWith( "System." ) == true )
                    continue;

                foreach ( var type in assembly.GetTypes() )
                {
                    if ( type.IsInterface == true )
                        continue;

                    if ( interfaceType.IsAssignableFrom( type ) == true )
                    {
                        tools.Add( type.Name, type );
                    }
                }
            }


            /*
             * 
             */
            int exitCode;

            if ( cl.Solution != null )<commit_msg>+ Add: In a vanilla machine (without Visual Studio installed), was getting a ReflectionTypeLoadException. Added the extra logging, but the error -- oddly -- stopped occurring. :/<commit_after>﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Xml;

namespace Platinum.VisualStudio.Command
{
    /// <summary />
    public class Program
    {
        /// <summary />
        public static void Main( string[] args )
        {
            /*
             * TODO
             */
            CommandLine cl = new CommandLine();
            cl.Solution = args[ 0 ];


            /*
             * Load referenced assemblies into domain, so that they are discoverable.
             * In this case, it is preferable to probing the entire directory -- since
             * these command-line tools tend to be put all together in a bin/ folder.
             */
            foreach ( string key in ConfigurationManager.AppSettings.Keys )
            {
                string assemblyName = ConfigurationManager.AppSettings[ key ];

                try
                {
                    AppDomain.CurrentDomain.Load( assemblyName );
                }
                catch ( Exception ex )
                {
                    Console.Error.WriteLine( "err: failed to load assembly '{0}'.", assemblyName );
                    Console.Error.WriteLine( ex.ToString() );
                    Environment.ExitCode = 1001;
                    return;
                }
            }


            /*
             *
             */
            Type interfaceType = typeof( ITool );
            Dictionary<string, Type> tools = new Dictionary<string, Type>();

            foreach ( var assembly in AppDomain.CurrentDomain.GetAssemblies() )
            {
                if ( assembly.IsDynamic == true )
                    continue;

                if ( assembly.FullName.StartsWith( "mscorlib, " ) == true )
                    continue;

                if ( assembly.FullName.StartsWith( "System, " ) == true )
                    continue;

                if ( assembly.FullName.StartsWith( "System." ) == true )
                    continue;

                Console.WriteLine( "loading tools from {0}...", assembly.FullName );


                /*
                 * 
                 */
                Type[] types;

                try
                {
                    types = assembly.GetTypes();
                }
                catch ( ReflectionTypeLoadException ex )
                {
                    Console.WriteLine( "Exception:" );
                    Console.WriteLine( ex.ToString() );

                    foreach ( var le in ex.LoaderExceptions )
                    {
                        Console.WriteLine();
                        Console.WriteLine( "Loader exception:" );
                        Console.WriteLine( le.ToString() );
                    }

                    Environment.ExitCode = 1002;
                    return;
                }
                catch ( Exception ex )
                {
                    Console.WriteLine( ex.ToString() );

                    Environment.ExitCode = 1003;
                    return;
                }

                foreach ( var type in types )
                {
                    if ( type.IsInterface == true )
                        continue;

                    if ( interfaceType.IsAssignableFrom( type ) == true )
                    {
                        Console.WriteLine( "+ {0}", type.Name );
                        tools.Add( type.Name, type );
                    }
                }
            }


            /*
             * 
             */
            int exitCode;

            if ( cl.Solution != null )
{'fraction_non_alphanumeric': 0.08646496815286624, 'fraction_numerical': 0.0035031847133757963, 'mean_word_length': 1.0887928167608913, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4254317', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1314, 'n_words': 367}