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

Open
wants to merge 80 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
c09fd83
Remove Dataflow usage
adamhathcock Nov 21, 2024
01cd963
format and remove dep
adamhathcock Nov 21, 2024
f251e4a
Merge branch 'dev' into remove-dataflow
adamhathcock Nov 22, 2024
6074b2c
merge fixes
adamhathcock Nov 22, 2024
49de3d1
Fix serializer
adamhathcock Nov 22, 2024
0ffdf6c
Add MainThreadContext
adamhathcock Nov 22, 2024
684a295
add some main context detection
adamhathcock Nov 22, 2024
ecbaed1
add RevitMainThreadContext
adamhathcock Nov 22, 2024
c1ddbc3
remove revit async?
adamhathcock Nov 22, 2024
d03a3f1
formatting
adamhathcock Nov 25, 2024
cc5e99f
use mainThreadContext
adamhathcock Nov 25, 2024
5a5de75
Use more MainThreadContext
adamhathcock Nov 25, 2024
0940fe7
some rearranging
adamhathcock Nov 26, 2024
4ee6d04
renaming
adamhathcock Nov 26, 2024
a7699f0
Revit needs new run async
adamhathcock Nov 26, 2024
21441cd
Merge branch 'dev' into remove-dataflow
adamhathcock Nov 26, 2024
25cbbb4
merge fixes
adamhathcock Nov 26, 2024
e38102f
gather on worker, convert on main
adamhathcock Nov 26, 2024
3644054
operations know threading but not host apps
adamhathcock Nov 26, 2024
d416e76
rhino options
adamhathcock Nov 27, 2024
9c83cee
revit can receive
adamhathcock Nov 27, 2024
8708779
autocad in progress
adamhathcock Nov 27, 2024
ca6ce6c
need to yield for UI thread async
adamhathcock Nov 27, 2024
ea45057
revamp yield
adamhathcock Nov 27, 2024
2971a5e
Found APIContext and removed it
adamhathcock Nov 27, 2024
05eba25
ArcGIS runs all workers on MCT thread
adamhathcock Nov 27, 2024
7450a29
Merge branch 'dev' into remove-dataflow
adamhathcock Nov 27, 2024
b59b37d
Refactor ThreadContext and ArcGIS saving is always on a worker
adamhathcock Nov 28, 2024
d826a3e
Revit threading is simplier?
adamhathcock Nov 28, 2024
2e437cb
ArcGIS can not always go to the queued task
adamhathcock Nov 28, 2024
4b24584
format
adamhathcock Nov 28, 2024
7a71b5d
fix tekla compile errors
adamhathcock Nov 28, 2024
bb0faaa
Use EventAggregator to decouple exception handler and UI
adamhathcock Nov 28, 2024
8e3b1da
it's ALIVE
adamhathcock Nov 28, 2024
67ddd62
regenerate locks
adamhathcock Nov 28, 2024
fded4db
Add Prism Evening to DUI
adamhathcock Nov 29, 2024
56811a9
clean up
adamhathcock Nov 29, 2024
bda6abe
always run on background thread
adamhathcock Nov 29, 2024
d0dae86
Merge remote-tracking branch 'origin/dev' into remove-dataflow
adamhathcock Nov 29, 2024
47fca75
Clean up to be specific
adamhathcock Nov 29, 2024
89332b8
Merge branch 'dev' into event-aggregator
adamhathcock Nov 29, 2024
9bdcdeb
Merge branch 'dev' into remove-dataflow
adamhathcock Nov 29, 2024
fe0fe68
Merge branch 'remove-dataflow' into event-aggregator
adamhathcock Nov 29, 2024
3c0a84e
update etabs
adamhathcock Nov 29, 2024
20ecbad
thread context
adamhathcock Nov 29, 2024
54dfd05
autocad threading?
adamhathcock Nov 29, 2024
e7e6df0
Merge branch 'dev' into remove-dataflow
adamhathcock Dec 2, 2024
287b719
merge fixes
adamhathcock Dec 2, 2024
8b3fb98
remove more async
adamhathcock Dec 2, 2024
0ae2676
clean up
adamhathcock Dec 2, 2024
6f23d90
Merge branch 'dev' into remove-dataflow
adamhathcock Dec 3, 2024
20e848d
Merge branch 'remove-dataflow' into event-aggregator
adamhathcock Dec 3, 2024
b1f41c6
fix build issues
adamhathcock Dec 3, 2024
69745bb
Do top level handling in event aggregator
adamhathcock Dec 3, 2024
50228be
add some rhino events
adamhathcock Dec 3, 2024
0816ad6
add more Rhino events and do Idle as OneTime with Id
adamhathcock Dec 3, 2024
2059023
fix up rhino idle usages
adamhathcock Dec 3, 2024
3f129bf
fmt
adamhathcock Dec 3, 2024
8954a93
Merge branch 'dev' into remove-dataflow
adamhathcock Dec 3, 2024
d5f6323
can build agian
adamhathcock Dec 3, 2024
caac2a7
Use valuetask
adamhathcock Dec 3, 2024
4a7a961
Merge remote-tracking branch 'origin/dev' into remove-dataflow
adamhathcock Dec 3, 2024
1ea4acb
fmt
adamhathcock Dec 3, 2024
027b0cc
fix up some bridge execution to be sync
adamhathcock Dec 3, 2024
7f61d95
cleanup
adamhathcock Dec 4, 2024
7927d5a
add some non async paths for progress
adamhathcock Dec 5, 2024
5548ac8
format
adamhathcock Dec 5, 2024
10d9f3b
remove needless selection
adamhathcock Dec 5, 2024
d2a3fce
Merge branch 'remove-dataflow' into event-aggregator
adamhathcock Dec 5, 2024
75d8c9a
Fixes
adamhathcock Dec 5, 2024
03a11b9
Convert tekla
adamhathcock Dec 5, 2024
b99206b
selection event is used without idle
adamhathcock Dec 5, 2024
b8f1a9e
Merge branch 'dev' into event-aggregator
adamhathcock Dec 30, 2024
f9c2ec7
Merge branch 'dev' into event-aggregator
adamhathcock Jan 2, 2025
9541ba7
Build fixes from merge
adamhathcock Jan 2, 2025
47ca942
Fix tests and clean up
adamhathcock Jan 2, 2025
91aa0d1
Merge remote-tracking branch 'origin/dev' into event-aggregator
adamhathcock Jan 8, 2025
8a3fd99
Merge remote-tracking branch 'origin/dev' into event-aggregator
adamhathcock Jan 8, 2025
35db076
Add new events
adamhathcock Jan 8, 2025
f66acbc
Merge branch 'dev' into event-aggregator
adamhathcock Jan 9, 2025
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
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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;
Expand Down Expand Up @@ -69,7 +70,9 @@ public ArcGISSendBinding(
ILogger<ArcGISSendBinding> logger,
IArcGISConversionSettingsFactory arcGisConversionSettingsFactory,
MapMembersUtils mapMemberUtils,
IThreadContext threadContext
IThreadContext threadContext,
IEventAggregator eventAggregator,
ITopLevelExceptionHandler topLevelExceptionHandler
)
{
_store = store;
Expand All @@ -79,18 +82,20 @@ IThreadContext threadContext
_sendConversionCache = sendConversionCache;
_operationProgressManager = operationProgressManager;
_logger = logger;
_topLevelExceptionHandler = parent.TopLevelExceptionHandler;
_topLevelExceptionHandler = topLevelExceptionHandler;
_arcGISConversionSettingsFactory = arcGisConversionSettingsFactory;
_mapMemberUtils = mapMemberUtils;
_threadContext = threadContext;

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

private void SubscribeToArcGISEvents()
Expand Down Expand Up @@ -201,23 +206,23 @@ private void SubscribeToAnyDataSourceChange(Table layerTable)
{
RowCreatedEvent.Subscribe(
(args) =>
Parent.TopLevelExceptionHandler.FireAndForget(async () =>
_topLevelExceptionHandler.FireAndForget(async () =>
{
await OnRowChanged(args);
}),
layerTable
);
RowChangedEvent.Subscribe(
(args) =>
Parent.TopLevelExceptionHandler.FireAndForget(async () =>
_topLevelExceptionHandler.FireAndForget(async () =>
{
await OnRowChanged(args);
}),
layerTable
);
RowDeletedEvent.Subscribe(
(args) =>
Parent.TopLevelExceptionHandler.FireAndForget(async () =>
_topLevelExceptionHandler.FireAndForget(async () =>
{
await OnRowChanged(args);
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
});
eventAggregator
.GetEvent<DocumentChangedEvent>()
.Subscribe(async _ => await Commands.NotifyDocumentChanged().ConfigureAwait(false));
}

public string GetSourceApplicationName() => _speckleApplication.Slug;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static void AddArcGIS(this IServiceCollection serviceCollection)
serviceCollection.AddSingleton<IBinding>(sp => sp.GetRequiredService<IBasicConnectorBinding>());
serviceCollection.AddSingleton<IBasicConnectorBinding, BasicConnectorBinding>();

serviceCollection.RegisterTopLevelExceptionHandler();
serviceCollection.AddSingleton(DefaultTraversal.CreateTraversalFunc());

// register send operation and dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using Speckle.Connectors.Common.Threading;

namespace Speckle.Connectors.ArcGIS.Utils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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(
_ =>
Expand All @@ -44,7 +48,7 @@ IThreadContext threadContext
{
IsDocumentInit = true;
LoadState();
OnDocumentChanged();
eventAggregator.GetEvent<DocumentChangedEvent>().Publish(new object());
}
}

Expand Down Expand Up @@ -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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -31,6 +32,7 @@ public AutocadBasicConnectorBinding(
IAccountManager accountManager,
ISpeckleApplication speckleApplication,
ILogger<AutocadBasicConnectorBinding> logger,
IEventAggregator eventAggregator,
IThreadContext threadContext
)
{
Expand All @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using Autodesk.AutoCAD.DatabaseServices;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand All @@ -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;
Expand Down Expand Up @@ -60,7 +61,9 @@ protected AutocadSendBaseBinding(
IOperationProgressManager operationProgressManager,
ILogger<AutocadSendBinding> logger,
ISpeckleApplication speckleApplication,
IThreadContext threadContext
ITopLevelExceptionHandler topLevelExceptionHandler,
IThreadContext threadContext,
IEventAggregator eventAggregator
)
{
_store = store;
Expand All @@ -73,7 +76,7 @@ IThreadContext threadContext
_logger = logger;
_speckleApplication = speckleApplication;
_threadContext = threadContext;
_topLevelExceptionHandler = parent.TopLevelExceptionHandler;
_topLevelExceptionHandler = topLevelExceptionHandler;
Parent = parent;
Commands = new SendBindingUICommands(parent);

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +31,9 @@ public AutocadSendBinding(
ILogger<AutocadSendBinding> logger,
IAutocadConversionSettingsFactory autocadConversionSettingsFactory,
ISpeckleApplication speckleApplication,
IThreadContext threadContext
ITopLevelExceptionHandler topLevelExceptionHandler,
IThreadContext threadContext,
IEventAggregator eventAggregator
)
: base(
store,
Expand All @@ -43,7 +46,9 @@ IThreadContext threadContext
operationProgressManager,
logger,
speckleApplication,
threadContext
topLevelExceptionHandler,
threadContext,
eventAggregator
)
{
_autocadConversionSettingsFactory = autocadConversionSettingsFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,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)
Expand Down
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;

Expand All @@ -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!
Expand Down Expand Up @@ -48,7 +52,7 @@ private void OnDocChangeInternal(Document? doc)

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

protected override void LoadState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,7 +35,9 @@ public Civil3dSendBinding(
ICivil3dConversionSettingsFactory civil3dConversionSettingsFactory,
IAutocadConversionSettingsFactory autocadConversionSettingsFactory,
ISpeckleApplication speckleApplication,
IThreadContext threadContext
ITopLevelExceptionHandler topLevelExceptionHandler,
IThreadContext threadContext,
IEventAggregator eventAggregator
)
: base(
store,
Expand All @@ -47,7 +50,9 @@ IThreadContext threadContext
operationProgressManager,
logger,
speckleApplication,
threadContext
topLevelExceptionHandler,
threadContext,
eventAggregator
)
{
_civil3dConversionSettingsFactory = civil3dConversionSettingsFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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