Console base WIP 2
This commit is contained in:
3
src/AppCommon/FileTime.App.Core/AppInitOptions.cs
Normal file
3
src/AppCommon/FileTime.App.Core/AppInitOptions.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace FileTime.App.Core;
|
||||
|
||||
public record AppInitOptions(string AppDataRoot, string EnvironmentName);
|
||||
@@ -14,6 +14,7 @@
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
|
||||
<PackageReference Include="morelinq" Version="3.4.2" />
|
||||
<PackageReference Include="MvvmGen" Version="1.2.1" />
|
||||
<PackageReference Include="ObservableComputations" Version="2.3.0" />
|
||||
|
||||
47
src/AppCommon/FileTime.App.Core/Init.cs
Normal file
47
src/AppCommon/FileTime.App.Core/Init.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace FileTime.App.Core;
|
||||
|
||||
public static class Init
|
||||
{
|
||||
public static AppInitOptions InitDevelopment()
|
||||
{
|
||||
var environmentName = "Development";
|
||||
|
||||
var appDataRoot = Path.Combine(Environment.CurrentDirectory, "appdata");
|
||||
|
||||
return new(appDataRoot, environmentName);
|
||||
}
|
||||
|
||||
public static AppInitOptions InitRelease()
|
||||
{
|
||||
var environmentName = "Release";
|
||||
|
||||
var possibleDataRootsPaths = new List<string>
|
||||
{
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FileTime"),
|
||||
Path.Combine(Assembly.GetEntryAssembly()?.Location ?? ".", "fallbackDataRoot")
|
||||
};
|
||||
|
||||
string? appDataRoot = null;
|
||||
foreach (var possibleAppDataRoot in possibleDataRootsPaths)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appDataRootDirectory = new DirectoryInfo(possibleAppDataRoot);
|
||||
if (!appDataRootDirectory.Exists) appDataRootDirectory.Create();
|
||||
|
||||
//TODO write test
|
||||
appDataRoot = possibleAppDataRoot;
|
||||
break;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return new(
|
||||
appDataRoot ?? throw new UnauthorizedAccessException(),
|
||||
environmentName);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using FileTime.App.Core.Configuration;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.App.Core.Services.UserCommandHandler;
|
||||
using FileTime.App.Core.StartupServices;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.App.Core.ViewModels.ItemPreview;
|
||||
using FileTime.App.Core.ViewModels.Timeline;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
@@ -11,7 +13,7 @@ namespace FileTime.App.Core;
|
||||
|
||||
public static class Startup
|
||||
{
|
||||
public static IServiceCollection AddCoreAppServices(this IServiceCollection serviceCollection)
|
||||
public static IServiceCollection AddCoreAppServices(this IServiceCollection serviceCollection, IConfigurationRoot configuration)
|
||||
{
|
||||
serviceCollection.TryAddTransient<ITabViewModel, TabViewModel>();
|
||||
serviceCollection.TryAddTransient<IContainerViewModel, ContainerViewModel>();
|
||||
@@ -34,6 +36,7 @@ public static class Startup
|
||||
|
||||
return serviceCollection
|
||||
.AddCommandHandlers()
|
||||
.AddConfiguration(configuration)
|
||||
.AddSingleton<IStartupHandler, DefaultIdentifiableCommandHandlerRegister>()
|
||||
.AddSingleton<IExitHandler, ContainerRefreshHandler>();
|
||||
}
|
||||
@@ -46,4 +49,12 @@ public static class Startup
|
||||
.AddSingleton<IUserCommandHandler, ToolUserCommandHandlerService>()
|
||||
.AddSingleton<IUserCommandHandler, CommandSchedulerUserCommandHandlerService>();
|
||||
}
|
||||
|
||||
internal static IServiceCollection AddConfiguration(this IServiceCollection serviceCollection, IConfigurationRoot configuration)
|
||||
{
|
||||
return serviceCollection
|
||||
.Configure<ProgramsConfiguration>(configuration.GetSection(SectionNames.ProgramsSectionName))
|
||||
.Configure<KeyBindingConfiguration>(configuration.GetSection(SectionNames.KeybindingSectionName))
|
||||
.AddSingleton<IConfiguration>(configuration);
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public static class DependencyInjection
|
||||
serviceCollection.AddSingleton<IStartupHandler, ITabPersistenceService>(sp => sp.GetRequiredService<ITabPersistenceService>());
|
||||
|
||||
return serviceCollection
|
||||
.AddCoreAppServices()
|
||||
.AddCoreAppServices(configuration)
|
||||
.AddLocalProviderServices()
|
||||
.AddLocalAdminProviderServices(configuration)
|
||||
.AddRemoteProviderServices()
|
||||
|
||||
Reference in New Issue
Block a user