Skip to content

Commit 6f8181c

Browse files
lxatstariongrouplxatrhea
authored andcommitted
Participant Role test and session fix (#204)
* Participant Role test and session fix * Refactor CanCancel and Cancel using only thread safe methods
1 parent 3c07251 commit 6f8181c

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

CDP4Common.NetCore.Tests/Poco/ParticipantRoleTestFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// --------------------------------------------------------------------------------------------------------------------
22
// <copyright file="ParticipantRoleTestFixture.cs" company="RHEA System S.A.">
3-
// Copyright (c) 2015-2020 RHEA System S.A.
3+
// Copyright (c) 2015-2021 RHEA System S.A.
44
//
5-
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou
5+
// Author: Sam Gerené, Alex Vorobiev, Naron Phou, Patxi Ozkoidi, Alexander van Delft, Nathanael Smiechowski, Ahmed Ahmed, Simon Wood
66
//
77
// This file is part of CDP4-SDK Community Edition
88
//
@@ -38,8 +38,8 @@ internal class ParticipantRoleTestFixture
3838
public void VerifyPopulateParticipantPermissions()
3939
{
4040
var participantRole = new ParticipantRole();
41-
Assert.AreEqual(48, participantRole.ParticipantPermission.Count);
41+
Assert.AreEqual(49, participantRole.ParticipantPermission.Count);
4242
Assert.IsTrue(participantRole.ParticipantPermission.All(x => x.AccessRight == ParticipantAccessRightKind.NONE));
4343
}
4444
}
45-
}
45+
}

CDP4Common.Tests/Poco/ParticipantRoleTestFixture.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#region Copyright
2-
// --------------------------------------------------------------------------------------------------------------------
1+
// --------------------------------------------------------------------------------------------------------------------
32
// <copyright file="ParticipantRoleTestFixture.cs" company="RHEA System S.A.">
4-
// Copyright (c) 2015-2019 RHEA System S.A.
3+
// Copyright (c) 2015-2021 RHEA System S.A.
54
//
6-
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou
5+
// Author: Sam Gerené, Alex Vorobiev, Naron Phou, Patxi Ozkoidi, Alexander van Delft, Nathanael Smiechowski, Ahmed Ahmed, Simon Wood
76
//
87
// This file is part of CDP4-SDK Community Edition
98
//
@@ -22,13 +21,14 @@
2221
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2322
// </copyright>
2423
// --------------------------------------------------------------------------------------------------------------------
25-
#endregion
2624

2725
namespace CDP4Common.Tests.Poco
2826
{
2927
using System.Linq;
28+
3029
using CDP4Common.CommonData;
3130
using CDP4Common.SiteDirectoryData;
31+
3232
using NUnit.Framework;
3333

3434
[TestFixture]
@@ -38,8 +38,8 @@ internal class ParticipantRoleTestFixture
3838
public void VerifyPopulateParticipantPermissions()
3939
{
4040
var participantRole = new ParticipantRole();
41-
Assert.AreEqual(48, participantRole.ParticipantPermission.Count);
41+
Assert.AreEqual(49, participantRole.ParticipantPermission.Count);
4242
Assert.IsTrue(participantRole.ParticipantPermission.All(x => x.AccessRight == ParticipantAccessRightKind.NONE));
4343
}
4444
}
45-
}
45+
}

CDP4Dal/Session.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,12 @@ private static bool CanCancel(CancellationTokenSource cancellationTokenSource)
785785
/// </returns>
786786
public bool CanCancel()
787787
{
788-
foreach (var cancellationTokenSourceKey in this.cancellationTokenSourceDictionary.Keys)
788+
foreach (var cancellationTokenSourceKey in this.cancellationTokenSourceDictionary.Keys.ToList())
789789
{
790-
this.cancellationTokenSourceDictionary.TryGetValue(cancellationTokenSourceKey, out var cancellationTokenSource);
790+
if (!this.cancellationTokenSourceDictionary.TryGetValue(cancellationTokenSourceKey, out var cancellationTokenSource))
791+
{
792+
continue;
793+
}
791794

792795
if (!CanCancel(cancellationTokenSource))
793796
{
@@ -805,11 +808,14 @@ public bool CanCancel()
805808
/// </summary>
806809
public void Cancel()
807810
{
808-
foreach (var cancellationTokenSourceKey in this.cancellationTokenSourceDictionary.Keys)
811+
foreach (var cancellationTokenSourceKey in this.cancellationTokenSourceDictionary.Keys.ToList())
809812
{
810-
if (CanCancel(this.cancellationTokenSourceDictionary[cancellationTokenSourceKey]))
813+
if (this.cancellationTokenSourceDictionary.TryGetValue(cancellationTokenSourceKey, out var cancellationTokenSource))
811814
{
812-
this.cancellationTokenSourceDictionary[cancellationTokenSourceKey].Cancel();
815+
if (CanCancel(cancellationTokenSource))
816+
{
817+
cancellationTokenSource.Cancel();
818+
}
813819
}
814820
}
815821
}

0 commit comments

Comments
 (0)