From 11a1b9c8283c2711f4ffa1707dfec628f11a4387 Mon Sep 17 00:00:00 2001 From: Simon G Date: Tue, 22 Sep 2020 14:06:22 +0200 Subject: [PATCH] - pass cancellationToken where needed --- GBase/GBase.cs | 4 ++-- GBase/GBaseTable.cs | 5 +++-- GBase/Interfaces/IGBase.cs | 2 +- GBase/Interfaces/IGBaseTable.cs | 3 ++- Test.GBase/GBaseIntegrationTest/Model.cs | 8 ++++---- Test.GBase/GBaseTableIntegrationTest.cs | 8 +++++--- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/GBase/GBase.cs b/GBase/GBase.cs index 91ff813..b449665 100644 --- a/GBase/GBase.cs +++ b/GBase/GBase.cs @@ -118,13 +118,13 @@ namespace GBase return Tables.Remove(table); } - public async Task AddEntry(T entry) where T : INotifyGBaseEntryChanged + public async Task AddEntry(T entry, CancellationToken cancellationToken) where T : INotifyGBaseEntryChanged { IGBaseTable table = GetTable(); if (table == null) throw new Exception(); //TODO: Create exception - return await table.AddEntry(entry); + return await table.AddEntry(entry, cancellationToken); } /// diff --git a/GBase/GBaseTable.cs b/GBase/GBaseTable.cs index 10bd705..790c9b5 100644 --- a/GBase/GBaseTable.cs +++ b/GBase/GBaseTable.cs @@ -118,13 +118,14 @@ namespace GBase /// Add an entry that implements to this /// /// The entry implementing + /// /// True if successful, false if not - public async Task AddEntry(T entry) + public async Task AddEntry(T entry, CancellationToken cancellationToken) { Entries.Add(entry); entry.GBaseEntryChanged += OnGBaseEntryChanged; - await _fileHandler.AddEntry(entry, this, TODO); + await _fileHandler.AddEntry(entry, this, cancellationToken); return true; } diff --git a/GBase/Interfaces/IGBase.cs b/GBase/Interfaces/IGBase.cs index 380d7cc..b49e0be 100644 --- a/GBase/Interfaces/IGBase.cs +++ b/GBase/Interfaces/IGBase.cs @@ -58,6 +58,6 @@ namespace GBase.Interfaces /// True if successful, false if not bool RemoveTable(IGBaseTable table); - Task AddEntry(T entry) where T : INotifyGBaseEntryChanged; + Task AddEntry(T entry, CancellationToken cancellationToken) where T : INotifyGBaseEntryChanged; } } \ No newline at end of file diff --git a/GBase/Interfaces/IGBaseTable.cs b/GBase/Interfaces/IGBaseTable.cs index e72bb9e..ca18623 100644 --- a/GBase/Interfaces/IGBaseTable.cs +++ b/GBase/Interfaces/IGBaseTable.cs @@ -21,8 +21,9 @@ namespace GBase.Interfaces /// Add an entry that implements to this /// /// The entry implementing + /// /// True if successful, false if not - Task AddEntry(T entry); + Task AddEntry(T entry, CancellationToken cancellationToken); //T GetEntry(T entry); //TODO: This doesn't make sense... (passing instance of T to get the same instance back...) diff --git a/Test.GBase/GBaseIntegrationTest/Model.cs b/Test.GBase/GBaseIntegrationTest/Model.cs index 8253bc1..ca58085 100644 --- a/Test.GBase/GBaseIntegrationTest/Model.cs +++ b/Test.GBase/GBaseIntegrationTest/Model.cs @@ -36,16 +36,16 @@ namespace Test.GBase.GBaseIntegrationTest Groups = groupsTable.Entries; } - public void AddItem(IItem item) + public void AddItem(IItem item, CancellationToken cancellationToken) { Items.Add(item); - _gBase.AddEntry(item); + _gBase.AddEntry(item, cancellationToken); } - public void AddGroup(IGroup group) + public void AddGroup(IGroup group, CancellationToken cancellationToken) { Groups.Add(group); - _gBase.AddEntry(@group); + _gBase.AddEntry(group, cancellationToken); } } } \ No newline at end of file diff --git a/Test.GBase/GBaseTableIntegrationTest.cs b/Test.GBase/GBaseTableIntegrationTest.cs index 8ec77c1..0bb97ff 100644 --- a/Test.GBase/GBaseTableIntegrationTest.cs +++ b/Test.GBase/GBaseTableIntegrationTest.cs @@ -27,13 +27,15 @@ namespace Test.GBase gBaseColumnFactoryMock.Setup(c => c.Create()).Returns(new GBaseColumn()); IGBaseTable table = new GBaseTable(fileHandlerFactoryMock.Object, gBaseColumnFactoryMock.Object); - table.Init(typeof(Foo), "", TODO, CancellationToken.None); + table.Init(typeof(Foo), "", "", CancellationToken.None); + CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); + Foo foo = new Foo("Test"); - table.AddEntry(foo); + table.AddEntry(foo, cancellationTokenSource.Token); Foo foo2 = new Foo("Test2"); - table.AddEntry(foo2); + table.AddEntry(foo2, cancellationTokenSource.Token); foo.Name = "Foo - ex Test"; foo2.Name = "Some Name";