Skip to content

Commit

Permalink
Merge pull request #50 from Luthetus/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Luthetus authored Sep 2, 2023
2 parents 85bbe83 + 9f0909c commit c6e3804
Show file tree
Hide file tree
Showing 42 changed files with 310 additions and 493 deletions.
4 changes: 1 addition & 3 deletions Docs/Notes/2023-08_Ide.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
2023-08-15 | Luthetus.Ide | Notes

This file is ordered with the most recent date as the first entry.
2023-08 | Luthetus.Ide | Notes

---

Expand Down
20 changes: 20 additions & 0 deletions Docs/Notes/2023-09_Ide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
2023-09 | Luthetus.Ide | Notes

---

## 2023-09-02

### .NET sln
.NET sln needs to be an immutable type
which is accessed through a `DotNetSolutionKey`.

All modifications to a .NET sln need be done via the `DotNetSolutionReducer`.

One can view the current state of a `DotNetSolution` by looking up into the `DotNetSolutionCollection` using a `DotNetSolutionKey`.

### Background Tasks
The current implementation of IBackgroundTaskQueue for the WASM host is incorrect.

I realized that each enqueue'd task was being invoked immediately, even if a prior task was still running.

This logic needs to be fixed, I think I've seen some oddities going on in the WASM app, and this might explain a few of them.
48 changes: 24 additions & 24 deletions Source/Host/Luthetus.Ide.Photino/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
using Luthetus.Ide.ClassLib.HostedServiceCase.FileSystem;
using Luthetus.Ide.ClassLib.HostedServiceCase.Terminal;
using Luthetus.Ide.RazorLib;
using Luthetus.TextEditor.RazorLib;
using Luthetus.TextEditor.RazorLib.HostedServiceCase.CompilerServiceCase;
using Luthetus.TextEditor.RazorLib.HostedServiceCase.TextEditorCase;
using Microsoft.Extensions.DependencyInjection;
using Photino.Blazor;
using System;
using System.Reflection.PortableExecutable;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -19,41 +21,24 @@ static void Main(string[] args)
{
var appBuilder = PhotinoBlazorAppBuilder.CreateDefault(args);

appBuilder.Services
.AddLogging();
appBuilder.Services.AddLogging();

appBuilder.Services.AddLuthetusIdeRazorLibServices(true);
appBuilder.Services.AddLuthetusIdeRazorLibServices(options => options with
{
IsNativeApplication = true,
});

// The code:
// builder.Services.AddHostedService<QueuedHostedService>();
//
// is not working for the Photino Blazor app.
// So manual starting of the service is done.
appBuilder.Services.AddSingleton<CommonQueuedHostedService>();
appBuilder.Services.AddSingleton<TextEditorQueuedHostedService>();
appBuilder.Services.AddSingleton<CompilerServiceQueuedHostedService>();
appBuilder.Services.AddSingleton<FileSystemQueuedHostedService>();
appBuilder.Services.AddSingleton<TerminalQueuedHostedService>();
appBuilder.Services.AddLuthetusIdePhotino();

appBuilder.RootComponents.Add<App>("app");

var app = appBuilder.Build();

var backgroundTasksCancellationTokenSource = new CancellationTokenSource();

var commonQueuedHostedService = app.Services.GetRequiredService<CommonQueuedHostedService>();
var textEditorQueuedHostedService = app.Services.GetRequiredService<TextEditorQueuedHostedService>();
var compilerServiceQueuedHostedService = app.Services.GetRequiredService<CompilerServiceQueuedHostedService>();
var fileSystemQueuedHostedService = app.Services.GetRequiredService<FileSystemQueuedHostedService>();
var terminalQueuedHostedService = app.Services.GetRequiredService<TerminalQueuedHostedService>();

var cancellationToken = backgroundTasksCancellationTokenSource.Token;

_ = Task.Run(async () => await commonQueuedHostedService.StartAsync(cancellationToken));
_ = Task.Run(async () => await textEditorQueuedHostedService.StartAsync(cancellationToken));
_ = Task.Run(async () => await compilerServiceQueuedHostedService.StartAsync(cancellationToken));
_ = Task.Run(async () => await fileSystemQueuedHostedService.StartAsync(cancellationToken));
_ = Task.Run(async () => await terminalQueuedHostedService.StartAsync(cancellationToken));
InvokeWorkers(app.Services, cancellationToken);

// customize window
app.MainWindow
Expand All @@ -74,4 +59,19 @@ static void Main(string[] args)

app.Run();
}

