using System;
using System.Collections.Generic;
using System.Web.UI;
using umbraco.BusinessLogic.Utils;
using umbraco.interfaces;
using umbraco.editorControls;
namespace umbraco.editorControls.macrocontainer
{
internal class MacroControlFactory
{
#region Private Fields
///
/// All Possible Macro types
///
private static List _macroControlTypes = null;
#endregion
#region Methods
///
/// Create an instance of a Macro control and return it.
/// Because the macro control uses inline client script whichs is not generated after postback
/// That's why we use the Page Picker instead of the content picker of the macro.
///
internal static Control GetMacroRenderControlByType(PersistableMacroProperty prop, string uniqueID)
{
Control macroControl;
Type m = MacroControlTypes.FindLast(delegate(Type macroGuiCcontrol) { return macroGuiCcontrol.ToString() == string.Format("{0}.{1}", prop.AssemblyName, prop.TypeName); });
IMacroGuiRendering typeInstance;
typeInstance = Activator.CreateInstance(m) as IMacroGuiRendering;
if (!string.IsNullOrEmpty(prop.Value))
{
((IMacroGuiRendering)typeInstance).Value = prop.Value;
}
macroControl = (Control)typeInstance;
macroControl.ID = uniqueID;
return macroControl;
}
///
/// Gets the value based on the type of control
///
///
///
internal static string GetValueFromMacroControl(Control macroControl)
{
return ((IMacroGuiRendering)macroControl).Value;
}
#endregion
#region Properties
///
/// All Possible Macro types
///
private static List MacroControlTypes
{
get
{
if (_macroControlTypes == null || _macroControlTypes.Count == 0)
{
//Populate the list with all the types of IMacroGuiRendering
_macroControlTypes = new List();
_macroControlTypes = TypeFinder.FindClassesOfType();
}
return _macroControlTypes;
}
}
#endregion
}
}