Skip to content

Commit

Permalink
Merge pull request #18745 from unoplatform/dev/dr/devSrvAddIns2
Browse files Browse the repository at this point in the history
fix: Fix the discovered processor list additive
  • Loading branch information
jeromelaban authored Nov 9, 2024
2 parents 86a5972 + 1071846 commit 48bd5c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Uno.UI.RemoteControl.Host/RemoteControlServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal class RemoteControlServer : IRemoteControlServer, IDisposable
private static readonly Dictionary<string, (AssemblyLoadContext Context, int Count)> _loadContexts = new();
private static readonly Dictionary<string, string> _resolveAssemblyLocations = new();
private readonly Dictionary<string, IServerProcessor> _processors = new();
private readonly List<DiscoveredProcessor> _discoveredProcessors = new();
private readonly CancellationTokenSource _ct = new();

private WebSocket? _socket;
Expand Down Expand Up @@ -257,7 +258,6 @@ private async Task ProcessPingFrame(Frame frame)
private async Task ProcessDiscoveryFrame(Frame frame)
{
var assemblies = new List<(string path, System.Reflection.Assembly assembly)>();
var discoveredProcessors = new List<DiscoveredProcessor>();
try
{
var msg = JsonConvert.DeserializeObject<ProcessorsDiscovery>(frame.Content)!;
Expand Down Expand Up @@ -358,12 +358,12 @@ private async Task ProcessDiscoveryFrame(Frame frame)
{
if (ActivatorUtilities.CreateInstance(_serviceProvider, processor.ProcessorType, parameters: new[] { this }) is IServerProcessor serverProcessor)
{
discoveredProcessors.Add(new(asm.path, processor.ProcessorType.FullName!, VersionHelper.GetVersion(processor.ProcessorType), IsLoaded: true));
_discoveredProcessors.Add(new(asm.path, processor.ProcessorType.FullName!, VersionHelper.GetVersion(processor.ProcessorType), IsLoaded: true));
RegisterProcessor(serverProcessor);
}
else
{
discoveredProcessors.Add(new(asm.path, processor.ProcessorType.FullName!, VersionHelper.GetVersion(processor.ProcessorType), IsLoaded: false));
_discoveredProcessors.Add(new(asm.path, processor.ProcessorType.FullName!, VersionHelper.GetVersion(processor.ProcessorType), IsLoaded: false));
if (this.Log().IsEnabled(LogLevel.Debug))
{
this.Log().LogDebug("Failed to create server processor {ProcessorType}", processor.ProcessorType);
Expand All @@ -372,7 +372,7 @@ private async Task ProcessDiscoveryFrame(Frame frame)
}
catch (Exception error)
{
discoveredProcessors.Add(new(asm.path, processor.ProcessorType.FullName!, VersionHelper.GetVersion(processor.ProcessorType), IsLoaded: false, LoadError: error.ToString()));
_discoveredProcessors.Add(new(asm.path, processor.ProcessorType.FullName!, VersionHelper.GetVersion(processor.ProcessorType), IsLoaded: false, LoadError: error.ToString()));
if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().LogError(error, "Failed to create server processor {ProcessorType}", processor.ProcessorType);
Expand Down Expand Up @@ -404,7 +404,7 @@ private async Task ProcessDiscoveryFrame(Frame frame)
{
await SendFrame(new ProcessorsDiscoveryResponse(
assemblies.Select(asm => asm.path).ToImmutableList(),
discoveredProcessors.ToImmutableList()));
_discoveredProcessors.ToImmutableList()));
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/Uno.UI.RemoteControl/RemoteControlClient.Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,19 @@ public void ReportServerProcessors(ProcessorsDiscoveryResponse response)

static IEnumerable<MissingProcessor> GetMissingServerProcessors(ImmutableHashSet<ProcessorInfo> requiredProcessors, ProcessorsDiscoveryResponse response)
{
var loaded = response.Processors.ToDictionary(p => p.Type, StringComparer.OrdinalIgnoreCase);
var loaded = response
.Processors
.GroupBy(p => p.Type, StringComparer.OrdinalIgnoreCase)
// If a processors is being loaded multiple times, we prefer to keep the result that has no error.
.Select(g => g
.OrderBy(p => p switch
{
{ LoadError: not null } => 0,
{ IsLoaded: false } => 1,
_ => 2
})
.Last())
.ToDictionary(p => p.Type, StringComparer.OrdinalIgnoreCase);
foreach (var required in requiredProcessors)
{
if (!loaded.TryGetValue(required.TypeFullName, out var actual))
Expand Down

0 comments on commit 48bd5c6

Please sign in to comment.