Skip to content

Commit 5ac7914

Browse files
committed
Fixed issue when card is updated and moved to the archive at the same time.
1 parent 11d9028 commit 5ac7914

5 files changed

Lines changed: 78 additions & 60 deletions

File tree

LeanKit.API.Client.Library/Extensions/CollectionExtensions.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
// <copyright company="LeanKit Inc.">
33
// Copyright (c) LeanKit Inc. All rights reserved.
4-
// </copyright>
4+
// </copyright>
55
//------------------------------------------------------------------------------
66

77
using System.Collections.Generic;
@@ -16,21 +16,24 @@ public static class CollectionExtensions
1616
public static Card FindContainedCard(this IEnumerable<Lane> lanes, long laneId, long cardId)
1717
{
1818
var list = lanes as IList<Lane> ?? lanes.ToList();
19-
var candidateLane = list.FindLane(laneId);
20-
21-
//Get the card from the lane
22-
var candidateCard = candidateLane.Cards.FirstOrDefault(card => card.Id == cardId);
19+
if (list.ContainsLane(laneId))
20+
{
21+
var candidateLane = list.FindLane(laneId);
2322

24-
if (candidateCard != null) return candidateCard.ToCard();
23+
//Get the card from the lane
24+
var candidateCard = candidateLane.Cards.FirstOrDefault(card => card.Id == cardId);
25+
if (candidateCard != null) return candidateCard.ToCard();
26+
}
2527

2628
//the card may have been moved so look in all the affected lanes
27-
candidateCard = list.SelectMany(x => x.Cards).FirstOrDefault(card => card.Id == cardId);
28-
if (candidateCard == null)
29+
var candidateCard2 = list.SelectMany(x => x.Cards).FirstOrDefault(card => card.Id == cardId);
30+
if (candidateCard2 == null)
2931
{
30-
throw new ItemNotFoundException(string.Format("Unable to find the Card [{0}] in the associated Lane [{1}].", cardId, laneId));
32+
throw new ItemNotFoundException(string.Format("Unable to find the Card [{0}] in the associated Lane [{1}].", cardId,
33+
laneId));
3134
}
3235

33-
return candidateCard.ToCard();
36+
return candidateCard2.ToCard();
3437
}
3538

3639
public static Lane FindLane(this IEnumerable<Lane> lanes, long laneId)
@@ -82,4 +85,4 @@ public static IEnumerable<Lane> GetFlatLanes(this IEnumerable<HierarchicalLane>
8285
}
8386
}
8487
}
85-
}
88+
}

LeanKit.API.Client.Library/LeanKitIntegration.cs

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
// <copyright company="LeanKit Inc.">
33
// Copyright (c) LeanKit Inc. All rights reserved.
4-
// </copyright>
4+
// </copyright>
55
//------------------------------------------------------------------------------
66

