Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Event aggregator #417

Draft
wants to merge 20 commits into
base: remove-dataflow
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -12,15 +12,18 @@ public class ArcGISSelectionBinding : ISelectionBinding
public string Name => "selectionBinding";
public IBrowserBridge Parent { get; }

public ArcGISSelectionBinding(IBrowserBridge parent, MapMembersUtils mapMemberUtils)
public ArcGISSelectionBinding(
IBrowserBridge parent,
MapMembersUtils mapMemberUtils,
ITopLevelExceptionHandler topLevelExceptionHandler
)
{
_mapMemberUtils = mapMemberUtils;
Parent = parent;
var topLevelHandler = parent.TopLevelExceptionHandler;

// example: https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/master/Map-Authoring/QueryBuilderControl/DefinitionQueryDockPaneViewModel.cs
// MapViewEventArgs args = new(MapView.Active);
TOCSelectionChangedEvent.Subscribe(_ => topLevelHandler.CatchUnhandled(OnSelectionChanged), true);
TOCSelectionChangedEvent.Subscribe(_ => topLevelExceptionHandler.CatchUnhandled(OnSelectionChanged), true);
}

private void OnSelectionChanged()
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
using Speckle.Connectors.Common.Operations;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Eventing;
using Speckle.Connectors.DUI.Exceptions;
using Speckle.Connectors.DUI.Logging;
using Speckle.Connectors.DUI.Models;
@@ -66,7 +67,9 @@ public ArcGISSendBinding(
IOperationProgressManager operationProgressManager,
ILogger<ArcGISSendBinding> logger,
IArcGISConversionSettingsFactory arcGisConversionSettingsFactory,
MapMembersUtils mapMemberUtils
ITopLevelExceptionHandler topLevelExceptionHandler,
MapMembersUtils mapMemberUtils,
IEventAggregator eventAggregator
)
{
_store = store;
@@ -76,17 +79,19 @@ MapMembersUtils mapMemberUtils
_sendConversionCache = sendConversionCache;
_operationProgressManager = operationProgressManager;
_logger = logger;
_topLevelExceptionHandler = parent.TopLevelExceptionHandler;
_topLevelExceptionHandler = topLevelExceptionHandler;
_arcGISConversionSettingsFactory = arcGisConversionSettingsFactory;
_mapMemberUtils = mapMemberUtils;

Parent = parent;
Commands = new SendBindingUICommands(parent);
SubscribeToArcGISEvents();
_store.DocumentChanged += (_, _) =>
{
_sendConversionCache.ClearCache();
};
eventAggregator
.GetEvent<DocumentChangedEvent>()
.Subscribe(_ =>
{
_sendConversionCache.ClearCache();
});
}

