Skip to content

Commit

Permalink
Fixed issue when card is updated and moved to the archive at the same…
Browse files Browse the repository at this point in the history
… time.
  • Loading branch information
reverentgeek committed Jun 12, 2015
1 parent 11d9028 commit 5ac7914
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 60 deletions.
25 changes: 14 additions & 11 deletions LeanKit.API.Client.Library/Extensions/CollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <copyright company="LeanKit Inc.">
// Copyright (c) LeanKit Inc. All rights reserved.
// </copyright>
// </copyright>
//------------------------------------------------------------------------------

using System.Collections.Generic;
Expand All @@ -16,21 +16,24 @@ public static class CollectionExtensions
public static Card FindContainedCard(this IEnumerable<Lane> lanes, long laneId, long cardId)
{
var list = lanes as IList<Lane> ?? lanes.ToList();
var candidateLane = list.FindLane(laneId);

//Get the card from the lane
var candidateCard = candidateLane.Cards.FirstOrDefault(card => card.Id == cardId);
if (list.ContainsLane(laneId))
{
var candidateLane = list.FindLane(laneId);

if (candidateCard != null) return candidateCard.ToCard();
//Get the card from the lane
var candidateCard = candidateLane.Cards.FirstOrDefault(card => card.Id == cardId);
if (candidateCard != null) return candidateCard.ToCard();
}

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

return candidateCard.ToCard();
return candidateCard2.ToCard();
}

public static Lane FindLane(this IEnumerable<Lane> lanes, long laneId)
Expand Down Expand Up @@ -82,4 +85,4 @@ public static IEnumerable<Lane> GetFlatLanes(this IEnumerable<HierarchicalLane>
}
}
}
}
}
93 changes: 54 additions & 39 deletions LeanKit.API.Client.Library/LeanKitIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <copyright company="LeanKit Inc.">
// Copyright (c) LeanKit Inc. All rights reserved.
// </copyright>
// </copyright>
//------------------------------------------------------------------------------

