Skip to content

Instantly share code, notes, and snippets.

View nootn's full-sized avatar

Andrew Newton nootn

View GitHub Profile
@nootn
nootn / Model.cs
Last active August 29, 2015 13:58
Yet another email validation mechanism
public class Model : IValidatableObject
{
[Display(Name = "Send to (email)")]
[Required(ErrorMessage = "'{0}' must be supplied")]
[RegularExpression(@".+\@.", ErrorMessage = "{0}' must be an email address")]
public override string ToEmailAddress { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
ValidationResult emailInvalidError = null;
@nootn
nootn / Program.cs
Created February 5, 2013 12:01
MiniProfiler.Windows IOC and AOP #4
private static void Main(string[] args)
{
//Configure building blocks
ConfigureIocAndAop();
//Start profiling
ConsoleProfiling.Start();
//Run the application, the log is all behind the IConsoleApplication's Run method so it can be easily unit tested
var app = _container.Resolve<IConsoleApplication>();
@nootn
nootn / ProfileMethodInterceptor.cs
Created February 5, 2013 11:59
MiniProfiler.Windows IOC and AOP #3
using System;
using System.Reflection;
using Castle.DynamicProxy;
using Snap;
using StackExchange.Profiling;
namespace ConsoleApplicationWithIocAndAop.AOP
{
public class ProfileMethodInterceptor : MethodInterceptor
{
@nootn
nootn / ProfileMethodAttribute.cs
Created February 5, 2013 11:59
MiniProfiler.Windows IOC and AOP #2
using Snap;
namespace ConsoleApplicationWithIocAndAop.AOP
{
public class ProfileMethodAttribute : MethodInterceptAttribute
{
}
}
@nootn
nootn / ConfigureIocAndAop.cs
Created February 5, 2013 11:58
MiniProfiler.Windows IOC and AOP #1
private static void ConfigureIocAndAop()
{
var builder = new ContainerBuilder();
//If using an IOC container, it is a handy to be able to us an IProfiler to
//wrap mini profiler calls just to remove that dependency for unit testing
builder.RegisterType<MiniProfilerWrapper>().AsImplementedInterfaces();
//We want some classes that do some work, but we don't want to have to wrap profiler steps
//around each method call, so use AOP to do it for us!
@nootn
nootn / Program.cs
Created February 5, 2013 11:51
Run Powershell from .NET avoiding System.Management.Automation #5
// /*
// Copyright (c) 2013 Andrew Newton (http://www.nootn.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT O
@nootn
nootn / RunPsUsingSystemManagementAutomation.cs
Created February 5, 2013 11:28
Run Powershell from .NET avoiding System.Management.Automation #4
// /*
// Copyright (c) 2013 Andrew Newton (http://www.nootn.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT O
@nootn
nootn / RunPsUsingBatchFile.cs
Created February 5, 2013 11:28
Run Powershell from .NET avoiding System.Management.Automation #3
// /*
// Copyright (c) 2013 Andrew Newton (http://www.nootn.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT O
@nootn
nootn / PowerShellRunner-SpecificVersion.bat
Created February 5, 2013 11:27
Run Powershell from .NET avoiding System.Management.Automation #2
C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe "%1"
@nootn
nootn / PowerShellRunner-Default.bat
Created February 5, 2013 11:24
Run Powershell from .NET avoiding System.Management.Automation #1
powershell "%1"