Skip to content

Instantly share code, notes, and snippets.

View stevenkuhn's full-sized avatar

Steven Kuhn stevenkuhn

View GitHub Profile
public class LocalFileStoreProvider : IFileStoreProvider
{
public bool SaveScreenshot(FluentSettings settings, byte[] contents, string fileName)
{
try
{
if (!string.IsNullOrEmpty(settings.ScreenshotPrefix))
{
fileName = Path.Combine(
Path.GetDirectoryName(fileName),
@stevenkuhn
stevenkuhn / IISExpressFixture.cs
Created November 19, 2014 02:35
IISExpressFixture
public class IISExpressFixture : IDisposable
{
public Uri Server { get; private set; }
public string SitePath { get; private set; }
private readonly Process _process;
public IISExpressFixture()
{
// Run site on a random port to prevent port clashes
@stevenkuhn
stevenkuhn / ConfigurationPropertyAttribute.cs
Created January 5, 2012 16:46
ConfigurationPropertyAttribute from nexuspwn
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class ConfigurationPropertyAttribute : Attribute, IComparable<ConfigurationPropertyAttribute>
{
public ConfigurationPropertyAttribute(string displayName)
{
DisplayName = displayName;
}
public string DisplayName { get; set; }
@stevenkuhn
stevenkuhn / gist:1655779
Created January 22, 2012 05:34
Extension Method to Sort ListItems in a ListControl in ASP.NET
public static void Sort(this ListItemCollection items)
{
IList<ListItem> itemList = new List<ListItem>();
foreach (ListItem item in items)
itemList.Add(item);
IEnumerable<ListItem> itemEnum =
from item in itemList orderby item.Text select item;
items.Clear();
@stevenkuhn
stevenkuhn / ICommunicationObjectExtensions.cs
Created January 22, 2012 05:39
Disposing a WCF Proxy Using an Extension Method
public static class ICommunicationObjectExtensions
{
public static void TryCloseOrAbort(this ICommunicationObject obj)
{
if (obj != null)
{
if (obj.State != CommunicationState.Faulted &&
obj.State != CommunicationState.Closed)
{
try { obj.Close(); }
using Dapper;
public class EmployeeController : Controller
{
private IDbContext DbContext { get; set; }
public EmployeeController(IDbContext dbContext)
{
DbContext = dbContext;
}
@stevenkuhn
stevenkuhn / EventService.cs
Created February 2, 2012 05:44
Triggering events in a Windows Service from an ASP.NET site using Redis
private void ProcessEvents() {
using (var client = redisManager.GetClient()) {
// incoming events are JSON, so deserialize each one to IDictionary<>.
var events = client.GetTypedClient<IDictionary<string, object>>().Lists["urn:events"];
while (true) {
// wait for next event, then convert it to an ExpandoObject;
dynamic @event = events.BlockingDequeue(null).ToExpando();
@stevenkuhn
stevenkuhn / releaseInfo.cshtml
Created February 13, 2012 20:08
Display release information via JavaScript using Octopus API, Knockout JS, and PageDown.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Octopus Release Information</title>
<style type="text/css">
</style>
</head>
<body>
<div data-bind="visible: version() != ''">
$configFile = Get-Item .\nexuspwn.Service.exe.config
$xml = [xml](Get-Content $configFile)
$smtpNode = $xml.SelectSingleNode("/configuration/system.net/mailSettings/smtp")
$smtpNode.network.host = $OctopusParameters["MailSettings.Smtp.Network.Host"]
$smtpNode.network.port = $OctopusParameters["MailSettings.Smtp.Network.Port"]
$smtpNode.network.enableSsl = $OctopusParameters["MailSettings.Smtp.Network.EnableSsl"]
$smtpNode.network.userName = $OctopusParameters["MailSettings.Smtp.Network.UserName"]
$smtpNode.network.password = $OctopusParameters["MailSettings.Smtp.Network.Password"]
@stevenkuhn
stevenkuhn / Program.cs
Created November 11, 2015 16:41
Swagger File Generation With Swashbuckle
public class Program
{
public static void Main(string[] args)
{
if (args == null || args.Length == 0) throw new InvalidOperationException("You must specify arguments.");
var path = args[0];
using (var server = TestServer.Create<Startup>())
{