Skip to content

Instantly share code, notes, and snippets.

View lkaczanowski's full-sized avatar

Łukasz Kaczanowski lkaczanowski

View GitHub Profile
@lkaczanowski
lkaczanowski / WinFormExceptionsHandler.cs
Created May 14, 2012 10:40
Global exception handler for windows forms
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
@lkaczanowski
lkaczanowski / ILogExtensions.cs
Created August 20, 2012 09:46
ILog extension for TRACE and VERBOSE log4net levels
public static class ILogExtentions
{
private static readonly log4net.ILog log =
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public static void Trace(this ILog log, string message, Exception exception)
{
log.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
log4net.Core.Level.Trace, message, exception);
@lkaczanowski
lkaczanowski / GetConflictingReferences.cs
Created August 20, 2012 09:51
Gets all conflicting references [with nunit test]
[TestFixture]
public class UtilityTest
{
[Test]
public void FindConflictingReferences()
{
var assemblies = GetAllAssemblies(@"path_to_assembly");
var references = GetReferencesFromAllAssemblies(assemblies);
@lkaczanowski
lkaczanowski / jquery.validate.unobtrusive.js
Created September 20, 2012 20:20
Styling asp.net MVC validation summary as Twitter bootstrap "flash"
function onErrors(form, validator) { // 'this' is the form element
var container = $(this).find("[data-valmsg-summary=true]"),
list = container.find("ul");
if (list && list.length && validator.errorList.length) {
list.empty();
container.addClass("validation-summary-errors").removeClass("validation-summary-valid");
$.each(validator.errorList, function () {
$("<li />").html(this.message).appendTo(list);
@lkaczanowski
lkaczanowski / README.markdown
Created September 20, 2012 20:36 — forked from beccasaurus/README.markdown
Adds hooks to jQuery.validate's form/element validation methods (via trigger())

jQuery Validate Hooks

If you're using [ASP.NET MVC3][], it uses [jQuery Validate][] to do client-side validations. Instead of using [jQuery Validate][] directly, however, it wraps it with its own jQuery plugin called [jQuery.Validate.Unobtrusive][]. [jQuery.Validate.Unobtrusive][] sets up [jQuery Validate][] for you, behind the scenes, so you don't have an opportunity to customize your [jQuery Validate][] settings at all!

We've been running into trouble with this when we've been doing our own custom client-side validations. We need a way to integrate with the build-in [ASP.NET MVC3][] validation so we can:

@lkaczanowski
lkaczanowski / SessionExpireFilterAttribute.cs
Last active September 28, 2020 08:28
Session Expire Filter Attribute
namespace Granite.Web.Services
{
using System.Web;
using System.Web.Mvc;
public class SessionExpireFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContextBase httpContext = filterContext.HttpContext;
@lkaczanowski
lkaczanowski / MvcMockHelpers.cs
Created November 29, 2012 09:56
Mvc Mocks Helper - taken from hanselman.com with added little tweaks
using System;
using System.Collections.Specialized;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Moq;
namespace Mvc.Tests
{
@lkaczanowski
lkaczanowski / HttpContextCurrentTests.cs
Created November 30, 2012 07:23
Creates HttpContext with Session to stub HttpContext.Current
using System.IO;
using System.Reflection;
using System.Web;
using System.Web.SessionState;
using NUnit.Framework;
namespace Mvc.Tests
{
[TestFixture]
@lkaczanowski
lkaczanowski / HtmlHelperTests.cs
Created January 10, 2013 14:42
Creates HtmlHelper mock for testing
[TestFixture]
public class HtmlHelperTests
{
// here put some tests...
public static HtmlHelper<T> CreateHtmlHelper<T>() where T : new ()
{
ViewDataDictionary viewData = new ViewDataDictionary(new T());
var controllerContext = new ControllerContext(
@lkaczanowski
lkaczanowski / ValidateGlobalAntiForgeryTokenAttribute.cs
Created January 22, 2013 13:20
ValidateGlobalAntiForgeryToken attribute (put it on controller, not separate actions)
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class ValidateGlobalAntiForgeryTokenAttribute : FilterAttribute, IAuthorizationFilter
{
private readonly ValidateAntiForgeryTokenAttribute validator;
private readonly AcceptVerbsAttribute acceptedVerbs;
public ValidateGlobalAntiForgeryTokenAttribute()
{
this.validator = new ValidateAntiForgeryTokenAttribute();