private static void InvokeWorkers(IServiceProvider serviceProvider, CancellationToken cancellationToken)
{
var commonQueuedHostedService = serviceProvider.GetRequiredService<LuthetusCommonBackgroundTaskServiceWorker>();
var textEditorQueuedHostedService = serviceProvider.GetRequiredService<LuthetusTextEditorTextEditorBackgroundTaskServiceWorker>();
var compilerServiceQueuedHostedService = serviceProvider.GetRequiredService<LuthetusTextEditorCompilerServiceBackgroundTaskServiceWorker>();
var fileSystemQueuedHostedService = serviceProvider.GetRequiredService<LuthetusIdeFileSystemBackgroundTaskServiceWorker>();
var terminalQueuedHostedService = serviceProvider.GetRequiredService<LuthetusIdeTerminalBackgroundTaskServiceWorker>();

_ = Task.Run(async () => await commonQueuedHostedService.StartAsync(cancellationToken));
_ = Task.Run(async () => await textEditorQueuedHostedService.StartAsync(cancellationToken));
_ = Task.Run(async () => await compilerServiceQueuedHostedService.StartAsync(cancellationToken));
_ = Task.Run(async () => await fileSystemQueuedHostedService.StartAsync(cancellationToken));
_ = Task.Run(async () => await terminalQueuedHostedService.StartAsync(cancellationToken));
}
}
27 changes: 27 additions & 0 deletions Source/Host/Luthetus.Ide.Photino/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Luthetus.Common.RazorLib.BackgroundTaskCase.Usage;
using Luthetus.Ide.ClassLib.HostedServiceCase.FileSystem;
using Luthetus.Ide.ClassLib.HostedServiceCase.Terminal;
using Luthetus.TextEditor.RazorLib.HostedServiceCase.CompilerServiceCase;
using Luthetus.TextEditor.RazorLib.HostedServiceCase.TextEditorCase;
using Microsoft.Extensions.DependencyInjection;

