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

Remove EA from ETabs #572

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
@@ -1,15 +1,16 @@
using Speckle.Connectors.CSiShared.Events;
using Speckle.Connectors.CSiShared.HostApp;
using Speckle.Connectors.CSiShared.HostApp;
using Speckle.Connectors.CSiShared.Utils;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Eventing;
using Speckle.Converters.CSiShared.Utils;
using Timer = System.Timers.Timer;

namespace Speckle.Connectors.CSiShared.Bindings;

public sealed class CsiSharedSelectionBinding : ISelectionBinding
public class CsiSharedSelectionBinding : ISelectionBinding, IDisposable
{
private bool _disposed;
private readonly Timer _selectionTimer;
private readonly ICsiApplicationService _csiApplicationService;
private HashSet<string> _lastSelection = new();

Expand All @@ -19,16 +20,17 @@ public sealed class CsiSharedSelectionBinding : ISelectionBinding
public CsiSharedSelectionBinding(
IBrowserBridge parent,
ICsiApplicationService csiApplicationService,
IEventAggregator eventAggregator
ITopLevelExceptionHandler topLevelExceptionHandler
)
{
Parent = parent;
_csiApplicationService = csiApplicationService;

eventAggregator.GetEvent<SelectionBindingEvent>().SubscribePeriodic(TimeSpan.FromSeconds(1), CheckSelectionChanged);
_selectionTimer = new Timer(1000);
_selectionTimer.Elapsed += (_, _) => topLevelExceptionHandler.CatchUnhandled(CheckSelectionChanged);
_selectionTimer.Start();
}

private void CheckSelectionChanged(object _)
private void CheckSelectionChanged()
{
var currentSelection = GetSelection();
var currentIds = new HashSet<string>(currentSelection.SelectedObjectIds);
Expand All @@ -40,6 +42,24 @@ private void CheckSelectionChanged(object _)
}
}

protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_selectionTimer?.Dispose();
}
_disposed = true;
}
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Gets the selection and creates an encoded ID (objectType and objectName).
/// </summary>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
using System.IO;
using System.Timers;
using Microsoft.Extensions.Logging;
using Speckle.Connectors.CSiShared.Events;
using Speckle.Connectors.DUI.Eventing;
using Speckle.Connectors.DUI.Models;
using Speckle.Connectors.DUI.Utils;
using Speckle.Sdk;
using Speckle.Sdk.Helpers;
using Speckle.Sdk.Logging;
using Timer = System.Timers.Timer;

namespace Speckle.Connectors.CSiShared.HostApp;

public class CsiDocumentModelStore : DocumentModelStore
public class CsiDocumentModelStore : DocumentModelStore, IDisposable
{
private readonly ISpeckleApplication _speckleApplication;
private readonly ILogger<CsiDocumentModelStore> _logger;
private readonly ICsiApplicationService _csiApplicationService;
private readonly Timer _modelCheckTimer;
private readonly IEventAggregator _eventAggregator;
private string _lastModelFilename = string.Empty;
private bool _disposed;
private string HostAppUserDataPath { get; set; }
private string DocumentStateFile { get; set; }
private string ModelPathHash { get; set; }
Expand All @@ -34,10 +37,14 @@ IEventAggregator eventAggregator
_logger = logger;
_csiApplicationService = csiApplicationService;
_eventAggregator = eventAggregator;
eventAggregator.GetEvent<ModelChangedEvent>().SubscribePeriodic(TimeSpan.FromSeconds(1), CheckModelChanges);

// initialize timer to check for model changes
_modelCheckTimer = new Timer(1000);
_modelCheckTimer.Elapsed += CheckModelChanges;
_modelCheckTimer.Start();
}

private async Task CheckModelChanges(object _)
private async void CheckModelChanges(object? source, ElapsedEventArgs e)
{
string currentFilename = _csiApplicationService.SapModel.GetModelFilename();

Expand Down Expand Up @@ -120,4 +127,25 @@ protected override void LoadState()
ClearAndSave();
}
}

protected virtual void Dispose(bool disposing)
{
if (_disposed)
{
return;
}

if (disposing)
{
_modelCheckTimer.Dispose();
}

_disposed = true;
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CsiSharedBasicConnectorBinding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CsiSharedSelectionBinding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bindings\CsiSharedSendBinding.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Events\ModelChangedEvent.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Events\SelectionBindingEvent.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Filters\CsiSharedSelectionFilter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\MaterialUnpacker.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HostApp\CsiSendCollectionManager.cs" />
Expand Down
Loading