Skip to content

Instantly share code, notes, and snippets.

View ramonsmits's full-sized avatar

Ramon Smits ramonsmits

View GitHub Profile
@ramonsmits
ramonsmits / gist:f7d20dbfd5335e6b1afc
Created June 18, 2015 19:42
NServiceBus behavior to share persistence database connection
using System;
using System.Data;
using System.Diagnostics;
using NServiceBus;
using NServiceBus.Persistence.NHibernate;
using NServiceBus.Pipeline;
using NServiceBus.Pipeline.Contexts;
class MyContextBehaviorRegistration : INeedInitialization
{
@ramonsmits
ramonsmits / gist:9d11e05276fd45763964
Created June 25, 2015 20:16
NServiceBus Unit of work that calls .SaveChanges on a DbContext using Func<DbContext>
busConfiguration.RegisterComponents(r => r.ConfigureComponent<ReceiverDataContext>(DependencyLifecycle.InstancePerUnitOfWork));
busConfiguration.RegisterComponents(r => r.ConfigureComponent<IDbConnection>(b => b.Build<NHibernateStorageContext>().Connection, DependencyLifecycle.InstancePerUnitOfWork));
class DbContextUnitOfWork : IManageUnitsOfWork
{
private readonly Func<ReceiverDataContext> createContext;
public DbContextUnitOfWork(Func<ReceiverDataContext> createContext)
{
@ramonsmits
ramonsmits / purge_all_msmq_queues_with_journal.ps1
Created October 7, 2015 14:01
Purge all MSMQ private queues and corresponding journal queues
[void] [Reflection.Assembly]::LoadWithPartialName("System.Messaging")
[System.Messaging.MessageQueue]::GetPrivateQueuesByMachine("LOCALHOST") | % { $_.Purge(); }
echo "All MSMQ queues purged"
[System.Messaging.MessageQueue]::GetPrivateQueuesByMachine("LOCALHOST") | ForEach-Object {
$queueFormatName = "$($_.Path);JOURNAL"
#Write-Host $queueFormatName -foregroundcolor cyan
@ramonsmits
ramonsmits / ThrottleThroughputWhenCheckFailsUsingScheduler.cs
Created November 10, 2015 14:58
Throttle NServiceBus throughput when a custom check fails using the scheduler
using System;
using NServiceBus;
using NServiceBus.Logging;
class ThrottleThroughputWhenCheckFailsUsingScheduler : IWantToRunWhenBusStartsAndStops
{
NServiceBus.Unicast.UnicastBus bus;
Schedule schedule;
ILog Log = LogManager.GetLogger(typeof(CheckBreaker));
@ramonsmits
ramonsmits / ThrottleThroughputWhenCheckFailsUsingPeriodicCheck.cs
Last active November 10, 2015 15:03
Throttle NServiceBus throughput when a custom check fails using service control custom checks
using System;
using NServiceBus;
using NServiceBus.Logging;
using ServiceControl.Plugin.CustomChecks;
class ThrottleThroughputWhenCheckFails : PeriodicCheck
{
NServiceBus.Unicast.UnicastBus bus;
ILog Log = LogManager.GetLogger(typeof(IntegrationCustomCheck));
@ramonsmits
ramonsmits / string-format-extension.cs
Last active December 17, 2015 10:19 — forked from terenced/string-format-extension.cs
Added alignment support for named values.
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
namespace StringExtensions
{
/// <remarks>
/// http://james.newtonking.com/archive/2008/03/27/formatwith-string-format-extension-method.aspx
@ramonsmits
ramonsmits / EndpointConfig.cs
Last active December 23, 2015 10:30
NServiceBus Host EndpointConfiguration initializing Log4net xml configuration, app domain diagnostic events and using Profile to target NHibernate persistence
using System;
using NServiceBus;
using NServiceBus.Hosting.Profiles;
using NServiceBus.Log4Net;
using NServiceBus.Logging;
public class EndpointConfig : IConfigureThisEndpoint
{
public EndpointConfig()
{
@ramonsmits
ramonsmits / InitNServiceBusLog4net.cs
Created February 5, 2016 10:04
Use log4net with NServiceBus using log4net xml configuration in application configuration file
//
// Run this before anything NServiceBus related. If using
// the host, put this in the constructor of the endpoint
// configuration class.
//
log4net.Config.XmlConfigurator.Configure();
NServiceBus.Logging.LogManager.Use<NServiceBus.Log4Net.Log4NetFactory>();
@ramonsmits
ramonsmits / LogExtensions.cs
Last active February 18, 2016 08:39 — forked from lkaczanowski/ILogExtensions.cs
ILog extension for TRACE and VERBOSE log4net levels
using System;
using System.Globalization;
using log4net.Util;
namespace log4net
{
public static class LogExtentions
{
private static readonly Type ThisDeclaringType = typeof(LogExtentions);
@ramonsmits
ramonsmits / buffered.xml
Last active March 14, 2016 13:49
Log4net appender examples
<?xml version="1.0" encoding="utf-8"?>
<log4net>
<!-- Buffer 128 entries except with log level severity is WARN or higher. -->
<appender name="buffer" type="log4net.Appender.BufferingForwardingAppender">
<bufferSize value="128" />
<appender-ref ref="console" />
<!--<lossy value="false" />-->
<!--<OnlyFixPartialEventData value="true"/>-->
<evaluator type="log4net.Core.LevelEvaluator">