Skip to content

Instantly share code, notes, and snippets.

View randyburden's full-sized avatar

Randy Burden randyburden

View GitHub Profile
@randyburden
randyburden / NHibernate_Duplicate_Mapping_Solution.cs
Created November 28, 2012 21:40
NHibernate Duplicate Mapping Problem Solution
/*
NHibernate now has the BeforeBindMapping event which gives you access to the object representation of the HBM XML files at runtime.
Use the BeforeBindMapping event to gain access to the object representation of the .HBM XML files.
This event allows you to modify any properties at runtime before the NHibernate Session Factory is created. This also makes the FluentNHibernate-equivalent convention unnecessary. Unfortunately there is currently no official documentation around this really great feature.
Here's a global solution to duplicate mapping problems ( Just remember that all HQL queries will now need to use Fully Qualified Type names instead of just the class names ).
*/
@randyburden
randyburden / NanoWindowsServiceExample.cs
Created October 20, 2015 14:35
This is a working example of using the Nano micro web framework hosted as a Windows Service using the System.ServiceProcess .NET dependency to create a low dependency, low memory footprint website or web API.
using System;
using System.Diagnostics;
using System.Threading;
using Nano.Web.Core;
using Nano.Web.Core.Host.HttpListener;
namespace NanoWindowsServiceExample
{
public class Program
{
@randyburden
randyburden / ContextStorage.cs
Last active December 10, 2015 08:08
Abstracts away the application's underlying storage context allowing you to simply call Get() or Store() and it will store the data in the appropriate context. It makes use of reflection too so that there is no need to reference the System.Web assembly if the application doesn't need it. For ASP.NET applications, it will store in the data in the…
/// <summary>
/// Provides a means of getting/storing data in the host application's
/// appropriate context.
/// </summary>
/// <remarks>
/// For ASP.NET applications, it will store in the data in the current HTTPContext.
/// For all other applications, it will store the data in the logical call context.
/// </remarks>
public static class ContextStorage
{
@randyburden
randyburden / StopwatchHelper.cs
Last active December 10, 2015 22:59
Simple StopWatcher helper class to give you back a nicely formatted elapsed time.
using System;
using System.Diagnostics;
namespace PDFMerger.Helpers
{
public static class StopwatchHelper
{
/// <summary>
/// Returns the elapsed time of the stopwatch in a formatted string.
/// </summary>
@randyburden
randyburden / DoubleBracketedTokenHelper.cs
Last active December 13, 2015 21:59
DoubleBracketedTokenHelper - A template / token helper thingy I put together where each token is wrapped in double brackets a la handlebars.js like. This is definately half-baked and is meant to be more of a "Hey, note to self: next time your coding a template helper, remember to look at this gist to get some ideas about how to go about writing …
public class DoubleBracketedTokenHelper
{
public Dictionary<string, string> TokensAndValues = new Dictionary<string, string>();
/// <summary>
/// Tokens to ignore.
/// </summary>
public List<string> IgnoredTokens = new List<string> { "{{cr}}" };
// This finds any characters in between open and closing double brackets
@randyburden
randyburden / CapitalizationHelper.cs
Created March 12, 2013 23:41
CapitalizationHelper intelligently capitalizes English names taking into account some common names that do not conform to the normal English capitalization rules.
using System;
using System.Globalization;
using System.Text.RegularExpressions;
namespace Utilities
{
/// <summary>
/// Provides intelligent capitalization methods.
/// </summary>
public static class CapitalizationHelper
@randyburden
randyburden / install.ps1
Created November 26, 2013 21:35
NuGet Installation Splash Page Script - Add this file under a folder named "tools" in the root of your NuGet package and it will open a splash web page upon package install. I have made the file more generic for better re-usability. Simply replace the $url variable value with your own URL and replace the $packageName variable value with the name…
param($installPath, $toolsPath, $package, $project)
# open splash page on package install
# don't open if it is installed as a dependency
# attribution: Modified from: https://github.com/JamesNK/Newtonsoft.Json/blob/master/Build/install.ps1
try
{
$url = "http://randyburden.com/Slapper.AutoMapper/"
$packageName = "slapper.automapper"
@randyburden
randyburden / InjectAppNameIntoConnectionString.cs
Last active January 11, 2016 19:53
Inject Application Name Into ConnectionString
public string GetConnectionString( string connectionStringName, string applicationName )
{
var connectionString = ConfigurationManager.ConnectionStrings[ connectionStringName ];
var builder = new System.Data.SqlClient.SqlConnectionStringBuilder( connectionString );
// Inject application name into connection string
if ( String.IsNullOrWhiteSpace( builder.ApplicationName ) )
{
if ( String.IsNullOrWhiteSpace( applicationName ) == false )
@randyburden
randyburden / DataTableMappingTestsWithSlapperAutoMapper.cs
Created December 18, 2013 20:37
Demonstrates converting a DataTable to a list of strongly typed objects using Slapper.AutoMapper.
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
namespace Atcs.Core.Tests
{
[TestFixture]
@randyburden
randyburden / ServiceInterceptorAttribute.cs
Last active September 1, 2016 16:19
Provides numerous service interceptors/hooks for a WCF service, endpoint, or method all wrapped up in a single attribute. You can derive from the ServiceInterceptorAttribute class to create your own custom interceptor attribute or use it in conjunction with a class that implements IServiceInterceptor. Update: This has graduated to it's own proje…
using System;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace Utilities.Wcf.Interceptors
{
/// <summary>