Skip to content

Instantly share code, notes, and snippets.

View AlonAm's full-sized avatar

Alon Amsalem AlonAm

View GitHub Profile
@AlonAm
AlonAm / Preconditions.cs
Created December 8, 2016 11:34
Preconditions
using System;
namespace Preconditions
{
/// <summary>
/// Preconditions for checking method arguments, state etc.
/// </summary>
public static class Preconditions
{
/// <summary>
@AlonAm
AlonAm / ToolWindowStyles.xaml
Created November 18, 2016 08:46 — forked from timsneath/ToolWindowStyles.xaml
Resource dictionary to map VS themes onto standard WPF controls
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0">
<Style TargetType="UserControl">
<Setter Property="Background" Value="{DynamicResource {x:Static vs:EnvironmentColors.ToolWindowBackgroundBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static vs:EnvironmentColors.ToolWindowTextBrushKey}}"/>
</Style>
using Autofac;
using Autofac.Core;
using Cloudinator.Portal.WebApi.Infrastructure;
using Cloudinator.Portal.WebApi.Infrastructure.Handlers;
using FluentValidation;
using MediatR;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@AlonAm
AlonAm / SignalGenerator.cs
Created February 8, 2016 09:06
Simple Signal Generator
class SignalGenerator
{
long startTime = Stopwatch.GetTimestamp();
long ticksPerSecond = Stopwatch.Frequency;
float amplitude = 1f;
float frequency = 1f;
float phase = 1f;
float offset = 0f;
@AlonAm
AlonAm / SignalGenerator.cs
Created February 8, 2016 09:06
Simple Signal Generator
class SignalGenerator
{
long startTime = Stopwatch.GetTimestamp();
long ticksPerSecond = Stopwatch.Frequency;
float amplitude = 1f;
float frequency = 1f;
float phase = 1f;
float offset = 0f;
public class MediatorPipelineModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
RegisterPipeline(builder);
RegisterAsyncPreRequestHandlers(builder);
RegisterAsyncPostRequestHandlers(builder);
RegisterPreRequestHandlers(builder);
RegisterPostRequestHandlers(builder);
}
public interface IPreRequestHandler<in TRequest>
{
void Handle(TRequest request);
}
public interface IAsyncPreRequestHandler<in TRequest>
{
Task Handle(TRequest request);
}
public class AsyncMediatorPipeline<TRequest, TResponse> : IAsyncRequestHandler<TRequest, TResponse>
where TRequest : IAsyncRequest<TResponse>
{
private readonly IAsyncRequestHandler<TRequest, TResponse> _inner;
private readonly IAsyncPreRequestHandler<TRequest>[] _preRequestHandlers;
private readonly IAsyncPostRequestHandler<TRequest, TResponse>[] _postRequestHandlers;
public AsyncMediatorPipeline(
IAsyncRequestHandler<TRequest, TResponse> inner,
IAsyncPreRequestHandler<TRequest>[] preRequestHandlers,
public class MediatorPipeline<TRequest, TResponse>
: IRequestHandler<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
private readonly IRequestHandler<TRequest, TResponse> _inner;
private readonly IPreRequestHandler<TRequest>[] _preRequestHandlers;
private readonly IAsyncPostRequestHandler<TRequest, TResponse>[] _postRequestHandlers;
public MediatorPipeline(
IRequestHandler<TRequest, TResponse> inner,
@AlonAm
AlonAm / NLoadExample.cs
Last active August 29, 2015 14:24
NLoad Example
var loadTest = NLoad.Test<MyTest>()
.WithNumberOfThreads(100)
.WithDurationOf(TimeSpan.FromMinutes(5))
.WithDeleyBetweenThreadStart(TimeSpan.FromMilliseconds(50))
.OnHeartbeat((s, e) => Console.WriteLine(e.Throughput))
.Build();
var result = loadTest.Run();