Skip to content

Commit

Permalink
Merge pull request #22 from marcwittke/hotfix/2.0.6
Browse files Browse the repository at this point in the history
Hotfix/2.0.6
  • Loading branch information
marcwittke committed Mar 26, 2018
2 parents 968ec7c + 3472171 commit 6edef59
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 10 deletions.
29 changes: 29 additions & 0 deletions lib/GitVersion/gitversion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

scriptDir=$(dirname -- "$(readlink -f -- "$BASH_SOURCE")")
mono ${scriptDir}/GitVersion.exe /updateassemblyinfo /output buildserver

echo "$GitVersion_Major"
echo "$GitVersion_Minor"
echo "$GitVersion_Patch"
echo "$GitVersion_PreReleaseTag"
echo "$GitVersion_PreReleaseTagWithDash"
echo "$GitVersion_PreReleaseLabel"
echo "$GitVersion_PreReleaseNumber"
echo "$GitVersion_BuildMetaData"
echo "$GitVersion_BuildMetaDataPadded"
echo "$GitVersion_FullBuildMetaData"
echo "$GitVersion_MajorMinorPatch"
echo "$GitVersion_SemVer"
echo "$GitVersion_LegacySemVer"
echo "$GitVersion_LegacySemVerPadded"
echo "$GitVersion_AssemblySemVer"
echo "$GitVersion_FullSemVer"
echo "$GitVersion_InformationalVersion"
echo "$GitVersion_BranchName"
echo "$GitVersion_Sha"
echo "$GitVersion_NuGetVersionV2"
echo "$GitVersion_NuGetVersion"
echo "$GitVersion_CommitsSinceVersionSource"
echo "$GitVersion_CommitsSinceVersionSourcePadded"
echo "$GitVersion_CommitDate"
Binary file removed lib/GitVersion/lib/osx/libgit2-381caf5.dylib
Binary file not shown.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Backend.Fx/Exceptions/ClientException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class ClientException : Exception
{
public ClientException()
public ClientException() : this("Bad Request")
{}

public ClientException(string message) : base(message)
Expand Down
2 changes: 1 addition & 1 deletion src/Backend.Fx/Exceptions/ExceptionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Dispose()
{
if (clientException.HasErrors())
{
throw new UnprocessableException("The provided arguments cannot be processed");
throw clientException;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Backend.Fx/Exceptions/UnprocessableException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class UnprocessableException : ClientException
{
public UnprocessableException()
public UnprocessableException() : this("The provided arguments could not be processed.")
{ }

public UnprocessableException(string message) : base(message)
Expand Down
139 changes: 132 additions & 7 deletions src/Backend.Fx/Extensions/AsyncHelper.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,147 @@
namespace Backend.Fx.Extensions
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

public static class AsyncHelper
{
private static readonly TaskFactory TheTaskFactory
= new TaskFactory(CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, TaskScheduler.Default);
/// <summary>
/// Execute's an async Task method which has a void return value synchronously
/// </summary>
/// <param name="task">Task method to execute</param>
/// <remarks>
/// See https://stackoverflow.com/questions/5095183/how-would-i-run-an-async-taskt-method-synchronously
/// This code was the only possibility to make a task synchronously without deadlocking on the SingleCPU Build agent
/// </remarks>
public static void RunSync(Func<Task> task)
{
var oldContext = SynchronizationContext.Current;
try
{
var synch = new ExclusiveSynchronizationContext();
SynchronizationContext.SetSynchronizationContext(synch);
synch.Post(async _ =>
{
try
{
await task();
}
catch (Exception e)
{
synch.InnerException = e;
throw;
}
finally
{
synch.EndMessageLoop();
}
}, null);
synch.BeginMessageLoop();
}
finally
{
SynchronizationContext.SetSynchronizationContext(oldContext);
}
}

public static TResult RunSync<TResult>(Func<Task<TResult>> func)
/// <summary>
/// Execute's an async Task&lt;T&gt; method which has a T return type synchronously
/// </summary>
/// <typeparam name="T">Return Type</typeparam>
/// <param name="task">TaskTask&lt;T&gt; method to execute</param>
/// <returns></returns>
public static T RunSync<T>(Func<Task<T>> task)
{
return TheTaskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult();
T ret = default(T);
var oldContext = SynchronizationContext.Current;
try
{
var exclusiveSynchronizationContext = new ExclusiveSynchronizationContext();
SynchronizationContext.SetSynchronizationContext(exclusiveSynchronizationContext);
exclusiveSynchronizationContext.Post(async _ =>
{
try
{
ret = await task();
}
catch (Exception e)
{
exclusiveSynchronizationContext.InnerException = e;
throw;
}
finally
{
exclusiveSynchronizationContext.EndMessageLoop();
}
}, null);
exclusiveSynchronizationContext.BeginMessageLoop();
}
finally
{
SynchronizationContext.SetSynchronizationContext(oldContext);
}
return ret;
}

public static void RunSync(Func<Task> func)
private class ExclusiveSynchronizationContext : SynchronizationContext
{
TheTaskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult();
private bool done;
public Exception InnerException { get; set; }
readonly AutoResetEvent workItemsWaiting = new AutoResetEvent(false);
readonly Queue<Tuple<SendOrPostCallback, object>> items = new Queue<Tuple<SendOrPostCallback, object>>();

public override void Send(SendOrPostCallback d, object state)
{
throw new NotSupportedException("We cannot send to our same thread");
}

public override void Post(SendOrPostCallback d, object state)
{
lock (items)
{
items.Enqueue(Tuple.Create(d, state));
}
workItemsWaiting.Set();
}

public void EndMessageLoop()
{
Post(_ => done = true, null);
}

public void BeginMessageLoop()
{
while (!done)
{
Tuple<SendOrPostCallback, object> task = null;
lock (items)
{
if (items.Count > 0)
{
task = items.Dequeue();
}
}
if (task != null)
{
task.Item1(task.Item2);
if (InnerException != null) // the method threw an exeption
{
throw new AggregateException("AsyncHelpers.Run method threw an exception.", InnerException);
}
}
else
{
workItemsWaiting.WaitOne();
}
}
}

public override SynchronizationContext CreateCopy()
{
return this;
}
}
}
}
}

0 comments on commit 6edef59

Please sign in to comment.