77
using System;
@@ -72,7 +72,7 @@ public void StartWatching(bool includeTaskboards)
7272
private void InitBoard()
7373
{
7474
//setup the loop intervals
75-
//Probably need to do this on a different thread
75+
//Probably need to do this on a different thread
7676
do
7777
{
7878
try
@@ -123,7 +123,7 @@ private CheckForUpdatesLoopResult SetupCheckForUpdatesLoop()
123123
{
124124
const int pulse = 1000;
125125
var pollingInterval = (long) _integrationSettings.CheckForUpdatesIntervalSeconds*1000;
126-
126+
127127
var stopWatch = new System.Diagnostics.Stopwatch();
128128
stopWatch.Start();
129129

@@ -301,7 +301,6 @@ private CheckForUpdatesLoopResult SetupCheckForUpdatesLoop()
301301
{
302302
OnClientError(new ClientErrorEventArgs {Exception = ex, Message = "Error checking for board events."});
303303
}
304-
305304
} while (ShouldContinue);
306305

307306
stopWatch.Stop();
@@ -533,8 +532,12 @@ private CardUpdateEvent CreateCardUpdateEvent(BoardHistoryEvent boardEvent, IEnu
533532
if (originalCard == null)
534533
return null;
535534

536-
var updatedCard =
537-
affectedLanes.FindContainedCard(boardEvent.ToLaneId, boardEvent.CardId);
535+
var lanes = affectedLanes.ToList();
536+
537+
var updatedCard = (lanes.ContainsCard(boardEvent.CardId))
538+
? lanes.FindContainedCard(boardEvent.ToLaneId, boardEvent.CardId)
539+
: GetCard(boardEvent.CardId, true);
540+
538541
return new CardUpdateEvent(boardEvent.EventDateTime, originalCard, updatedCard);
539542
}
540543
catch (ItemNotFoundException ex)
@@ -566,34 +569,39 @@ private static EventType GetEventType(string eventType)
566569

567570
public virtual Card GetCard(long cardId)
568571
{
569-
Card card;
570-
_boardLock.EnterReadLock();
571-
try
572-
{
573-
card = _board.GetCardById(cardId);
574-
}
575-
finally
572+
return GetCard(cardId, false);
573+
}
574+
575+
public virtual Card GetCard(long cardId, bool bypassCache)
576+
{
577+
Card card = null;
578+
if (!bypassCache)
576579
{
577-
_boardLock.ExitReadLock();
580+
_boardLock.EnterReadLock();
581+
try
582+
{
583+
card = _board.GetCardById(cardId);
584+
}
585+
finally
586+
{
587+
_boardLock.ExitReadLock();
588+
}
578589
}
579590

591+
if (card != null) return card;
592+
580593
// try getting card directly from the api
581-
if (card == null)
582-
{
583-
var c = _api.GetCard(_boardId, cardId);
584-
card = (c != null) ? c.ToCard() : null;
585-
}
594+
var c = _api.GetCard(_boardId, cardId);
595+
card = (c != null) ? c.ToCard() : null;
596+
if (card != null) return card;
586597

587598
//try to find in archive, suppose it is not loaded
588-
if (card == null)
589-
{
590-
var archive = _api.GetArchiveCards(_boardId);
591-
var firstOrDefault = (archive != null) ? archive.FirstOrDefault(x => x.Id == cardId) : null;
592-
if (firstOrDefault != null) card = firstOrDefault.ToCard();
593-
//TODO: need to load the archive
594-
//Also, could be possible that the card is part of the cards older than 90 days
595-
//In that case we my need to do a search too.
596-
}
599+
var archive = _api.GetArchiveCards(_boardId);
600+
var firstOrDefault = (archive != null) ? archive.FirstOrDefault(x => x.Id == cardId) : null;
601+
if (firstOrDefault != null) card = firstOrDefault.ToCard();
602+
//TODO: need to load the archive
603+
//Also, could be possible that the card is part of the cards older than 90 days
604+
//In that case we my need to do a search too.
597605

598606
if (card == null) throw new ItemNotFoundException();
599607

@@ -826,7 +834,7 @@ public void AddTask(Card task, long cardId, string wipOverrideReason)
826834
// //ApplyBoardChanges(results.BoardVersion, new[] {results.Lane});
827835
//} finally {
828836
// _boardLock.ExitWriteLock();
829-
//}
837+
//}
830838
}
831839

832840
public void UpdateTask(Card task, long cardId)
@@ -853,7 +861,7 @@ public void UpdateTask(Card task, long cardId, string wipOverrideReason)
853861
// }
854862
// finally {
855863
// _boardLock.ExitWriteLock();
856-
// }
864+
// }
857865
}
858866

859867
public void DeleteTask(long taskId, long cardId)
@@ -864,7 +872,7 @@ public void DeleteTask(long taskId, long cardId)
864872

865873
public void MoveTask(long taskId, long cardId, long toLaneId, int position)
866874
{
867-
MoveTask(taskId, cardId, toLaneId, position, string.Empty);
875+
MoveTask(taskId, cardId, toLaneId, position, string.Empty);
868876
}
869877

870878
public void MoveTask(long taskId, long cardId, long toLaneId, int position, string wipOverrideReason)
@@ -901,7 +909,8 @@ public DrillThroughStatistics GetDrillThroughStatistics(long boardId, long cardI
901909
#region obsolete
902910

903911
[Obsolete("Creating taskboards is no longer supported", true)]
904-
public void CreateTaskboard(long cardId, TaskboardTemplateType templateType, long cardContextId) {
912+
public void CreateTaskboard(long cardId, TaskboardTemplateType templateType, long cardContextId)
913+
{
905914
//_boardLock.EnterUpgradeableReadLock();
906915
//try
907916
//{
@@ -931,7 +940,8 @@ public void CreateTaskboard(long cardId, TaskboardTemplateType templateType, lon
931940
}
932941

933942
[Obsolete("Deleting taskboards is no longer supported", true)]
934-
public void DeleteTaskboard(long cardId, long taskboardId) {
943+
public void DeleteTaskboard(long cardId, long taskboardId)
944+
{
935945
//_boardLock.EnterUpgradeableReadLock();
936946
//try
937947
//{
@@ -962,12 +972,14 @@ public void DeleteTaskboard(long cardId, long taskboardId) {
962972
}
963973

964974
[Obsolete("Use AddTask instead")]
965-
public void AddTaskboardCard(Card card, long taskboardId) {
975+
public void AddTaskboardCard(Card card, long taskboardId)
976+
{
966977
AddTaskboardCard(card, taskboardId, string.Empty);
967978
}
968979

969980
[Obsolete("Use AddTask instead")]
970-
public void AddTaskboardCard(Card card, long taskboardId, string wipOverrideReason) {
981+
public void AddTaskboardCard(Card card, long taskboardId, string wipOverrideReason)
982+
{
971983
//var results = string.IsNullOrEmpty(wipOverrideReason)
972984
// ? _api.AddTaskboardCard(_boardId, taskboardId, card)
973985
// : _api.AddTaskboardCard(_boardId, taskboardId, card, wipOverrideReason);
@@ -982,12 +994,14 @@ public void AddTaskboardCard(Card card, long taskboardId, string wipOverrideReas
982994
}
983995

984996
[Obsolete("Use UpdateTask instead")]
985-
public void UpdateTaskboardCard(Card card, long taskboardId) {
997+
public void UpdateTaskboardCard(Card card, long taskboardId)
998+
{
986999
UpdateTaskboardCard(card, taskboardId, string.Empty);
9871000
}
9881001

9891002
[Obsolete("Use UpdateTask instead")]
990-
public void UpdateTaskboardCard(Card card, long taskboardId, string wipOverrideReason) {
1003+
public void UpdateTaskboardCard(Card card, long taskboardId, string wipOverrideReason)
1004+
{
9911005
//var results = string.IsNullOrEmpty(wipOverrideReason)
9921006
// ? _api.UpdateTaskboardCard(_boardId, taskboardId, card)
9931007
// : _api.UpdateTaskboardCard(_boardId, taskboardId, card, wipOverrideReason);
@@ -1008,7 +1022,8 @@ public void UpdateTaskboardCard(Card card, long taskboardId, string wipOverrideR
10081022
}
10091023

10101024
[Obsolete("Use DeleteTask instead")]
1011-
public void DeleteTaskboardCard(long cardId, long taskboardId) {
1025+
public void DeleteTaskboardCard(long cardId, long taskboardId)
1026+
{
10121027
throw new NotImplementedException();
10131028
}
10141029

@@ -1028,4 +1043,4 @@ public void MoveTaskboardCard(long cardId, long taskboardId, long toLaneId, int
10281043

10291044
#endregion
10301045
}
1031-
}
1046+
}

LeanKit.API.Client.Library/Properties/AssemblyInfo.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//------------------------------------------------------------------------------
22
// <copyright company="LeanKit Inc.">
33
// Copyright (c) LeanKit Inc. All rights reserved.
4-
// </copyright>
4+
// </copyright>
55
//------------------------------------------------------------------------------
66

77
using System.Reflection;
88
using System.Runtime.InteropServices;
99

10-
// General Information about an assembly is controlled through the following
10+
// General Information about an assembly is controlled through the following
1111
// set of attributes. Change these attribute values to modify the information
1212
// associated with an assembly.
1313

@@ -20,8 +20,8 @@
2020
[assembly: AssemblyTrademark("")]
2121
[assembly: AssemblyCulture("")]
2222

23-
// Setting ComVisible to false makes the types in this assembly not visible
24-
// to COM components. If you need to access a type in this assembly from
23+
// Setting ComVisible to false makes the types in this assembly not visible
24+
// to COM components. If you need to access a type in this assembly from
2525
// COM, set the ComVisible attribute to true on that type.
2626

2727
[assembly: ComVisible(false)]
@@ -33,13 +33,13 @@
3333
// Version information for an assembly consists of the following four values:
3434
//
3535
// Major Version
36-
// Minor Version
36+
// Minor Version
3737
// Build Number
3838
// Revision
3939
//
40-
// You can specify all the values or you can default the Build and Revision Numbers
40+
// You can specify all the values or you can default the Build and Revision Numbers
4141
// by using the '*' as shown below:
4242
// [assembly: AssemblyVersion("1.0.*")]
4343

44-
[assembly: AssemblyVersion("1.1.1.0")]
45-
[assembly: AssemblyFileVersion("1.1.1.0")]
44+
[assembly: AssemblyVersion("1.2.0.0")]
45+
[assembly: AssemblyFileVersion("1.2.0.0")]

publish/LeanKit.API.Client.Library.dll.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>LeanKit.API.Client</id>
5-
<version>1.1.1</version>
5+
<version>1.2.0</version>
66
<authors>LeanKit</authors>
77
<owners>LeanKit</owners>
88
<licenseUrl>https://raw.githubusercontent.com/LeanKit/LeanKit.API.Client/master/License.txt</licenseUrl>

publish/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Copy latest .dll into .\lib\net40
66

77
`nuget pack .\LeanKit.API.Client.Library.dll.nuspec`
88

9-
`nuget push .\LeanKit.API.Client.1.1.0.nupkg`
9+
`nuget push .\LeanKit.API.Client.1.2.0.nupkg`

0 commit comments

Comments
 (0)