Пример #1
0
 public static ProjectConfigurationDetails CreateProjectConfigurationDetails(ProjectRootSnapshot project)
 {
     return(new ProjectConfigurationDetails {
         IgnorePathsSection = CreateSectionDetails(project.Project.IgnorePathsConfiguration),
         IgnoreSearchableFilesSection = CreateSectionDetails(project.Project.IgnoreSearchableFilesConfiguration),
         IncludeSearchableFilesSection = CreateSectionDetails(project.Project.IncludeSearchableFilesConfiguration)
     });
 }
Пример #2
0
        private static OptionalDirectoryEntry MapDirectoryEntry(ProjectRootSnapshot project, string relativePath)
        {
            var directoryEntry = GetDirectoryEntriesRequestHandler.CreateDirectoryEntry(project, relativePath);

            return(directoryEntry == null
        ? new OptionalDirectoryEntry {
                HasValue = false
            }
        : new OptionalDirectoryEntry {
                HasValue = true, Value = directoryEntry
            });
        }
Пример #3
0
        public static DirectoryEntry CreateDirectoryEntry(ProjectRootSnapshot project, string relativePath)
        {
            var directorySnapshot = FindDirectorySnapshot(project, relativePath);

            if (directorySnapshot == null)
            {
                return(null);
            }

            return(new DirectoryEntry {
                Name = directorySnapshot.DirectoryName.RelativePath.Value,
                Entries = BuildEntries(directorySnapshot),
            });
        }
Пример #4
0
        private DirectorySnapshot FindDirectorySnapshot(FullPath directoryPath, ProjectRootSnapshot projectSnapshot)
        {
            var splitPath = PathHelpers.SplitPrefix(directoryPath.Value, projectSnapshot.Project.RootPath.Value);
            var current   = projectSnapshot.Directory;

            foreach (var name in PathHelpers.SplitPath(splitPath.Suffix))
            {
                current = current.ChildDirectories
                          .FirstOrDefault(x => SystemPathComparer.EqualsNames(name, x.DirectoryName.Name));
                if (current == null)
                {
                    return(null);
                }
            }
            return(current);
        }
Пример #5
0
        private static DirectorySnapshot FindDirectorySnapshot(ProjectRootSnapshot project, string relativePath)
        {
            if (project == null)
            {
                return(null);
            }

            var entry = project.Directory;

            foreach (var name in PathHelpers.SplitPath(relativePath))
            {
                var child = entry.ChildDirectories.FirstOrDefault(x =>
                                                                  SystemPathComparer.EqualsNames(x.DirectoryName.Name, name));
                if (child == null)
                {
                    entry = null;
                    break;
                }

                entry = child;
            }

            return(entry);
        }
Пример #6
0
        public static ProjectDetails CreateProjectDetails(IFileDatabaseSnapshot database, ProjectRootSnapshot project,
                                                          int maxFilesByExtensionDetailsCount, int maxLargeFilesDetailsCount)
        {
            return(new ProjectDetails {
                RootPath = project.Project.RootPath.Value,

                DirectoryDetails = GetDirectoryDetailsRequestHandler.CreateDirectoryDetails(database, project,
                                                                                            project.Directory,
                                                                                            maxFilesByExtensionDetailsCount, maxLargeFilesDetailsCount),

                ConfigurationDetails = CreateProjectConfigurationDetails(project)
            });
        }
Пример #7
0
        public static DirectoryDetails CreateDirectoryDetails(IFileDatabaseSnapshot database,
                                                              ProjectRootSnapshot projectSnapshot,
                                                              DirectorySnapshot baseDirectory, int maxFilesByExtensionDetailsCount, int maxLargeFilesDetailsCount)
        {
            var directoryPath = baseDirectory.DirectoryName.FullPath;
            var fileDatabse   = (FileDatabaseSnapshot)database;

            var directoryFileNames = fileDatabse.FileNames
                                     .Where(x => directoryPath.ContainsPath(x.FullPath))
                                     .ToHashSet();

            var directoryFiles = fileDatabse.Files.Values
                                 .Where(x => directoryFileNames.Contains(x.FileName))
                                 .ToList();

            var searchableFiles = directoryFiles
                                  .Where(x => x.HasContents())
                                  .ToList();

            var binaryFiles = directoryFiles
                              .Where(x => (x.Contents is BinaryFileContents) && (((BinaryFileContents)x.Contents).BinaryFileSize > 0))
                              .ToList();

            return(new DirectoryDetails {
                Path = directoryPath.Value,

                DirectoryCount = FileSystemSnapshotManager.CountDirectoryEntries(baseDirectory),

                FileCount = FileSystemSnapshotManager.CountFileEntries(baseDirectory),

                SearchableFilesCount = searchableFiles.Count,

                SearchableFilesByteLength = searchableFiles.Aggregate(0L, (acc, x) => acc + x.Contents.ByteLength),

                BinaryFilesCount = binaryFiles.Count,

                BinaryFilesByteLength = binaryFiles.Aggregate(0L, (acc, x) => acc + ((BinaryFileContents)x.Contents).BinaryFileSize),

                SearchableFilesByExtensionDetails = searchableFiles
                                                    .GroupBy(x => GetFileExtension(x.FileName))
                                                    .Select(g => new FileByExtensionDetails {
                    FileExtension = g.Key,
                    FileCount = g.Count(),
                    FilesByteLength = g.Aggregate(0L, (acc, x) => acc + x.Contents.ByteLength)
                })
                                                    .OrderByDescendingThenTake(maxFilesByExtensionDetailsCount, x => x.FilesByteLength)
                                                    .ToList(),

                LargeSearchableFilesDetails = searchableFiles
                                              .OrderByDescendingThenTake(maxLargeFilesDetailsCount, x => x.Contents.ByteLength)
                                              .Select(x => new LargeFileDetails {
                    RelativePath = GetRelativePath(directoryPath, x.FileName.FullPath),
                    ByteLength = x.Contents.ByteLength
                })
                                              .ToList(),

                BinaryFilesByExtensionDetails = binaryFiles
                                                .GroupBy(x => GetFileExtension(x.FileName))
                                                .Select(g => new FileByExtensionDetails {
                    FileExtension = g.Key,
                    FileCount = g.Count(),
                    FilesByteLength = g.Aggregate(0L, (acc, x) => acc + ((BinaryFileContents)x.Contents).BinaryFileSize)
                })
                                                .OrderByDescendingThenTake(maxFilesByExtensionDetailsCount, x => x.FilesByteLength)
                                                .ToList(),

                LargeBinaryFilesDetails = binaryFiles
                                          .OrderByDescendingThenTake(maxLargeFilesDetailsCount, x => ((BinaryFileContents)x.Contents).BinaryFileSize)
                                          .Select(x => new LargeFileDetails {
                    RelativePath = GetRelativePath(directoryPath, x.FileName.FullPath),
                    ByteLength = ((BinaryFileContents)x.Contents).BinaryFileSize
                })
                                          .ToList()
            });
        }