Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<ItemGroup>
<PackageVersion Include="Microsoft.Build" Version="17.15.0-preview-25277-114" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.9.1" />
<PackageVersion Include="Spectre.Console" Version="0.50.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta7.25380.108" />
<PackageVersion Include="Spectre.Console" Version="0.51.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-rc.1.25451.107" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Microsoft.Sbom.Api" Version="2.2.8" />
<PackageVersion Include="CycloneDX.Core" Version="6.0.5" />
Expand All @@ -15,9 +15,9 @@
<PackageVersion Include="NuGet.Versioning" Version="6.14.0" />
<PackageVersion Include="NuGet.Packaging" Version="6.14.0" />
<PackageVersion Include="NuGet.Frameworks" Version="6.14.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.4" />
</ItemGroup>
</Project>
114 changes: 114 additions & 0 deletions ENUMERATOR_IMPLEMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Enumerator Implementation

## Overview

This document describes the new `Enumerator` class that enhances the existing `SlnScanner` functionality by providing a unified interface for enumerating both solution files and project files based on the specified enumeration type.

## Key Features

### EnumerationType Enum
- **Sln**: Enumerates solution files (.sln, .slnx, .slnf) and extracts all project paths from them
- **Project**: Directly enumerates project files (.csproj, .vbproj, .sqlproj, .fsproj, .vcxproj)

### Enhanced Functionality
1. **Unified Interface**: Single method `EnumerateProjectPaths()` handles both solution and project enumeration
2. **Parallel Processing**: Solutions are processed in parallel for better performance
3. **Recursive Scanning**: Supports recursive directory traversal with configurable depth
4. **File Format Support**:
- Solution formats: .sln, .slnx, .slnf
- Project formats: .csproj, .vbproj, .sqlproj, .fsproj, .vcxproj
5. **Error Handling**: Robust error handling with detailed error reporting via ErrorSink

## Implementation Details

### Core Classes

#### Enumerator
- Location: `bld/Infrastructure/Enumerator.cs`
- Constructor: `Enumerator(CleaningOptions Options, ErrorSink ErrorSink)`
- Main Method: `EnumerateProjectPaths(string path, EnumerationType enumerationType)`

#### EnumerationType Enum
- Location: `bld/Models/DirectoryModels.cs`
- Values: `Sln`, `Project`

### Key Methods

1. **EnumerateProjectPaths**: Main entry point for enumeration
2. **EnumerateProjectsFromSolutions**: Processes solution files and extracts projects
3. **EnumerateProjectsFromSolution**: Parses individual solution files
4. **EnumerateProjectFiles**: Direct project file enumeration
5. **GetSolutionFilesAsync**: Asynchronously finds solution files
6. **GetProjectFilesAsync**: Asynchronously finds project files

### Performance Optimizations

- **Parallel Processing**: Solution files are processed concurrently using `Task.WhenAll`
- **Async/Await Pattern**: Full async enumeration for non-blocking operations
- **Efficient File Filtering**: Uses `Directory.EnumerateFiles` with proper enumeration options

## Usage Examples

### Basic Usage
```csharp
var options = new CleaningOptions();
var errorSink = new ErrorSink(console);
var enumerator = new Enumerator(options, errorSink);

// Enumerate projects from solution files
await foreach (var projectPath in enumerator.EnumerateProjectPaths(rootPath, EnumerationType.Sln)) {
Console.WriteLine($"Project from solution: {projectPath}");
}

// Enumerate project files directly
await foreach (var projectPath in enumerator.EnumerateProjectPaths(rootPath, EnumerationType.Project)) {
Console.WriteLine($"Direct project file: {projectPath}");
}
```

### Integration with Existing Services
The `EnumeratorDemoService` demonstrates how to integrate the new functionality:
```csharp
var demoService = new EnumeratorDemoService(console, options);
await demoService.CompareEnumerationApproachesAsync(rootPath);
```

## Comparison with SlnScanner

| Feature | SlnScanner | Enumerator |
|---------|------------|------------|
| Solution Files | ✅ .sln, .slnf, .slnx | ✅ .sln, .slnf, .slnx |
| Project Files | ❌ Not directly | ✅ All MSBuild formats |
| Project Enumeration | ❌ Manual parsing needed | ✅ Automatic extraction |
| Parallel Processing | ❌ Sequential | ✅ Parallel solutions |
| Unified Interface | ❌ Separate methods | ✅ Single method with enum |
| Error Handling | ✅ Basic | ✅ Enhanced |

## Testing

The implementation includes comprehensive tests in `bld.Tests/EnumeratorTests.cs` covering:
- Solution file parsing and project extraction
- Direct project file enumeration
- Error handling for invalid paths
- Edge cases (empty paths, non-existent directories)

## Integration Points

The new `Enumerator` can be used as a drop-in replacement or complement to `SlnScanner` in:
- `CleaningApplication`
- `NugetAnalysisApplication`
- `TfmService`
- `OutdatedService`
- `CpmService`
- `ContainerizeService`

## Future Enhancements

1. **Caching**: Add project metadata caching for repeated enumerations
2. **Filtering**: Enhanced filtering based on project types or conditions
3. **Progress Reporting**: Integration with progress reporting for large solutions
4. **Configuration**: More granular configuration options for enumeration behavior

## Conclusion

The `Enumerator` class provides a modern, efficient, and unified approach to project enumeration that extends beyond the current `SlnScanner` capabilities while maintaining backward compatibility with existing patterns.
Loading