Skip to content

Instantly share code, notes, and snippets.

// wrap ASF Stateless Service. Customer would implement this base class instead of StatelessService
public abstract class NServiceBusStatelessService : StatelessService, IProvideEndPointConfiguration
{
//plumbing for starting NSB on Service start
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
yield return new ServiceInstanceListener(
createCommunicationListener:
_ => new NServiceBusCommunicationsListener(this),
name:
@LSTANCZYK
LSTANCZYK / Firewall.cs
Created March 21, 2017 17:02 — forked from ChrisPelatari/Firewall.cs
ASP.NET MVC ActionFilter to allow or deny IPv4 addresses with optional subnet mask. For use with AppHarbor or any other server solution which uses the X-Forwarded-For header.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
namespace AppHarbor.Web {
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true,
AllowMultiple = false)]
@LSTANCZYK
LSTANCZYK / AppInsightsFilter.cs
Created March 21, 2017 17:02 — forked from debugthings/AppInsightsFilter.cs
Enable Application Insights on Migraged Azure Mobile Services applications
internal static class RequestTrackingConstants
{
/// <summary>
/// Name of the HttpContext item containing RequestTelemetry object.
/// </summary>
internal const string RequestTelemetryItemName = "Microsoft.ApplicationInsights.RequestTelemetry";
internal const string EndRequestCallFlag = "Microsoft.ApplicationInsights.EndRequestCallFlag";
/// <summary>
@LSTANCZYK
LSTANCZYK / CapturingResponseFilter.cs
Created March 21, 2017 17:02 — forked from allenp/CapturingResponseFilter.cs
Filter attribute to capture and log requests and responses in ASP.NET
class CapturingResponseFilter : Stream
{
private Stream _sink;
private MemoryStream mem;
public APIAccessLogItem AccessLogItem { get; set; }
public CapturingResponseFilter(Stream sink, APIAccessLogItem item)
{
_sink = sink;
@LSTANCZYK
LSTANCZYK / PdfFilterAttribute.cs
Created March 21, 2017 17:02 — forked from kmpm/PdfFilterAttribute.cs
Filter for an MVC4 application to render all views as PDF if AcceptTypes contains "application/pdf" or querystring contains asPDF=1. Uses wkthml2pdf via Pechkin. Currently requires https://github.com/gmanny/Pechkin/pull/42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using System.IO;
using System.Web.UI;
using Pechkin;
using System.Text.RegularExpressions;
using System;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Caching;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
/// <summary>
/// Decorates any Action that needs to have client requests limited by concurrent requests.
[AttributeUsage(AttributeTargets.Method)]
public class ValidationActionFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
InnerOnActionExecuting(actionContext);
var modelState = actionContext.ModelState;
if (modelState.IsValid)
@LSTANCZYK
LSTANCZYK / RestrictByIpAddressAttribute.cs
Created March 21, 2017 17:01
Ip address restriction action filter
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Web.Attributes
{
public class RestrictByIpAddressAttribute : ActionFilterAttribute
using Auction.Web.Domain;
using Auction.Web.Domain.Commands;
using Auction.Web.Domain.Entities;
using Auction.Web.Domain.Queries;
using Facebook;
using Microsoft.Web.WebPages.OAuth;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
@LSTANCZYK
LSTANCZYK / BeforeFilterAttribute.cs
Created March 21, 2017 16:55 — forked from beccasaurus/BeforeFilterAttribute.cs
Rails-like before filter
public class BeforeAttribute : ActionFilterAttribute {
public BeforeAttribute() {
Methods = string.Empty;
Except = string.Empty;
Only = string.Empty;
}
public BeforeAttribute(params string[] methodNames) : this() {
Methods = string.Join(" ", methodNames);
}