Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Terry Bayne committed Jul 11, 2016
0 parents commit 8090e29
Show file tree
Hide file tree
Showing 14 changed files with 1,365 additions and 0 deletions.
509 changes: 509 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions BlockingQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;

namespace ThreadSupport
{

public class BlockingQueue<T> : IEnumerable<T>
{
public int Count { get; private set; }
//private Queue<T> _queue = new Queue<T>();
// ReSharper disable once FieldCanBeMadeReadOnly.Local
private BlockingCollection<T> _queue = new BlockingCollection<T>();
public T Dequeue()
{
T result;
_queue.TryTake(out result);
return result;
}

public void Enqueue(T data)
{
if (data == null) throw new ArgumentNullException(nameof(data));
_queue.TryAdd(data);
Count++;
}

public IEnumerator<T> GetEnumerator()
{
return _queue.GetConsumingEnumerable().GetEnumerator();
}

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

}
}
157 changes: 157 additions & 0 deletions MsgDataCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Runtime.Serialization;
using System.Security.Permissions;

namespace ThreadSupport
{
[Serializable]
public class MsgDataCollection : NameObjectCollectionBase
{
// You can add non-serializable types to the collection.
// However, the serializer with throw an exception if you try to
// serialize the collection when it contains non-serializable types.

private IEqualityComparer _keyComparer;
private SerializationInfo _collectionInfo;

public MsgDataCollection()
: this(0)
{
}
public MsgDataCollection(IEqualityComparer equalityComparer)
: this(0, equalityComparer)
{
}
public MsgDataCollection(Int32 capacity)
: base(capacity)
{
_keyComparer = StringComparer.InvariantCultureIgnoreCase;
}
public MsgDataCollection(Int32 capacity, IEqualityComparer equalityComparer)
: base(capacity, equalityComparer)
{
_keyComparer = equalityComparer ?? StringComparer.InvariantCultureIgnoreCase;
}

protected MsgDataCollection(SerializationInfo info, StreamingContext context)
: base(info, context)
{
_collectionInfo = info;
}

public Object this[Int32 index]
{
// ReSharper disable once ConvertPropertyToExpressionBody
get { return BaseGet(index); }
}
public Object this[String name]
{
get { return BaseGet(name); }
set
{
OnValidate(name, value);
BaseSet(name, value);
}
}

private Int32 IndexOfInternal(String name)
{
int keyIndex = -1;
string[] names = BaseGetAllKeys();
if (names.Length > 0)
{
for (int index = 0; index < names.Length; index++)
{
if (_keyComparer.Equals(names[index], name))
{
keyIndex = index;
break;
}
}
}
return keyIndex;
}


protected virtual void OnValidate(String name, Object value)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
if (name.Length == 0)
{
throw new ArgumentException("Name cannot be empty (zero length).", nameof(name));
}
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
}

public void Add(String name, Object value)
{
OnValidate(name, value);

// Required IF 'name' MUST be unique...
if (IndexOfInternal(name) > -1)
{
throw new ArgumentException("Duplicate name.", nameof(name));
}
BaseAdd(name, value);
}
public String[] AllKeys()
{
return BaseGetAllKeys();
}
public Object[] AllValues()
{
return BaseGetAllValues(typeof(Object));
}
public void Clear()
{
BaseClear();
}
public Boolean Contains(String name)
{
return (IndexOfInternal(name) > -1);
}
public void CopyTo(Object[] array, Int32 index)
{
// Copies values to destination array.
// ICollection.CopyTo copies keys to destination array.
Object[] sourceArray = AllValues();
sourceArray.CopyTo(array, index);
}
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("keyComparer", _keyComparer, typeof(IEqualityComparer));
}
public Int32 IndexOf(string name)
{
return IndexOfInternal(name);
}
public override void OnDeserialization(Object sender)
{
base.OnDeserialization(sender);
if (_collectionInfo != null)
{
_keyComparer = _collectionInfo.GetValue("keyComparer", typeof(IEqualityComparer)) as IEqualityComparer;
_collectionInfo = null;
}
}
public void Remove(String name)
{
BaseRemove(name);
}
public void RemoveAt(Int32 index)
{
BaseRemoveAt(index);
}

}
}
35 changes: 35 additions & 0 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// 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.
[assembly: AssemblyTitle("ThreadSupport")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ThreadSupport")]
[assembly: AssemblyCopyright("")]
[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
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8db8db11-2184-4957-aa06-a9c08d097557")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// 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("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
13 changes: 13 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ThreadSupport

## Introduction
A general purpose .NET library to support threads and blocking queues to feed those threads.

## .NET Version: 5.5

## Prerequisites
* Visual Studion 2015




Loading

0 comments on commit 8090e29

Please sign in to comment.