Skip to content

Commit

Permalink
fix: overview table will check all instance everytime now, to make su…
Browse files Browse the repository at this point in the history
…re no instances are lost
  • Loading branch information
Jasper De Keukelaere (imec) authored and Jasper De Keukelaere (imec) committed Oct 10, 2024
1 parent e9bd549 commit 48299e7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
1 change: 1 addition & 0 deletions PLCsimAdvanced_Manager/Pages/PlcOverview.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public partial class PlcOverview

protected override void OnInitialized()
{
managerFacade.InstanceHandler.UpdateExistingInstances();
managerFacade.InstanceHandler.OnInstanceChanged += OnInstanceChanged;
managerFacade.InstanceHandler.OnIssue += OnIssue;
base.OnInitialized();
Expand Down
5 changes: 4 additions & 1 deletion PLCsimAdvanced_Manager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@
builder.Services.AddSingleton<InstanceLogger>();
builder.Services.AddSingleton<InstanceHandler>();
builder.Services.AddSingleton<EventDispatchService>();
builder.Services.AddSingleton<ManagerFacade>();
builder.Services.AddSingleton<PersistenceHandler>();

//hosted services
builder.Services.AddSingleton<ManagerFacade>();
builder.Services.AddHostedService(sp => sp.GetRequiredService<ManagerFacade>()); // TODO -> split hosted services and singleton part

var app = builder.Build();
app.Services.GetService<EventDispatchService>();

Expand Down
22 changes: 22 additions & 0 deletions PLCsimAdvanced_Manager/Services/InstanceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,31 @@ private void GetExistingInstances()
OnIssue?.Invoke(this, e);
}
}

public void UpdateExistingInstances()
{
try
{
foreach (var instanceInfo in SimulationRuntimeManager.RegisteredInstanceInfo)
{
// Check if the instance already exists
if (_instances.Any(instance => instance.ID == instanceInfo.ID))
{
// Instance already exists, no need to add it again
continue;
}
InstanceRegisteredCallback(instanceInfo.ID);
}
}
catch (Exception e)
{
OnIssue?.Invoke(this, e);
}
}

public void InstanceRegisteredCallback(int id)
{

var instance = SimulationRuntimeManager.CreateInterface(id);
_instances.Add(instance);
OnInstanceChanged?.Invoke(this, new InstanceChangedEventArgs($"Instance {instance.Name} registered"));
Expand Down
23 changes: 18 additions & 5 deletions PLCsimAdvanced_Manager/Services/ManagerFacade.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
namespace PLCsimAdvanced_Manager.Services;

public class ManagerFacade
public class ManagerFacade: IHostedService, IDisposable
{
private readonly EventDispatchService _eventDispatchService;
public readonly InstanceHandler InstanceHandler;
private EventDispatchService _eventDispatchService;
public InstanceHandler InstanceHandler;

public ManagerFacade()


public Task StartAsync(CancellationToken cancellationToken)
{
this.InstanceHandler = new InstanceHandler();
this._eventDispatchService = new EventDispatchService(this.InstanceHandler);
this._eventDispatchService = new EventDispatchService(this.InstanceHandler);
return Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public void Dispose()
{
// throw new NotImplementedException();
}
}

0 comments on commit 48299e7

Please sign in to comment.