This commit is contained in:
2022-06-09 08:27:51 +02:00
parent 6d9bf7ab32
commit 94e71954ee
21 changed files with 135 additions and 52 deletions

View File

@@ -1,19 +1,23 @@
using System.Reactive.Linq;
using System.Reactive.Subjects;
using DynamicData;
using FileTime.Core.Command;
using Microsoft.Extensions.DependencyInjection;
using FileTime.Core.Models;
namespace FileTime.Core.Timeline;
public class CommandScheduler : ICommandScheduler
{
private readonly IServiceProvider _serviceProvider;
private readonly SourceList<ParallelCommands> _commandsToRun = new();
private readonly List<ICommandExecutor> _commandExecutors = new();
private readonly Subject<FullName> _containerToRefresh = new();
private readonly object _guard = new();
private bool _enableRunning = true;
private bool _resourceIsInUse;
public IObservable<FullName> ContainerToRefresh { get; }
public bool EnableRunning
{
get
@@ -26,10 +30,10 @@ public class CommandScheduler : ICommandScheduler
set { RunWithLock(() => _enableRunning = value); }
}
public CommandScheduler(IServiceProvider serviceProvider)
public CommandScheduler(ILocalCommandExecutor localExecutor)
{
_serviceProvider = serviceProvider;
var localExecutor = serviceProvider.GetRequiredService<ILocalCommandExecutor>();
ContainerToRefresh = _containerToRefresh.AsObservable();
localExecutor.CommandFinished += LocalExecutorOnCommandFinished;
_commandExecutors.Add(localExecutor);
}
@@ -74,6 +78,8 @@ public class CommandScheduler : ICommandScheduler
});
}
public void RefreshContainer(FullName container) => _containerToRefresh.OnNext(container);
private void ExecuteCommands()
{
if (!_enableRunning) return;