Skip to content

Commit

Permalink
Made more things configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
devedse committed Jul 26, 2020
1 parent f00b252 commit 6aef455
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
11 changes: 9 additions & 2 deletions WebOptimizationProject.Runner/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Configuration;
using DeveImageOptimizer.FileProcessing;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
using System.Reflection;
Expand All @@ -24,7 +25,13 @@ public static async Task Main(string[] args)
var wopConfig = new WopConfig();
configuration.Bind(wopConfig);

var githubRepositoryOptimizer = new GitHubRepositoryOptimizer(wopConfig);
var deveImageOptimizerConfiguration = new DeveImageOptimizerConfiguration()
{
ExecuteImageOptimizationParallel = true,
MaxDegreeOfParallelism = Environment.ProcessorCount
};

var githubRepositoryOptimizer = new GitHubRepositoryOptimizer(wopConfig, deveImageOptimizerConfiguration, new WopProgressReporter());
await githubRepositoryOptimizer.GoOptimize("WebOptimizationProject", "TestRepo1");

//string owner = "vuejs";
Expand Down
19 changes: 19 additions & 0 deletions WebOptimizationProject.Runner/WopProgressReporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using DeveImageOptimizer.State;
using System;
using System.Threading;

namespace WebOptimizationProject.Runner
{
public class WopProgressReporter : IProgressReporter
{
public void OptimizableFileProgressUpdated(OptimizableFile optimizableFile)
{
Console.WriteLine($"{Thread.CurrentThread.ManagedThreadId} File Optimized: {optimizableFile}");
}

public void TotalFileCountDiscovered(int count)
{
Console.WriteLine($"{Thread.CurrentThread.ManagedThreadId} Total file count: {count}");
}
}
}
21 changes: 8 additions & 13 deletions WebOptimizationProject/GitHubRepositoryOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@
using WebOptimizationProject.Configuration;
using WebOptimizationProject.Helpers;
using WebOptimizationProject.Helpers.Git;
using WebOptimizationProject.ImageOptimization;

namespace WebOptimizationProject
{
public class GitHubRepositoryOptimizer
{
private readonly WopConfig _wopConfig;
private readonly DeveImageOptimizerConfiguration _deveImageOptimizerConfiguration;
private readonly IProgressReporter _progressReporter;
private readonly GitOctoKitHandler _gitOctoKitHandler;
private readonly GitCommandLineHandler _git;

public GitHubRepositoryOptimizer(WopConfig wopConfig)
public GitHubRepositoryOptimizer(WopConfig wopConfig, DeveImageOptimizerConfiguration deveImageOptimizerConfiguration, IProgressReporter progressReporter)
{
_wopConfig = wopConfig;


_deveImageOptimizerConfiguration = deveImageOptimizerConfiguration;
_progressReporter = progressReporter;
_gitOctoKitHandler = new GitOctoKitHandler(_wopConfig);
_git = new GitCommandLineHandler(_wopConfig);
}
Expand Down Expand Up @@ -188,19 +189,13 @@ public async Task GoOptimize(Repository repository, string branchName = null)
Console.WriteLine();
}

private static async Task<IEnumerable<OptimizableFile>> GoOptimize(string dir, WopConfig config)
private async Task<IEnumerable<OptimizableFile>> GoOptimize(string dir, WopConfig config)
{
var c = new DeveImageOptimizerConfiguration()
{
MaxDegreeOfParallelism = Environment.ProcessorCount
};

var wopProgressReporter = new WopProgressReporter();
var fileRememberer = new FileProcessedStateRememberer(false);
var dirRememberer = new DirProcessedStateRememberer(true);

var fileProcessor = new DeveImageOptimizerProcessor(c, wopProgressReporter, fileRememberer, dirRememberer);
var optimizedFileResults = await fileProcessor.ProcessDirectoryParallel(dir);
var fileProcessor = new DeveImageOptimizerProcessor(_deveImageOptimizerConfiguration, _progressReporter, fileRememberer, dirRememberer);
var optimizedFileResults = await fileProcessor.ProcessDirectory(dir);

return optimizedFileResults;
}
Expand Down
15 changes: 0 additions & 15 deletions WebOptimizationProject/ImageOptimization/WopProgressReporter.cs

This file was deleted.

2 changes: 1 addition & 1 deletion WebOptimizationProject/WebOptimizationProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<ItemGroup>
<PackageReference Include="AdysTech.CredentialManager" Version="2.2.0" />
<PackageReference Include="DeveImageOptimizer" Version="1.0.341" />
<PackageReference Include="DeveImageOptimizer" Version="1.0.344" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Octokit" Version="0.48.0" />
</ItemGroup>
Expand Down

0 comments on commit 6aef455

Please sign in to comment.