wasSharp

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 54  →  ?path2? @ 55
File deleted
\ No newline at end of file
/Collections/Specialized/NotifyConcurrentQueueChangedAction.cs
File deleted
\ No newline at end of file
/Collections/Specialized/NotifyConcurrentQueueChangedEventArgs.cs
File deleted
\ No newline at end of file
/Collections/Specialized/ConcurrentQueueChangedEventHandler.cs
/Collections/Specialized/ObservableConcurrentQueue.cs
@@ -1,14 +1,12 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ObservableConcurrentQueue.cs" company="BledSoft">
// This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
// To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
// </copyright>
// <Author>
// Cheikh Younes
// </Author>
// --------------------------------------------------------------------------------------------------------------------
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
 
namespace wasSharp.Collections.Specialized
{
@@ -18,114 +16,71 @@
/// <typeparam name="T">
/// The content type
/// </typeparam>
public sealed class ObservableConcurrentQueue<T> : ConcurrentQueue<T>
public sealed class ObservableConcurrentQueue<T> : ConcurrentQueue<T>, INotifyCollectionChanged
{
#region Public Events
public event NotifyCollectionChangedEventHandler CollectionChanged;
 
/// <summary>
/// Occurs when concurrent queue elements [changed].
/// </summary>
public event ConcurrentQueueChangedEventHandler<T> ContentChanged;
private new void Enqueue(T item)
{
EnqueueAsync(item).RunSynchronously();
}
 
#endregion
 
#region Public Methods and Operators
 
/// <summary>
/// Adds an object to the end of the <see cref="T:System.Collections.Concurrent.ConcurrentQueue`1"/>.
/// </summary>
/// <param name="item">
/// The object to add to the end of the <see cref="T:System.Collections.Concurrent.ConcurrentQueue`1"/>
/// . The value can be a null reference (Nothing in Visual Basic) for reference types.
/// </param>
public new async Task Enqueue(T item)
{
await new Task(() =>
public async Task EnqueueAsync(T item) => await Task.Run(() =>
{
base.Enqueue(item);
 
// Raise event added event
this.OnContentChanged(
new NotifyConcurrentQueueChangedEventArgs<T>(NotifyConcurrentQueueChangedAction.Enqueue, item));
OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
});
}
 
/// <summary>
/// Attempts to remove and return the object at the beginning of the
/// <see cref="T:System.Collections.Concurrent.ConcurrentQueue`1"/>.
/// </summary>
/// <param name="result">
/// When this method returns, if the operation was successful, <paramref name="result"/> contains the
/// object removed. If no object was available to be removed, the value is unspecified.
/// </param>
/// <returns>
/// true if an element was removed and returned from the beginning of the
/// <see cref="T:System.Collections.Concurrent.ConcurrentQueue`1"/> successfully; otherwise, false.
/// </returns>
public new bool TryDequeue(out T result)
private new bool TryDequeue(out T result)
{
if (!base.TryDequeue(out result))
{
result = DequeueAsync().Result;
if (result.Equals(default(T)))
return false;
}
 
// Raise item dequeued event
this.OnContentChanged(
new NotifyConcurrentQueueChangedEventArgs<T>(NotifyConcurrentQueueChangedAction.Dequeue, result));
return true;
}
 
if (this.IsEmpty)
public async Task<T> DequeueAsync() => await Task.Run(() =>
{
// Raise Queue empty event
this.OnContentChanged(
new NotifyConcurrentQueueChangedEventArgs<T>(NotifyConcurrentQueueChangedAction.Empty));
}
if (!base.TryDequeue(out T item))
return default(T);
 
OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item));
 
return item;
});
 
public async Task<T> PeekAsync() => await Task.Run(() =>
{
if (!base.TryPeek(out T item))
return default(T);
 
return item;
});
 
private new bool TryPeek(out T result)
{
result = PeekAsync().Result;
 
if (result.Equals(default(T)))
return false;
 
return true;
}
 
