aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--RhSolutions.AddIn/Controllers/RibbonController.cs2
-rw-r--r--RhSolutions.AddIn/Services/IExcelReader.cs3
-rw-r--r--RhSolutions.AddIn/Services/IExcelWriter.cs3
-rw-r--r--RhSolutions.AddIn/Tools/ToolBase.cs8
4 files changed, 12 insertions, 4 deletions
diff --git a/RhSolutions.AddIn/Controllers/RibbonController.cs b/RhSolutions.AddIn/Controllers/RibbonController.cs
index 0e82060..efc0d15 100644
--- a/RhSolutions.AddIn/Controllers/RibbonController.cs
+++ b/RhSolutions.AddIn/Controllers/RibbonController.cs
@@ -63,7 +63,7 @@ public class RibbonController : ExcelRibbon
{
try
{
- ToolBase tool = control.Id switch
+ using ToolBase tool = control.Id switch
{
"export" => new ExportTool(),
"convert" => new ConvertTool(),
diff --git a/RhSolutions.AddIn/Services/IExcelReader.cs b/RhSolutions.AddIn/Services/IExcelReader.cs
index a134e4c..897d452 100644
--- a/RhSolutions.AddIn/Services/IExcelReader.cs
+++ b/RhSolutions.AddIn/Services/IExcelReader.cs
@@ -1,8 +1,9 @@
namespace RhSolutions.Services;
-public interface IExcelReader
+public interface IExcelReader : IDisposable
{
public Dictionary<Product, double> ReadProducts(Range range);
public List<(string, Dictionary<Product, double>)> ReadProducts(IEnumerable<Worksheet> worksheets);
public List<(string, Dictionary<Product, double>)> ReadProducts(string[] files);
+ new void Dispose();
}
diff --git a/RhSolutions.AddIn/Services/IExcelWriter.cs b/RhSolutions.AddIn/Services/IExcelWriter.cs
index 5d2ea29..ea6bf5a 100644
--- a/RhSolutions.AddIn/Services/IExcelWriter.cs
+++ b/RhSolutions.AddIn/Services/IExcelWriter.cs
@@ -1,7 +1,8 @@
namespace RhSolutions.Services;
-public interface IExcelWriter
+public interface IExcelWriter : IDisposable
{
public void WriteProducts(IEnumerable<(string, Dictionary<Product, double>)> products);
public void WriteProducts(Dictionary<Product, double> products);
+ new void Dispose();
}
diff --git a/RhSolutions.AddIn/Tools/ToolBase.cs b/RhSolutions.AddIn/Tools/ToolBase.cs
index 9c37bc3..518cefe 100644
--- a/RhSolutions.AddIn/Tools/ToolBase.cs
+++ b/RhSolutions.AddIn/Tools/ToolBase.cs
@@ -7,7 +7,7 @@ namespace RhSolutions.Tools;
#if !NET472
[SupportedOSPlatform("windows")]
#endif
-internal abstract class ToolBase
+internal abstract class ToolBase : IDisposable
{
protected readonly IExcelReader _reader;
protected readonly IExcelWriter _writer;
@@ -18,5 +18,11 @@ internal abstract class ToolBase
_writer = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IExcelWriter>();
}
+ public void Dispose()
+ {
+ _reader.Dispose();
+ _writer.Dispose();
+ }
+
public abstract void Execute();
} \ No newline at end of file