/// <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);
        }
Beispiel #2
0
        public string GetSourceFileContent(BranchInfo branchInfo, string path)
        {
            ThrowIfNotLoggedIn();
            ThrowIfNullOrInvalid(branchInfo);

            string content = null;

            using (StreamReader sr = new StreamReader(path))
            {
                content = sr.ReadToEnd();
            }

            Thread.Sleep(_delay * 2);
            return(content);
        }
        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);
                }
            }
        }
Beispiel #4
0
        public IEnumerable <SourceItemInfo> GetSourceItemsList(BranchInfo branchInfo, string path)
        {
            ThrowIfNotLoggedIn();
            ThrowIfNullOrInvalid(branchInfo);

            var sourceDirectory = new DirectoryInfo($"{BaseUrl}\\{branchInfo.Repo.Project.Key}\\{branchInfo.Repo.Key}\\__branches\\{branchInfo.Key}\\{path}");

            var dirs = sourceDirectory
                       .GetDirectories()
                       .Select(dir =>
                               new SourceItemInfo
            {
                Id         = Constants.UndefinedId,
                Key        = dir.FullName,
                Name       = dir.Name,
                FolderPath = sourceDirectory.FullName,
                Type       = SourceItemTypes.Directory,
                Branch     = branchInfo
            });

            var files = sourceDirectory
                        .GetFiles()
                        .Select(file =>
                                new SourceItemInfo
            {
                Id        = Constants.UndefinedId,
                Key       = file.FullName,
                Name      = file.Name,
                Extension = string.IsNullOrEmpty(file.Extension)
                            ? file.Extension
                            : file.Extension[0] == '.'
                                ? file.Extension.Substring(1)
                                : file.Extension,
                FolderPath = sourceDirectory.FullName,
                Type       = SourceItemTypes.File,
                Branch     = branchInfo
            });

            Thread.Sleep(_delay);
            return(dirs.Concat(files));
        }
 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 IEnumerable <SourceItemInfo> GetSourceItemsList(this ICodebaseService codebaseService, BranchInfo branchInfo)
 {
     return(codebaseService.GetSourceItemsList(branchInfo, string.Empty));
 }