Skip to content

Instantly share code, notes, and snippets.

View tugberkugurlu's full-sized avatar
:shipit:
💥 shakalaka

Tugberk Ugurlu tugberkugurlu

:shipit:
💥 shakalaka
View GitHub Profile
[Auth(Roles = "Admin")]
public class FooHub : Hub {
[Log]
public void Send() {
//do something here...
}
}
public class Global : System.Web.HttpApplication {
protected void Application_Start(object sender, EventArgs e) {
GlobalHost.Something.Add(new TheThingsThatRunsOnEverRequestBeforeHubs());
}
}
@tugberkugurlu
tugberkugurlu / DefaultServices.cs
Created July 4, 2012 12:36
DefaultServices class in ASP.NET Web API project
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Class needs references to large number of types.")]
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "We're registering the ValidationCache to be disposed by the HttpConfiguration.")]
public DefaultServices(HttpConfiguration configuration)
{
if (configuration == null)
{
throw Error.ArgumentNull("configuration");
}
_configuration = configuration;
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
namespace System.Threading.Tasks
{
/// <summary>
/// Helpers for safely using Task libraries.
//From SignalR project
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
namespace SignalR
// Func<Task<HttpResponseMessage>>
Task<HttpResponseMessage> result = InvokeActionWithAuthorizationFilters(actionContext, cancellationToken, authorizationFilters, () =>
{
HttpActionBinding actionBinding = actionDescriptor.ActionBinding;
Task bindTask = actionBinding.ExecuteBindingAsync(actionContext, cancellationToken);
return bindTask.Then<HttpResponseMessage>(() =>
{
_modelState = actionContext.ModelState;
Func<Task<HttpResponseMessage>> invokeFunc = InvokeActionWithActionFilters(actionContext, cancellationToken, actionFilters, () =>
{
@tugberkugurlu
tugberkugurlu / enc_dec.ps1
Created July 7, 2012 16:44
ENCRYPTING A STRING USING CERTIFICATES AND POWERSHELL
Function encrypt-envelope ($unprotectedcontent, $cert)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
$utf8content = [Text.Encoding]::UTF8.GetBytes($unprotectedcontent)
$content = New-Object Security.Cryptography.Pkcs.ContentInfo `
@tugberkugurlu
tugberkugurlu / Global.asax.cs
Created July 13, 2012 14:27
Don't allow param for POST
protected void Application_Start(object sender, EventArgs e) {
var config = GlobalConfiguration.Configuration;
var routes = config.Routes;
routes.MapHttpRoute(
"DefaultHttpRoute",
"api/{controller}/{id}",
new { id = RouteParameter.Optional },
new {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Xml.Serialization;
namespace MvcApplication56.Controllers {
public class AsyncFactory {
public static Task<int> GetIntAsync() {
var tcs = new TaskCompletionSource<int>();
var timer = new System.Timers.Timer(2000);
timer.AutoReset = false;
timer.Elapsed += (s, e) => {
tcs.SetResult(10);