Skip to content

Instantly share code, notes, and snippets.

View yreynhout's full-sized avatar
👔
ceci n'est pas une cravate

Yves Reynhout yreynhout

👔
ceci n'est pas une cravate
View GitHub Profile
@yreynhout
yreynhout / MemoryProjectionBuilder.cs
Last active August 29, 2015 14:01
Parking it here
using System;
using System.Linq;
namespace FiveMinuteProject
{
public class ProjectionBuilder<TState>
{
private readonly ProjectionHandler<TState>[] _handlers;
public ProjectionBuilder()
using System;
using System.Linq;
using System.Security.Policy;
using Newtonsoft.Json;
using Raven.Client;
using Raven.Client.Embedded;
namespace FiveMinuteProject
{
public class ProjectionBuilder
@yreynhout
yreynhout / LunchTime.fs
Created May 28, 2014 15:17
Projac meets F#
open System;
open Projac;
type PortfolioCreated = { PortfolioId : int; Name : string }
type PhotoAddToPortfolio = { PortfolioId : int; PhotoId : int }
type PhotoRemovedFromPortfolio = { PortfolioId : int; PhotoId : int }
type PortfolioArchived = { PortfolioId : int; Name : string }
let PortfolioProjection (message:Object) =
seq {
public static class PlaceHolderForProjections {
public static readonly PortfolioProjection = TSql.Projection().
When<PortfolioAdded>(@event =>
TSql.NonQuery(
"INSERT INTO [Portfolio] (Id, Name) VALUES (@P1, @P2)",
new { P1 = TSql.Int(@event.Id), P2 = TSql.NVarChar(@event.Name, 40) }
).
When<PortfolioRemoved>(@event =>
TSql.NonQuery(
"DELETE FROM [Portfolio] WHERE Id = @P1",
using Projac;
using Paramol.SqlClient;
public namespace AliensNeverOnceAbductedMe
{
public static class PortfolioProjection
{
public static readonly SqlProjectionDescriptor Descriptor =
new SqlProjectionDescriptorBuilder("portfolio-v1")
{
using Paramol.SqlClient;
namespace Paramol.Tests.SqlClient
{
public class ParameterCountLimitedExceeded
{
public static readonly ParameterCountLimitedExceeded Instance = new ParameterCountLimitedExceeded();
private ParameterCountLimitedExceeded() { }
@yreynhout
yreynhout / SampleReaction.cs
Created December 17, 2014 11:22
Sample Reactol
using Reactol;
//Fictitious scenario:
//Add an entry in the feed of a subscriber each time
//someone writes a blog post on a blog he's subscribed to.
var subscriptions = new SubscriptionRepository(/* ommitted */);
var reaction = new ReactionBuilder().
When<BlogPostWritten>(message => subscriptions.
FindForBlog(message.BlogId).
@yreynhout
yreynhout / XhtmlParser.cs
Created January 12, 2015 16:19
XhtmlParser bits
//Original technique courtesy of
//- http://scott.willeke.com
//- http://blogs.pingpoet.com/overflow/archive/2005/07/20/6607.aspx
//- https://devio.wordpress.com/2007/12/05/parsing-xhtml-with-c/
//- http://sticklebackplastic.com/post/2007/06/28/How-to-use-XmlResolver-Or-reading-an-xhtml-file-in-net.aspx
public static class XhtmlParser
{
public static XmlDocument Parse(string xhtml)
{
using (var textReader = new StringReader(xhtml))
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<system.data>
<DbProviderFactories>
<add name="SQLite Data Provider" invariant="System.Data.SQLite"
description="ADO.NET Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.94.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
@yreynhout
yreynhout / AggregateReader.cs
Last active August 29, 2015 14:14
Goodbye repository, Hello aggregate reader!
public class AggregateReader
{
private readonly Func<IAggregateRootEntity> _rootFactory;
private readonly IEventStoreConnection _connection;
private readonly EventStoreReaderConfiguration _configuration;
public AggregateReader(
Func<IAggregateRootEntity> rootFactory,
IEventStoreConnection connection,
EventStoreReaderConfiguration configuration)