/// <summary>
/// Attempts to return an object from the beginning of the
/// <see cref="T:System.Collections.Concurrent.ConcurrentQueue`1"/> without removing it.
/// </summary>
/// <param name="result">
/// When this method returns, <paramref name="result"/> contains an object from the beginning of the
/// <see cref="T:System.Collections.Concurrent.ConcurrentQueue`1"/> or an unspecified value if the operation failed.
/// </param>
/// <returns>
/// true if and object was returned successfully; otherwise, false.
/// </returns>
public new bool TryPeek(out T result)
private void OnCollectionChanged(NotifyCollectionChangedEventArgs args)
{
var retValue = base.TryPeek(out result);
if (retValue)
{
// Raise item dequeued event
this.OnContentChanged(
new NotifyConcurrentQueueChangedEventArgs<T>(NotifyConcurrentQueueChangedAction.Peek, result));
}
 
return retValue;
CollectionChanged?.Invoke(this, args);
}
 
#endregion
 
#region Methods
 
/// <summary>
/// Raises the <see cref="E:Changed"/> event.
/// </summary>
/// <param name="args">
/// The <see cref="NotifyConcurrentQueueChangedEventArgs{T}"/> instance containing the event data.
/// </param>
private void OnContentChanged(NotifyConcurrentQueueChangedEventArgs<T> args)
public async Task Clear()
{
var handler = this.ContentChanged;
if (handler != null)
{
handler(this, args);
}
while (!base.IsEmpty)
await DequeueAsync();
}
 
#endregion
}
}
/Lambda/Extensions.cs
@@ -207,6 +207,22 @@
/// <param name="pass">function with no parameters and return type T in case condition passes</param>
/// <param name="fail">function with no parameters and return type T in case condition fails</param>
/// <returns>the result of pass in case condition holds or the result of fail otherwise</returns>
public static V IfElse<T, V>(this T arg, Func<T, bool> condition, Func<T, V> pass, Func<T, V> fail)
{
return condition.Invoke(arg) ? pass.Invoke(arg) : fail.Invoke(arg);
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>
/// Invokes pass if and only if condition holds or fail otherwise.
/// </summary>
/// <typeparam name="T">the return type of the pass and fail functions</typeparam>
/// <param name="condition">the branch condition</param>
/// <param name="pass">function with no parameters and return type T in case condition passes</param>
/// <param name="fail">function with no parameters and return type T in case condition fails</param>
/// <returns>the result of pass in case condition holds or the result of fail otherwise</returns>
public static T IfElse<T>(this bool condition, Func<T> pass, Func<T> fail)
{
return condition ? pass.Invoke() : fail.Invoke();
/Languages/CSV.cs
@@ -8,7 +8,7 @@
using System.Linq;
using System.Text;
 
namespace wasSharp
namespace wasSharp.Languages
{
public static class CSV
{
/Languages/KeyValue.cs
@@ -8,7 +8,7 @@
using System.Collections.Generic;
using System.Linq;
 
namespace wasSharp
namespace wasSharp.Languages
{
public static class KeyValue
{
/Languages/XML.cs
@@ -13,7 +13,7 @@
using System.Threading.Tasks;
using System.Xml.Linq;
 
namespace wasSharp
namespace wasSharp.Languages
{
public static class XML
{
/Web/wasHTTPClient.cs
@@ -12,6 +12,7 @@
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using wasSharp.Languages;
 
namespace wasSharp.Web
{
/wasSharp.csproj
@@ -73,9 +73,6 @@
<Compile Include="Cryptography\Extensions.cs" />
<Compile Include="Sets\Extensions.cs" />
<Compile Include="Collections\Specialized\ObservableConcurrentQueue.cs" />
<Compile Include="Collections\Specialized\NotifyConcurrentQueueChangedEventArgs.cs" />
<Compile Include="Collections\Specialized\NotifyConcurrentQueueChangedAction.cs" />
<Compile Include="Collections\Specialized\ConcurrentQueueChangedEventHandler.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>