Skip to content

Commit

Permalink
Interfaced out TopLevelExceptionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-Morgan committed Jun 20, 2024
1 parent c5fe301 commit 0b352a4
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ArcGISSelectionBinding : ISelectionBinding
public string Name => "selectionBinding";
public IBridge Parent { get; }

public ArcGISSelectionBinding(IBridge parent, TopLevelExceptionHandler topLevelHandler)
public ArcGISSelectionBinding(IBridge parent, ITopLevelExceptionHandler topLevelHandler)
{
Parent = parent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public sealed class ArcGISSendBinding : ISendBinding
private readonly List<ISendFilter> _sendFilters;
private readonly CancellationManager _cancellationManager;
private readonly ISendConversionCache _sendConversionCache;
private readonly TopLevelExceptionHandler _topLevelExceptionHandler;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;

/// <summary>
/// Used internally to aggregate the changed objects' id.
Expand All @@ -47,7 +47,7 @@ public ArcGISSendBinding(
IUnitOfWorkFactory unitOfWorkFactory,
CancellationManager cancellationManager,
ISendConversionCache sendConversionCache,
TopLevelExceptionHandler topLevelExceptionHandler
ITopLevelExceptionHandler topLevelExceptionHandler
)
{
_store = store;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ namespace Speckle.Connectors.ArcGIS.Utils;

public class ArcGISDocumentStore : DocumentModelStore
{
public ArcGISDocumentStore(JsonSerializerSettings serializerOption, TopLevelExceptionHandler topLevelExceptionHandler)
public ArcGISDocumentStore(
JsonSerializerSettings serializerOption,
ITopLevelExceptionHandler topLevelExceptionHandler
)
: base(serializerOption, true)
{
ActiveMapViewChangedEvent.Subscribe(a => topLevelExceptionHandler.CatchUnhandled(() => OnMapViewChanged(a)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace Speckle.Connectors.Autocad.Bindings;
public class AutocadSelectionBinding : ISelectionBinding
{
private const string SELECTION_EVENT = "setSelection";
private readonly TopLevelExceptionHandler _topLevelExceptionHandler;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;
private readonly HashSet<Document> _visitedDocuments = new();

public string Name => "selectionBinding";

public IBridge Parent { get; }

public AutocadSelectionBinding(IBridge parent, TopLevelExceptionHandler topLevelExceptionHandler)
public AutocadSelectionBinding(IBridge parent, ITopLevelExceptionHandler topLevelExceptionHandler)
{
_topLevelExceptionHandler = topLevelExceptionHandler;
Parent = parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public sealed class AutocadSendBinding : ISendBinding
private readonly IUnitOfWorkFactory _unitOfWorkFactory;
private readonly AutocadSettings _autocadSettings;
private readonly ISendConversionCache _sendConversionCache;
private readonly TopLevelExceptionHandler _topLevelExceptionHandler;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;

/// <summary>
/// Used internally to aggregate the changed objects' id.
Expand All @@ -45,7 +45,7 @@ public AutocadSendBinding(
AutocadSettings autocadSettings,
IUnitOfWorkFactory unitOfWorkFactory,
ISendConversionCache sendConversionCache,
TopLevelExceptionHandler topLevelExceptionHandler
ITopLevelExceptionHandler topLevelExceptionHandler
)
{
_store = store;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AutocadDocumentStore : DocumentModelStore
public AutocadDocumentStore(
JsonSerializerSettings jsonSerializerSettings,
AutocadDocumentManager autocadDocumentManager,
TopLevelExceptionHandler topLevelExceptionHandler
ITopLevelExceptionHandler topLevelExceptionHandler
)
: base(jsonSerializerSettings, true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal sealed class RevitSendBinding : RevitBaseBinding, ISendBinding
private readonly CancellationManager _cancellationManager;
private readonly IUnitOfWorkFactory _unitOfWorkFactory;
private readonly ISendConversionCache _sendConversionCache;
private readonly TopLevelExceptionHandler _topLevelExceptionHandler;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;

public RevitSendBinding(
IRevitIdleManager idleManager,
Expand All @@ -38,7 +38,7 @@ public RevitSendBinding(
IUnitOfWorkFactory unitOfWorkFactory,
RevitSettings revitSettings,
ISendConversionCache sendConversionCache,
TopLevelExceptionHandler topLevelExceptionHandler
ITopLevelExceptionHandler topLevelExceptionHandler
)
: base("sendBinding", store, bridge, revitContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ namespace Speckle.Connectors.Revit.Bindings;
internal sealed class SelectionBinding : RevitBaseBinding, ISelectionBinding
{
private readonly IRevitIdleManager _revitIdleManager;
private readonly TopLevelExceptionHandler _topLevelExceptionHandler;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;

public SelectionBinding(
RevitContext revitContext,
DocumentModelStore store,
IRevitIdleManager idleManager,
IBridge bridge,
TopLevelExceptionHandler topLevelExceptionHandler
ITopLevelExceptionHandler topLevelExceptionHandler
)
: base("selectionBinding", store, bridge, revitContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public RevitDocumentStore(
JsonSerializerSettings serializerSettings,
DocumentModelStorageSchema documentModelStorageSchema,
IdStorageSchema idStorageSchema,
TopLevelExceptionHandler topLevelExceptionHandler
ITopLevelExceptionHandler topLevelExceptionHandler
)
: base(serializerSettings, true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ namespace Speckle.Connectors.Revit.Plugin;
// is probably misnamed, perhaps OnIdleCallbackManager
internal sealed class RevitIdleManager : IRevitIdleManager
{
private readonly TopLevelExceptionHandler _topLevelExceptionHandler;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;
private readonly UIApplication _uiApplication;

private readonly ConcurrentDictionary<string, Action> _calls = new();

// POC: still not thread safe
private volatile bool _hasSubscribed;

public RevitIdleManager(RevitContext revitContext, TopLevelExceptionHandler topLevelExceptionHandler)
public RevitIdleManager(RevitContext revitContext, ITopLevelExceptionHandler topLevelExceptionHandler)
{
_topLevelExceptionHandler = topLevelExceptionHandler;
_uiApplication = revitContext.UIApplication!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Speckle.Connectors.Rhino7.Bindings;
public class RhinoSelectionBinding : ISelectionBinding
{
private readonly RhinoIdleManager _idleManager;
private readonly TopLevelExceptionHandler _topLevelExceptionHandler;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;
private const string SELECTION_EVENT = "setSelection";

public string Name => "selectionBinding";
Expand All @@ -18,7 +18,7 @@ public class RhinoSelectionBinding : ISelectionBinding
public RhinoSelectionBinding(
RhinoIdleManager idleManager,
IBridge parent,
TopLevelExceptionHandler topLevelExceptionHandler
ITopLevelExceptionHandler topLevelExceptionHandler
)
{
_idleManager = idleManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public sealed class RhinoSendBinding : ISendBinding
private HashSet<string> ChangedObjectIds { get; set; } = new();

private readonly ISendConversionCache _sendConversionCache;
private readonly TopLevelExceptionHandler _topLevelExceptionHandler;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;

public RhinoSendBinding(
DocumentModelStore store,
Expand All @@ -48,7 +48,7 @@ public RhinoSendBinding(
RhinoSettings rhinoSettings,
CancellationManager cancellationManager,
ISendConversionCache sendConversionCache,
TopLevelExceptionHandler topLevelExceptionHandler
ITopLevelExceptionHandler topLevelExceptionHandler
)
{
_store = store;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace Speckle.Connectors.Rhino7.HostApp;

public class RhinoDocumentStore : DocumentModelStore
{
private readonly TopLevelExceptionHandler _topLevelExceptionHandler;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;
private const string SPECKLE_KEY = "Speckle_DUI3";
public override bool IsDocumentInit { get; set; } = true; // Note: because of rhino implementation details regarding expiry checking of sender cards.

public RhinoDocumentStore(
JsonSerializerSettings jsonSerializerSettings,
TopLevelExceptionHandler topLevelExceptionHandler
ITopLevelExceptionHandler topLevelExceptionHandler
)
: base(jsonSerializerSettings, true)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace Speckle.Connectors.DUI.WebView;
public sealed partial class DUI3ControlWebView : UserControl
{
private readonly IEnumerable<Lazy<IBinding>> _bindings;
private readonly TopLevelExceptionHandler _topLevelExceptionHandler;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;

public DUI3ControlWebView(IEnumerable<Lazy<IBinding>> bindings, TopLevelExceptionHandler topLevelExceptionHandler)
public DUI3ControlWebView(IEnumerable<Lazy<IBinding>> bindings, ITopLevelExceptionHandler topLevelExceptionHandler)
{
_bindings = bindings;
_topLevelExceptionHandler = topLevelExceptionHandler;
Expand Down
4 changes: 2 additions & 2 deletions DUI3-DX/DUI3/Speckle.Connectors.DUI/Bridge/BrowserBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class BrowserBridge : IBridge
private readonly JsonSerializerSettings _serializerOptions;
private readonly ConcurrentDictionary<string, string?> _resultsStore = new();
private readonly SynchronizationContext _mainThreadContext;
private readonly TopLevelExceptionHandler _topLevelExceptionHandler;
private readonly ITopLevelExceptionHandler _topLevelExceptionHandler;

private IReadOnlyDictionary<string, MethodInfo> _bindingMethodCache = new Dictionary<string, MethodInfo>();

Expand Down Expand Up @@ -79,7 +79,7 @@ public BrowserBridge(JsonSerializerSettings jsonSerializerSettings, ILoggerFacto
{
_serializerOptions = jsonSerializerSettings;
_logger = loggerFactory.CreateLogger<BrowserBridge>();
_topLevelExceptionHandler = new(loggerFactory, this); //TODO: Probably we could inject this with a Lazy somewhere
_topLevelExceptionHandler = new TopLevelExceptionHandler(loggerFactory, this); //TODO: Probably we could inject this with a Lazy somewhere
// Capture the main thread's SynchronizationContext
_mainThreadContext = SynchronizationContext.Current;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Speckle.Connectors.Utils;
using Speckle.Core.Logging;
using Speckle.Core.Models.Extensions;
using Speckle.InterfaceGenerator;

namespace Speckle.Connectors.DUI.Bridge;

Expand Down Expand Up @@ -53,7 +54,8 @@ public Result([NotNull] Exception? result)
/// Depending on the host app, this may trigger windows event logging, and recovery snapshots before ultimately terminating the process<br/>
/// Attempting to swallow them may lead to data corruption, deadlocking, or things worse than a managed host app crash.
/// </remarks>
public sealed class TopLevelExceptionHandler
[GenerateAutoInterface]
public sealed class TopLevelExceptionHandler : ITopLevelExceptionHandler
{
private readonly ILogger<TopLevelExceptionHandler> _logger;
private readonly IBridge _bridge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void AddDUI(this SpeckleContainerBuilder speckleContainerBuilder)
speckleContainerBuilder.AddTransient<ITransport, ServerTransport>();
speckleContainerBuilder.AddSingleton<IRootObjectSender, RootObjectSender>();
speckleContainerBuilder.AddTransient<IBridge, BrowserBridge>(); // POC: Each binding should have it's own bridge instance
speckleContainerBuilder.AddSingleton<TopLevelExceptionHandler>();
speckleContainerBuilder.AddSingleton<ITopLevelExceptionHandler, TopLevelExceptionHandler>();
speckleContainerBuilder.AddSingleton(GetJsonSerializerSettings());
}

Expand Down

0 comments on commit 0b352a4

Please sign in to comment.