This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static X509Certificate2 GetX509Certificate2(string thumbprint) | |
{ | |
var store = new X509Store(StoreLocation.LocalMachine); | |
store.Open(OpenFlags.ReadOnly); | |
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly); | |
var certificates = store.Certificates.Cast<X509Certificate2>().ToList(); | |
var cert = | |
certificates.FirstOrDefault( | |
x => x.Thumbprint.Equals(thumbprint, StringComparison.InvariantCultureIgnoreCase)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class GuidRouteConstraint : IRouteConstraint | |
{ | |
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) | |
{ | |
object value; | |
if (!values.TryGetValue(parameterName, out value)) | |
{ | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BiDictionary<TFirst, TSecond> | |
{ | |
private readonly IDictionary<TFirst, TSecond> firstToSecond; | |
private readonly IDictionary<TSecond, TFirst> secondToFirst; | |
public BiDictionary() | |
{ | |
firstToSecond = new Dictionary<TFirst, TSecond>(); | |
secondToFirst = new Dictionary<TSecond, TFirst>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EnsureRouteValueAttribute : ActionFilterAttribute | |
{ | |
private readonly bool ignoreCase; | |
private readonly string routeValueKey; | |
private readonly string ensureRouteValue; | |
public EnsureRouteValueAttribute(string routeValueKey, string ensureRouteValue, bool ignoreCase = true) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
choco pack | |
choco install {PACKAGE_NAME} -s "$pwd" -f # -y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on: | |
// https://github.com/rbrian/mccszlib/blob/master/Crc32.cs | |
public static class Crc32 | |
{ | |
private const uint CrcSeed = 0xFFFFFFFF; | |
#region CRC Table | |
private static readonly uint[] CrcTable = new uint[] | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DiskFileDependencyHelper | |
{ | |
public static void AddRestartWatch(string filePath) | |
{ | |
var fileInfo = new FileInfo(filePath); | |
if (fileInfo.Directory == null) | |
{ | |
throw new FileNotFoundException("File or folder not found.", filePath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RequestLazy<T> | |
{ | |
private readonly Func<T> valueFactory; | |
private readonly Func<IDictionary> storeFactory; | |
internal RequestLazy(Func<T> valueFactory, string storeKey, Func<IDictionary> storeFactory) | |
{ | |
this.storeFactory = storeFactory ?? (() => (HttpContext.Current != null) ? HttpContext.Current.Items : null); | |
this.valueFactory = valueFactory ?? this.GetValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<TSource> Duplicates<TSource>(this IEnumerable<TSource> source) | |
{ | |
return from grouping in source.GroupBy(x => x) where grouping.Count() > 1 from item in grouping select item; | |
} | |
public static IEnumerable<TSource> Duplicates<TSource>( | |
this IEnumerable<TSource> source, Func<TSource, object> keySelector) | |
{ | |
return from grouping in source.GroupBy(keySelector) | |
where grouping.Count() > 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<Type> GetAssemblyTypes<TType>(params Assembly[] assemblies) | |
{ | |
return GetAssemblyTypes(typeof(TType), assemblies); | |
} | |
public static IEnumerable<Type> GetAssemblyTypes(Type rootType, params Assembly[] assemblies) | |
{ | |
if (assemblies == null || !assemblies.Any()) | |
{ | |
assemblies = new[] { rootType.Assembly }; |