Skip to content

Instantly share code, notes, and snippets.

View dataneek's full-sized avatar

Nic Myers dataneek

View GitHub Profile
using System;
using System.Linq;
using System.Net.Http;
using System.Web.Http.Filters;
using Newtonsoft.Json;
using PaginableCollections;
public class PaginableResultActionFilter : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
@dataneek
dataneek / Factory.cs
Created December 17, 2015 22:06
Factory Method, Multitenancy, StructureMap, and Other Stuff
using System;
using System.Collections.Generic;
using System.Linq;
using StructureMap;
class Program
{
static void Main(string[] args)
{
var container = new Container(t =>
using System;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
//# Rename code first foreign keys from [{Table}_{ColumnId}] to [{ColumnId}].
public class ForeignKeyNamingConvention : IStoreModelConvention<AssociationType>
{
public void Apply(AssociationType association, DbModel model)
{
@dataneek
dataneek / AuthorizationService.sql
Created November 23, 2015 22:36
Baseline schema to create AuthenticationService
CREATE TABLE [Account].[Client] (
[ClientId] BIGINT IDENTITY (1, 1) NOT NULL,
[ClientKey] UNIQUEIDENTIFIER NOT NULL,
[CommonName] NVARCHAR (50) NOT NULL,
[TeamName] NVARCHAR (50) NOT NULL,
[EmailDomainName] NVARCHAR (50) NULL,
[IsArchived] BIT CONSTRAINT [DF_Account.Client_IsArchived] DEFAULT ((0)) NOT NULL,
[Created] DATETIMEOFFSET (7) CONSTRAINT [DF_Account.Client_Created] DEFAULT (sysdatetimeoffset()) NOT NULL,
[LastUpdated] DATETIMEOFFSET (7) NULL,
[Watermark] ROWVERSION NOT NULL,
@dataneek
dataneek / DummyAuthenticationHandler.cs
Last active November 23, 2015 21:34
Use this to test webapi endpoints without having to build a working authentication system.
//# setup: config.MessageHandlers.Add(new DummyAuthenticationHandler());
public class DummyAuthenticationHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(Thread.CurrentPrincipal.Identity.AuthenticationType))
{
var claims =
new List<Claim>
{
@dataneek
dataneek / CachableRequestHandler.cs
Last active August 29, 2015 14:28
Generic interface for identifying messages that participate in caching operations.
public class CachableRequestHandler<TRequest, TResponse>
: IAsyncRequestHandler<TRequest, TResponse>
where TRequest : IAsyncRequest<TResponse>, ICacheable<TRequest>
where TResponse : class
{
private readonly IAsyncRequestHandler<TRequest, TResponse> innerHandler;
private readonly ObjectCache objectCache;
private readonly ReaderWriterLockSlim cacheLock = new ReaderWriterLockSlim();
@dataneek
dataneek / Period.cs
Last active August 29, 2015 14:19
The following snippet generates a date-based dataset using the parameters as boundaries.
public class Period
{
public int PeriodID { get; set; }
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public int YearValue { get; set; }
public int MonthValue { get; set; }
public string MonthName { get; set; }
using System;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
namespace TripIt
{
class Program
{
static void Main(string[] args)
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TripIt
{