namespace Luthetus.TextEditor.RazorLib;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddLuthetusIdePhotino(
this IServiceCollection services)
{
// The code:
// builder.Services.AddHostedService<QueuedHostedService>();
//
// is not working for the Photino Blazor app.
// So manual starting of the service is done.
return services
.AddSingleton<LuthetusCommonBackgroundTaskServiceWorker>()
.AddSingleton<LuthetusTextEditorTextEditorBackgroundTaskServiceWorker>()
.AddSingleton<LuthetusTextEditorCompilerServiceBackgroundTaskServiceWorker>()
.AddSingleton<LuthetusIdeFileSystemBackgroundTaskServiceWorker>()
.AddSingleton<LuthetusIdeTerminalBackgroundTaskServiceWorker>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ public interface ILuthetusIdeComponentRenderers
public Type? GitDisplayRendererType { get; }
public Type? RemoveCSharpProjectFromSolutionRendererType { get; }
public Type? InputFileRendererType { get; }
public Type? CompilerServiceBackgroundTaskDisplayRendererType { get; }
public Type? FileSystemBackgroundTaskDisplayRendererType { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public LuthetusIdeComponentRenderers(
Type? gitDisplayRendererType,
Type? removeCSharpProjectFromSolutionRendererType,
Type? inputFileRendererType,
Type? compilerServiceBackgroundTaskDisplayRendererType,
Type? fileSystemBackgroundTaskDisplayRendererType,
Type? treeViewCSharpProjectDependenciesRendererType,
Type? treeViewCSharpProjectNugetPackageReferencesRendererType,
Type? treeViewCSharpProjectToProjectReferencesRendererType,
Expand All @@ -32,8 +30,6 @@ public LuthetusIdeComponentRenderers(
GitDisplayRendererType = gitDisplayRendererType;
RemoveCSharpProjectFromSolutionRendererType = removeCSharpProjectFromSolutionRendererType;
InputFileRendererType = inputFileRendererType;
CompilerServiceBackgroundTaskDisplayRendererType = compilerServiceBackgroundTaskDisplayRendererType;
FileSystemBackgroundTaskDisplayRendererType = fileSystemBackgroundTaskDisplayRendererType;
TreeViewCSharpProjectDependenciesRendererType = treeViewCSharpProjectDependenciesRendererType;
TreeViewCSharpProjectNugetPackageReferencesRendererType = treeViewCSharpProjectNugetPackageReferencesRendererType;
TreeViewCSharpProjectToProjectReferencesRendererType = treeViewCSharpProjectToProjectReferencesRendererType;
Expand All @@ -58,6 +54,4 @@ public LuthetusIdeComponentRenderers(
public Type? GitDisplayRendererType { get; }
public Type? RemoveCSharpProjectFromSolutionRendererType { get; }
public Type? InputFileRendererType { get; }
public Type? CompilerServiceBackgroundTaskDisplayRendererType { get; }
public Type? FileSystemBackgroundTaskDisplayRendererType { get; }
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Luthetus.Ide.ClassLib.HostedServiceCase.FileSystem;

public interface IFileSystemBackgroundTaskMonitor : IBackgroundTaskMonitor
public interface ILuthetusIdeFileSystemBackgroundTaskService : IBackgroundTaskService
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

namespace Luthetus.Ide.ClassLib.HostedServiceCase.FileSystem;

public class FileSystemBackgroundTaskQueue : IFileSystemBackgroundTaskQueue
public class LuthetusIdeFileSystemBackgroundTaskService : ILuthetusIdeFileSystemBackgroundTaskService
{
private readonly ConcurrentQueue<IBackgroundTask> _backgroundTasks = new();
private readonly SemaphoreSlim _workItemsQueueSemaphoreSlim = new(0);

public event Action? ExecutingBackgroundTaskChanged;

public IBackgroundTask? ExecutingBackgroundTask { get; private set; }

public void QueueBackgroundWorkItem(
IBackgroundTask backgroundTask)
{
Expand All @@ -34,4 +38,10 @@ public void QueueBackgroundWorkItem(

return backgroundTask;
}
}

public void SetExecutingBackgroundTask(IBackgroundTask? backgroundTask)
{
ExecutingBackgroundTask = backgroundTask;
ExecutingBackgroundTaskChanged?.Invoke();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,22 @@

namespace Luthetus.Ide.ClassLib.HostedServiceCase.FileSystem;

public class FileSystemQueuedHostedService : BackgroundService
public class LuthetusIdeFileSystemBackgroundTaskServiceWorker : BackgroundService
{
private readonly ILuthetusCommonComponentRenderers _luthetusCommonComponentRenderers;
private readonly ILogger _logger;

public FileSystemQueuedHostedService(
IFileSystemBackgroundTaskQueue taskQueue,
IFileSystemBackgroundTaskMonitor taskMonitor,
public LuthetusIdeFileSystemBackgroundTaskServiceWorker(
ILuthetusIdeFileSystemBackgroundTaskService backgroundTaskService,
ILuthetusCommonComponentRenderers luthetusCommonComponentRenderers,
ILoggerFactory loggerFactory)
{
_luthetusCommonComponentRenderers = luthetusCommonComponentRenderers;
TaskQueue = taskQueue;
TaskMonitor = taskMonitor;
_logger = loggerFactory.CreateLogger<FileSystemQueuedHostedService>();
BackgroundTaskService = backgroundTaskService;
_logger = loggerFactory.CreateLogger<LuthetusIdeFileSystemBackgroundTaskServiceWorker>();
}

public IBackgroundTaskQueue TaskQueue { get; }
public IBackgroundTaskMonitor TaskMonitor { get; }
public IBackgroundTaskService BackgroundTaskService { get; }

protected async override Task ExecuteAsync(
CancellationToken cancellationToken)
Expand All @@ -35,14 +32,14 @@ protected async override Task ExecuteAsync(

while (!cancellationToken.IsCancellationRequested)
{
var backgroundTask = await TaskQueue
var backgroundTask = await BackgroundTaskService
.DequeueAsync(cancellationToken);

if (backgroundTask is not null)
{
try
{
TaskMonitor.SetExecutingBackgroundTask(backgroundTask);
BackgroundTaskService.SetExecutingBackgroundTask(backgroundTask);

var task = backgroundTask.InvokeWorkItem(cancellationToken);
}
Expand Down Expand Up @@ -81,7 +78,7 @@ protected async override Task ExecuteAsync(
}
finally
{
TaskMonitor.SetExecutingBackgroundTask(null);
BackgroundTaskService.SetExecutingBackgroundTask(null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Luthetus.Ide.ClassLib.HostedServiceCase.Terminal;

public interface ITerminalBackgroundTaskMonitor : IBackgroundTaskMonitor
public interface ILuthetusIdeTerminalBackgroundTaskService : IBackgroundTaskService
{

}

This file was deleted.

Loading

0 comments on commit c6e3804

Please sign in to comment.