Skip to content
This repository has been archived by the owner on Dec 29, 2021. It is now read-only.

Commit

Permalink
Extracted appropriate interfaces. Removed Nito.AsyncEx dependency. Wo…
Browse files Browse the repository at this point in the history
…rkItemStore pooling works now properly.
  • Loading branch information
joergbattermann committed Feb 11, 2012
1 parent 0f9e546 commit 15f03d1
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 220 deletions.
6 changes: 3 additions & 3 deletions JB.Tfs.Common/GlobalList.cs
Expand Up @@ -10,7 +10,7 @@

namespace JB.Tfs.Common
{
public class GlobalList
public class GlobalList : IGlobalList
{
private const string GlobalListsListItemIdentifier = "LISTITEM";

Expand All @@ -22,7 +22,7 @@ public class GlobalList
/// <summary>
/// Gets the values.
/// </summary>
public IList<string> Values
public IEnumerable<string> Values
{
get { return _values.AsReadOnly(); }
}
Expand Down Expand Up @@ -65,7 +65,7 @@ internal GlobalList(XmlElement globalListXmlElement)
/// </summary>
/// <param name="globalListXmlElement">The global list XML element.</param>
/// <returns></returns>
private IEnumerable<string> GetGlobalListItemValues(XmlElement globalListXmlElement)
public IEnumerable<string> GetGlobalListItemValues(XmlElement globalListXmlElement)
{
if (globalListXmlElement == null) throw new ArgumentNullException("globalListXmlElement");

Expand Down
145 changes: 1 addition & 144 deletions JB.Tfs.Common/GlobalListCollection.cs
Expand Up @@ -13,7 +13,7 @@

namespace JB.Tfs.Common
{
public class GlobalListCollection : IList<GlobalList>
public class GlobalListCollection : IGlobalListCollection
{
private readonly List<GlobalList> _globalListCollection = new List<GlobalList>();

Expand Down Expand Up @@ -154,148 +154,5 @@ IEnumerator IEnumerable.GetEnumerator()
}

#endregion

#region Implementation of ICollection<GlobalList>

/// <summary>
/// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"/>.
/// </summary>
/// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.</exception>
public void Add(GlobalList item)
{
if (item == null) throw new ArgumentNullException("item");
_globalListCollection.Add(item);
}

/// <summary>
/// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1"/>.
/// </summary>
/// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only. </exception>
public void Clear()
{
_globalListCollection.Clear();
}

/// <summary>
/// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"/> contains a specific value.
/// </summary>
/// <returns>
/// true if <paramref name="item"/> is found in the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false.
/// </returns>
/// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
public bool Contains(GlobalList item)
{
return _globalListCollection.Contains(item);
}

/// <summary>
/// Copies the elements of the <see cref="T:System.Collections.Generic.ICollection`1"/> to an <see cref="T:System.Array"/>, starting at a particular <see cref="T:System.Array"/> index.
/// </summary>
/// <param name="array">The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see cref="T:System.Collections.Generic.ICollection`1"/>. The <see cref="T:System.Array"/> must have zero-based indexing.</param><param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="arrayIndex"/> is less than 0.</exception><exception cref="T:System.ArgumentException"><paramref name="array"/> is multidimensional.-or-The number of elements in the source <see cref="T:System.Collections.Generic.ICollection`1"/> is greater than the available space from <paramref name="arrayIndex"/> to the end of the destination <paramref name="array"/>.-or-Type <paramref name="T"/> cannot be cast automatically to the type of the destination <paramref name="array"/>.</exception>
public void CopyTo(GlobalList[] array, int arrayIndex)
{
_globalListCollection.CopyTo(array, arrayIndex);
}

/// <summary>
/// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1"/>.
/// </summary>
/// <returns>
/// true if <paramref name="item"/> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false. This method also returns false if <paramref name="item"/> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1"/>.
/// </returns>
/// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.</exception>
public bool Remove(GlobalList item)
{
return _globalListCollection.Remove(item);
}

/// <summary>
/// Gets the number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>.
/// </summary>
/// <returns>
/// The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>.
/// </returns>
public int Count
{
get { return _globalListCollection.Count; }
}

/// <summary>
/// Gets a value indicating whether the <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.
/// </summary>
/// <returns>
/// true if the <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only; otherwise, false.
/// </returns>
public bool IsReadOnly
{
get { return true; } // Writing / Saving not yet supported
}

#endregion

#region Implementation of IList<GlobalList>

/// <summary>
/// Determines the index of a specific item in the <see cref="T:System.Collections.Generic.IList`1"/>.
/// </summary>
/// <returns>
/// The index of <paramref name="item"/> if found in the list; otherwise, -1.
/// </returns>
/// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.IList`1"/>.</param>
public int IndexOf(GlobalList item)
{
return _globalListCollection.IndexOf(item);
}

/// <summary>
/// Inserts an item to the <see cref="T:System.Collections.Generic.IList`1"/> at the specified index.
/// </summary>
/// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param><param name="item">The object to insert into the <see cref="T:System.Collections.Generic.IList`1"/>.</param><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is not a valid index in the <see cref="T:System.Collections.Generic.IList`1"/>.</exception><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.IList`1"/> is read-only.</exception>
public void Insert(int index, GlobalList item)
{
_globalListCollection.Insert(index, item);
}

/// <summary>
/// Removes the <see cref="T:System.Collections.Generic.IList`1"/> item at the specified index.
/// </summary>
/// <param name="index">The zero-based index of the item to remove.</param><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is not a valid index in the <see cref="T:System.Collections.Generic.IList`1"/>.</exception><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.IList`1"/> is read-only.</exception>
public void RemoveAt(int index)
{
_globalListCollection.RemoveAt(index);
}

/// <summary>
/// Gets or sets the element at the specified index.
/// </summary>
/// <returns>
/// The element at the specified index.
/// </returns>
/// <param name="index">The zero-based index of the element to get or set.</param><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is not a valid index in the <see cref="T:System.Collections.Generic.IList`1"/>.</exception><exception cref="T:System.NotSupportedException">The property is set and the <see cref="T:System.Collections.Generic.IList`1"/> is read-only.</exception>
public GlobalList this[int index]
{
get
{
return _globalListCollection[index];
}
set
{
_globalListCollection[index] = value;
}
}

/// <summary>
/// Gets the <see cref="GlobalList">GlobalList</see>
/// with the specified name.
/// </summary>
public GlobalList this[string name]
{
get
{
return _globalListCollection.FirstOrDefault(globalList => globalList.Name.Equals(name));
}
}

#endregion
}
}
31 changes: 31 additions & 0 deletions JB.Tfs.Common/IGlobalList.cs
@@ -0,0 +1,31 @@
// <copyright file="IGlobalList.cs" company="Joerg Battermann">
// (c) 2012 Joerg Battermann.
// License: Microsoft Public License (Ms-PL). For details see https://github.com/jbattermann/JB.Tfs.Common/blob/master/LICENSE
// </copyright>
// <author>Joerg Battermann</author>

namespace JB.Tfs.Common
{
using System.Collections.Generic;
using System.Xml;

public interface IGlobalList
{
/// <summary>
/// Gets the name.
/// </summary>
string Name { get; }

/// <summary>
/// Gets the values.
/// </summary>
IEnumerable<string> Values { get; }

/// <summary>
/// Gets the global list item values.
/// </summary>
/// <param name="globalListXmlElement">The global list XML element.</param>
/// <returns></returns>
IEnumerable<string> GetGlobalListItemValues(XmlElement globalListXmlElement);
}
}
24 changes: 24 additions & 0 deletions JB.Tfs.Common/IGlobalListCollection.cs
@@ -0,0 +1,24 @@
// <copyright file="IGlobalListCollection.cs" company="Joerg Battermann">
// (c) 2012 Joerg Battermann.
// License: Microsoft Public License (Ms-PL). For details see https://github.com/jbattermann/JB.Tfs.Common/blob/master/LICENSE
// </copyright>
// <author>Joerg Battermann</author>

namespace JB.Tfs.Common
{
using System.Collections.Generic;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

public interface IGlobalListCollection : IEnumerable<GlobalList>
{
/// <summary>
/// Saves the data to the team foundation server.
/// </summary>
void Save(WorkItemStore workItemStore);

/// <summary>
/// Refreshes the data from the team foundation server.
/// </summary>
void Refresh(WorkItemStore workItemStore);
}
}
31 changes: 31 additions & 0 deletions JB.Tfs.Common/IPooledWorkItemStore.cs
@@ -0,0 +1,31 @@
// <copyright file="IPooledWorkItemStore.cs" company="Joerg Battermann">
// (c) 2012 Joerg Battermann.
// License: Microsoft Public License (Ms-PL). For details see https://github.com/jbattermann/JB.Tfs.Common/blob/master/LICENSE
// </copyright>
// <author>Joerg Battermann</author>

namespace JB.Tfs.Common
{
using System;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

public interface IPooledWorkItemStore : IDisposable
{
/// <summary>
/// Gets the work item store.
/// </summary>
WorkItemStore WorkItemStore { get; }

/// <summary>
/// Gets the parent work item store connection pool.
/// </summary>
WorkItemStoreConnectionPool WorkItemStoreConnectionPool { get; }

/// <summary>
/// Tries to release the underlying WorkItemStore back to pool. Cannot be used safely anymore afterwards.
/// </summary>
/// <param name="retryAttempts">The retry attempts.</param>
/// <returns>True if successful, otherwise false.</returns>
bool TryRelease(int retryAttempts = 0);
}
}
44 changes: 44 additions & 0 deletions JB.Tfs.Common/IWorkItemStoreConnectionPool.cs
@@ -0,0 +1,44 @@
// <copyright file="IWorkItemStoreConnectionPool.cs" company="Joerg Battermann">
// (c) 2012 Joerg Battermann.
// License: Microsoft Public License (Ms-PL). For details see https://github.com/jbattermann/JB.Tfs.Common/blob/master/LICENSE
// </copyright>
// <author>Joerg Battermann</author>

namespace JB.Tfs.Common
{
using System;

public interface IWorkItemStoreConnectionPool : IDisposable
{
/// <summary>
/// Increases the size of the pool.
/// </summary>
/// <param name="increaseBy">The amount of stores to increase the pool by.</param>
void IncreasePoolSize(int increaseBy = 1);

/// <summary>
/// Decreases the size of the pool.
/// </summary>
/// <param name="decreaseBy">The amount of stores to decrease the pool by.</param>
void DecreasePoolSize(int decreaseBy = 1);

/// <summary>
/// Tries to get and reserve an avalable, pooled <see cref="T:Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore"/>.
/// Important: Use the using(..) construct or call .Dispose() when done to release the work item store back to the pool.
/// </summary>
/// <returns></returns>
PooledWorkItemStore TryGetWorkItemStore();

/// <summary>
/// Gets the used work item stores count.
/// </summary>
/// <returns></returns>
int GetUsedWorkItemStoresCount();

/// <summary>
/// Gets the available work item stores count.
/// </summary>
/// <returns></returns>
int GetAvailableWorkItemStoresCount();
}
}
4 changes: 4 additions & 0 deletions JB.Tfs.Common/JB.Tfs.Common.csproj
Expand Up @@ -47,6 +47,10 @@
<ItemGroup>
<Compile Include="GlobalList.cs" />
<Compile Include="GlobalListCollection.cs" />
<Compile Include="IGlobalList.cs" />
<Compile Include="IGlobalListCollection.cs" />
<Compile Include="IPooledWorkItemStore.cs" />
<Compile Include="IWorkItemStoreConnectionPool.cs" />
<Compile Include="PooledWorkItemStore.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QueryExtensions.cs" />
Expand Down

0 comments on commit 15f03d1

Please sign in to comment.