...
This commit is contained in:
parent
96e90f8693
commit
aad679b3f1
@ -13,6 +13,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,19 +1,35 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace PhotoRenamer
|
||||
{
|
||||
class Program
|
||||
internal static class Program
|
||||
{
|
||||
private static async Task Main(string[] args)
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
var Configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile(AppDomain.CurrentDomain.BaseDirectory + "\\appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
var configuration = CreateHostBuilder(args).Build();
|
||||
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
|
||||
var logger = loggerFactory.CreateLogger(nameof(Program));
|
||||
try
|
||||
{
|
||||
var p = new Renamer(configuration, loggerFactory);
|
||||
return p.Run();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Error executing program");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static IConfigurationBuilder CreateHostBuilder(string[] args) => new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile(AppDomain.CurrentDomain.BaseDirectory + "\\appsettings.json", optional: true,
|
||||
reloadOnChange: true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args);
|
||||
|
||||
}
|
||||
}
|
||||
|
27
PhotoRenamer/Renamer.cs
Normal file
27
PhotoRenamer/Renamer.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace PhotoRenamer
|
||||
{
|
||||
internal class Renamer
|
||||
{
|
||||
private readonly IConfigurationRoot _configuration;
|
||||
private readonly ILogger<Renamer> _logger;
|
||||
|
||||
public Renamer(IConfigurationRoot configuration, ILoggerFactory loggerFactory)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_logger = loggerFactory.CreateLogger<Renamer>();
|
||||
}
|
||||
|
||||
public int Run()
|
||||
{
|
||||
var sourcePath = _configuration["Source"];
|
||||
var targetPath = _configuration["Target"];
|
||||
_logger.LogInformation($"Source path {sourcePath}");
|
||||
_logger.LogInformation($"Target path {targetPath}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
2
PhotoRenamer/appsettings.json
Normal file
2
PhotoRenamer/appsettings.json
Normal file
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user