Skip to content

Commit

Permalink
Feature/nuget semver (#5)
Browse files Browse the repository at this point in the history
* Added gitversion file

* Added TraceQueue test and updated nuspec

* Ran code cleanup to remove unused using statements

* Removing merge-message-formats field from GitVersion.yml

* Updated nuget package info in knightwarecore.csproj

* Added some additional unit  tests
  • Loading branch information
dsmithson authored Nov 28, 2019
1 parent 20414c5 commit 949f0ea
Show file tree
Hide file tree
Showing 54 changed files with 325 additions and 287 deletions.
8 changes: 3 additions & 5 deletions src/KnightwareCore/Collections/CompositeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knightware.Collections
{
Expand All @@ -18,7 +16,7 @@ public ObservableCollection<IList> Collections
{
get { return collections; }
}

public event NotifyCollectionChangedEventHandler CollectionChanged;

protected void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Expand Down Expand Up @@ -59,7 +57,7 @@ void collections_CollectionChanged(object sender, NotifyCollectionChangedEventAr
if (e.Action == NotifyCollectionChangedAction.Reset)
{
//De-register all items
while(registeredNotifyingCollections.Count > 0)
while (registeredNotifyingCollections.Count > 0)
{
registeredNotifyingCollections[0].CollectionChanged -= observable_CollectionChanged;
registeredNotifyingCollections.RemoveAt(0);
Expand All @@ -74,7 +72,7 @@ void collections_CollectionChanged(object sender, NotifyCollectionChangedEventAr
if (observable != null)
{
observable.CollectionChanged -= observable_CollectionChanged;
if(registeredNotifyingCollections.Contains(observable))
if (registeredNotifyingCollections.Contains(observable))
registeredNotifyingCollections.Remove(observable);
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/KnightwareCore/Collections/Grouping.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knightware.Collections
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Collections.Specialized;

namespace Knightware.Collections
{
Expand Down
26 changes: 12 additions & 14 deletions src/KnightwareCore/Collections/ListExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knightware.Collections
{
Expand All @@ -23,15 +21,15 @@ public static void CopyTo<T, U, K>(this IEnumerable<T> source, IList<U> destinat
/// Synchronizes a destination list of items from a provided source list, constrained by the type of object
/// </summary>
public static void ConstrainedCopyTo<T, U, K, C>(this IEnumerable<T> source, IList<U> destination, Func<T, K> getSourceKey, Func<C, K> getDestKey, Func<T, C> createNew, Action<T, C> copyFrom, Action<U> onRemoved = null)
where C: U
where C : U
{
ConstrainedCopyTo<T,U,K>(
ConstrainedCopyTo<T, U, K>(
source,
destination,
(item) => item is C,
getSourceKey,
(item) => getDestKey((C)item),
(item) => (U)createNew(item),
(item) => createNew(item),
(from, to) => copyFrom(from, (C)to),
(removed) =>
{
Expand All @@ -42,13 +40,13 @@ public static void ConstrainedCopyTo<T, U, K, C>(this IEnumerable<T> source, ILi

public static void ConstrainedCopyTo<TKey, USrc, UDst>(this IDictionary<TKey, USrc> source, IDictionary<TKey, UDst> destination, Func<UDst, bool> destinationItemsToCompareFilter, Func<USrc, UDst> createNew, Action<USrc, UDst> copyFrom, Action<UDst> onRemoved = null)
{
if(source == null || destination == null)
if (source == null || destination == null)
return;

//By default, if no dest list filter is provided, all items will be compared
if (destinationItemsToCompareFilter == null)
destinationItemsToCompareFilter = new Func<UDst, bool>(item => true);

//Process updates and deletes
var removeList = new List<KeyValuePair<TKey, UDst>>();
foreach (var item in destination)
Expand All @@ -70,7 +68,7 @@ public static void ConstrainedCopyTo<TKey, USrc, UDst>(this IDictionary<TKey, US
foreach (var item in removeList)
{
destination.Remove(item.Key);
if(onRemoved != null)
if (onRemoved != null)
onRemoved(item.Value);
}
}
Expand All @@ -93,12 +91,12 @@ public static void ConstrainedCopyTo<T, U, K>(this IEnumerable<T> source, IList<
return;

//By default, if no dest list filter is provided, all items will be compared
if(destinationItemsToCompareFilter == null)
destinationItemsToCompareFilter = new Func<U,bool>(item => true);
if (destinationItemsToCompareFilter == null)
destinationItemsToCompareFilter = new Func<U, bool>(item => true);

var sourceDict = source.ToDictionary((item) => getSourceKey(item));
var destDict = destination.Where(destinationItemsToCompareFilter).ToDictionary((item) => getDestKey(item));

//Process updates and deletes
var removeList = new Dictionary<K, U>();
foreach (var destItem in destDict)
Expand All @@ -120,7 +118,7 @@ public static void ConstrainedCopyTo<T, U, K>(this IEnumerable<T> source, IList<
destDict.Remove(removeItem.Key);
destination.Remove(removeItem.Value);

if(onRemoved != null)
if (onRemoved != null)
onRemoved(removeItem.Value);
}

Expand All @@ -137,10 +135,10 @@ public static void RemoveWhere<K, V>(this IDictionary<K, V> source, Func<V, bool
{
List<K> keysToRemove = new List<K>();

foreach(var item in source)
foreach (var item in source)
{
if (removeIf(item.Value))
keysToRemove.Add(item.Key);
keysToRemove.Add(item.Key);
}

foreach (K key in keysToRemove)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Knightware.Collections
{
Expand Down
17 changes: 6 additions & 11 deletions src/KnightwareCore/Collections/NotifyingObservableCollection.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Reflection;

namespace Knightware.Collections
{
Expand Down Expand Up @@ -40,7 +35,7 @@ public NotifyingObservableCollection(IEnumerable<T> items)
foreach (T item in items)
this.Add(item);
}

protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
base.OnCollectionChanged(e);
Expand Down Expand Up @@ -71,19 +66,19 @@ void NotifyingObservableCollection_PropertyChanged(object sender, PropertyChange
{
OnCollectionItemChanged(new NotifyCollectionItemChangedEventArgs(sender, e.PropertyName, this.IndexOf((T)sender)));
}

private void hookPropertyChange(T item)
{
var propertyChangedItem = item as INotifyPropertyChanged;
if(propertyChangedItem != null)
propertyChangedItem.PropertyChanged += new PropertyChangedEventHandler(NotifyingObservableCollection_PropertyChanged);
if (propertyChangedItem != null)
propertyChangedItem.PropertyChanged += new PropertyChangedEventHandler(NotifyingObservableCollection_PropertyChanged);
}

private void unhookPropertyChange(T item)
{
var propertyChangedItem = item as INotifyPropertyChanged;
if (propertyChangedItem != null)
propertyChangedItem.PropertyChanged -= new PropertyChangedEventHandler(NotifyingObservableCollection_PropertyChanged);
propertyChangedItem.PropertyChanged -= new PropertyChangedEventHandler(NotifyingObservableCollection_PropertyChanged);
}
}
}
6 changes: 1 addition & 5 deletions src/KnightwareCore/Diagnostics/TraceMessage.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knightware.Diagnostics
{
Expand All @@ -20,7 +16,7 @@ public string SenderShortName
{
get
{
if(Sender == null)
if (Sender == null)
return "<Unknown>";
else
return Sender.GetType().Name;
Expand Down
8 changes: 2 additions & 6 deletions src/KnightwareCore/Diagnostics/TraceQueue.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using Knightware.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knightware.Diagnostics
Expand All @@ -14,7 +10,7 @@ public static class TraceQueue
{
private const int maxMessageQueueCount = 100;
private static readonly AsyncListProcessor<TraceMessage> messageQueue;

/// <summary>
/// Event raised when a new Trace message is generated
/// </summary>
Expand Down Expand Up @@ -83,7 +79,7 @@ public static void Trace(TraceMessage message)

private static Task ProcessQueue(AsyncListProcessorItemEventArgs<TraceMessage> args)
{
if(args?.Item != null)
if (args?.Item != null)
{
TraceMessageRaised?.Invoke(args.Item);
}
Expand Down
8 changes: 1 addition & 7 deletions src/KnightwareCore/Diagnostics/TracingLevel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knightware.Diagnostics
namespace Knightware.Diagnostics
{
public enum TracingLevel
{
Expand Down
18 changes: 8 additions & 10 deletions src/KnightwareCore/DispatcherPropertyChangedBase.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using Knightware.Diagnostics;
using Knightware.Threading;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Knightware.Diagnostics;
using Knightware.Threading;

namespace Knightware
{
Expand All @@ -15,17 +13,17 @@ namespace Knightware
/// </summary>
public class DispatcherPropertyChangedBase : INotifyPropertyChanged
{
private readonly List<Tuple<PropertyChangedEventHandler, Dispatcher>> subscribers = new List<Tuple<PropertyChangedEventHandler,Dispatcher>>();
private readonly List<Tuple<PropertyChangedEventHandler, Dispatcher>> subscribers = new List<Tuple<PropertyChangedEventHandler, Dispatcher>>();
private readonly object subscribserLock = new object();

public event PropertyChangedEventHandler PropertyChanged
{
add
add
{
lock(subscribserLock)
lock (subscribserLock)
subscribers.Add(new Tuple<PropertyChangedEventHandler, Dispatcher>(value, new Dispatcher()));
}
remove
remove
{
lock (subscribserLock)
{
Expand Down Expand Up @@ -60,7 +58,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
subscriber.Item1(this, args);
}
}
catch(Exception ex)
catch (Exception ex)
{
TraceQueue.Trace(this, TracingLevel.Warning, "{0} occurred while raising propertyChanged: {1}", ex.GetType().Name, ex.Message);
}
Expand Down
11 changes: 3 additions & 8 deletions src/KnightwareCore/Drawing/BitmapHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using Knightware.Primitives;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knightware.Drawing
{
Expand Down Expand Up @@ -36,7 +31,7 @@ public static void GenerateSolidColorBitmap(Stream stream, Color color, int widt

int fileSize = bmpHeaderSize + dibHeaderSize + (strideBytes * height);
int imageStartPosition = bmpHeaderSize + dibHeaderSize;

//Write out BMP Header
stream.WriteByte((byte)'B');
stream.WriteByte((byte)'M');
Expand All @@ -60,14 +55,14 @@ public static void GenerateSolidColorBitmap(Stream stream, Color color, int widt
//Write pixel data now
byte[] line = new byte[strideBytes];
int index = 0;
for(int i=0 ; i<width ; i++)
for (int i = 0; i < width; i++)
{
line[index++] = color.B;
line[index++] = color.G;
line[index++] = color.R;
}

for(int i=0 ; i<height ; i++)
for (int i = 0; i < height; i++)
{
stream.Write(line, 0, line.Length);
}
Expand Down
7 changes: 1 addition & 6 deletions src/KnightwareCore/Drawing/DrawingHelper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Knightware.Primitives;
using Knightware.Primitives;

namespace Knightware.Drawing
{
Expand Down
9 changes: 9 additions & 0 deletions src/KnightwareCore/GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mode: Mainline
next-version: 3.1.0
branches:
feature:
tag: alpha
master:
tag: ''
ignore:
sha: []
7 changes: 1 addition & 6 deletions src/KnightwareCore/IO/GZipStreamDecompressor.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knightware.IO
{
Expand Down
8 changes: 1 addition & 7 deletions src/KnightwareCore/IO/IGZipStreamDecompressor.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knightware.IO
namespace Knightware.IO
{
/// <summary>
/// Interface used to identify a decompression algorithm for a GZip compressed stream
Expand Down
Loading

0 comments on commit 949f0ea

Please sign in to comment.