private void SubscribeToArcGISEvents()
@@ -190,23 +195,23 @@ private void SubscribeToAnyDataSourceChange(Table layerTable)
{
RowCreatedEvent.Subscribe(
(args) =>
Parent.TopLevelExceptionHandler.FireAndForget(async () =>
_topLevelExceptionHandler.FireAndForget(async () =>
{
await OnRowChanged(args).ConfigureAwait(false);
}),
layerTable
);
RowChangedEvent.Subscribe(
(args) =>
Parent.TopLevelExceptionHandler.FireAndForget(async () =>
_topLevelExceptionHandler.FireAndForget(async () =>
{
await OnRowChanged(args).ConfigureAwait(false);
}),
layerTable
);
RowDeletedEvent.Subscribe(
(args) =>
Parent.TopLevelExceptionHandler.FireAndForget(async () =>
_topLevelExceptionHandler.FireAndForget(async () =>
{
await OnRowChanged(args).ConfigureAwait(false);
}),
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
using Speckle.Connectors.ArcGIS.Utils;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Eventing;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Sdk;
@@ -21,18 +22,21 @@ public class BasicConnectorBinding : IBasicConnectorBinding
private readonly DocumentModelStore _store;
private readonly ISpeckleApplication _speckleApplication;

public BasicConnectorBinding(DocumentModelStore store, IBrowserBridge parent, ISpeckleApplication speckleApplication)
public BasicConnectorBinding(
DocumentModelStore store,
IBrowserBridge parent,
ISpeckleApplication speckleApplication,
IEventAggregator eventAggregator
)
{
_store = store;
_speckleApplication = speckleApplication;
Parent = parent;
Commands = new BasicConnectorBindingCommands(parent);

_store.DocumentChanged += (_, _) =>
parent.TopLevelExceptionHandler.FireAndForget(async () =>
{
await Commands.NotifyDocumentChanged().ConfigureAwait(false);
});
eventAggregator
.GetEvent<DocumentChangedEvent>()
.Subscribe(async _ => await Commands.NotifyDocumentChanged().ConfigureAwait(false));
}

public string GetSourceApplicationName() => _speckleApplication.Slug;
Original file line number Diff line number Diff line change
@@ -34,8 +34,6 @@ public static void AddArcGIS(this IServiceCollection serviceCollection)
serviceCollection.AddSingleton<IBinding, ConfigBinding>();
serviceCollection.AddSingleton<IBinding, AccountBinding>();

serviceCollection.RegisterTopLevelExceptionHandler();

serviceCollection.AddSingleton<IBinding>(sp => sp.GetRequiredService<IBasicConnectorBinding>());
serviceCollection.AddSingleton<IBasicConnectorBinding, BasicConnectorBinding>();

Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
using ArcGIS.Desktop.Mapping.Events;
using Speckle.Connectors.Common.Threading;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Eventing;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Utils;

@@ -12,15 +13,18 @@ namespace Speckle.Connectors.ArcGIS.Utils;
public class ArcGISDocumentStore : DocumentModelStore
{
private readonly IThreadContext _threadContext;
private readonly IEventAggregator _eventAggregator;

public ArcGISDocumentStore(
IJsonSerializer jsonSerializer,
ITopLevelExceptionHandler topLevelExceptionHandler,
IThreadContext threadContext
IThreadContext threadContext,
IEventAggregator eventAggregator
)
: base(jsonSerializer)
{
_threadContext = threadContext;
_eventAggregator = eventAggregator;
ActiveMapViewChangedEvent.Subscribe(a => topLevelExceptionHandler.CatchUnhandled(() => OnMapViewChanged(a)), true);
ProjectSavingEvent.Subscribe(
_ =>
@@ -44,7 +48,7 @@ IThreadContext threadContext
{
IsDocumentInit = true;
LoadState();
OnDocumentChanged();
eventAggregator.GetEvent<DocumentChangedEvent>().Publish(new object());
}
}

@@ -78,7 +82,7 @@ private void OnMapViewChanged(ActiveMapViewChangedEventArgs args)

IsDocumentInit = true;
LoadState();
OnDocumentChanged();
_eventAggregator.GetEvent<DocumentChangedEvent>().Publish(new object());
}

protected override void HostAppSaveState(string modelCardState) =>
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
using Speckle.Connectors.Common.Threading;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Eventing;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card;
using Speckle.Sdk;
@@ -31,6 +32,7 @@ public AutocadBasicConnectorBinding(
IAccountManager accountManager,
ISpeckleApplication speckleApplication,
ILogger<AutocadBasicConnectorBinding> logger,
IEventAggregator eventAggregator,
IThreadContext threadContext
)
{
@@ -39,8 +41,9 @@ IThreadContext threadContext
_accountManager = accountManager;
_speckleApplication = speckleApplication;
Commands = new BasicConnectorBindingCommands(parent);
_store.DocumentChanged += (_, _) =>
parent.TopLevelExceptionHandler.FireAndForget(async () =>
eventAggregator
.GetEvent<DocumentChangedEvent>()
.Subscribe(async _ =>
{
await Commands.NotifyDocumentChanged().ConfigureAwait(false);
});
Original file line number Diff line number Diff line change
@@ -18,9 +18,13 @@ public class AutocadSelectionBinding : ISelectionBinding

public IBrowserBridge Parent { get; }

public AutocadSelectionBinding(IBrowserBridge parent, IThreadContext threadContext)
public AutocadSelectionBinding(
IBrowserBridge parent,
IThreadContext threadContext,
ITopLevelExceptionHandler topLevelExceptionHandler
)
{
_topLevelExceptionHandler = parent.TopLevelExceptionHandler;
_topLevelExceptionHandler = topLevelExceptionHandler;
Parent = parent;
_threadContext = threadContext;

Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
using Speckle.Connectors.Common.Threading;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Eventing;
using Speckle.Connectors.DUI.Exceptions;
using Speckle.Connectors.DUI.Logging;
using Speckle.Connectors.DUI.Models;
@@ -60,7 +61,9 @@ protected AutocadSendBaseBinding(
IOperationProgressManager operationProgressManager,
ILogger<AutocadSendBinding> logger,
ISpeckleApplication speckleApplication,
IThreadContext threadContext
ITopLevelExceptionHandler topLevelExceptionHandler,
IThreadContext threadContext,
IEventAggregator eventAggregator
)
{
_store = store;
@@ -73,7 +76,7 @@ IThreadContext threadContext
_logger = logger;
_speckleApplication = speckleApplication;
_threadContext = threadContext;
_topLevelExceptionHandler = parent.TopLevelExceptionHandler;
_topLevelExceptionHandler = topLevelExceptionHandler;
Parent = parent;
Commands = new SendBindingUICommands(parent);

@@ -86,10 +89,8 @@ IThreadContext threadContext
SubscribeToObjectChanges(Application.DocumentManager.CurrentDocument);
}
// Since ids of the objects generates from same seed, we should clear the cache always whenever doc swapped.
_store.DocumentChanged += (_, _) =>
{
_sendConversionCache.ClearCache();
};

eventAggregator.GetEvent<DocumentChangedEvent>().Subscribe(_ => _sendConversionCache.ClearCache());
}

private readonly List<string> _docSubsTracker = new();
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
using Speckle.Connectors.Common.Threading;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Eventing;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Converters.Autocad;
@@ -30,7 +31,9 @@ public AutocadSendBinding(
ILogger<AutocadSendBinding> logger,
IAutocadConversionSettingsFactory autocadConversionSettingsFactory,
ISpeckleApplication speckleApplication,
IThreadContext threadContext
ITopLevelExceptionHandler topLevelExceptionHandler,
IThreadContext threadContext,
IEventAggregator eventAggregator
)
: base(
store,
@@ -43,7 +46,9 @@ IThreadContext threadContext
operationProgressManager,
logger,
speckleApplication,
threadContext
topLevelExceptionHandler,
threadContext,
eventAggregator
)
{
_autocadConversionSettingsFactory = autocadConversionSettingsFactory;
Original file line number Diff line number Diff line change
@@ -59,8 +59,6 @@ public static void AddAutocadBase(this IServiceCollection serviceCollection)
serviceCollection.AddSingleton<IBinding>(sp => sp.GetRequiredService<IBasicConnectorBinding>());
serviceCollection.AddSingleton<IBasicConnectorBinding, AutocadBasicConnectorBinding>();
serviceCollection.AddSingleton<IBinding, ConfigBinding>();

serviceCollection.RegisterTopLevelExceptionHandler();
}

public static void LoadSend(this IServiceCollection serviceCollection)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Eventing;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Utils;

@@ -9,15 +10,18 @@ public class AutocadDocumentStore : DocumentModelStore
private readonly string _nullDocumentName = "Null Doc";
private string _previousDocName;
private readonly AutocadDocumentManager _autocadDocumentManager;
private readonly IEventAggregator _eventAggregator;

public AutocadDocumentStore(
IJsonSerializer jsonSerializer,
AutocadDocumentManager autocadDocumentManager,
ITopLevelExceptionHandler topLevelExceptionHandler
ITopLevelExceptionHandler topLevelExceptionHandler,
IEventAggregator eventAggregator
)
: base(jsonSerializer)
{
_autocadDocumentManager = autocadDocumentManager;
_eventAggregator = eventAggregator;
_previousDocName = _nullDocumentName;

// POC: Will be addressed to move it into AutocadContext!
@@ -48,7 +52,8 @@ private void OnDocChangeInternal(Document? doc)

_previousDocName = currentDocName;
LoadState();
OnDocumentChanged();
LoadState();
_eventAggregator.GetEvent<DocumentChangedEvent>().Publish(new object());
}

protected override void LoadState()
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
using Speckle.Connectors.Common.Threading;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Eventing;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Models.Card.SendFilter;
using Speckle.Converters.Autocad;
@@ -34,7 +35,9 @@ public Civil3dSendBinding(
ICivil3dConversionSettingsFactory civil3dConversionSettingsFactory,
IAutocadConversionSettingsFactory autocadConversionSettingsFactory,
ISpeckleApplication speckleApplication,
IThreadContext threadContext
ITopLevelExceptionHandler topLevelExceptionHandler,
IThreadContext threadContext,
IEventAggregator eventAggregator
)
: base(
store,
@@ -47,7 +50,9 @@ IThreadContext threadContext
operationProgressManager,
logger,
speckleApplication,
threadContext
topLevelExceptionHandler,
threadContext,
eventAggregator
)
{
_civil3dConversionSettingsFactory = civil3dConversionSettingsFactory;
Original file line number Diff line number Diff line change
@@ -43,8 +43,6 @@ public static IServiceCollection AddCSi(this IServiceCollection services)
services.AddScoped<IRootObjectBuilder<ICSiWrapper>, CSiRootObjectBuilder>();
services.AddScoped<SendOperation<ICSiWrapper>>();

services.RegisterTopLevelExceptionHandler();

return services;
}
}
Loading
Loading