Anul 3 Semestrul 2
This commit is contained in:
+48
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using FileCompression.Enums;
|
||||
using FileCompression.Interfaces;
|
||||
using FileCompression.Models;
|
||||
using FileCompression.Services.Strategies;
|
||||
|
||||
namespace FileCompression.Services.Composites;
|
||||
|
||||
public class FolderCompressor : ICompressor
|
||||
{
|
||||
private readonly string sourcePath;
|
||||
private readonly string destinationPath;
|
||||
private readonly StrategyContext strategyContext;
|
||||
private readonly string basePath;
|
||||
public FolderCompressor(string sourcePath, string destinationPath, string basePath, StrategyContext strategyContext)
|
||||
{
|
||||
this.sourcePath = sourcePath;
|
||||
this.destinationPath = destinationPath;
|
||||
this.strategyContext = strategyContext;
|
||||
this.basePath = basePath;
|
||||
}
|
||||
public void Compress()
|
||||
{
|
||||
strategyContext.CompressDirectory(sourcePath, destinationPath, basePath);
|
||||
var entries = GetEntries();
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
entry.Compress();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<ICompressor> GetEntries()
|
||||
{
|
||||
List<ICompressor> entries = [];
|
||||
foreach (var file in Directory.GetFiles(sourcePath))
|
||||
{
|
||||
entries.Add(new FileCompressor(file, destinationPath, basePath, strategyContext));
|
||||
}
|
||||
|
||||
foreach (var directory in Directory.GetDirectories(sourcePath))
|
||||
{
|
||||
entries.Add(new FolderCompressor(directory, destinationPath, basePath, strategyContext));
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user