<commit_before>﻿using System;
using System.Collections.Generic;
using SystemInterface.IO;
using SystemInterface.Reflection;
using SystemWrapper.IO;
using SystemWrapper.Reflection;
using Autofac;
using JetBrains.Annotations;
using ManyConsole;
using SolutionInspector.Api.Commands;
using SolutionInspector.Api.Configuration;
using SolutionInspector.Api.Reporting;
using SolutionInspector.Api.Rules;
using SolutionInspector.Api.Utilities;

namespace SolutionInspector.Api
{
  /// <summary>
  ///   Entry point for a SolutionInspector run.
  /// </summary>
  [PublicAPI]
  public static class SolutionInspector
  {
    /// <summary>
    ///   Runs the SolutionInspector with the given console <paramref name="args" />.
    /// </summary>
    public static int Run (string[] args)
    {
      ////var solution =
      ////    Solution.Load(@"C:\Users\Chris\Documents\Visual Studio 2015\Projects\SolutionInspector.TestSolution\SolutionInspector.TestSolution.sln");

      //var solution =
      //    Solution.Load(@"D:\Development\SolutionInspector\SolutionInspector.sln");

      //// "D:\Development\SolutionInspector\SolutionInspector.sln"

      //var project = solution.Projects.Single(p => p.Name == "SolutionInspector");

      using (var container = SetupContainer())
      {
        var ruleAssemblyLoader = container.Resolve<IRuleAssemblyLoader>();
        var solutionInspectorConfiguration = container.Resolve<ISolutionInspectorConfiguration>();
        ruleAssemblyLoader.LoadRuleAssemblies(solutionInspectorConfiguration.RuleAssemblyImports.Imports);

        var commands = container.Resolve<IEnumerable<ConsoleCommand>>();
        return ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out);
      }
    }

    private static IContainer SetupContainer ()
    {
      var builder = new ContainerBuilder();

      var configuration = SolutionInspectorConfiguration.Load();
      builder.Register(ctx => configuration).As<ISolutionInspectorConfiguration>();

      builder.RegisterType<FileWrap>().As<IFile>();<commit_msg>Added check to make sure MSBuild Tools 2015 are installed to make sure SolutionInspector can run correctly.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using SystemInterface.IO;
using SystemInterface.Reflection;
using SystemWrapper.IO;
using SystemWrapper.Reflection;
using Autofac;
using JetBrains.Annotations;
using ManyConsole;
using SolutionInspector.Api.Commands;
using SolutionInspector.Api.Configuration;
using SolutionInspector.Api.Reporting;
using SolutionInspector.Api.Rules;
using SolutionInspector.Api.Utilities;

namespace SolutionInspector.Api
{
  /// <summary>
  ///   Entry point for a SolutionInspector run.
  /// </summary>
  [PublicAPI]
  public static class SolutionInspector
  {
    /// <summary>
    ///   Runs the SolutionInspector with the given console <paramref name="args" />.
    /// </summary>
    public static int Run (string[] args)
    {
      CheckMsBuildToolsInstallation();

      using (var container = SetupContainer())
      {
        var ruleAssemblyLoader = container.Resolve<IRuleAssemblyLoader>();
        var solutionInspectorConfiguration = container.Resolve<ISolutionInspectorConfiguration>();
        ruleAssemblyLoader.LoadRuleAssemblies(solutionInspectorConfiguration.RuleAssemblyImports.Imports);

        var commands = container.Resolve<IEnumerable<ConsoleCommand>>();
        return ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out);
      }
    }

    private static void CheckMsBuildToolsInstallation ()
    {
      try
      {
        Assembly.Load("Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=<KEY>");
      }
      catch (FileNotFoundException)
      {
        Console.Error.WriteLine(
            "Could not find MSBuild assemblies in version 14.0 this most likely means that 'MSBuild Tools 2015' was not installed.");
        Console.Error.WriteLine("Just press any key to open a browser with the download page of the 'MSBuild Tools 2015'...");
        Console.ReadKey();
        Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=48159");
        Environment.Exit(1);
      }
    }

    private static IContainer SetupContainer ()
    {
      var builder = new ContainerBuilder();

      var configuration = SolutionInspectorConfiguration.Load();
      builder.Register(ctx => configuration).As<ISolutionInspectorConfiguration>();

      builder.RegisterType<FileWrap>().As<IFile>();
{'fraction_non_alphanumeric': 0.10457948040510788, 'fraction_numerical': 0.0066050198150594455, 'mean_word_length': 3.8278427205100956, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 31, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2758804', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1157, 'n_words': 271}