public static bool TryGetSourceFileContentIfExists(this ICodebaseService codebaseService, BranchInfo branchInfo, string path, out string content)
 {
     try
     {
         content = codebaseService.GetSourceFileContent(branchInfo, path);
         return(true);
     }
     catch (FileNotFoundException)
     {
         content = null;
         return(false);
     }
 }
        /// <summary>
        /// Получает последовательность всех солюшенов из репозитория (на указанной ветке)
        /// </summary>
        public static IEnumerable <Result <CsSolution> > GetAllSolutions(
            ICodebaseService codebaseService
            , BranchInfo branch
            , ProgressObserver progressObserver = null)
        {
            if (codebaseService == null)
            {
                throw new ArgumentNullException(nameof(codebaseService));
            }

            bool isSolutionFileInfo(SourceItemInfo item)
            => item.Type == SourceItemTypes.File && item.Extension?.ToLower() == "sln";

            return(codebaseService.FindAllItems(
                       branch
                       , null
                       , isSolutionFileInfo
                       , items => items.Any(isSolutionFileInfo)
                       , true
                       , progressObserver)
                   .Select(solutionFileInfo =>
            {
                try
                {
                    var solutionFileContent = codebaseService.GetSourceFileContent(solutionFileInfo);
                    var solutionFile = CsSolutionFile.Parse(solutionFileContent, solutionFileInfo);
                    var projectFiles = solutionFile.CsProjectFileInfos
                                       .Select(projectFileInfo => CsProjectFile.Parse(codebaseService, projectFileInfo));

                    return new Result <CsSolution>
                    {
                        IsSuccessful = true,
                        Data = new CsSolution(solutionFile, projectFiles)
                    };
                }
                catch (Exception e)
                {
                    return new Result <CsSolution>
                    {
                        IsSuccessful = false,
                        Tag = solutionFileInfo,
                        ErrorMessage = e.Message
                    };
                }
            }));
        }
示例#3
0
        public static CsProjectFile Parse(ICodebaseService codebaseService, CsProjectFileInfo projFileInfo)
        {
            var projFileContent = codebaseService.GetSourceFileContent(projFileInfo);

            var result = new CsProjectFile
            {
                ProjectFileInfo = projFileInfo,
                //IsNewFormat = CsParsingHelper.IsProjectOfNewFormat(projFileContent)
            };

            CsParsingHelper.ParseFieldsFromCsProjectXml(result, projFileContent);

            if (!result.IsNewFormat)
            {
                if (codebaseService.TryGetSourceFileContentIfExists(projFileInfo.Branch
                                                                    , $"{projFileInfo.FolderPath}/packages.config", out var packagesConfigContent))
                {
                    result.PackageReferences = CsParsingHelper.ParsePackageReferencesFromConfig(packagesConfigContent);
                }
            }

            return(result);
        }
        public static string GetSourceFileContent(this ICodebaseService codebaseService, SourceItemInfo fileInfo)
        {
            ThrowIfNullOrInvalid(fileInfo);

            return(codebaseService.GetSourceFileContent(fileInfo.Branch, fileInfo.Key));
        }