diff --git a/examples/fdc3-chart-and-grid/js-chart/chart.js b/examples/fdc3-chart-and-grid/js-chart/chart.js index 4a086af95..fa9c8cd66 100644 --- a/examples/fdc3-chart-and-grid/js-chart/chart.js +++ b/examples/fdc3-chart-and-grid/js-chart/chart.js @@ -12,14 +12,11 @@ let currentChannel; NoDataToDisplay(Highcharts); -window.addEventListener('load', function() { +window.addEventListener('fdc3Ready', async() => { chart = Highcharts.chart('container', { chart: { type: 'column', - events: { - load: requestData - } }, title: { text: 'Monthly Sales Data' @@ -43,6 +40,8 @@ window.addEventListener('load', function() { data: [] }] }); + + await requestData(); }); window.addEventListener('close', async function(){ diff --git a/examples/fdc3-chart-and-grid/js-datagrid/src/app/main-view/services/mock-data.service.ts b/examples/fdc3-chart-and-grid/js-datagrid/src/app/main-view/services/mock-data.service.ts index 8c31996ae..4ae360f9c 100644 --- a/examples/fdc3-chart-and-grid/js-datagrid/src/app/main-view/services/mock-data.service.ts +++ b/examples/fdc3-chart-and-grid/js-datagrid/src/app/main-view/services/mock-data.service.ts @@ -20,12 +20,15 @@ export class MockDataService{ constructor(){ this.market = new Market(); - this.connecting = new Promise(async(resolve, reject) => { - try{ - resolve(await this.checkFdc3Connection()); - } catch(err) { - reject(err); - }; + + window.addEventListener('fdc3Ready', () => { + this.connecting = new Promise(async(resolve, reject) => { + try{ + resolve(await this.checkFdc3Connection()); + } catch(err) { + reject(err); + }; + }); }); interval(1000).subscribe(() => { diff --git a/examples/fdc3-pricing-and-chat/js-chat/chat.js b/examples/fdc3-pricing-and-chat/js-chat/chat.js index a6331b350..d539ecf91 100644 --- a/examples/fdc3-pricing-and-chat/js-chat/chat.js +++ b/examples/fdc3-pricing-and-chat/js-chat/chat.js @@ -91,7 +91,7 @@ window.app = function () { } }(); -window.addEventListener('load', async function () { +window.addEventListener('fdc3Ready', async function () { intentListener = await window.fdc3.addIntentListener("StartChat", window.app.handleChatIntent); await window.fdc3.joinUserChannel("fdc3.channel.1"); diff --git a/examples/fdc3-pricing-and-chat/js-pricing/pricing.js b/examples/fdc3-pricing-and-chat/js-pricing/pricing.js index ea2f40d38..69dd257df 100644 --- a/examples/fdc3-pricing-and-chat/js-pricing/pricing.js +++ b/examples/fdc3-pricing-and-chat/js-pricing/pricing.js @@ -14,7 +14,7 @@ import "bootstrap/dist/css/bootstrap.css"; -window.addEventListener('load', async function () { +window.addEventListener('fdc3Ready', async function () { const pricingForm = document.querySelector("#pricing"); await this.window.fdc3.joinUserChannel("fdc3.channel.1"); pricingForm.addEventListener('submit', app.submitPrice); diff --git a/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/DependencyInjection/ServiceCollectionExtensions.cs b/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/DependencyInjection/ServiceCollectionExtensions.cs index 9be52d896..2a6fa60dd 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/DependencyInjection/ServiceCollectionExtensions.cs @@ -13,10 +13,7 @@ */ using MorganStanley.ComposeUI.Fdc3.DesktopAgent; -using MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Infrastructure.Internal; -using MorganStanley.ComposeUI.Messaging; -using MorganStanley.ComposeUI.Messaging.Abstractions; using MorganStanley.ComposeUI.ModuleLoader; using MorganStanley.ComposeUI.Shell.Fdc3; @@ -35,6 +32,8 @@ public static IServiceCollection AddFdc3DesktopAgent( builderAction(builder); } + + serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddTransient(); diff --git a/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3DesktopAgent.cs b/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3DesktopAgent.cs index 77d467c87..995471b92 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3DesktopAgent.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3DesktopAgent.cs @@ -35,17 +35,9 @@ using Screenshot = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.Screenshot; using AppChannel = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Channels.AppChannel; using MorganStanley.ComposeUI.Messaging; -using System.Text.Json; -using System.IO.Abstractions; -using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Converters; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol; -using System.Text.Json.Serialization; -using DisplayMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.DisplayMetadata; using ImplementationMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.ImplementationMetadata; using Constants = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Infrastructure.Internal.Constants; -using FileSystem = System.IO.Abstractions.FileSystem; -using System.Reflection; -using System; namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent; @@ -53,6 +45,7 @@ internal class Fdc3DesktopAgent : IFdc3DesktopAgentBridge { private readonly ILogger _logger; private readonly IResolverUICommunicator _resolverUI; + private readonly IUserChannelSetReader _userChannelSetReader; private readonly ConcurrentDictionary _userChannels = new(); private readonly ConcurrentDictionary _privateChannels = new(); private readonly ConcurrentDictionary _appChannels = new(); @@ -64,27 +57,20 @@ internal class Fdc3DesktopAgent : IFdc3DesktopAgentBridge private readonly ConcurrentDictionary _raisedIntentResolutions = new(); private readonly ConcurrentDictionary> _pendingStartRequests = new(); private IAsyncDisposable? _subscription; - private readonly IFileSystem _fileSystem; - private readonly HttpClient _httpClient = new(); - private ConcurrentDictionary? _userChannelSet; - private readonly JsonSerializerOptions _jsonSerializerOptions = new(JsonSerializerDefaults.Web) - { - Converters = { new DisplayMetadataJsonConverter(), new JsonStringEnumConverter() } - }; public Fdc3DesktopAgent( IAppDirectory appDirectory, IModuleLoader moduleLoader, IOptions options, IResolverUICommunicator resolverUI, - IFileSystem? fileSystem = null, + IUserChannelSetReader userChannelSetReader, ILoggerFactory? loggerFactory = null) { _appDirectory = appDirectory; _moduleLoader = moduleLoader; _options = options.Value; _resolverUI = resolverUI; - _fileSystem = fileSystem ?? new FileSystem(); + _userChannelSetReader = userChannelSetReader; _loggerFactory = loggerFactory ?? NullLoggerFactory.Instance; _logger = _loggerFactory.CreateLogger() ?? NullLogger.Instance; } @@ -92,7 +78,9 @@ public Fdc3DesktopAgent( public async ValueTask AddUserChannel(Func addUserChannelFactory, string channelId) { ChannelItem? channelItem = null; - if (_userChannelSet != null && !_userChannelSet.TryGetValue(channelId, out channelItem) || channelItem == null) + var userChannelSet = await _userChannelSetReader.GetUserChannelSet(); + + if (!userChannelSet.TryGetValue(channelId, out channelItem) || channelItem == null) { return null; } @@ -217,7 +205,6 @@ public async Task StartAsync(CancellationToken cancellationToken) }); _subscription = subscription; - _userChannelSet = await ReadUserChannelSet(cancellationToken); } public async Task StopAsync(CancellationToken cancellationToken) @@ -245,7 +232,6 @@ public async Task StopAsync(CancellationToken cancellationToken) _userChannels.Clear(); _privateChannels.Clear(); _appChannels.Clear(); - _httpClient.Dispose(); } public bool FindChannel(string channelId, ChannelType channelType) @@ -506,30 +492,30 @@ public async ValueTask> AddIntentListe }; } - public ValueTask GetUserChannels(GetUserChannelsRequest? request) + public async ValueTask GetUserChannels(GetUserChannelsRequest? request) { if (request == null) { - return ValueTask.FromResult(GetUserChannelsResponse.Failure(Fdc3DesktopAgentErrors.PayloadNull)); + return GetUserChannelsResponse.Failure(Fdc3DesktopAgentErrors.PayloadNull); } if (!Guid.TryParse(request.InstanceId, out var instanceId)) { - return ValueTask.FromResult(GetUserChannelsResponse.Failure(Fdc3DesktopAgentErrors.MissingId)); + return GetUserChannelsResponse.Failure(Fdc3DesktopAgentErrors.MissingId); } if (!_runningModules.TryGetValue(instanceId, out _)) { - return ValueTask.FromResult(GetUserChannelsResponse.Failure(ChannelError.AccessDenied)); + return GetUserChannelsResponse.Failure(ChannelError.AccessDenied); } - var result = _userChannelSet?.Values; + var result = (await _userChannelSetReader.GetUserChannelSet()).Values; if (result == null) { - return ValueTask.FromResult(GetUserChannelsResponse.Failure(Fdc3DesktopAgentErrors.NoUserChannelSetFound)); + return GetUserChannelsResponse.Failure(Fdc3DesktopAgentErrors.NoUserChannelSetFound); } - return ValueTask.FromResult(GetUserChannelsResponse.Success(result)); + return GetUserChannelsResponse.Success(result); } public async ValueTask JoinUserChannel(Func addUserChannelFactory, JoinUserChannelRequest request) @@ -539,8 +525,9 @@ public ValueTask GetUserChannels(GetUserChannelsRequest return JoinUserChannelResponse.Failed(Fdc3DesktopAgentErrors.MissingId); } + var userChannelSet = await _userChannelSetReader.GetUserChannelSet(); ChannelItem? channelItem = null; - if (_userChannelSet != null && !_userChannelSet.TryGetValue(request.ChannelId, out channelItem)) + if (!userChannelSet.TryGetValue(request.ChannelId, out channelItem)) { return JoinUserChannelResponse.Failed(ChannelError.NoChannelFound); } @@ -1224,55 +1211,6 @@ private AppMetadata GetAppMetadata(Fdc3App app, string? instanceId, IntentMetada }; } - private async Task?> ReadUserChannelSet(CancellationToken cancellationToken = default) - { - var uri = _options.UserChannelConfigFile; - IEnumerable? userChannelSet = null; - - if (uri == null && _options.UserChannelConfig == null) - { - var assembly = Assembly.GetExecutingAssembly(); - using var stream = assembly.GetManifestResourceStream(ResourceNames.DefaultUserChannelSet); - if (stream == null) - { - return null; - } - - using var streamReader = new StreamReader(stream); - - var result = streamReader.ReadToEnd(); - userChannelSet = JsonSerializer.Deserialize(result, _jsonSerializerOptions); - } - else if (_options.UserChannelConfig != null) - { - userChannelSet = _options.UserChannelConfig; - } - else if (uri != null) - { - if (uri.IsFile) - { - var path = uri.IsAbsoluteUri ? uri.AbsolutePath : Path.GetFullPath(uri.ToString()); - - if (!_fileSystem.File.Exists(path)) - { - _logger.LogError($"{Fdc3DesktopAgentErrors.NoUserChannelSetFound}, no user channel set was configured."); - return null; - } - - await using var stream = _fileSystem.File.OpenRead(path); - userChannelSet = JsonSerializer.Deserialize(stream, _jsonSerializerOptions); - } - else if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps) - { - var response = await _httpClient.GetAsync(uri, cancellationToken); - await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken); - userChannelSet = JsonSerializer.Deserialize(stream, _jsonSerializerOptions); - } - } - - return new((userChannelSet ?? Array.Empty()).ToDictionary(x => x.Id, y => y)); - } - private Task RemoveModuleAsync(IModuleInstance instance) { if (!IsFdc3StartedModule(instance, out var fdc3InstanceId)) diff --git a/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3StartupAction.cs b/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3StartupAction.cs index 5c0a55871..c4e7e4e29 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3StartupAction.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3StartupAction.cs @@ -18,21 +18,25 @@ using ResourceReader = MorganStanley.ComposeUI.Utilities.ResourceReader; using Microsoft.Extensions.Options; using MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection; +using System.Text; namespace MorganStanley.ComposeUI.Shell.Fdc3; internal sealed class Fdc3StartupAction : IStartupAction { private readonly IAppDirectory _appDirectory; + private readonly IUserChannelSetReader _userChannelSetReader; private readonly Fdc3DesktopAgentOptions _options; private readonly ILogger _logger; public Fdc3StartupAction( IAppDirectory appDirectory, + IUserChannelSetReader userChannelSetReader, IOptions options, ILogger? logger = null) { _appDirectory = appDirectory; + _userChannelSetReader = userChannelSetReader; _options = options.Value; _logger = logger ?? NullLogger.Instance; } @@ -45,29 +49,60 @@ public async Task InvokeAsync(StartupContext startupContext, Func next) try { var appId = (await _appDirectory.GetApp(startupContext.StartRequest.ModuleId)).AppId; + var userChannelSet = await _userChannelSetReader.GetUserChannelSet(); var fdc3InstanceId = startupContext.StartRequest.Parameters.FirstOrDefault(parameter => parameter.Key == Fdc3StartupParameters.Fdc3InstanceId).Value ?? Guid.NewGuid().ToString(); - var channelId = _options.ChannelId ?? "fdc3.channel.1"; + + //TODO: decide if we want to join to a channel automatically on startup of an fdc3 module + var channelId = _options.ChannelId ?? userChannelSet.FirstOrDefault().Key; + var fdc3StartupProperties = new Fdc3StartupProperties() { InstanceId = fdc3InstanceId, ChannelId = channelId }; fdc3InstanceId = startupContext.GetOrAddProperty(_ => fdc3StartupProperties).InstanceId; var webProperties = startupContext.GetOrAddProperty(); - webProperties - .ScriptProviders.Add(_ => - new ValueTask( - $$""" - window.composeui.fdc3 = { - ...window.composeui.fdc3, - config: { - appId: "{{appId}}", - instanceId: "{{fdc3InstanceId}}" - }, - channelId: "{{channelId}}" - }; - """)); + var stringBuilder = new StringBuilder(); + stringBuilder.Append($$""" + window.composeui.fdc3 = { + ...window.composeui.fdc3, + config: { + appId: "{{appId}}", + instanceId: "{{fdc3InstanceId}}" + } + """); - webProperties - .ScriptProviders.Add(_ => new ValueTask(ResourceReader.ReadResource(ResourceNames.Fdc3Bundle))); + if (channelId != null) + { + stringBuilder.Append($$""" + , + channelId: "{{channelId}}" + """); + } + + stringBuilder.Append($$""" + }; + """); + + stringBuilder.AppendLine(); + stringBuilder.Append(ResourceReader.ReadResource(ResourceNames.Fdc3Bundle)); + + webProperties.ScriptProviders.Add(_ => new ValueTask(stringBuilder.ToString())); + + //webProperties + // .ScriptProviders.Add(_ => + // new ValueTask( + // $$""" + // window.composeui.fdc3 = { + // ...window.composeui.fdc3, + // config: { + // appId: "{{appId}}", + // instanceId: "{{fdc3InstanceId}}" + // }, + // channelId: "{{channelId}}" + // }; + // """)); + + //webProperties + // .ScriptProviders.Add(_ => new ValueTask(ResourceReader.ReadResource(ResourceNames.Fdc3Bundle))); } catch (AppNotFoundException exception) { diff --git a/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3StartupProperties.cs b/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3StartupProperties.cs index acb7a3c73..6c0a67158 100644 --- a/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3StartupProperties.cs +++ b/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Fdc3StartupProperties.cs @@ -24,5 +24,5 @@ internal class Fdc3StartupProperties /// /// Id of the channel the opened app should join /// - public string ChannelId { get; init; } + public string? ChannelId { get; init; } } diff --git a/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/IUserChannelSetReader.cs b/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/IUserChannelSetReader.cs new file mode 100644 index 000000000..9a3bf8e8c --- /dev/null +++ b/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/IUserChannelSetReader.cs @@ -0,0 +1,27 @@ +/* + * Morgan Stanley makes this available to you under the Apache License, + * Version 2.0 (the "License"). You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0. + * + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. Unless required by applicable law or agreed + * to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol; + +namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent; + +public interface IUserChannelSetReader +{ + /// + /// Reads the defined user channel set. + /// + /// + /// + public Task> GetUserChannelSet(CancellationToken cancellationToken = default); +} diff --git a/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Infrastructure/Internal/UserChannelSetReader.cs b/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Infrastructure/Internal/UserChannelSetReader.cs new file mode 100644 index 000000000..141500c70 --- /dev/null +++ b/src/fdc3/dotnet/DesktopAgent/src/MorganStanley.ComposeUI.DesktopAgent/Infrastructure/Internal/UserChannelSetReader.cs @@ -0,0 +1,105 @@ +/* + * Morgan Stanley makes this available to you under the Apache License, + * Version 2.0 (the "License"). You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0. + * + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. Unless required by applicable law or agreed + * to in writing, software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Exceptions; +using System.Reflection; +using System.Text.Json; +using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol; +using System.IO.Abstractions; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; +using MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection; +using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Converters; +using System.Text.Json.Serialization; +using System.Collections.Immutable; + +namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Infrastructure.Internal; + +internal class UserChannelSetReader : IUserChannelSetReader, IDisposable +{ + private readonly Fdc3DesktopAgentOptions _options; + private readonly IFileSystem _fileSystem; + private readonly HttpClient _httpClient; + private readonly ILogger _logger; + private IReadOnlyDictionary? _userChannelSet; + private readonly JsonSerializerOptions _jsonSerializerOptions = new(JsonSerializerDefaults.Web) + { + Converters = { new DisplayMetadataJsonConverter(), new JsonStringEnumConverter() } + }; + + public UserChannelSetReader( + IOptions options, + IFileSystem? fileSystem = null, + ILogger? logger = null) + { + _options = options.Value; + _fileSystem = fileSystem ?? new FileSystem(); + _httpClient = new HttpClient(); + _logger = logger ?? NullLogger.Instance; + } + + public void Dispose() + { + _httpClient.Dispose(); + } + + public async Task> GetUserChannelSet(CancellationToken cancellationToken = default) + { + if (_userChannelSet != null) + { + return _userChannelSet; + } + + var uri = _options.UserChannelConfigFile; + + if (uri == null && _options.UserChannelConfig == null) + { + var assembly = Assembly.GetExecutingAssembly(); + using var stream = assembly.GetManifestResourceStream(ResourceNames.DefaultUserChannelSet); + if (stream != null) + { + using var streamReader = new StreamReader(stream); + var result = streamReader.ReadToEnd(); + var userChannels = JsonSerializer.Deserialize(result, _jsonSerializerOptions); + _userChannelSet = userChannels?.ToDictionary(x => x.Id, y => y); + } + } + else if (_options.UserChannelConfig != null) + { + _userChannelSet = _options.UserChannelConfig.ToDictionary(x => x.Id, y => y); + } + else if (uri != null) + { + if (uri.IsFile) + { + var path = uri.IsAbsoluteUri ? uri.AbsolutePath : Path.GetFullPath(uri.ToString()); + + if (_fileSystem.File.Exists(path)) + { + await using var stream = _fileSystem.File.OpenRead(path); + _userChannelSet = (JsonSerializer.Deserialize(stream, _jsonSerializerOptions))?.ToDictionary(x => x.Id, y => y); + } + } + else if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps) + { + var response = await _httpClient.GetAsync(uri, cancellationToken); + await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken); + _userChannelSet = (JsonSerializer.Deserialize(stream, _jsonSerializerOptions))?.ToDictionary(x => x.Id, y => y); + } + } + + return _userChannelSet ?? ImmutableDictionary.Empty; + } +} diff --git a/src/fdc3/dotnet/DesktopAgent/test/MorganStanley.ComposeUI.DesktopAgent.Tests/Fdc3DesktopAgentTests.cs b/src/fdc3/dotnet/DesktopAgent/test/MorganStanley.ComposeUI.DesktopAgent.Tests/Fdc3DesktopAgentTests.cs index 295eb6057..bb742c34c 100644 --- a/src/fdc3/dotnet/DesktopAgent/test/MorganStanley.ComposeUI.DesktopAgent.Tests/Fdc3DesktopAgentTests.cs +++ b/src/fdc3/dotnet/DesktopAgent/test/MorganStanley.ComposeUI.DesktopAgent.Tests/Fdc3DesktopAgentTests.cs @@ -38,6 +38,7 @@ using Icon = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.Icon; using ImplementationMetadata = MorganStanley.ComposeUI.Fdc3.DesktopAgent.Protocol.ImplementationMetadata; using System.Collections.Concurrent; +using System.Collections.Immutable; namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.Tests; @@ -57,12 +58,14 @@ public class Fdc3DesktopAgentTests : IAsyncLifetime public Fdc3DesktopAgentTests() { + var options = new Fdc3DesktopAgentOptions(); + _fdc3 = new Fdc3DesktopAgent( _appDirectory, _mockModuleLoader.Object, - new Fdc3DesktopAgentOptions(), + options, _mockResolverUICommunicator.Object, - null, + new UserChannelSetReader(options), NullLoggerFactory.Instance); } @@ -684,15 +687,19 @@ public async Task GetUserChannels_returns_access_denied_error() } [Fact] - public async Task GetUserChannels_returns_no_user_channel_set_configured_error() + public async Task GetUserChannels_returns_empty_userChannel_set() { + var options = new Fdc3DesktopAgentOptions + { + UserChannelConfigFile = new Uri("C://hello/world/test.json"), + }; + var fdc3 = new Fdc3DesktopAgent( _appDirectory, _mockModuleLoader.Object, - new Fdc3DesktopAgentOptions - { - UserChannelConfigFile = new Uri("C://hello/world/test.json"), - }, _mockResolverUICommunicator.Object); + options, + _mockResolverUICommunicator.Object, + new UserChannelSetReader(options)); await fdc3.StartAsync(CancellationToken.None); @@ -708,7 +715,7 @@ public async Task GetUserChannels_returns_no_user_channel_set_configured_error() var result = await fdc3.GetUserChannels(request); result.Should().NotBeNull(); - result.Should().BeEquivalentTo(GetUserChannelsResponse.Failure(Fdc3DesktopAgentErrors.NoUserChannelSetFound)); + result.Should().BeEquivalentTo(GetUserChannelsResponse.Success(Enumerable.Empty())); } [Fact] diff --git a/src/fdc3/dotnet/DesktopAgent/test/MorganStanley.ComposeUI.DesktopAgent.Tests/Infrastructure/Internal/Fdc3DesktopAgentMessageRouterService.Tests.cs b/src/fdc3/dotnet/DesktopAgent/test/MorganStanley.ComposeUI.DesktopAgent.Tests/Infrastructure/Internal/Fdc3DesktopAgentMessageRouterService.Tests.cs index 911ce193d..752bed751 100644 --- a/src/fdc3/dotnet/DesktopAgent/test/MorganStanley.ComposeUI.DesktopAgent.Tests/Infrastructure/Internal/Fdc3DesktopAgentMessageRouterService.Tests.cs +++ b/src/fdc3/dotnet/DesktopAgent/test/MorganStanley.ComposeUI.DesktopAgent.Tests/Infrastructure/Internal/Fdc3DesktopAgentMessageRouterService.Tests.cs @@ -56,18 +56,20 @@ public class Fdc3DesktopAgentMessageRouterServiceTests : IAsyncLifetime public Fdc3DesktopAgentMessageRouterServiceTests() { + var options = new Fdc3DesktopAgentOptions() + { + IntentResultTimeout = TimeSpan.FromMilliseconds(100), + ListenerRegistrationTimeout = TimeSpan.FromMilliseconds(100) + }; + _fdc3 = new Fdc3DesktopAgentMessageRouterService( _mockMessageRouter.Object, new Fdc3DesktopAgent( _appDirectory, _mockModuleLoader.Object, - new Fdc3DesktopAgentOptions() - { - IntentResultTimeout = TimeSpan.FromMilliseconds(100), - ListenerRegistrationTimeout = TimeSpan.FromMilliseconds(100) - }, + options, _mockResolverUICommunicator.Object, - null, + new UserChannelSetReader(options), NullLoggerFactory.Instance), new Fdc3DesktopAgentOptions(), NullLoggerFactory.Instance); diff --git a/src/fdc3/js/composeui-fdc3/src/index.ts b/src/fdc3/js/composeui-fdc3/src/index.ts index 6ff685270..0657727a9 100644 --- a/src/fdc3/js/composeui-fdc3/src/index.ts +++ b/src/fdc3/js/composeui-fdc3/src/index.ts @@ -32,11 +32,12 @@ declare global { async function initialize(): Promise { //TODO: decide if we want to join to a channel by default. let channelId: string | undefined = window.composeui.fdc3.channelId; - let fdc3 = new ComposeUIDesktopAgent(createMessageRouter()); + const fdc3 = new ComposeUIDesktopAgent(createMessageRouter()); if (channelId) { await fdc3.joinUserChannel(channelId) .then(() => { + console.log("Hello"); window.fdc3 = fdc3; window.dispatchEvent(new Event("fdc3Ready")); }); diff --git a/src/shell/dotnet/Shell/Properties/launchSettings.json b/src/shell/dotnet/Shell/Properties/launchSettings.json index b4f4c5dee..c774ab1d3 100644 --- a/src/shell/dotnet/Shell/Properties/launchSettings.json +++ b/src/shell/dotnet/Shell/Properties/launchSettings.json @@ -1,4 +1,4 @@ -{ +{ "profiles": { "Chart and grid": { "commandName": "Project", diff --git a/src/shell/dotnet/Shell/appsettings.json b/src/shell/dotnet/Shell/appsettings.json index d8b13a9dd..5d9e6699f 100644 --- a/src/shell/dotnet/Shell/appsettings.json +++ b/src/shell/dotnet/Shell/appsettings.json @@ -8,9 +8,6 @@ "FDC3": { "EnableFdc3": true, - "DesktopAgent": { - "ChannelId": "fdc3.channel.1" - }, "AppDirectory": { "Source": "https://directory.fdc3.finos.org/v2/apps/" }