Admin mode WIP

This commit is contained in:
2023-07-26 10:24:22 +02:00
parent ba1210b2c4
commit 0c49071a3b
46 changed files with 695 additions and 55 deletions

2
.gitignore vendored
View File

@@ -413,3 +413,5 @@ FodyWeavers.xsd
appdata appdata
**/.idea **/.idea
appsettings.Local.json

View File

@@ -23,10 +23,9 @@ namespace FileTime.App.Core.ViewModels;
public partial class TabViewModel : ITabViewModel public partial class TabViewModel : ITabViewModel
{ {
private readonly IServiceProvider _serviceProvider; private readonly IServiceProvider _serviceProvider;
private readonly IItemNameConverterService _itemNameConverterService;
private readonly IAppState _appState; private readonly IAppState _appState;
private readonly IRxSchedulerService _rxSchedulerService;
private readonly ITimelessContentProvider _timelessContentProvider; private readonly ITimelessContentProvider _timelessContentProvider;
private readonly IRefreshSmoothnessCalculator _refreshSmoothnessCalculator;
private readonly SourceList<FullName> _markedItems = new(); private readonly SourceList<FullName> _markedItems = new();
private readonly List<IDisposable> _disposables = new(); private readonly List<IDisposable> _disposables = new();
private bool _disposed; private bool _disposed;
@@ -50,19 +49,17 @@ public partial class TabViewModel : ITabViewModel
public TabViewModel( public TabViewModel(
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
IItemNameConverterService itemNameConverterService,
IAppState appState, IAppState appState,
IRxSchedulerService rxSchedulerService, ITimelessContentProvider timelessContentProvider,
ITimelessContentProvider timelessContentProvider) IRefreshSmoothnessCalculator refreshSmoothnessCalculator)
{ {
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_itemNameConverterService = itemNameConverterService;
_appState = appState; _appState = appState;
MarkedItems = _markedItems.Connect().StartWithEmpty(); MarkedItems = _markedItems.Connect().StartWithEmpty();
IsSelected = _appState.SelectedTab.Select(s => s == this); IsSelected = _appState.SelectedTab.Select(s => s == this);
_rxSchedulerService = rxSchedulerService;
_timelessContentProvider = timelessContentProvider; _timelessContentProvider = timelessContentProvider;
_refreshSmoothnessCalculator = refreshSmoothnessCalculator;
} }
public void Init(ITab tab, int tabNumber) public void Init(ITab tab, int tabNumber)
@@ -103,7 +100,7 @@ public partial class TabViewModel : ITabViewModel
CurrentSelectedItemAsContainer = CurrentSelectedItem.Map(i => i as IContainerViewModel); CurrentSelectedItemAsContainer = CurrentSelectedItem.Map(i => i as IContainerViewModel);
SelectedsChildren = CurrentSelectedItem SelectedsChildren = CurrentSelectedItem
.Debounce(TimeSpan.FromMilliseconds(200), resetTimer: true) .Debounce(() => _refreshSmoothnessCalculator.RefreshDelay, resetTimer: true)
.DistinctUntilChanged() .DistinctUntilChanged()
.Map(item => .Map(item =>
{ {

View File

@@ -12,6 +12,9 @@ using FileTime.Core.ContentAccess;
using FileTime.Core.Services; using FileTime.Core.Services;
using FileTime.Core.Timeline; using FileTime.Core.Timeline;
using FileTime.Providers.Local; using FileTime.Providers.Local;
using FileTime.Providers.LocalAdmin;
using FileTime.Providers.Remote;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -19,7 +22,7 @@ namespace FileTime.App.DependencyInjection;
public static class DependencyInjection public static class DependencyInjection
{ {
public static IServiceCollection RegisterDefaultServices(IServiceCollection? serviceCollection = null) public static IServiceCollection RegisterDefaultServices(IConfigurationRoot configuration, IServiceCollection? serviceCollection = null)
{ {
serviceCollection ??= new ServiceCollection(); serviceCollection ??= new ServiceCollection();
@@ -41,18 +44,18 @@ public static class DependencyInjection
return serviceCollection return serviceCollection
.AddCoreAppServices() .AddCoreAppServices()
.AddLocalServices() .AddLocalProviderServices()
.AddLocalAdminProviderServices(configuration)
.AddRemoteProviderServices()
.RegisterCommands() .RegisterCommands()
.AddDefaultCommandHandlers(); .AddDefaultCommandHandlers();
} }
private static IServiceCollection RegisterCommands(this IServiceCollection serviceCollection) private static IServiceCollection RegisterCommands(this IServiceCollection serviceCollection)
{ => serviceCollection
return serviceCollection
.AddCommands() .AddCommands()
.AddTransient<CreateContainerCommand>() .AddTransient<CreateContainerCommand>()
.AddTransient<CreateElementCommand>() .AddTransient<CreateElementCommand>()
.AddTransient<CopyCommand>() .AddTransient<CopyCommand>()
.AddTransient<DeleteCommand>(); .AddTransient<DeleteCommand>();
}
} }

View File

@@ -16,6 +16,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Core\FileTime.Core.CommandHandlers\FileTime.Core.CommandHandlers.csproj" /> <ProjectReference Include="..\..\Core\FileTime.Core.CommandHandlers\FileTime.Core.CommandHandlers.csproj" />
<ProjectReference Include="..\..\Core\FileTime.Core.Timeline\FileTime.Core.Timeline.csproj" /> <ProjectReference Include="..\..\Core\FileTime.Core.Timeline\FileTime.Core.Timeline.csproj" />
<ProjectReference Include="..\..\Providers\FileTime.Providers.LocalAdmin\FileTime.Providers.LocalAdmin.csproj" />
<ProjectReference Include="..\..\Providers\FileTime.Providers.Local\FileTime.Providers.Local.csproj" /> <ProjectReference Include="..\..\Providers\FileTime.Providers.Local\FileTime.Providers.Local.csproj" />
<ProjectReference Include="..\FileTime.App.Core\FileTime.App.Core.csproj" /> <ProjectReference Include="..\FileTime.App.Core\FileTime.App.Core.csproj" />
</ItemGroup> </ItemGroup>

View File

@@ -15,7 +15,6 @@ public class Tab : ITab
{ {
private readonly ITimelessContentProvider _timelessContentProvider; private readonly ITimelessContentProvider _timelessContentProvider;
private readonly ITabEvents _tabEvents; private readonly ITabEvents _tabEvents;
private readonly IRefreshSmoothnessCalculator _refreshSmoothnessCalculator;
private readonly DeclarativeProperty<IContainer?> _currentLocation = new(null); private readonly DeclarativeProperty<IContainer?> _currentLocation = new(null);
private readonly BehaviorSubject<IContainer?> _currentLocationForced = new(null); private readonly BehaviorSubject<IContainer?> _currentLocationForced = new(null);
private readonly DeclarativeProperty<AbsolutePath?> _currentRequestItem = new(null); private readonly DeclarativeProperty<AbsolutePath?> _currentRequestItem = new(null);
@@ -38,7 +37,6 @@ public class Tab : ITab
{ {
_timelessContentProvider = timelessContentProvider; _timelessContentProvider = timelessContentProvider;
_tabEvents = tabEvents; _tabEvents = tabEvents;
_refreshSmoothnessCalculator = refreshSmoothnessCalculator;
_currentPointInTime = null!; _currentPointInTime = null!;
_timelessContentProvider.CurrentPointInTime.Subscribe(p => _currentPointInTime = p); _timelessContentProvider.CurrentPointInTime.Subscribe(p => _currentPointInTime = p);
@@ -54,7 +52,8 @@ public class Tab : ITab
return Task.CompletedTask; return Task.CompletedTask;
}); });
CurrentItems = CurrentLocation.Map((container, _) => CurrentItems = CurrentLocation
.Map((container, _) =>
{ {
var items = container is null var items = container is null
? (ObservableCollection<IItem>?) null ? (ObservableCollection<IItem>?) null
@@ -77,8 +76,8 @@ public class Tab : ITab
CurrentSelectedItem.Subscribe((v) => CurrentSelectedItem.Subscribe((v) =>
{ {
_refreshSmoothnessCalculator.RegisterChange(); refreshSmoothnessCalculator.RegisterChange();
_refreshSmoothnessCalculator.RecalculateSmoothness(); refreshSmoothnessCalculator.RecalculateSmoothness();
}); });
CurrentSelectedItem.Subscribe(async (s, _) => CurrentSelectedItem.Subscribe(async (s, _) =>

View File

@@ -10,4 +10,8 @@
<ProjectReference Include="..\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" /> <ProjectReference Include="..\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
</ItemGroup>
</Project> </Project>

View File

@@ -1,15 +1,18 @@
using FileTime.Core.Command; using FileTime.Core.Command;
using Microsoft.Extensions.Logging;
namespace FileTime.Core.Timeline; namespace FileTime.Core.Timeline;
public class LocalCommandExecutor : ILocalCommandExecutor public class LocalCommandExecutor : ILocalCommandExecutor
{ {
private readonly ICommandRunner _commandRunner; private readonly ICommandRunner _commandRunner;
private readonly ILogger<LocalCommandExecutor> _logger;
public event EventHandler<ICommand>? CommandFinished; public event EventHandler<ICommand>? CommandFinished;
public LocalCommandExecutor(ICommandRunner commandRunner) public LocalCommandExecutor(ICommandRunner commandRunner, ILogger<LocalCommandExecutor> logger)
{ {
_commandRunner = commandRunner; _commandRunner = commandRunner;
_logger = logger;
} }
public void ExecuteCommand(ICommand command) public void ExecuteCommand(ICommand command)
@@ -27,7 +30,10 @@ public class LocalCommandExecutor : ILocalCommandExecutor
{ {
await _commandRunner.RunCommandAsync(context.Command); await _commandRunner.RunCommandAsync(context.Command);
} }
catch (Exception ex) { } catch (Exception ex)
{
_logger.LogError(ex, "Error executing command {Command}", context.Command.GetType().Name);
}
CommandFinished?.Invoke(this, context.Command); CommandFinished?.Invoke(this, context.Command);
} }

View File

@@ -85,6 +85,28 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeclarativeProperty", "Libr
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Defer", "Library\Defer\Defer.csproj", "{609FFADA-C221-4E41-B377-C6AF56C0A900}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Defer", "Library\Defer\Defer.csproj", "{609FFADA-C221-4E41-B377-C6AF56C0A900}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Server", "Server", "{778AAF38-20FF-438C-A9C3-60850C8B5A27}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTime.Server", "Server\FileTime.Server\FileTime.Server.csproj", "{190762DB-7353-4F02-AD42-E29C36DEE218}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTime.Server.App", "Server\FileTime.Server.App\FileTime.Server.App.csproj", "{2E2B6F68-D20C-4F07-A3C1-95E7D8F1DAF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTime.Server.App.Abstractions", "Server\FileTime.Server.App.Abstractions\FileTime.Server.App.Abstractions.csproj", "{85B04DA4-6B2C-4772-B915-EB4C53CA31A2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTime.Providers.LocalAdmin", "Providers\FileTime.Providers.LocalAdmin\FileTime.Providers.LocalAdmin.csproj", "{28914EA2-396A-444F-A5DF-4072497E48D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTime.Providers.LocalAdmin.Abstractions", "Providers\FileTime.Providers.LocalAdmin.Abstractions\FileTime.Providers.LocalAdmin.Abstractions.csproj", "{2FB2C2EF-ADBA-48AE-AD3A-D51625C044CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTime.Providers.Remote", "Providers\FileTime.Providers.Remote\FileTime.Providers.Remote.csproj", "{5E721AB2-9107-4F36-A602-70D5E00FAC0C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTime.Providers.Remote.Abstractions", "Providers\FileTime.Providers.Remote.Abstractions\FileTime.Providers.Remote.Abstractions.csproj", "{72072CA3-954D-4D97-BE70-928021D8F66E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTime.Server.Common", "Server\FileTime.Server.Common\FileTime.Server.Common.csproj", "{181BC62C-EDEA-4DD1-8837-A4B1CBF8BE42}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTime.Server.Common.Abstractions", "Server\FileTime.Server.Common.Abstractions\FileTime.Server.Common.Abstractions.csproj", "{C82B417F-94E6-4D4D-B261-0CAF40551D5E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileTime.Server.Web", "Server\FileTime.Server.Web\FileTime.Server.Web.csproj", "{9062F7D2-34DE-44B7-A2D6-8B3AFDEBB606}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -223,6 +245,46 @@ Global
{609FFADA-C221-4E41-B377-C6AF56C0A900}.Debug|Any CPU.Build.0 = Debug|Any CPU {609FFADA-C221-4E41-B377-C6AF56C0A900}.Debug|Any CPU.Build.0 = Debug|Any CPU
{609FFADA-C221-4E41-B377-C6AF56C0A900}.Release|Any CPU.ActiveCfg = Release|Any CPU {609FFADA-C221-4E41-B377-C6AF56C0A900}.Release|Any CPU.ActiveCfg = Release|Any CPU
{609FFADA-C221-4E41-B377-C6AF56C0A900}.Release|Any CPU.Build.0 = Release|Any CPU {609FFADA-C221-4E41-B377-C6AF56C0A900}.Release|Any CPU.Build.0 = Release|Any CPU
{190762DB-7353-4F02-AD42-E29C36DEE218}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{190762DB-7353-4F02-AD42-E29C36DEE218}.Debug|Any CPU.Build.0 = Debug|Any CPU
{190762DB-7353-4F02-AD42-E29C36DEE218}.Release|Any CPU.ActiveCfg = Release|Any CPU
{190762DB-7353-4F02-AD42-E29C36DEE218}.Release|Any CPU.Build.0 = Release|Any CPU
{2E2B6F68-D20C-4F07-A3C1-95E7D8F1DAF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E2B6F68-D20C-4F07-A3C1-95E7D8F1DAF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E2B6F68-D20C-4F07-A3C1-95E7D8F1DAF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E2B6F68-D20C-4F07-A3C1-95E7D8F1DAF0}.Release|Any CPU.Build.0 = Release|Any CPU
{85B04DA4-6B2C-4772-B915-EB4C53CA31A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85B04DA4-6B2C-4772-B915-EB4C53CA31A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85B04DA4-6B2C-4772-B915-EB4C53CA31A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85B04DA4-6B2C-4772-B915-EB4C53CA31A2}.Release|Any CPU.Build.0 = Release|Any CPU
{28914EA2-396A-444F-A5DF-4072497E48D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28914EA2-396A-444F-A5DF-4072497E48D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28914EA2-396A-444F-A5DF-4072497E48D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28914EA2-396A-444F-A5DF-4072497E48D0}.Release|Any CPU.Build.0 = Release|Any CPU
{2FB2C2EF-ADBA-48AE-AD3A-D51625C044CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2FB2C2EF-ADBA-48AE-AD3A-D51625C044CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2FB2C2EF-ADBA-48AE-AD3A-D51625C044CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2FB2C2EF-ADBA-48AE-AD3A-D51625C044CB}.Release|Any CPU.Build.0 = Release|Any CPU
{5E721AB2-9107-4F36-A602-70D5E00FAC0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E721AB2-9107-4F36-A602-70D5E00FAC0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E721AB2-9107-4F36-A602-70D5E00FAC0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E721AB2-9107-4F36-A602-70D5E00FAC0C}.Release|Any CPU.Build.0 = Release|Any CPU
{72072CA3-954D-4D97-BE70-928021D8F66E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72072CA3-954D-4D97-BE70-928021D8F66E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72072CA3-954D-4D97-BE70-928021D8F66E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72072CA3-954D-4D97-BE70-928021D8F66E}.Release|Any CPU.Build.0 = Release|Any CPU
{181BC62C-EDEA-4DD1-8837-A4B1CBF8BE42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{181BC62C-EDEA-4DD1-8837-A4B1CBF8BE42}.Debug|Any CPU.Build.0 = Debug|Any CPU
{181BC62C-EDEA-4DD1-8837-A4B1CBF8BE42}.Release|Any CPU.ActiveCfg = Release|Any CPU
{181BC62C-EDEA-4DD1-8837-A4B1CBF8BE42}.Release|Any CPU.Build.0 = Release|Any CPU
{C82B417F-94E6-4D4D-B261-0CAF40551D5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C82B417F-94E6-4D4D-B261-0CAF40551D5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C82B417F-94E6-4D4D-B261-0CAF40551D5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C82B417F-94E6-4D4D-B261-0CAF40551D5E}.Release|Any CPU.Build.0 = Release|Any CPU
{9062F7D2-34DE-44B7-A2D6-8B3AFDEBB606}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9062F7D2-34DE-44B7-A2D6-8B3AFDEBB606}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9062F7D2-34DE-44B7-A2D6-8B3AFDEBB606}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9062F7D2-34DE-44B7-A2D6-8B3AFDEBB606}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@@ -262,6 +324,16 @@ Global
{D0EC224E-F043-4657-BD6A-1ADE52DFF8B5} = {01F231DE-4A65-435F-B4BB-77EE5221890C} {D0EC224E-F043-4657-BD6A-1ADE52DFF8B5} = {01F231DE-4A65-435F-B4BB-77EE5221890C}
{D5C85B69-6345-4FAA-A00C-3A73BA677664} = {07CA18AA-B85D-4DEE-BB86-F569F6029853} {D5C85B69-6345-4FAA-A00C-3A73BA677664} = {07CA18AA-B85D-4DEE-BB86-F569F6029853}
{609FFADA-C221-4E41-B377-C6AF56C0A900} = {07CA18AA-B85D-4DEE-BB86-F569F6029853} {609FFADA-C221-4E41-B377-C6AF56C0A900} = {07CA18AA-B85D-4DEE-BB86-F569F6029853}
{190762DB-7353-4F02-AD42-E29C36DEE218} = {778AAF38-20FF-438C-A9C3-60850C8B5A27}
{2E2B6F68-D20C-4F07-A3C1-95E7D8F1DAF0} = {778AAF38-20FF-438C-A9C3-60850C8B5A27}
{85B04DA4-6B2C-4772-B915-EB4C53CA31A2} = {778AAF38-20FF-438C-A9C3-60850C8B5A27}
{28914EA2-396A-444F-A5DF-4072497E48D0} = {2FC40FE1-4446-44AB-BF77-00F94D995FA3}
{2FB2C2EF-ADBA-48AE-AD3A-D51625C044CB} = {2FC40FE1-4446-44AB-BF77-00F94D995FA3}
{5E721AB2-9107-4F36-A602-70D5E00FAC0C} = {2FC40FE1-4446-44AB-BF77-00F94D995FA3}
{72072CA3-954D-4D97-BE70-928021D8F66E} = {2FC40FE1-4446-44AB-BF77-00F94D995FA3}
{181BC62C-EDEA-4DD1-8837-A4B1CBF8BE42} = {778AAF38-20FF-438C-A9C3-60850C8B5A27}
{C82B417F-94E6-4D4D-B261-0CAF40551D5E} = {778AAF38-20FF-438C-A9C3-60850C8B5A27}
{9062F7D2-34DE-44B7-A2D6-8B3AFDEBB606} = {778AAF38-20FF-438C-A9C3-60850C8B5A27}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {859FB3DF-C60A-46B1-82E5-90274905D1EF} SolutionGuid = {859FB3DF-C60A-46B1-82E5-90274905D1EF}

View File

@@ -1,5 +1,6 @@
using Avalonia.Input; using Avalonia.Input;
using FileTime.App.Core.UserCommand; using FileTime.App.Core.UserCommand;
using FileTime.Providers.LocalAdmin;
namespace FileTime.GuiApp.Configuration; namespace FileTime.GuiApp.Configuration;
@@ -7,17 +8,21 @@ public static class MainConfiguration
{ {
private static readonly Lazy<List<CommandBindingConfiguration>> _defaultKeybindings = new(InitDefaultKeyBindings); private static readonly Lazy<List<CommandBindingConfiguration>> _defaultKeybindings = new(InitDefaultKeyBindings);
public static Dictionary<string, string> Configuration { get; } public static Dictionary<string, string?> Configuration { get; }
static MainConfiguration() static MainConfiguration()
{ {
Configuration = new(); Configuration = new()
{
{AdminElevationConfiguration.SectionName + ":" + nameof(AdminElevationConfiguration.ServerExecutablePath), "FileTime.Server.exe"},
};
PopulateDefaultEditorPrograms(Configuration); PopulateDefaultEditorPrograms(Configuration);
PopulateDefaultKeyBindings(Configuration, _defaultKeybindings.Value, PopulateDefaultKeyBindings(Configuration, _defaultKeybindings.Value,
SectionNames.KeybindingSectionName + ":" + nameof(KeyBindingConfiguration.DefaultKeyBindings)); SectionNames.KeybindingSectionName + ":" + nameof(KeyBindingConfiguration.DefaultKeyBindings));
} }
private static void PopulateDefaultKeyBindings(Dictionary<string, string> configuration, private static void PopulateDefaultKeyBindings(Dictionary<string, string?> configuration,
List<CommandBindingConfiguration> commandBindingConfigs, string basePath) List<CommandBindingConfiguration> commandBindingConfigs, string basePath)
{ {
for (var i = 0; i < commandBindingConfigs.Count; i++) for (var i = 0; i < commandBindingConfigs.Count; i++)
@@ -113,7 +118,7 @@ public static class MainConfiguration
//new CommandBindingConfiguration(ConfigCommand.ToggleAdvancedIcons, new[] { Key.Z, Key.I }), //new CommandBindingConfiguration(ConfigCommand.ToggleAdvancedIcons, new[] { Key.Z, Key.I }),
}; };
private static void PopulateDefaultEditorPrograms(Dictionary<string, string> configuration) private static void PopulateDefaultEditorPrograms(Dictionary<string, string?> configuration)
{ {
var editorPrograms = new List<ProgramConfiguration>() var editorPrograms = new List<ProgramConfiguration>()
{ {

View File

@@ -22,6 +22,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\AppCommon\FileTime.App.Core.Abstraction\FileTime.App.Core.Abstraction.csproj" /> <ProjectReference Include="..\..\..\AppCommon\FileTime.App.Core.Abstraction\FileTime.App.Core.Abstraction.csproj" />
<ProjectReference Include="..\..\..\Core\FileTime.Core.Models\FileTime.Core.Models.csproj" /> <ProjectReference Include="..\..\..\Core\FileTime.Core.Models\FileTime.Core.Models.csproj" />
<ProjectReference Include="..\..\..\Providers\FileTime.Providers.LocalAdmin.Abstractions\FileTime.Providers.LocalAdmin.Abstractions.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -8,6 +8,7 @@ using FileTime.App.Search;
using FileTime.GuiApp.Font; using FileTime.GuiApp.Font;
using FileTime.GuiApp.ViewModels; using FileTime.GuiApp.ViewModels;
using FileTime.GuiApp.Views; using FileTime.GuiApp.Views;
using FileTime.Server.Common;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -19,7 +20,8 @@ public class App : Application
{ {
var configuration = Startup.CreateConfiguration(); var configuration = Startup.CreateConfiguration();
DI.ServiceProvider = DependencyInjection DI.ServiceProvider = DependencyInjection
.RegisterDefaultServices() .RegisterDefaultServices(configuration: configuration)
.AddRemoteServices()
.AddFrequencyNavigation() .AddFrequencyNavigation()
.AddCommandPalette() .AddCommandPalette()
.AddSearch() .AddSearch()

View File

@@ -52,4 +52,7 @@
<ItemGroup Condition="'$(Configuration)' == 'Debug'"> <ItemGroup Condition="'$(Configuration)' == 'Debug'">
<Content Include="appsettings.Development.json" CopyToOutputDirectory="PreserveNewest" /> <Content Include="appsettings.Development.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<Content Include="appsettings.Local.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project> </Project>

View File

@@ -1,4 +1,3 @@
using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using FileTime.App.Core.Services; using FileTime.App.Core.Services;
@@ -14,7 +13,6 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using Serilog; using Serilog;
using Serilog.Configuration;
namespace FileTime.GuiApp.App; namespace FileTime.GuiApp.App;
@@ -25,7 +23,8 @@ public static class Startup
var configurationBuilder = new ConfigurationBuilder() var configurationBuilder = new ConfigurationBuilder()
.AddInMemoryCollection(MainConfiguration.Configuration) .AddInMemoryCollection(MainConfiguration.Configuration)
.AddJsonFile("appsettings.json", optional: true) .AddJsonFile("appsettings.json", optional: true)
.AddJsonFile($"appsettings.{Program.EnvironmentName}.json", true); .AddJsonFile($"appsettings.{Program.EnvironmentName}.json", true)
.AddJsonFile("appsettings.Local.json", optional: true);
var configurationDirectory = new DirectoryInfo(Path.Combine(Program.AppDataRoot, "config")); var configurationDirectory = new DirectoryInfo(Path.Combine(Program.AppDataRoot, "config"));
if (configurationDirectory.Exists) if (configurationDirectory.Exists)

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12,12H19C18.47,16.11 15.72,19.78 12,20.92V12H5V6.3L12,3.19M12,1L3,5V11C3,16.55 6.84,21.73 12,23C17.16,21.73 21,16.55 21,11V5L12,1Z" /></svg>

After

Width:  |  Height:  |  Size: 210 B

View File

@@ -42,6 +42,7 @@
<ProjectReference Include="..\..\..\AppCommon\FileTime.App.Core.Abstraction\FileTime.App.Core.Abstraction.csproj" /> <ProjectReference Include="..\..\..\AppCommon\FileTime.App.Core.Abstraction\FileTime.App.Core.Abstraction.csproj" />
<ProjectReference Include="..\..\..\AppCommon\FileTime.App.FrequencyNavigation.Abstractions\FileTime.App.FrequencyNavigation.Abstractions.csproj" /> <ProjectReference Include="..\..\..\AppCommon\FileTime.App.FrequencyNavigation.Abstractions\FileTime.App.FrequencyNavigation.Abstractions.csproj" />
<ProjectReference Include="..\..\..\Providers\FileTime.Providers.Local.Abstractions\FileTime.Providers.Local.Abstractions.csproj" /> <ProjectReference Include="..\..\..\Providers\FileTime.Providers.Local.Abstractions\FileTime.Providers.Local.Abstractions.csproj" />
<ProjectReference Include="..\..\..\Providers\FileTime.Providers.LocalAdmin.Abstractions\FileTime.Providers.LocalAdmin.Abstractions.csproj" />
<ProjectReference Include="..\FileTime.GuiApp.Abstractions\FileTime.GuiApp.Abstractions.csproj" /> <ProjectReference Include="..\FileTime.GuiApp.Abstractions\FileTime.GuiApp.Abstractions.csproj" />
<ProjectReference Include="..\FileTime.GuiApp.DesignPreview\FileTime.GuiApp.DesignPreview.csproj" /> <ProjectReference Include="..\FileTime.GuiApp.DesignPreview\FileTime.GuiApp.DesignPreview.csproj" />
<ProjectReference Include="..\FileTime.GuiApp.Font.Abstractions\FileTime.GuiApp.Font.Abstractions.csproj" /> <ProjectReference Include="..\FileTime.GuiApp.Font.Abstractions\FileTime.GuiApp.Font.Abstractions.csproj" />

View File

@@ -2,6 +2,7 @@
using FileTime.App.Core.Services; using FileTime.App.Core.Services;
using FileTime.App.FrequencyNavigation.Services; using FileTime.App.FrequencyNavigation.Services;
using FileTime.GuiApp.Services; using FileTime.GuiApp.Services;
using FileTime.Providers.LocalAdmin;
namespace FileTime.GuiApp.ViewModels; namespace FileTime.GuiApp.ViewModels;
@@ -13,5 +14,6 @@ public interface IMainWindowViewModel : IMainWindowViewModelBase
IDialogService DialogService { get; } IDialogService DialogService { get; }
IFrequencyNavigationService FrequencyNavigationService { get; } IFrequencyNavigationService FrequencyNavigationService { get; }
ICommandPaletteService CommandPaletteService { get; } ICommandPaletteService CommandPaletteService { get; }
public IRefreshSmoothnessCalculator RefreshSmoothnessCalculator { get; } IRefreshSmoothnessCalculator RefreshSmoothnessCalculator { get; }
IAdminElevationManager AdminElevationManager { get; }
} }

View File

@@ -9,6 +9,7 @@ using FileTime.Core.Models;
using FileTime.Core.Timeline; using FileTime.Core.Timeline;
using FileTime.GuiApp.Services; using FileTime.GuiApp.Services;
using FileTime.Providers.Local; using FileTime.Providers.Local;
using FileTime.Providers.LocalAdmin;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using MvvmGen; using MvvmGen;
@@ -29,6 +30,7 @@ namespace FileTime.GuiApp.ViewModels;
[Inject(typeof(IFrequencyNavigationService), PropertyAccessModifier = AccessModifier.Public)] [Inject(typeof(IFrequencyNavigationService), PropertyAccessModifier = AccessModifier.Public)]
[Inject(typeof(ICommandPaletteService), PropertyAccessModifier = AccessModifier.Public)] [Inject(typeof(ICommandPaletteService), PropertyAccessModifier = AccessModifier.Public)]
[Inject(typeof(IRefreshSmoothnessCalculator), PropertyAccessModifier = AccessModifier.Public)] [Inject(typeof(IRefreshSmoothnessCalculator), PropertyAccessModifier = AccessModifier.Public)]
[Inject(typeof(IAdminElevationManager), PropertyAccessModifier = AccessModifier.Public)]
public partial class MainWindowViewModel : IMainWindowViewModel public partial class MainWindowViewModel : IMainWindowViewModel
{ {
public bool Loading => false; public bool Loading => false;

View File

@@ -62,10 +62,24 @@
<Grid Grid.Column="1" PointerPressed="HeaderPointerPressed"> <Grid Grid.Column="1" PointerPressed="HeaderPointerPressed">
<Rectangle Fill="#01000000" /> <Rectangle Fill="#01000000" />
<StackPanel Margin="20,10" Orientation="Horizontal"> <Grid ColumnDefinitions="*, Auto">
<local:PathPresenter DataContext="{Binding AppState.SelectedTab^.CurrentLocation^.FullName.Path, Converter={StaticResource PathPreformatter}}" /> <StackPanel Margin="20,10" Orientation="Horizontal">
<TextBlock Foreground="{StaticResource AccentBrush}" Text="{Binding AppState.SelectedTab^.CurrentSelectedItem.Value.DisplayNameText}" /> <local:PathPresenter DataContext="{Binding AppState.SelectedTab^.CurrentLocation^.FullName.Path, Converter={StaticResource PathPreformatter}}" />
</StackPanel> <TextBlock Foreground="{StaticResource AccentBrush}" Text="{Binding AppState.SelectedTab^.CurrentSelectedItem.Value.DisplayNameText}" />
</StackPanel>
<StackPanel
Grid.Column="1"
Margin="20,10,160,10"
Orientation="Vertical">
<Image
Height="20"
HorizontalAlignment="Left"
IsVisible="{Binding AdminElevationManager.IsAdminInstanceRunning}"
Source="{SvgImage /Assets/material/security.svg}"
VerticalAlignment="Center"
Width="20" />
</StackPanel>
</Grid>
</Grid> </Grid>
<Grid Grid.Row="1" RowDefinitions="Auto,Auto,Auto,Auto"> <Grid Grid.Row="1" RowDefinitions="Auto,Auto,Auto,Auto">

View File

@@ -10,7 +10,7 @@ public sealed class DebounceProperty<T> : TimingPropertyBase<T>
public DebounceProperty( public DebounceProperty(
IDeclarativeProperty<T> from, IDeclarativeProperty<T> from,
TimeSpan interval, Func<TimeSpan> interval,
Action<T?>? setValueHook = null) : base(from, interval, setValueHook) Action<T?>? setValueHook = null) : base(from, interval, setValueHook)
{ {
} }
@@ -33,7 +33,7 @@ public sealed class DebounceProperty<T> : TimingPropertyBase<T>
{ {
try try
{ {
while (DateTime.Now - _startTime < Interval) while (DateTime.Now - _startTime < Interval())
{ {
await Task.Delay(WaitInterval, newToken); await Task.Delay(WaitInterval, newToken);
} }

View File

@@ -7,7 +7,10 @@ namespace DeclarativeProperty;
public static class DeclarativePropertyExtensions public static class DeclarativePropertyExtensions
{ {
public static IDeclarativeProperty<T> Debounce<T>(this IDeclarativeProperty<T> from, TimeSpan interval, bool resetTimer = false) public static IDeclarativeProperty<T> Debounce<T>(this IDeclarativeProperty<T> from, TimeSpan interval, bool resetTimer = false)
=> new DebounceProperty<T>(from, interval){ResetTimer = resetTimer}; => new DebounceProperty<T>(from, () => interval) {ResetTimer = resetTimer};
public static IDeclarativeProperty<T> Debounce<T>(this IDeclarativeProperty<T> from, Func<TimeSpan> interval, bool resetTimer = false)
=> new DebounceProperty<T>(from, interval) {ResetTimer = resetTimer};
public static IDeclarativeProperty<T> DistinctUntilChanged<T>(this IDeclarativeProperty<T> from) public static IDeclarativeProperty<T> DistinctUntilChanged<T>(this IDeclarativeProperty<T> from)
=> new DistinctUntilChangedProperty<T>(from); => new DistinctUntilChangedProperty<T>(from);

View File

@@ -7,7 +7,7 @@ public class ThrottleProperty<T> : TimingPropertyBase<T>
public ThrottleProperty( public ThrottleProperty(
IDeclarativeProperty<T> from, IDeclarativeProperty<T> from,
TimeSpan interval, Func<TimeSpan> interval,
Action<T?>? setValueHook = null) : base(from, interval, setValueHook) Action<T?>? setValueHook = null) : base(from, interval, setValueHook)
{ {
} }
@@ -15,7 +15,8 @@ public class ThrottleProperty<T> : TimingPropertyBase<T>
protected override Task SetValue(T? next, CancellationToken cancellationToken = default) protected override Task SetValue(T? next, CancellationToken cancellationToken = default)
{ {
_debounceCts?.Cancel(); _debounceCts?.Cancel();
if (DateTime.Now - _lastFired > Interval) var interval = Interval();
if (DateTime.Now - _lastFired > interval)
{ {
_lastFired = DateTime.Now; _lastFired = DateTime.Now;
// Note: Recursive chains can happen. Awaiting this can cause a deadlock. // Note: Recursive chains can happen. Awaiting this can cause a deadlock.
@@ -28,7 +29,7 @@ public class ThrottleProperty<T> : TimingPropertyBase<T>
{ {
try try
{ {
await Task.Delay(Interval, _debounceCts.Token); await Task.Delay(interval, _debounceCts.Token);
await FireIfNeededAsync( await FireIfNeededAsync(
next, next,
() => { _lastFired = DateTime.Now; }, () => { _lastFired = DateTime.Now; },

View File

@@ -3,11 +3,11 @@
public abstract class TimingPropertyBase<T> : DeclarativePropertyBase<T> public abstract class TimingPropertyBase<T> : DeclarativePropertyBase<T>
{ {
private readonly SemaphoreSlim _semaphore = new(1, 1); private readonly SemaphoreSlim _semaphore = new(1, 1);
protected TimeSpan Interval { get; } protected Func<TimeSpan> Interval { get; }
protected TimingPropertyBase( protected TimingPropertyBase(
IDeclarativeProperty<T> from, IDeclarativeProperty<T> from,
TimeSpan interval, Func<TimeSpan> interval,
Action<T?>? setValueHook = null) : base(from.Value, setValueHook) Action<T?>? setValueHook = null) : base(from.Value, setValueHook)
{ {
Interval = interval; Interval = interval;
@@ -65,7 +65,7 @@ public abstract class TimingPropertyBase<T> : DeclarativePropertyBase<T>
CancellationToken timingCancellationToken = default, CancellationToken timingCancellationToken = default,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
await Task.Delay(Interval, timingCancellationToken); await Task.Delay(Interval(), timingCancellationToken);
var shouldFire = WithLock(() => var shouldFire = WithLock(() =>
{ {
if (timingCancellationToken.IsCancellationRequested) if (timingCancellationToken.IsCancellationRequested)

View File

@@ -0,0 +1,6 @@
namespace FileTime.Providers.Local;
public static class LocalContentProviderConstants
{
public const string ContentProviderId = "local";
}

View File

@@ -21,6 +21,7 @@
<ProjectReference Include="..\..\Core\FileTime.Core.Models\FileTime.Core.Models.csproj" /> <ProjectReference Include="..\..\Core\FileTime.Core.Models\FileTime.Core.Models.csproj" />
<ProjectReference Include="..\..\Core\FileTime.Core.Services\FileTime.Core.Services.csproj" /> <ProjectReference Include="..\..\Core\FileTime.Core.Services\FileTime.Core.Services.csproj" />
<ProjectReference Include="..\FileTime.Providers.Local.Abstractions\FileTime.Providers.Local.Abstractions.csproj" /> <ProjectReference Include="..\FileTime.Providers.Local.Abstractions\FileTime.Providers.Local.Abstractions.csproj" />
<ProjectReference Include="..\FileTime.Providers.LocalAdmin.Abstractions\FileTime.Providers.LocalAdmin.Abstractions.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -14,7 +14,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
private readonly ITimelessContentProvider _timelessContentProvider; private readonly ITimelessContentProvider _timelessContentProvider;
private readonly bool _isCaseInsensitive; private readonly bool _isCaseInsensitive;
public LocalContentProvider(ITimelessContentProvider timelessContentProvider) : base("local") public LocalContentProvider(ITimelessContentProvider timelessContentProvider) : base(LocalContentProviderConstants.ContentProviderId)
{ {
_timelessContentProvider = timelessContentProvider; _timelessContentProvider = timelessContentProvider;
_isCaseInsensitive = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); _isCaseInsensitive = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

View File

@@ -6,7 +6,7 @@ public class LocalContentWriter : IContentWriter
{ {
private readonly FileStream _writerStream; private readonly FileStream _writerStream;
private readonly BinaryWriter _binaryWriter; private readonly BinaryWriter _binaryWriter;
private bool disposed; private bool _disposed;
public int PreferredBufferSize => 1024 * 1024; public int PreferredBufferSize => 1024 * 1024;
public LocalContentWriter(FileStream writerStream) public LocalContentWriter(FileStream writerStream)
@@ -47,7 +47,7 @@ public class LocalContentWriter : IContentWriter
private void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (!disposed) if (!_disposed)
{ {
if (disposing) if (disposing)
{ {
@@ -55,6 +55,6 @@ public class LocalContentWriter : IContentWriter
_binaryWriter.Dispose(); _binaryWriter.Dispose();
} }
} }
disposed = true; _disposed = true;
} }
} }

View File

@@ -6,5 +6,7 @@ namespace FileTime.Providers.Local;
public class LocalContentWriterFactory : IContentWriterFactory<ILocalContentProvider> public class LocalContentWriterFactory : IContentWriterFactory<ILocalContentProvider>
{ {
public Task<IContentWriter> CreateContentWriterAsync(IElement element) public Task<IContentWriter> CreateContentWriterAsync(IElement element)
=> Task.FromResult((IContentWriter)new LocalContentWriter(File.OpenWrite(element.NativePath!.Path))); {
return Task.FromResult((IContentWriter) new LocalContentWriter(File.OpenWrite(element.NativePath!.Path)));
}
} }

View File

@@ -1,23 +1,57 @@
using FileTime.Core.ContentAccess; using FileTime.Core.ContentAccess;
using FileTime.Core.Models; using FileTime.Core.Models;
using FileTime.Providers.LocalAdmin;
namespace FileTime.Providers.Local; namespace FileTime.Providers.Local;
public class LocalItemCreator : ItemCreatorBase<ILocalContentProvider> public class LocalItemCreator : ItemCreatorBase<ILocalContentProvider>
{ {
public override Task CreateContainerAsync(ILocalContentProvider contentProvider, FullName fullName) private readonly IAdminContentAccessorFactory _adminContentAccessorFactory;
private readonly IAdminContentProvider _adminContentProvider;
public LocalItemCreator(
IAdminContentAccessorFactory adminContentAccessorFactory,
IAdminContentProvider adminContentProvider)
{
_adminContentAccessorFactory = adminContentAccessorFactory;
_adminContentProvider = adminContentProvider;
}
public override async Task CreateContainerAsync(ILocalContentProvider contentProvider, FullName fullName)
{ {
var path = contentProvider.GetNativePath(fullName).Path; var path = contentProvider.GetNativePath(fullName).Path;
if (!Directory.Exists(path)) Directory.CreateDirectory(path); if (Directory.Exists(path)) return;
return Task.CompletedTask; try
{
Directory.CreateDirectory(path);
}
catch (UnauthorizedAccessException)
{
if (!_adminContentAccessorFactory.IsAdminModeSupported) throw;
var adminContentAccessor = await _adminContentAccessorFactory.CreateAdminItemCreatorAsync();
await adminContentAccessor.CreateContainerAsync(_adminContentProvider, fullName);
}
} }
public override async Task CreateElementAsync(ILocalContentProvider contentProvider, FullName fullName) public override async Task CreateElementAsync(ILocalContentProvider contentProvider, FullName fullName)
{ {
var path = contentProvider.GetNativePath(fullName).Path; var path = contentProvider.GetNativePath(fullName).Path;
await using (File.Create(path)) if (File.Exists(path)) return;
try
{ {
await using (File.Create(path))
{
}
}
catch (UnauthorizedAccessException)
{
if (!_adminContentAccessorFactory.IsAdminModeSupported) throw;
var adminContentAccessor = await _adminContentAccessorFactory.CreateAdminItemCreatorAsync();
await adminContentAccessor.CreateElementAsync(_adminContentProvider, fullName);
} }
} }
} }

View File

@@ -6,7 +6,7 @@ namespace FileTime.Providers.Local;
public static class Startup public static class Startup
{ {
public static IServiceCollection AddLocalServices(this IServiceCollection serviceCollection) public static IServiceCollection AddLocalProviderServices(this IServiceCollection serviceCollection)
{ {
serviceCollection.TryAddSingleton<ILocalContentProvider, LocalContentProvider>(); serviceCollection.TryAddSingleton<ILocalContentProvider, LocalContentProvider>();
serviceCollection.TryAddSingleton<IContentProvider>(sp => sp.GetRequiredService<ILocalContentProvider>()); serviceCollection.TryAddSingleton<IContentProvider>(sp => sp.GetRequiredService<ILocalContentProvider>());

View File

@@ -0,0 +1,9 @@
namespace FileTime.Providers.LocalAdmin;
public class AdminElevationConfiguration
{
public const string SectionName = "AdminElevation";
public string ServerExecutablePath { get; set; }
public int? ServerPort { get; set; }
public bool? StartProcess { get; set; }
}

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileTime.Providers.LocalAdmin</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
<ProjectReference Include="..\FileTime.Providers.Remote.Abstractions\FileTime.Providers.Remote.Abstractions.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,9 @@
using FileTime.Providers.Remote;
namespace FileTime.Providers.LocalAdmin;
public interface IAdminContentAccessorFactory
{
bool IsAdminModeSupported { get; }
Task<IRemoteItemCreator> CreateAdminItemCreatorAsync();
}

View File

@@ -0,0 +1,8 @@
using FileTime.Core.ContentAccess;
namespace FileTime.Providers.LocalAdmin;
public interface IAdminContentProvider : IContentProvider
{
}

View File

@@ -0,0 +1,12 @@
using FileTime.Server.Common;
namespace FileTime.Providers.LocalAdmin;
public interface IAdminElevationManager
{
bool IsAdminModeSupported { get; }
bool IsAdminInstanceRunning { get; }
Task<IRemoteConnection> CreateConnectionAsync();
string ProviderName { get; }
Task CreateAdminInstanceIfNecessaryAsync(string? confirmationMessage = null);
}

View File

@@ -0,0 +1,36 @@
using System.Diagnostics;
using FileTime.Providers.Remote;
using InitableService;
namespace FileTime.Providers.LocalAdmin;
public class AdminContentAccessorFactory : IAdminContentAccessorFactory
{
private readonly IAdminElevationManager _adminElevationManager;
private readonly IServiceProvider _serviceProvider;
public AdminContentAccessorFactory(
IAdminElevationManager adminElevationManager,
IServiceProvider serviceProvider
)
{
_adminElevationManager = adminElevationManager;
_serviceProvider = serviceProvider;
}
public bool IsAdminModeSupported => _adminElevationManager.IsAdminModeSupported;
public async Task<IRemoteItemCreator> CreateAdminItemCreatorAsync()
{
await _adminElevationManager.CreateAdminInstanceIfNecessaryAsync();
var connection = await _adminElevationManager.CreateConnectionAsync();
Debug.Assert(connection != null);
var adminItemCreator = _serviceProvider.GetInitableResolver(
connection,
_adminElevationManager.ProviderName)
.GetRequiredService<IRemoteItemCreator>();
return adminItemCreator;
}
}

View File

@@ -0,0 +1,30 @@
using FileTime.Core.ContentAccess;
using FileTime.Core.Enums;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
using FileTime.Providers.Remote;
namespace FileTime.Providers.LocalAdmin;
//TODO: this should be a RemoteContentProvider if there will be one
public class AdminContentProvider : RemoteContentProvider, IAdminContentProvider
{
public AdminContentProvider() : base("local", "localAdmin")
{
}
public override Task<IItem> GetItemByNativePathAsync(NativePath nativePath, PointInTime pointInTime, bool forceResolve = false, AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown, ItemInitializationSettings itemInitializationSettings = default)
=> throw new NotImplementedException();
public override NativePath GetNativePath(FullName fullName)
=> throw new NotImplementedException();
public override FullName GetFullName(NativePath nativePath)
=> throw new NotImplementedException();
public override Task<byte[]?> GetContentAsync(IElement element, int? maxLength = null, CancellationToken cancellationToken = default)
=> throw new NotImplementedException();
public override bool CanHandlePath(NativePath path)
=> throw new NotImplementedException();
}

View File

@@ -0,0 +1,197 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using FileTime.App.Core.Services;
using FileTime.Core.Interactions;
using FileTime.Providers.Local;
using FileTime.Server.Common;
using FileTime.Server.Common.Connections.SignalR;
using InitableService;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace FileTime.Providers.LocalAdmin;
public class AdminElevationManager : IAdminElevationManager, INotifyPropertyChanged, IExitHandler
{
private class ConnectionInfo
{
public string? SignalRBaseUrl { get; init; }
}
private readonly SemaphoreSlim _lock = new(1, 1);
private readonly IUserCommunicationService _dialogService;
private readonly ILogger<AdminElevationManager> _logger;
private readonly IOptionsMonitor<AdminElevationConfiguration> _configuration;
private readonly IServiceProvider _serviceProvider;
private ConnectionInfo? _connectionInfo;
private bool _isAdminInstanceRunning;
private Process? _adminProcess;
public bool IsAdminModeSupported => true;
private bool StartProcess => _configuration.CurrentValue.StartProcess ?? true;
public bool IsAdminInstanceRunning
{
get => _isAdminInstanceRunning;
private set => SetField(ref _isAdminInstanceRunning, value);
}
public string ProviderName => LocalContentProviderConstants.ContentProviderId;
public AdminElevationManager(
IUserCommunicationService dialogService,
ILogger<AdminElevationManager> logger,
IOptionsMonitor<AdminElevationConfiguration> configuration,
IServiceProvider serviceProvider
)
{
_dialogService = dialogService;
_logger = logger;
_configuration = configuration;
_serviceProvider = serviceProvider;
}
public async Task CreateAdminInstanceIfNecessaryAsync(string? confirmationMessage = null)
{
ArgumentNullException.ThrowIfNull(_configuration.CurrentValue.ServerExecutablePath, "ServerExecutablePath");
await _lock.WaitAsync();
try
{
if (IsAdminInstanceRunning) return;
confirmationMessage ??= "This operation requires admin privileges. Please confirm to continue.";
var confirmationResult = await _dialogService.ShowMessageBox(confirmationMessage);
if (confirmationResult == MessageBoxResult.Cancel) return;
var port = _configuration.CurrentValue.ServerPort;
_logger.LogTrace("Admin server port is {Port}", port is null ? "<not set>" : $"{port}");
if (StartProcess || port is null)
{
var portFileName = Path.GetTempFileName();
var process = new Process
{
StartInfo = new()
{
FileName = _configuration.CurrentValue.ServerExecutablePath,
ArgumentList =
{
"--PortWriter:FileName",
portFileName
},
UseShellExecute = true,
Verb = "runas"
},
EnableRaisingEvents = true
};
process.Exited += ProcessExitHandler;
process.Start();
_adminProcess = process;
IsAdminInstanceRunning = true;
//TODO: timeout
while (!File.Exists(portFileName) || new FileInfo(portFileName).Length == 0)
await Task.Delay(10);
var content = await File.ReadAllLinesAsync(portFileName);
if (int.TryParse(content.FirstOrDefault(), out var parsedPort))
{
port = parsedPort;
}
else
{
_logger.LogError(
"Could not parse port from content {Content}",
string.Join(Environment.NewLine, content)
);
}
}
var connectionInfo = new ConnectionInfo
{
SignalRBaseUrl = $"http://localhost:{port}/RemoteHub"
};
_connectionInfo = connectionInfo;
}
catch (Exception ex)
{
IsAdminInstanceRunning = false;
_logger.LogError(ex, "Error creating admin instance");
}
finally
{
_lock.Release();
}
}
public async Task<IRemoteConnection> CreateConnectionAsync()
{
ArgumentNullException.ThrowIfNull(_connectionInfo);
try
{
//TODO: use other connections too (if there will be any)
ArgumentNullException.ThrowIfNull(_connectionInfo.SignalRBaseUrl);
var connection = await _serviceProvider
.GetAsyncInitableResolver(_connectionInfo.SignalRBaseUrl)
.GetRequiredServiceAsync<SignalRConnection>();
return connection;
}
catch (Exception ex)
{
_logger.LogError(ex, "Error creating SignalR connection");
throw;
}
}
private void ProcessExitHandler(object? sender, EventArgs e)
{
_lock.Wait();
IsAdminInstanceRunning = false;
_lock.Release();
}
public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
private bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
public async Task ExitAsync()
{
if (!StartProcess)
{
_logger.LogTrace("Not stopping admin process as it was not started by this instance");
return;
}
if (!IsAdminInstanceRunning)
{
_logger.LogTrace("Not stopping admin process as it is not running");
return;
}
try
{
_logger.LogInformation("Stopping admin process");
var connection = await CreateConnectionAsync();
await connection.Exit();
_logger.LogInformation("Admin process stopped successfully");
}
catch(Exception ex)
{
_logger.LogError(ex, "Error stopping admin process, trying to kill it");
_adminProcess?.Kill();
}
}
}

View File

@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\FileTime.Core.ContentAccess\FileTime.Core.ContentAccess.csproj" />
<ProjectReference Include="..\..\Server\FileTime.Server.Common\FileTime.Server.Common.csproj" />
<ProjectReference Include="..\FileTime.Providers.Local.Abstractions\FileTime.Providers.Local.Abstractions.csproj" />
<ProjectReference Include="..\FileTime.Providers.LocalAdmin.Abstractions\FileTime.Providers.LocalAdmin.Abstractions.csproj" />
<ProjectReference Include="..\FileTime.Providers.Remote\FileTime.Providers.Remote.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Configuration.Abstractions">
<HintPath>..\..\..\..\..\Program Files\dotnet\shared\Microsoft.AspNetCore.App\7.0.9\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,20 @@
using FileTime.App.Core.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace FileTime.Providers.LocalAdmin;
public static class Startup
{
public static IServiceCollection AddLocalAdminProviderServices(this IServiceCollection services, IConfigurationRoot configuration)
{
services.AddOptions<AdminElevationConfiguration>().Bind(configuration.GetSection(AdminElevationConfiguration.SectionName));
services.TryAddSingleton<IAdminContentAccessorFactory, AdminContentAccessorFactory>();
services.TryAddSingleton<IAdminContentProvider, AdminContentProvider>();
services.TryAddSingleton<AdminElevationManager>();
services.TryAddSingleton<IAdminElevationManager>(sp => sp.GetRequiredService<AdminElevationManager>());
services.AddSingleton<IExitHandler>(sp => sp.GetRequiredService<AdminElevationManager>());
return services;
}
}

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileTime.Providers.Remote</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
<ProjectReference Include="..\..\Server\FileTime.Server.Common.Abstractions\FileTime.Server.Common.Abstractions.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,8 @@
using FileTime.Core.ContentAccess;
namespace FileTime.Providers.Remote;
public interface IRemoteContentProvider : IContentProvider
{
}

View File

@@ -0,0 +1,12 @@
using FileTime.Core.ContentAccess;
using FileTime.Server.Common;
using InitableService;
namespace FileTime.Providers.Remote;
public interface IRemoteItemCreator :
IItemCreator<IRemoteContentProvider>,
IInitable<IRemoteConnection, string>
{
}

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
<ProjectReference Include="..\..\Core\FileTime.Core.ContentAccess\FileTime.Core.ContentAccess.csproj" />
<ProjectReference Include="..\FileTime.Providers.Remote.Abstractions\FileTime.Providers.Remote.Abstractions.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,24 @@
using FileTime.Core.ContentAccess;
using FileTime.Core.Enums;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
namespace FileTime.Providers.Remote;
public class RemoteContentProvider : ContentProviderBase, IRemoteContentProvider
{
public RemoteContentProvider(string remoteName, string name = "remote") : base(name)
{
}
//TODO implement
public override Task<IItem> GetItemByNativePathAsync(NativePath nativePath, PointInTime pointInTime, bool forceResolve = false, AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown, ItemInitializationSettings itemInitializationSettings = default) => throw new NotImplementedException();
public override NativePath GetNativePath(FullName fullName) => throw new NotImplementedException();
public override FullName GetFullName(NativePath nativePath) => throw new NotImplementedException();
public override Task<byte[]?> GetContentAsync(IElement element, int? maxLength = null, CancellationToken cancellationToken = default) => throw new NotImplementedException();
public override bool CanHandlePath(NativePath path) => throw new NotImplementedException();
}

View File

@@ -0,0 +1,24 @@
using FileTime.Core.ContentAccess;
using FileTime.Core.Models;
using FileTime.Server.Common;
namespace FileTime.Providers.Remote;
public class RemoteItemCreator :
ItemCreatorBase<IRemoteContentProvider>,
IRemoteItemCreator
{
private IRemoteConnection _remoteConnection = null!;
private string _remoteContentProviderId = null!;
public void Init(IRemoteConnection remoteConnection, string remoteContentProviderId)
{
_remoteConnection = remoteConnection;
_remoteContentProviderId = remoteContentProviderId;
}
public override async Task CreateContainerAsync(IRemoteContentProvider contentProvider, FullName fullName)
=> await _remoteConnection.CreateContainerAsync(_remoteContentProviderId, fullName);
public override async Task CreateElementAsync(IRemoteContentProvider contentProvider, FullName fullName)
=> await _remoteConnection.CreateElementAsync(_remoteContentProviderId, fullName);
}

View File

@@ -0,0 +1,16 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace FileTime.Providers.Remote;
public static class Startup
{
public static IServiceCollection AddRemoteProviderServices(this IServiceCollection serviceCollection)
{
serviceCollection.TryAddSingleton<IRemoteContentProvider, RemoteContentProvider>();
serviceCollection.TryAddTransient<IRemoteItemCreator, RemoteItemCreator>();
return serviceCollection;
}
}