public virtual List<Type> GetControlTypesInBundles(string[] bundles, string fileName)
{
// TODO reduce complexity
var registeredControls = new List<Type>();
var registeredBundles = new List<string>();
//var fileName = Path.Combine(HttpRuntime.AppDomainAppPath, ConfigFileVirtualPath);
if(!File.Exists(fileName)) {
// No configuration config (AjaxControlToolkit.config) is specified
// Bundle names specified, but AjaxControlToolkit.config is not provided then exception should be thrown
if(bundles != null && bundles.Length > 0)
throw new Exception("Can not resolve requested control bundle since " + ConfigFileVirtualPath +
" file is not defined.");
// Load all AjaxControlToolkit controls if there is no bundle specified neither the config file
registeredControls.AddRange(ControlDependencyMap.Maps.SelectMany(m => m.Value.Dependecies));
} else {
var actConfig = ParseConfiguration(ReadConfiguration(fileName));
if(actConfig.ControlBundleSections != null && actConfig.ControlBundleSections.Length > 0) {
// Iterate all control bundle sections. Normaly, there will be only 1 section.
foreach(var bundle in actConfig.ControlBundleSections) {
if(bundle != null && bundle.ControlBundles != null && bundle.ControlBundles.Length > 0) {
// Iterate all control bundles in a section.
foreach(var controlBundle in bundle.ControlBundles) {
// Only add control types if ...
if(
// ... bundle contains control(s) and ...
(controlBundle.Controls != null && controlBundle.Controls.Length > 0) && (
// ... this is default control bundle and requested bundle not specified.
(string.IsNullOrEmpty(controlBundle.Name) &&
(bundles == null || bundles.Length == 0)) ||
// .. or this is not default bundle and its specified in requested bundle
(bundles != null && bundles.Contains(controlBundle.Name))
)) {
// Iterate all controls registered in control bundle. Determining control types is works here.
foreach(var control in controlBundle.Controls) {
if(string.IsNullOrEmpty(control.Assembly) ||
control.Assembly == "AjaxControlToolkit") {
// Processing AjaxControlToolkit controls
var controlName = "AjaxControlToolkit." + control.Name;
// Verify that control is a standard AjaxControlToolkit control
if(!ControlDependencyMap.Maps.ContainsKey(controlName))
throw new Exception(
string.Format(
"Could not find control '{0}'. Please make sure you entered the correct control name in AjaxControlToolkit.config file.",
control.Name));
registeredControls.AddRange(ControlDependencyMap.Maps[controlName].Dependecies);
} else {
// Processing custom controls
registeredControls.Add(
GetAssembly(control.Assembly)
.GetType(control.Assembly + "." + control.Name));
}
}
// Mark that bundle is registered for future verification
registeredBundles.Add(controlBundle.Name);
}
}
}
}
}
// Verify, is there any control in bundle that not registered yet
if(bundles != null) {
foreach(var bundle in bundles) {
if(!registeredBundles.Contains(bundle))
throw new Exception(string.Format("Could not resolve bundle {0}.", bundle));
}
}
}
// Return unique types
return registeredControls.Distinct().ToList();
}