Skip to content

Instantly share code, notes, and snippets.

View chgeuer's full-sized avatar
🏠
Working from Düsseldorf

Dr. Christian Geuer-Pollmann chgeuer

🏠
Working from Düsseldorf
View GitHub Profile
@chgeuer
chgeuer / MEFOutput.cs
Created July 21, 2011 14:26
MEF Debugging - Spit out values
try
{
// Just try to check whether the actual service instance can be created.
var svc = container.GetExportedValue<AppStoreServiceImpl>();
Debug.Assert(
svc != null,
"container.GetExportedValue<AppStoreServiceImpl>() != null");
}
catch (CompositionException ce)
@chgeuer
chgeuer / NoHttpKeepAlive.cs
Created August 16, 2011 14:45
Turn off HTTP KeepAlive
// When testing in an NLB environment, it's helpful to test
// with a WCF client which doesn't reuse open TCP connections
// for HTTP...
var bindingElements = wcfBinding.CreateBindingElements();
var httpBe = bindingElements.OfType<HttpTransportBindingElement>().FirstOrDefault();
if (httpBe != null)
{
httpBe.KeepAliveEnabled = false;
@chgeuer
chgeuer / DisableRequireSecurityContextCancellation.cs
Created August 16, 2011 14:46
How to programatically disable WS-SC session tokens and turn on cookies
public static Binding DisableRequireSecurityContextCancellation(Binding binding)
{
var bindingElements = binding.CreateBindingElements();
var securityBindingElement = bindingElements.OfType<SymmetricSecurityBindingElement>().FirstOrDefault();
if (securityBindingElement == null)
{
throw new NotSupportedException("Cannot locate SymmetricSecurityBindingElement");
}
var protectionTokenParameters = securityBindingElement.ProtectionTokenParameters;
@chgeuer
chgeuer / gist:1156278
Created August 19, 2011 07:50
CSDEF file with virtual applications in a web role
<WebRole name="Cloud.WebRole" vmsize="Small">
<Sites>
<Site name="Web">
<VirtualApplication name="App1" physicalDirectory="..\Site.App1" />
<VirtualApplication name="App2" physicalDirectory="..\Site.App2" />
<VirtualApplication name="App3" physicalDirectory="..\Site.App3" />
<VirtualApplication name="App4" physicalDirectory="..\Site.App4" />
<Bindings>
<Binding name="HttpPort80" endpointName="HttpPort80" />
<Binding name="HttpsPort443" endpointName="HttpsPort443" />
@chgeuer
chgeuer / app.config.xml
Created August 25, 2011 13:33
MEF Debugging - config
<sources>
<source name="System.ComponentModel.Composition" switchValue="All">
<listeners>
<add name="fileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="composition.log" />
</listeners>
</source>
</sources>
<trace autoflush="true"/>
@chgeuer
chgeuer / gist:1246033
Created September 27, 2011 19:47
CrossProcessBarrier1 - the names
IEnumerable<string> allNames = new List<string>
{
"deployment(400).GenericWorkerRole.Cloud.WebRole.0_Web",
"deployment(400).GenericWorkerRole.Cloud.WebRole.1_Web",
"deployment(400).GenericWorkerRole.Cloud.WebRole.2_Web",
"deployment(400).GenericWorkerRole.Cloud.WebRole.3_Web",
"deployment(400).GenericWorkerRole.Cloud.WebRole.4_Web"
};
Func<string, string> escapeMutexName = instanceId => instanceId.Replace("(", ".").Replace(")", ".").Replace(".", "");
allNames = allNames.Select(escapeMutexName);
@chgeuer
chgeuer / gist:1286768
Created October 14, 2011 10:28
Currying
using System;
using System.Net;
namespace curry
{
class Program
{
static void Main(string[] args)
{
var url = "http://www.microsoft.com/";
@chgeuer
chgeuer / Remove-Thumbs.db.ps1
Created October 20, 2011 14:16
Get rid of Thumbs.db...
Get-ChildItem -Recurse -Force -Filter Thumbs.db | foreach ($_) { Remove-Item -Force -Path $_.fullname }
@chgeuer
chgeuer / WCF_Silverlight_Cookie_Tester.cs
Created February 17, 2012 09:36
Silverlight password cookie and testing
@chgeuer
chgeuer / MEFExistingInstanceInjectionSample.cs
Created February 23, 2012 08:12
MEF - Show how a specific object instance can be injected into a container.
namespace MEFExistingInstanceInjection
{
using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
/// <seealso href="http://stackoverflow.com/questions/7684766/is-it-possible-to-inject-an-existing-instance-into-a-mef-plugin"/>
class MEFExistingInstanceInjectionSample
{
static void Main(string[] args)