using System;
Expand Down Expand Up @@ -72,7 +72,7 @@ public void StartWatching(bool includeTaskboards)
private void InitBoard()
{
//setup the loop intervals
//Probably need to do this on a different thread
//Probably need to do this on a different thread
do
{
try
Expand Down Expand Up @@ -123,7 +123,7 @@ private CheckForUpdatesLoopResult SetupCheckForUpdatesLoop()
{
const int pulse = 1000;
var pollingInterval = (long) _integrationSettings.CheckForUpdatesIntervalSeconds*1000;

var stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();

Expand Down Expand Up @@ -301,7 +301,6 @@ private CheckForUpdatesLoopResult SetupCheckForUpdatesLoop()
{
OnClientError(new ClientErrorEventArgs {Exception = ex, Message = "Error checking for board events."});
}

} while (ShouldContinue);

stopWatch.Stop();
Expand Down Expand Up @@ -533,8 +532,12 @@ private CardUpdateEvent CreateCardUpdateEvent(BoardHistoryEvent boardEvent, IEnu
if (originalCard == null)
return null;

var updatedCard =
affectedLanes.FindContainedCard(boardEvent.ToLaneId, boardEvent.CardId);
var lanes = affectedLanes.ToList();

var updatedCard = (lanes.ContainsCard(boardEvent.CardId))
? lanes.FindContainedCard(boardEvent.ToLaneId, boardEvent.CardId)
: GetCard(boardEvent.CardId, true);

return new CardUpdateEvent(boardEvent.EventDateTime, originalCard, updatedCard);
}
catch (ItemNotFoundException ex)
Expand Down Expand Up @@ -566,34 +569,39 @@ private static EventType GetEventType(string eventType)

public virtual Card GetCard(long cardId)
{
Card card;
_boardLock.EnterReadLock();
try
{
card = _board.GetCardById(cardId);
}
finally
return GetCard(cardId, false);
}

public virtual Card GetCard(long cardId, bool bypassCache)
{
Card card = null;
if (!bypassCache)
{
_boardLock.ExitReadLock();
_boardLock.EnterReadLock();
try
{
card = _board.GetCardById(cardId);
}
finally
{
_boardLock.ExitReadLock();
}
}

if (card != null) return card;

// try getting card directly from the api
if (card == null)
{
var c = _api.GetCard(_boardId, cardId);
card = (c != null) ? c.ToCard() : null;
}
var c = _api.GetCard(_boardId, cardId);
card = (c != null) ? c.ToCard() : null;
if (card != null) return card;

//try to find in archive, suppose it is not loaded
if (card == null)
{
var archive = _api.GetArchiveCards(_boardId);
var firstOrDefault = (archive != null) ? archive.FirstOrDefault(x => x.Id == cardId) : null;
if (firstOrDefault != null) card = firstOrDefault.ToCard();
//TODO: need to load the archive
//Also, could be possible that the card is part of the cards older than 90 days
//In that case we my need to do a search too.
}
var archive = _api.GetArchiveCards(_boardId);
var firstOrDefault = (archive != null) ? archive.FirstOrDefault(x => x.Id == cardId) : null;
if (firstOrDefault != null) card = firstOrDefault.ToCard();
//TODO: need to load the archive
//Also, could be possible that the card is part of the cards older than 90 days
//In that case we my need to do a search too.

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

Expand Down Expand Up @@ -826,7 +834,7 @@ public void AddTask(Card task, long cardId, string wipOverrideReason)
// //ApplyBoardChanges(results.BoardVersion, new[] {results.Lane});
//} finally {
// _boardLock.ExitWriteLock();
//}
//}
}

public void UpdateTask(Card task, long cardId)
Expand All @@ -853,7 +861,7 @@ public void UpdateTask(Card task, long cardId, string wipOverrideReason)
// }
// finally {
// _boardLock.ExitWriteLock();
// }
// }
}

public void DeleteTask(long taskId, long cardId)
Expand All @@ -864,7 +872,7 @@ public void DeleteTask(long taskId, long cardId)

public void MoveTask(long taskId, long cardId, long toLaneId, int position)
{
MoveTask(taskId, cardId, toLaneId, position, string.Empty);
MoveTask(taskId, cardId, toLaneId, position, string.Empty);
}

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

[Obsolete("Creating taskboards is no longer supported", true)]
public void CreateTaskboard(long cardId, TaskboardTemplateType templateType, long cardContextId) {
public void CreateTaskboard(long cardId, TaskboardTemplateType templateType, long cardContextId)
{
//_boardLock.EnterUpgradeableReadLock();
//try
//{
Expand Down Expand Up @@ -931,7 +940,8 @@ public void CreateTaskboard(long cardId, TaskboardTemplateType templateType, lon
}

[Obsolete("Deleting taskboards is no longer supported", true)]
public void DeleteTaskboard(long cardId, long taskboardId) {
public void DeleteTaskboard(long cardId, long taskboardId)
{
//_boardLock.EnterUpgradeableReadLock();
//try
//{
Expand Down Expand Up @@ -962,12 +972,14 @@ public void DeleteTaskboard(long cardId, long taskboardId) {
}

[Obsolete("Use AddTask instead")]
public void AddTaskboardCard(Card card, long taskboardId) {
public void AddTaskboardCard(Card card, long taskboardId)
{
AddTaskboardCard(card, taskboardId, string.Empty);
}

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

[Obsolete("Use UpdateTask instead")]
public void UpdateTaskboardCard(Card card, long taskboardId) {
public void UpdateTaskboardCard(Card card, long taskboardId)
{
UpdateTaskboardCard(card, taskboardId, string.Empty);
}

[Obsolete("Use UpdateTask instead")]
public void UpdateTaskboardCard(Card card, long taskboardId, string wipOverrideReason) {
public void UpdateTaskboardCard(Card card, long taskboardId, string wipOverrideReason)
{
//var results = string.IsNullOrEmpty(wipOverrideReason)
// ? _api.UpdateTaskboardCard(_boardId, taskboardId, card)
// : _api.UpdateTaskboardCard(_boardId, taskboardId, card, wipOverrideReason);
Expand All @@ -1008,7 +1022,8 @@ public void UpdateTaskboardCard(Card card, long taskboardId, string wipOverrideR
}

[Obsolete("Use DeleteTask instead")]
public void DeleteTaskboardCard(long cardId, long taskboardId) {
public void DeleteTaskboardCard(long cardId, long taskboardId)
{
throw new NotImplementedException();
}

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

#endregion
}
}
}
16 changes: 8 additions & 8 deletions LeanKit.API.Client.Library/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//------------------------------------------------------------------------------
// <copyright company="LeanKit Inc.">
// Copyright (c) LeanKit Inc. All rights reserved.
// </copyright>
// </copyright>
//------------------------------------------------------------------------------

using System.Reflection;
using System.Runtime.InteropServices;

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

Expand All @@ -20,8 +20,8 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

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

[assembly: ComVisible(false)]
Expand All @@ -33,13 +33,13 @@
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.1.1.0")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
2 changes: 1 addition & 1 deletion publish/LeanKit.API.Client.Library.dll.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>LeanKit.API.Client</id>
<version>1.1.1</version>
<version>1.2.0</version>
<authors>LeanKit</authors>
<owners>LeanKit</owners>
<licenseUrl>https://raw.githubusercontent.com/LeanKit/LeanKit.API.Client/master/License.txt</licenseUrl>
Expand Down
2 changes: 1 addition & 1 deletion publish/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Copy latest .dll into .\lib\net40

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

`nuget push .\LeanKit.API.Client.1.1.0.nupkg`
`nuget push .\LeanKit.API.Client.1.2.0.nupkg`

0 comments on commit 5ac7914

Please sign in to comment.