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

namespace Bounce.Framework {
    public class VisualStudioSolution : Task {
        [Dependency]
        public Task<string> SolutionPath;
        [Dependency]
        public Task<string> Configuration;
        [Dependency]
        public Task<string> MsBuildExe;

        public VisualStudioSolution() {
            MsBuildExe = @"C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe";
        }

        public VisualStudioSolutionProjects Projects {
            get {
                return new VisualStudioSolutionProjects(this);
            }
        }

        public override void Build(IBounce bounce) {
            bounce.Log.Info("building solution at: " + SolutionPath.Value);

            bounce.ShellCommand.ExecuteAndExpectSuccess(MsBuildExe.Value, String.Format(@"""{0}""", SolutionPath.Value));
        }

        internal VisualStudioSolutionDetails SolutionDetails {
            get {
                var details = TryGetSolutionDetails();

                if (details != null) {
                    return details;
                } else {
                    throw new DependencyBuildFailureException(this,
                                                              String.Format("VisualStudio solution file `{0}' does not exist",
                                                                            SolutionPath.Value));
                }
            }
        }

        internal VisualStudioSolutionDetails TryGetSolutionDetails() {
            if (SolutionExists) {
                return new VisualStudioSolutionFileReader().ReadSolution(SolutionPath.Value, Config);
            } else {
                return null;
            }
        }

        private bool SolutionExists {
            get {
                return File.Exists(SolutionPath.Value);
            }
        }

        public override void Clean(IBounce bounce) {
            if (SolutionExists) {
                bounce.Log.Info("cleaning solution at: " + SolutionPath.Value);
                bounce.ShellCommand.ExecuteAndExpectSuccess(MsBuildExe.Value, String.Format(@"/target:Clean ""{0}""", SolutionPath.Value));
            }
        }

        private string Config {
            get {
                if (Configuration == null) {
                    return "";
                } else {
                    return Configuration.Value;
                }
            }
        }

        internal VisualStudioProjectFileDetails GetProjectDetails(string name) {
            return SolutionDetails.Projects.First(p => p.Name == name);
        }
    }
}<commit_msg>Configuration now works for building solutions<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace Bounce.Framework {
    public class VisualStudioSolution : Task {
        [Dependency]
        public Task<string> SolutionPath;
        [Dependency]
        public Task<string> Configuration;
        [Dependency]
        public Task<string> MsBuildExe;

        public VisualStudioSolution() {
            MsBuildExe = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe");
        }

        public VisualStudioSolutionProjects Projects {
            get {
                return new VisualStudioSolutionProjects(this);
            }
        }

        public override void Build(IBounce bounce) {
            bounce.Log.Info("building solution at: " + SolutionPath.Value);

            var arguments = Arguments(
                "\"" + SolutionPath.Value + "\"",
                ConfigIfSpecified
            );

            bounce.ShellCommand.ExecuteAndExpectSuccess(MsBuildExe.Value, arguments);
        }

        private static string Arguments(params string [] args)
        {
            return String.Join(" ", args.Where(a => a != null).ToArray());
        }

        protected string ConfigIfSpecified
        {
            get
            {
                if (Configuration == null)
                {
                    return null;
                }
                else
                {
                    return "/p:Configuration=" + Configuration.Value;
                }
            }
        }

        internal VisualStudioSolutionDetails SolutionDetails {
            get {
                var details = TryGetSolutionDetails();

                if (details != null) {
                    return details;
                } else {
                    throw new DependencyBuildFailureException(this,
                                                              String.Format("VisualStudio solution file `{0}' does not exist",
                                                                            SolutionPath.Value));
                }
            }
        }

        internal VisualStudioSolutionDetails TryGetSolutionDetails() {
            if (SolutionExists) {
                return new VisualStudioSolutionFileReader().ReadSolution(SolutionPath.Value, Config);
            } else {
                return null;
            }
        }

        private bool SolutionExists {
            get {
                return File.Exists(SolutionPath.Value);
            }
        }

        public override void Clean(IBounce bounce) {
            if (SolutionExists) {
                bounce.Log.Info("cleaning solution at: " + SolutionPath.Value);
                bounce.ShellCommand.ExecuteAndExpectSuccess(MsBuildExe.Value, String.Format(@"/target:Clean ""{0}""", SolutionPath.Value));
            }
        }

        private string Config {
            get {
                if (Configuration == null) {
                    return "";
                } else {
                    return Configuration.Value;
                }
            }
        }

        internal VisualStudioProjectFileDetails GetProjectDetails(string name) {
            return SolutionDetails.Projects.First(p => p.Name == name);
        }
    }
}
{'fraction_non_alphanumeric': 0.08047642040882022, 'fraction_numerical': 0.0022533397714469662, 'mean_word_length': 1.3352123261931605, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4998169', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1309, 'n_words': 283}