Skip to content

Instantly share code, notes, and snippets.

View Im5tu's full-sized avatar
👊
Let's do this!

Stuart Blackler Im5tu

👊
Let's do this!
View GitHub Profile
@Im5tu
Im5tu / .vsts-ci.yml
Last active June 30, 2018 17:10
Sample Service Fabric YML Build File
name: 0.1$(Rev:.r)
queue: Hosted VS2017
variables:
buildConfiguration: 'Release'
buildProjects: '**/*.csproj'
packageProjects: '**/*.sfproj'
testProjects: '**/*Tests*.csproj'
dotnetCliVersion: '2.1.300'
steps:
# Restore the packages for all projects in the 'buildProjects' variable
@Im5tu
Im5tu / .vsts-ci.yml
Last active June 17, 2018 20:12
Sample VSTS YML Build Definition
name: 0.1.0
trigger:
branches:
include:
- master
- hotfix/*
- release/*
- feature/*
- bugfix/*
- backlog/*
@Im5tu
Im5tu / CorrelationExample.cs
Created January 7, 2018 22:04
CorrelationExample
class Program
{
static void Main(string[] args)
{
using(CorrelationContext.CreateCorrelationIfNotExists())
{
Console.WriteLine(CorrelationContext.GetCorrelationId());
using(CorrelationContext.CreateCorrelationIfNotExists())
{
@Im5tu
Im5tu / DisposeCorrelation.cs
Created January 7, 2018 22:03
DisposeCorrelation
private class DisposeCorrelation : IDisposable
{
private readonly AsyncLocal<Stack<Guid>> _localStack;
public DisposeCorrelation(AsyncLocal<Stack<Guid>> localStack)
{
_localStack = localStack;
}
public void Dispose()
{
@Im5tu
Im5tu / CreateCorrelationIfNotExists.cs
Created January 7, 2018 22:02
CreateCorrelationIfNotExists
public static IDisposable CreateCorrelationIfNotExists(Guid? correlationId = null)
{
if(GetCorrelationStack().Count > 0)
return new EmptyDisposable();
return CreateCorrelation(correlationId);
}
@Im5tu
Im5tu / CreateCorrelation.cs
Last active January 7, 2018 22:24
CreateCorrelation
public static IDisposable CreateCorrelation(Guid? correlationId = null)
{
if (_correlationStack.Value == null)
_correlationStack.Value = new Stack<Guid>();
_correlationStack.Value.Push(correlationId ?? Guid.NewGuid());
return new DisposeCorrelation(_correlationStack);
}
@Im5tu
Im5tu / GetCorrelationId.cs
Created January 7, 2018 22:00
GetCorrelationId
public static Guid? GetCorrelationId()
{
var stack = GetCorrelationStack();
if(stack.Count > 0)
return stack.Peek();
return null; // TODO :: decide what you are going to do
}
@Im5tu
Im5tu / GetCorrelationStack.cs
Created January 7, 2018 21:57
GetCorrelationStack
private static readonly AsyncLocal<Stack<Guid>> _correlationStack = new AsyncLocal<Stack<Guid>>();
public static Stack<Guid> GetCorrelationStack() => _correlationStack.Value ?? new Stack<Guid>();
@Im5tu
Im5tu / CorrelationContext.cs
Created January 7, 2018 21:57
Correlation_Context_Api
public static class CorrelationContext
{
public static Stack<Guid> GetCorrelationStack() {}
public static Guid? GetCorrelationId() {}
public static IDisposable CreateCorrelation(Guid? correlationId = null) {}
public static IDisposable CreateCorrelationIfNotExists(Guid? correlationId = null) {}
}
@Im5tu
Im5tu / CorrelationContext.cs
Last active January 7, 2018 21:53
Correlation Part 1: The Context
public static class CorrelationContext
{
public static Stack<Guid> GetCorrelationStack() {}
  public static Guid? GetCorrelationId() {}
  public static IDisposable CreateCorrelation(Guid? correlationId = null) {}
  public static IDisposable CreateCorrelationIfNotExists(Guid? correlationId = null) {}
}