<commit_before>﻿//----------------------------------------------------------------------- 
// <copyright file="SolutionFileReader.cs" company="Copacetic Software"> 
// Copyright (c) Copacetic Software.  
// <author><NAME></author> 
// <date>Wednesday, April 30, 2014 11:07:08 PM</date> 
// Licensed under the Apache License, Version 2.0,
// you may not use this file except in compliance with this License.
//  
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright> 
//-----------------------------------------------------------------------

using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
using CopaceticSoftware.CodeGenerator.StarterKit.Infrastructure.IO;
using CopaceticSoftware.Common.Infrastructure;
using log4net;

namespace CopaceticSoftware.CodeGenerator.StarterKit.Infrastructure.VisualStudioSolution
{
    public class SolutionFileProjectReference
    {
        public string Title;
        public string ProjectFileName;
    }
    public interface ISolutionFileReader
    {
        IEnumerable<SolutionFileProjectReference> ReadProjectReferences(string solutionFileName);
    }

    public class SolutionFileReader : ISolutionFileReader
    {
        private readonly IFileReader _fileReader;

        private static readonly Regex ProjectLinePattern = new Regex(
            "Project\\(\"(?<TypeGuid>.*)\"\\)\\s+=\\s+\"(?<Title>.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\"");

        private static ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public SolutionFileReader(IFileReader fileReader)
        {
            _fileReader = fileReader;
        }

        public IEnumerable<SolutionFileProjectReference> ReadProjectReferences(string solutionFileName)
        {
            if (!File.Exists(solutionFileName))
                throw new FileNotFoundException("Solution FileName", solutionFileName);

            Ensure.ArgumentNotNullOrEmpty(solutionFileName, "solutionFileName");

            var directory = Path.GetDirectoryName(solutionFileName);

            foreach (string line in _fileReader.ReadLines(solutionFileName))
            {
                Match match = ProjectLinePattern.Match(line);
                if (match.Success)
                {
                    string typeGuid = match.Groups["TypeGuid"].Value;
                    string title = match.Groups["Title"].Value;
                    string location = match.Groups["Location"].Value;
                    
                    switch (typeGuid.ToUpperInvariant())
                    {
                        case "{2150E333-8FDC-42A3-9474-1A3956D46DE8}": // Solution Folder
                            // ignore folders
                            break;
                        case "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}": // C# project
                           yield return new SolutionFileProjectReference
                                        {
                                            ProjectFileName = Path.Combine(directory, location),
                                            Title = title
                                        };<commit_msg>Bug fix - GetFullPath to project file<commit_after>﻿//----------------------------------------------------------------------- 
// <copyright file="SolutionFileReader.cs" company="Copacetic Software"> 
// Copyright (c) Copacetic Software.  
// <author><NAME></author> 
// <date>Wednesday, April 30, 2014 11:07:08 PM</date> 
// Licensed under the Apache License, Version 2.0,
// you may not use this file except in compliance with this License.
//  
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright> 
//-----------------------------------------------------------------------

using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
using CopaceticSoftware.CodeGenerator.StarterKit.Infrastructure.IO;
using CopaceticSoftware.Common.Infrastructure;
using log4net;

namespace CopaceticSoftware.CodeGenerator.StarterKit.Infrastructure.VisualStudioSolution
{
    public class SolutionFileProjectReference
    {
        public string Title;
        public string ProjectFileName;
    }
    public interface ISolutionFileReader
    {
        IEnumerable<SolutionFileProjectReference> ReadProjectReferences(string solutionFileName);
    }

    public class SolutionFileReader : ISolutionFileReader
    {
        private readonly IFileReader _fileReader;

        private static readonly Regex ProjectLinePattern = new Regex(
            "Project\\(\"(?<TypeGuid>.*)\"\\)\\s+=\\s+\"(?<Title>.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\"");

        private static ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public SolutionFileReader(IFileReader fileReader)
        {
            _fileReader = fileReader;
        }

        public IEnumerable<SolutionFileProjectReference> ReadProjectReferences(string solutionFileName)
        {
            if (!File.Exists(solutionFileName))
                throw new FileNotFoundException("Solution FileName", solutionFileName);

            Ensure.ArgumentNotNullOrEmpty(solutionFileName, "solutionFileName");

            var directory = Path.GetDirectoryName(solutionFileName);

            foreach (string line in _fileReader.ReadLines(solutionFileName))
            {
                Match match = ProjectLinePattern.Match(line);
                if (match.Success)
                {
                    string typeGuid = match.Groups["TypeGuid"].Value;
                    string title = match.Groups["Title"].Value;
                    string location = match.Groups["Location"].Value;
                    
                    switch (typeGuid.ToUpperInvariant())
                    {
                        case "{2150E333-8FDC-42A3-9474-1A3956D46DE8}": // Solution Folder
                            // ignore folders
                            break;
                        case "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}": // C# project
                           yield return new SolutionFileProjectReference
                                        {
                                            ProjectFileName = Path.GetFullPath(Path.Combine(directory, location)),
                                            Title = title
                                        };
{'fraction_non_alphanumeric': 0.13056792873051226, 'fraction_numerical': 0.015590200445434299, 'mean_word_length': 1.9242979242979243, 'pattern_counts': {'":': 4, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6277811', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1612, 'n_words': 423}