diff --git a/Laerdal.McuMgr.Tests/FileDownloader/FileDownloaderTestbed.cs b/Laerdal.McuMgr.Tests/FileDownloader/FileDownloaderTestbed.cs
index 9ef5745d..6c216d27 100644
--- a/Laerdal.McuMgr.Tests/FileDownloader/FileDownloaderTestbed.cs
+++ b/Laerdal.McuMgr.Tests/FileDownloader/FileDownloaderTestbed.cs
@@ -66,6 +66,10 @@ public void FatalErrorOccurredAdvertisement(string resource, string errorMessage
public void FileDownloadProgressPercentageAndDataThroughputChangedAdvertisement(int progressPercentage, float averageThroughput)
=> _downloaderCallbacksProxy.FileDownloadProgressPercentageAndDataThroughputChangedAdvertisement(progressPercentage, averageThroughput); //raises the actual event
+
+ public void Dispose()
+ {
+ }
}
}
}
\ No newline at end of file
diff --git a/Laerdal.McuMgr.Tests/FirmwareInstaller/FirmwareInstallerTestbed.cs b/Laerdal.McuMgr.Tests/FirmwareInstaller/FirmwareInstallerTestbed.cs
index 75b5b2c2..bf282a08 100644
--- a/Laerdal.McuMgr.Tests/FirmwareInstaller/FirmwareInstallerTestbed.cs
+++ b/Laerdal.McuMgr.Tests/FirmwareInstaller/FirmwareInstallerTestbed.cs
@@ -78,6 +78,10 @@ public void FirmwareUploadProgressPercentageAndDataThroughputChangedAdvertisemen
public void CleanupResourcesOfLastInstallation()
{
}
+
+ public void Dispose()
+ {
+ }
}
}
}
\ No newline at end of file
diff --git a/Laerdal.McuMgr/Droid/FileDownloader/FileDownloader.cs b/Laerdal.McuMgr/Droid/FileDownloader/FileDownloader.cs
index a6a075b4..a69ffc2d 100644
--- a/Laerdal.McuMgr/Droid/FileDownloader/FileDownloader.cs
+++ b/Laerdal.McuMgr/Droid/FileDownloader/FileDownloader.cs
@@ -57,7 +57,39 @@ internal AndroidFileDownloaderProxy(INativeFileDownloaderCallbacksProxy fileDown
_fileDownloaderCallbacksProxy = fileDownloaderCallbacksProxy ?? throw new ArgumentNullException(nameof(fileDownloaderCallbacksProxy));
}
+ // public new void Dispose() { ... } dont there is no need to override the base implementation
+
+ private bool _alreadyDisposed;
+ protected override void Dispose(bool disposing)
+ {
+ if (_alreadyDisposed)
+ {
+ base.Dispose(disposing); //vital
+ return;
+ }
+
+ if (disposing)
+ {
+ CleanupInfrastructure();
+ }
+
+ _alreadyDisposed = true;
+
+ base.Dispose(disposing);
+ }
+ private void CleanupInfrastructure()
+ {
+ try
+ {
+ Disconnect();
+ }
+ catch
+ {
+ // ignored
+ }
+ }
+
#region commands
public new EFileDownloaderVerdict BeginDownload(string remoteFilePath)
@@ -66,7 +98,6 @@ internal AndroidFileDownloaderProxy(INativeFileDownloaderCallbacksProxy fileDown
}
#endregion commands
-
#region android callbacks -> csharp event emitters
diff --git a/Laerdal.McuMgr/Droid/FileUploader/FileUploader.cs b/Laerdal.McuMgr/Droid/FileUploader/FileUploader.cs
index 1715be89..c1b75c5c 100644
--- a/Laerdal.McuMgr/Droid/FileUploader/FileUploader.cs
+++ b/Laerdal.McuMgr/Droid/FileUploader/FileUploader.cs
@@ -59,6 +59,39 @@ internal AndroidFileUploaderProxy(INativeFileUploaderCallbacksProxy fileUploader
_fileUploaderCallbacksProxy = fileUploaderCallbacksProxy ?? throw new ArgumentNullException(nameof(fileUploaderCallbacksProxy));
}
+ // public new void Dispose() { ... } dont there is no need to override the base implementation
+
+ private bool _alreadyDisposed;
+ protected override void Dispose(bool disposing)
+ {
+ if (_alreadyDisposed)
+ {
+ base.Dispose(disposing); //vital
+ return;
+ }
+
+ if (disposing)
+ {
+ CleanupInfrastructure();
+ }
+
+ _alreadyDisposed = true;
+
+ base.Dispose(disposing);
+ }
+
+ private void CleanupInfrastructure()
+ {
+ try
+ {
+ Disconnect();
+ }
+ catch
+ {
+ // ignored
+ }
+ }
+
public void CleanupResourcesOfLastUpload()
{
//nothing to do in android
diff --git a/Laerdal.McuMgr/Droid/FirmwareInstaller/FirmwareInstaller.cs b/Laerdal.McuMgr/Droid/FirmwareInstaller/FirmwareInstaller.cs
index 1fb81c82..64d19e07 100644
--- a/Laerdal.McuMgr/Droid/FirmwareInstaller/FirmwareInstaller.cs
+++ b/Laerdal.McuMgr/Droid/FirmwareInstaller/FirmwareInstaller.cs
@@ -59,6 +59,39 @@ internal AndroidFirmwareInstallerProxy(INativeFirmwareInstallerCallbacksProxy fi
_firmwareInstallerCallbacksProxy = firmwareInstallerCallbacksProxy ?? throw new ArgumentNullException(nameof(firmwareInstallerCallbacksProxy));
}
+ // public new void Dispose() { ... } dont there is no need to override the base implementation
+
+ private bool _alreadyDisposed;
+ protected override void Dispose(bool disposing)
+ {
+ if (_alreadyDisposed)
+ {
+ base.Dispose(disposing); //vital
+ return;
+ }
+
+ if (disposing)
+ {
+ CleanupInfrastructure();
+ }
+
+ _alreadyDisposed = true;
+
+ base.Dispose(disposing);
+ }
+
+ private void CleanupInfrastructure()
+ {
+ try
+ {
+ Disconnect();
+ }
+ catch
+ {
+ // ignored
+ }
+ }
+
public void CleanupResourcesOfLastInstallation()
{
//nothing to do here for android only ios needs this
diff --git a/Laerdal.McuMgr/Shared/FileDownloader/Contracts/IFileDownloader.cs b/Laerdal.McuMgr/Shared/FileDownloader/Contracts/IFileDownloader.cs
index 979093fb..ad030e3b 100644
--- a/Laerdal.McuMgr/Shared/FileDownloader/Contracts/IFileDownloader.cs
+++ b/Laerdal.McuMgr/Shared/FileDownloader/Contracts/IFileDownloader.cs
@@ -1,11 +1,17 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable EventNeverSubscribedTo.Global
+using System;
+
namespace Laerdal.McuMgr.FileDownloader.Contracts
{
/// Downloads a file on a specific Nordic-chip-based BLE device
/// For the file-downloading process to even commence you need to be authenticated with the AED device that's being targeted.
- public interface IFileDownloader : IFileDownloaderCommandable, IFileDownloaderQueryable, IFileDownloaderEventSubscribable
+ public interface IFileDownloader :
+ IFileDownloaderCommandable,
+ IFileDownloaderQueryable,
+ IFileDownloaderEventSubscribable,
+ IDisposable
{
}
}
diff --git a/Laerdal.McuMgr/Shared/FileDownloader/Contracts/Native/INativeFileDownloaderProxy.cs b/Laerdal.McuMgr/Shared/FileDownloader/Contracts/Native/INativeFileDownloaderProxy.cs
index 00f05f0c..6d18d82c 100644
--- a/Laerdal.McuMgr/Shared/FileDownloader/Contracts/Native/INativeFileDownloaderProxy.cs
+++ b/Laerdal.McuMgr/Shared/FileDownloader/Contracts/Native/INativeFileDownloaderProxy.cs
@@ -1,6 +1,12 @@
-namespace Laerdal.McuMgr.FileDownloader.Contracts.Native
+using System;
+
+namespace Laerdal.McuMgr.FileDownloader.Contracts.Native
{
- internal interface INativeFileDownloaderProxy : INativeFileDownloaderQueryableProxy, INativeFileDownloaderCommandableProxy, INativeFileDownloaderCallbacksProxy
+ internal interface INativeFileDownloaderProxy :
+ INativeFileDownloaderQueryableProxy,
+ INativeFileDownloaderCommandableProxy,
+ INativeFileDownloaderCallbacksProxy,
+ IDisposable
{
}
}
\ No newline at end of file
diff --git a/Laerdal.McuMgr/Shared/FileDownloader/FileDownloader.cs b/Laerdal.McuMgr/Shared/FileDownloader/FileDownloader.cs
index abeb0fe7..aaf1a99d 100644
--- a/Laerdal.McuMgr/Shared/FileDownloader/FileDownloader.cs
+++ b/Laerdal.McuMgr/Shared/FileDownloader/FileDownloader.cs
@@ -28,6 +28,13 @@ internal FileDownloader(INativeFileDownloaderProxy nativeFileDownloaderProxy)
_nativeFileDownloaderProxy = nativeFileDownloaderProxy ?? throw new ArgumentNullException(nameof(nativeFileDownloaderProxy));
_nativeFileDownloaderProxy.FileDownloader = this; //vital
}
+
+ public void Dispose()
+ {
+ _nativeFileDownloaderProxy?.Dispose();
+
+ GC.SuppressFinalize(this);
+ }
public string LastFatalErrorMessage => _nativeFileDownloaderProxy?.LastFatalErrorMessage;
diff --git a/Laerdal.McuMgr/Shared/FileUploader/Contracts/IFileUploader.cs b/Laerdal.McuMgr/Shared/FileUploader/Contracts/IFileUploader.cs
index 67370a49..f416653e 100644
--- a/Laerdal.McuMgr/Shared/FileUploader/Contracts/IFileUploader.cs
+++ b/Laerdal.McuMgr/Shared/FileUploader/Contracts/IFileUploader.cs
@@ -7,7 +7,12 @@ namespace Laerdal.McuMgr.FileUploader.Contracts
{
/// Uploads a file on a specific Nordic-chip-based BLE device
/// For the file-uploading process to even commence you need to be authenticated with the AED device that's being targeted.
- public interface IFileUploader : IFileUploaderCommandable, IFileUploaderQueryable, IFileUploaderEventSubscribable, IFileUploaderCleanupable, IDisposable
+ public interface IFileUploader :
+ IFileUploaderCommandable,
+ IFileUploaderQueryable,
+ IFileUploaderEventSubscribable,
+ IFileUploaderCleanupable,
+ IDisposable
{
}
}
diff --git a/Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs b/Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs
index e4191484..3ba3fb68 100644
--- a/Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs
+++ b/Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs
@@ -31,6 +31,13 @@ internal FileUploader(INativeFileUploaderProxy nativeFileUploaderProxy)
_nativeFileUploaderProxy.FileUploader = this; //vital
}
+ public void Dispose()
+ {
+ _nativeFileUploaderProxy?.Dispose();
+
+ GC.SuppressFinalize(this);
+ }
+
public bool TrySetContext(object context) => _nativeFileUploaderProxy?.TrySetContext(context) ?? false;
public bool TrySetBluetoothDevice(object bluetoothDevice) => _nativeFileUploaderProxy?.TrySetContext(bluetoothDevice) ?? false;
public bool TryInvalidateCachedTransport() => _nativeFileUploaderProxy?.TryInvalidateCachedTransport() ?? false;
@@ -438,7 +445,5 @@ public void FileUploadProgressPercentageAndDataThroughputChangedAdvertisement(in
progressPercentage: progressPercentage
));
}
-
- public void Dispose() => _nativeFileUploaderProxy?.Dispose();
}
}
\ No newline at end of file
diff --git a/Laerdal.McuMgr/Shared/FirmwareInstaller/Contracts/IFirmwareInstaller.cs b/Laerdal.McuMgr/Shared/FirmwareInstaller/Contracts/IFirmwareInstaller.cs
index 0e4f1936..829c93e3 100644
--- a/Laerdal.McuMgr/Shared/FirmwareInstaller/Contracts/IFirmwareInstaller.cs
+++ b/Laerdal.McuMgr/Shared/FirmwareInstaller/Contracts/IFirmwareInstaller.cs
@@ -1,10 +1,16 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable EventNeverSubscribedTo.Global
+using System;
+
namespace Laerdal.McuMgr.FirmwareInstaller.Contracts
{
/// Upgrades the firmware on a specific Nordic-chip-based BLE device
- public interface IFirmwareInstaller : IFirmwareInstallerQueryable, IFirmwareInstallerEventSubscribable, IFirmwareInstallerCommandable
+ public interface IFirmwareInstaller :
+ IFirmwareInstallerQueryable,
+ IFirmwareInstallerEventSubscribable,
+ IFirmwareInstallerCommandable,
+ IDisposable
{
}
}
diff --git a/Laerdal.McuMgr/Shared/FirmwareInstaller/Contracts/Native/INativeFirmwareInstallerProxy.cs b/Laerdal.McuMgr/Shared/FirmwareInstaller/Contracts/Native/INativeFirmwareInstallerProxy.cs
index f53a8f11..1338115a 100644
--- a/Laerdal.McuMgr/Shared/FirmwareInstaller/Contracts/Native/INativeFirmwareInstallerProxy.cs
+++ b/Laerdal.McuMgr/Shared/FirmwareInstaller/Contracts/Native/INativeFirmwareInstallerProxy.cs
@@ -1,10 +1,13 @@
+using System;
+
namespace Laerdal.McuMgr.FirmwareInstaller.Contracts.Native
{
internal interface INativeFirmwareInstallerProxy :
INativeFirmwareInstallerCommandableProxy,
INativeFirmwareInstallerQueryableProxy,
INativeFirmwareInstallerCleanupableProxy,
- INativeFirmwareInstallerCallbacksProxy
+ INativeFirmwareInstallerCallbacksProxy,
+ IDisposable
{
string Nickname { get; set; }
}
diff --git a/Laerdal.McuMgr/Shared/FirmwareInstaller/FirmwareInstaller.cs b/Laerdal.McuMgr/Shared/FirmwareInstaller/FirmwareInstaller.cs
index df63d8b8..310fe576 100644
--- a/Laerdal.McuMgr/Shared/FirmwareInstaller/FirmwareInstaller.cs
+++ b/Laerdal.McuMgr/Shared/FirmwareInstaller/FirmwareInstaller.cs
@@ -29,6 +29,13 @@ internal FirmwareInstaller(INativeFirmwareInstallerProxy nativeFirmwareInstaller
_nativeFirmwareInstallerProxy = nativeFirmwareInstallerProxy ?? throw new ArgumentNullException(nameof(nativeFirmwareInstallerProxy));
_nativeFirmwareInstallerProxy.FirmwareInstaller = this; //vital
}
+
+ public void Dispose()
+ {
+ _nativeFirmwareInstallerProxy?.Dispose();
+
+ GC.SuppressFinalize(this);
+ }
public EFirmwareInstallationVerdict BeginInstallation(
byte[] data,
diff --git a/Laerdal.McuMgr/iOS/FileUploader/FileUploader.cs b/Laerdal.McuMgr/iOS/FileUploader/FileUploader.cs
index d9e9e75f..1b99a5fe 100644
--- a/Laerdal.McuMgr/iOS/FileUploader/FileUploader.cs
+++ b/Laerdal.McuMgr/iOS/FileUploader/FileUploader.cs
@@ -71,7 +71,7 @@ protected override void Dispose(bool disposing)
}
_alreadyDisposed = true;
-
+
base.Dispose(disposing);
}