|
using System;
using System.Configuration;
using System.Configuration.Provider;
using System.Web.Configuration;
namespace ConfigActivities {
public class MyProviderManager {
//Initialization related variables and logic
private static bool isInitialized = false;
private static Exception initializationException;
private static object initializationLock = new object();
static MyProviderManager() {
Initialize();
}
private static void Initialize() {
try {
//Get the feature's configuration info
MyProviderConfiguration qc =
(MyProviderConfiguration)ConfigurationManager.GetSection("MyProvider");
if (qc.DefaultProvider == null || qc.Providers == null || qc.Providers.Count < 1)
throw new ProviderException("You must specify a valid default provider.");
//Instantiate the providers
providerCollection = new MyProviderProviderCollection();
ProvidersHelper.InstantiateProviders(qc.Providers, providerCollection, typeof(MyProviderProvider));
providerCollection.SetReadOnly();
defaultProvider = providerCollection[qc.DefaultProvider];
if (defaultProvider == null) {
throw new ConfigurationErrorsException(
"You must specify a default provider for the feature.",
qc.ElementInformation.Properties["defaultProvider"].Source,
qc.ElementInformation.Properties["defaultProvider"].LineNumber);
}
}
catch (Exception ex) {
initializationException = ex;
isInitialized = true;
throw ex;
}
isInitialized = true; //error-free initialization
}
//Public feature API
private static MyProviderProvider defaultProvider;
private static MyProviderProviderCollection providerCollection;
public static MyProviderProvider Provider {
get {
return defaultProvider;
}
}
public static MyProviderProviderCollection Providers {
get {
return providerCollection;
}
}
public static string DoWork() {
return Provider.DoWork();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.