forked from EasyNetQ/EasyNetQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created DNX project targeting DNXCore50, modified shared source to ge…
…t it to compile.
- Loading branch information
Showing
32 changed files
with
459 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
|
||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>ed270a39-d32c-438a-bf4f-aa0e66c7879c</ProjectGuid> | ||
<RootNamespace>EasyNetQ_DNX</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyNetQ.Internals | ||
{ | ||
/// <summary> | ||
/// AsyncSemaphore should be used with a lot of care. | ||
/// </summary> | ||
public class AsyncSemaphore | ||
{ | ||
private readonly SemaphoreSlim semaphore; | ||
|
||
public AsyncSemaphore(int initial) | ||
{ | ||
semaphore = new SemaphoreSlim(initial); | ||
} | ||
|
||
public int Available | ||
{ | ||
get { return semaphore.CurrentCount; } | ||
} | ||
|
||
public void Wait() | ||
{ | ||
semaphore.Wait(); | ||
} | ||
|
||
public Task WaitAsync() | ||
{ | ||
return semaphore.WaitAsync(); | ||
} | ||
|
||
public void Release() | ||
{ | ||
semaphore.Release(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyNetQ.Internals | ||
{ | ||
public static class TaskHelpers | ||
{ | ||
/// <summary> | ||
/// We want to prevent callers hijacking the reader thread; this is a bit nasty, but works; | ||
/// see http://stackoverflow.com/a/22588431/23354 for more information; a huge | ||
/// thanks to Eli Arbel for spotting this (even though it is pure evil; it is *my kind of evil*) | ||
/// </summary> | ||
private static readonly Func<Task, bool> IsSyncSafe; | ||
|
||
static TaskHelpers() | ||
{ | ||
try | ||
{ | ||
var taskType = typeof(Task); | ||
var continuationField = taskType.GetField("m_continuationObject", BindingFlags.Instance | BindingFlags.NonPublic); | ||
var safeScenario = taskType.GetNestedType("SetOnInvokeMres", BindingFlags.NonPublic); | ||
if (continuationField != null && continuationField.FieldType == typeof(object) && safeScenario != null) | ||
{ | ||
var method = new DynamicMethod("IsSyncSafe", typeof(bool), new[] { typeof(Task) }, typeof(Task), true); | ||
var il = method.GetILGenerator(); | ||
//var hasContinuation = il.DefineLabel(); | ||
il.Emit(OpCodes.Ldarg_0); | ||
il.Emit(OpCodes.Ldfld, continuationField); | ||
Label nonNull = il.DefineLabel(), goodReturn = il.DefineLabel(); | ||
// check if null | ||
il.Emit(OpCodes.Brtrue_S, nonNull); | ||
il.MarkLabel(goodReturn); | ||
il.Emit(OpCodes.Ldc_I4_1); | ||
il.Emit(OpCodes.Ret); | ||
|
||
// check if is a SetOnInvokeMres - if so, we're OK | ||
il.MarkLabel(nonNull); | ||
il.Emit(OpCodes.Ldarg_0); | ||
il.Emit(OpCodes.Ldfld, continuationField); | ||
il.Emit(OpCodes.Isinst, safeScenario); | ||
il.Emit(OpCodes.Brtrue_S, goodReturn); | ||
|
||
il.Emit(OpCodes.Ldc_I4_0); | ||
il.Emit(OpCodes.Ret); | ||
|
||
IsSyncSafe = (Func<Task, bool>)method.CreateDelegate(typeof(Func<Task, bool>)); | ||
|
||
// and test them (check for an exception etc) | ||
var tcs = new TaskCompletionSource<int>(); | ||
var expectTrue = IsSyncSafe(tcs.Task); | ||
tcs.Task.ContinueWith(delegate { }); | ||
var expectFalse = IsSyncSafe(tcs.Task); | ||
tcs.SetResult(0); | ||
if (!expectTrue || expectFalse) | ||
{ | ||
Debug.WriteLine("IsSyncSafe reported incorrectly!"); | ||
Trace.WriteLine("IsSyncSafe reported incorrectly!"); | ||
// revert to not trusting /them | ||
IsSyncSafe = null; | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine(ex.Message); | ||
Trace.WriteLine(ex.Message); | ||
IsSyncSafe = null; | ||
} | ||
if (IsSyncSafe == null) | ||
IsSyncSafe = t => false; // assume: not | ||
} | ||
|
||
public static readonly Task Completed = FromResult<object>(null); | ||
|
||
public static Task ExecuteSynchronously(Action action) | ||
{ | ||
var tcs = new TaskCompletionSource<object>(); | ||
try | ||
{ | ||
action(); | ||
tcs.SetResult(null); | ||
} | ||
catch (Exception e) | ||
{ | ||
tcs.SetException(e); | ||
} | ||
return tcs.Task; | ||
} | ||
|
||
public static Task<T> FromResult<T>(T result) | ||
{ | ||
return Task.FromResult(result); | ||
} | ||
|
||
public static Task FromException(Exception ex) | ||
{ | ||
var tcs = new TaskCompletionSource<object>(); | ||
tcs.SetException(ex); | ||
return tcs.Task; | ||
} | ||
|
||
public static Task Delay(TimeSpan delay, CancellationToken cancellation) | ||
{ | ||
return Task.Delay(delay, cancellation); | ||
} | ||
|
||
public static Task<Task> WhenAny(params Task[] tasks) | ||
{ | ||
return Task.WhenAny(tasks); | ||
} | ||
|
||
public static void TrySetResultSafe<T>(this TaskCompletionSource<T> source, T result) | ||
{ | ||
if (IsSyncSafe(source.Task)) | ||
{ | ||
source.TrySetResult(result); | ||
} | ||
else | ||
{ | ||
Task.Run(() => source.TrySetResult(result)); | ||
} | ||
} | ||
|
||
public static void TrySetCanceledSafe<T>(this TaskCompletionSource<T> source) | ||
{ | ||
if (IsSyncSafe(source.Task)) | ||
{ | ||
source.TrySetCanceled(); | ||
} | ||
else | ||
{ | ||
Task.Run(() => source.TrySetCanceled()); | ||
} | ||
} | ||
|
||
public static void TrySetExceptionSafe<T>(this TaskCompletionSource<T> source, Exception exception) | ||
{ | ||
if (IsSyncSafe(source.Task)) | ||
{ | ||
source.TrySetException(exception); | ||
} | ||
else | ||
{ | ||
Task.Run(() => source.TrySetException(exception)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
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("EasyNetQ_DNX")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("EasyNetQ_DNX")] | ||
[assembly: AssemblyCopyright("Copyright © 2015")] | ||
[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("ed270a39-d32c-438a-bf4f-aa0e66c7879c")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"version": "1.0.0-*", | ||
"description": "EasyNetQ DNX Class Library", | ||
"authors": [ "SapientGuardian" ], | ||
"tags": [ "" ], | ||
"projectUrl": "", | ||
"licenseUrl": "", | ||
"compile": [ "../EasyNetQ/*.cs", "../EasyNetQ/**/*.cs" ], | ||
"frameworks": { | ||
"dotnet5.4": { | ||
"dependencies": { | ||
"Microsoft.CSharp": "4.0.1-beta-23516", | ||
"System.Collections": "4.0.11-beta-23516", | ||
"System.Linq": "4.0.1-beta-23516", | ||
"System.Threading": "4.0.11-beta-23516", | ||
"System.Reflection.TypeExtensions": "4.1.0-beta-23516", | ||
"System.Runtime.Handles": "4.0.1-beta-23516", | ||
"System.Reflection": "4.1.0-beta-23516", | ||
"System.Threading.Tasks": "4.0.11-beta-23516", | ||
"System.Reflection.Primitives": "4.0.1-beta-23516", | ||
"System.Reflection.Extensions": "4.0.1-beta-23516", | ||
"System.Runtime.InteropServices": "4.0.21-beta-23516", | ||
"System.Linq.Expressions": "4.0.11-beta-23516", | ||
"System.Runtime.Extensions": "4.0.11-beta-23516", | ||
"System.Resources.ResourceManager": "4.0.1-beta-23516", | ||
"System.Globalization": "4.0.11-beta-23516", | ||
"System.Diagnostics.Debug": "4.0.11-beta-23516", | ||
"System.Dynamic.Runtime": "4.0.11-beta-23516", | ||
"System.Reflection.Emit": "4.0.1-beta-23516", | ||
"System.Reflection.Emit.ILGeneration": "4.0.1-beta-23516", | ||
"System.Reflection.Emit.Lightweight": "4.0.1-beta-23516", | ||
"System.ObjectModel": "4.0.11-beta-23516", | ||
"System.Text.Encoding.Extensions": "4.0.11-beta-23516", | ||
"System.IO.FileSystem.Primitives": "4.0.1-beta-23516", | ||
"System.IO.FileSystem": "4.0.1-beta-23516", | ||
"System.IO": "4.0.11-beta-23516", | ||
"System.Diagnostics.Tools": "4.0.1-beta-23516", | ||
"System.Text.Encoding": "4.0.11-beta-23516", | ||
"System.IO.Compression": "4.1.0-beta-23516", | ||
"System.Threading.Timer": "4.0.1-beta-23516", | ||
"System.Net.NameResolution": "4.0.0-beta-23516" | ||
} | ||
} | ||
}, | ||
"dependencies": { | ||
"Newtonsoft.Json": "8.0.1", | ||
"RabbitMQ.Client.CoreClrUnofficial": "3.5.6.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.