/// <summary> /// Рекурсивный поиск элементов в указанной папке репозитория по условию /// </summary> /// <param name="codebaseService">База кода</param> /// <param name="branchInfo">Инфо о ветке</param> /// <param name="path">Путь, с которого начинается поиск</param> /// <param name="resultCondition">Условие поиска</param> /// <param name="escapeFolderCondition">Условие выхода из папки (остановка рекурсии)</param> /// <param name="includeResultsFromEscapingFolder">Учитывать или нет результаты поиска из папки, в которой прекращается рекурсия</param> /// <param name="progressObserver">Наблюдатель за прогрессом выполнения</param> /// <returns>Список результатов, не null</returns> public static ICollection <SourceItemInfo> FindAllItems(this ICodebaseService codebaseService , BranchInfo branchInfo, string path, Func <SourceItemInfo, bool> resultCondition , Func <IEnumerable <SourceItemInfo>, bool> escapeFolderCondition, bool includeResultsFromEscapingFolder , ProgressObserver progressObserver = null) { ThrowIfNullOrInvalid(branchInfo); var resultList = new List <SourceItemInfo>(64); if (progressObserver != null) { progressObserver.ProgressData = $"[{branchInfo.Repo.Project.Name}/{branchInfo.Repo.Name}: {branchInfo.Name}]/{path}"; progressObserver.Status = ProgressObserver.StartedStatus; } FindAllItemsBody(codebaseService, branchInfo, path, resultCondition, escapeFolderCondition , includeResultsFromEscapingFolder, ref resultList, progressObserver); if (progressObserver != null) { progressObserver.ProgressData = $"[{branchInfo.Repo.Project.Name}/{branchInfo.Repo.Name}: {branchInfo.Name}]/{path}"; progressObserver.Status = ProgressObserver.FinishedStatus; } return(resultList); }
public AnalysisServices(ICollectionStepFactory collectionStepFactory, ICodebaseService codebaseService, IAnalyzerFactory analyzerFactory, IFileSystem fileSystem) { this.collectionStepFactory = collectionStepFactory; this.codebaseService = codebaseService; this.analyzerFactory = analyzerFactory; this.fileSystem = fileSystem; fileSystem.CreateFolder(fileSystem.MetricsOutputFolder); }
public AnalysisServices(ICollectionStepFactory collectionStepFactory, ICodebaseService codebaseService, IAnalyzerFactory analyzerFactory, IFileSystem fileSystem, IYamlFileDeserializer <MetricsCommandArguments> fileDeserializer) { this.collectionStepFactory = collectionStepFactory; this.codebaseService = codebaseService; this.analyzerFactory = analyzerFactory; this.fileSystem = fileSystem; this.fileDeserializer = fileDeserializer; fileSystem.CreateFolder(fileSystem.MetricsOutputFolder); }
public WorkspaceProvider(ICodebaseService codebaseService, IAnalysisService analysisService, IUserPreferences userPreferences, IFileSystem fileSystem, IAutoSaveService autoSaveService) { this.codebaseService = codebaseService; this.analysisService = analysisService; this.userPreferences = userPreferences; this.fileSystem = fileSystem; this.autoSaveService = autoSaveService; fileSystem.CreateMetropolisSpecialFolders(); CodeBase = CodeBase.Empty(); }
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); } }
public static bool TryParse(ICodebaseService codebaseService, CsProjectFileInfo projFileInfo, out CsProjectFile csProject) { try { csProject = CsProjectFile.Parse(codebaseService, projFileInfo); return(true); } catch { csProject = null; return(false); } }
private static void FindAllItemsBody(ICodebaseService codebaseService , BranchInfo branchInfo, string path, Func <SourceItemInfo, bool> resultCondition , Func <IEnumerable <SourceItemInfo>, bool> escapeFolderCondition, bool includeResultsFromEscapingFolder , ref List <SourceItemInfo> results, ProgressObserver progressObserver) { var itemsList = codebaseService.GetSourceItemsList(branchInfo, path); if (!itemsList.Any()) { return; } if (progressObserver != null) { progressObserver.ProgressData = $"[{branchInfo.Repo.Project.Name}/{branchInfo.Repo.Name}: {branchInfo.Name}]/{path}"; } bool escaping = escapeFolderCondition(itemsList); if (escaping && !includeResultsFromEscapingFolder) { return; } var resultItemsList = itemsList.Where(i => resultCondition(i)); foreach (var item in resultItemsList) { results.Add(item); } if (!escaping) { var folderList = itemsList.Where(i => i.Name?.Substring(0, 1) != "." && i.Type == SourceItemTypes.Directory); if (!folderList.Any()) { return; } var pathPrefix = !string.IsNullOrEmpty(path) ? $"{path}/" : string.Empty; foreach (var folder in folderList) { FindAllItemsBody(codebaseService, branchInfo, $"{pathPrefix}{folder.Name}", resultCondition , escapeFolderCondition, includeResultsFromEscapingFolder, ref results, progressObserver); } } }
/// <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 }; } })); }
public static T Resolve <T>(params object[] ctorParams) { if (typeof(T) == typeof(ICodebaseService)) { if (_codebaseService == null) { var instance = new BitbucketService((string)ctorParams[0]); //var instance = new CodebaseServiceStub(); _codebaseService = instance; return((T)_codebaseService); } else { throw new NotImplementedException(); } } else { throw new NotImplementedException(); } }
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 BranchInfo GetDefaultBranch(this ICodebaseService codebaseService, RepoInfo repoInfo) { return(codebaseService.GetBranches(repoInfo) .First(branch => branch.IsDefault)); }
public static bool TryGetSourceFileContentIfExists(this ICodebaseService codebaseService, SourceItemInfo fileInfo, out string content) { ThrowIfNullOrInvalid(fileInfo); return(codebaseService.TryGetSourceFileContentIfExists(fileInfo.Branch, fileInfo.Key, out content)); }
public static string GetSourceFileContent(this ICodebaseService codebaseService, SourceItemInfo fileInfo) { ThrowIfNullOrInvalid(fileInfo); return(codebaseService.GetSourceFileContent(fileInfo.Branch, fileInfo.Key)); }
public static IEnumerable <SourceItemInfo> GetSourceItemsList(this ICodebaseService codebaseService, BranchInfo branchInfo) { return(codebaseService.GetSourceItemsList(branchInfo, string.Empty)); }
/// <summary> /// .ctor /// </summary> public TreeDataService(ICodebaseService codebaseService) { _codebaseService = codebaseService ?? throw new ArgumentNullException(nameof(codebaseService)); Tree = new ObservableCollection <Node>(); }