Created
September 11, 2010 01:18
-
-
Save anonymous/574649 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Configuration; | |
using NServiceBus.Config; | |
using NServiceBus.Config.ConfigurationSource; | |
namespace NServiceBus | |
{ | |
public class UserConfigurationSource : IConfigurationSource | |
{ | |
readonly Action<UnicastBusConfig> UnicastCallback; | |
readonly Action<MsmqTransportConfig> MsmqTransportCallback; | |
public UserConfigurationSource() | |
: this(null, null) | |
{ | |
} | |
public UserConfigurationSource(Action<UnicastBusConfig> unicastCallback) | |
: this(unicastCallback, null) | |
{ | |
} | |
public UserConfigurationSource(Action<MsmqTransportConfig> msmqTransportCallback) | |
: this(null, msmqTransportCallback) | |
{ | |
} | |
public UserConfigurationSource(Action<UnicastBusConfig> unicastCallback, Action<MsmqTransportConfig> msmqTransportCallback) | |
{ | |
this.UnicastCallback = unicastCallback; | |
this.MsmqTransportCallback = msmqTransportCallback; | |
} | |
public T GetConfiguration<T>() where T : class | |
{ | |
if (typeof(T) == typeof(MsmqSubscriptionStorageConfig)) | |
return ConfigurationManager.GetSection(typeof(T).Name) as T; | |
if (typeof(T) == typeof(DBSubscriptionStorageConfig)) | |
return ConfigurationManager.GetSection(typeof(T).Name) as T; | |
if (typeof(T) == typeof(MsmqTransportConfig) && MsmqTransportCallback != null) | |
return MsmqTransportConfiguration() as T; | |
if (typeof(T) == typeof(UnicastBusConfig) && UnicastCallback != null) | |
return UnicastBusConfiguration() as T; | |
return ConfigurationManager.GetSection(typeof(T).Name) as T; | |
} | |
private UnicastBusConfig UnicastBusConfiguration() | |
{ | |
var config = new UnicastBusConfig(); | |
UnicastCallback(config); | |
return config; | |
} | |
private MsmqTransportConfig MsmqTransportConfiguration() | |
{ | |
var config = new MsmqTransportConfig(); | |
MsmqTransportCallback(config); | |
return config; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment