using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using Umbraco.Core.Macros;
using umbraco.interfaces;
namespace Umbraco.Core.ObjectResolution
{
///
/// A resolver to return all IMacroGuiRendering objects
///
///
/// Much of this classes methods are based on legacy code from umbraco.editorControls.macrocontainer.MacroControlFactory
/// this code should probably be reviewed and cleaned up if necessary.
///
internal sealed class MacroFieldEditorsResolver : ManyObjectsResolverBase
{
///
/// Constructor
///
///
internal MacroFieldEditorsResolver(IEnumerable macroEditors)
: base(macroEditors, ObjectLifetimeScope.Transient)
{
}
///
/// Gets the implementations.
///
public IEnumerable MacroFieldEditors
{
get
{
return Values;
}
}
///
/// Gets the value based on the type of control
///
///
///
///
/// This is legacy code migrated from umbraco.editorControls.macrocontainer.MacroControlFactory
///
internal string GetValueFromMacroControl(Control macroControl)
{
return HttpUtility.HtmlDecode(((IMacroGuiRendering)macroControl).Value);
}
///
/// This is legacy code migrated from umbraco.editorControls.macrocontainer.MacroControlFactory
///
internal List MacroControlTypes
{
get { return InstanceTypes; }
}
///
/// 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.
///
///
/// This is legacy code migrated from umbraco.editorControls.macrocontainer.MacroControlFactory
///
internal Control GetMacroRenderControlByType(PersistableMacroProperty prop, string uniqueId)
{
var m = MacroControlTypes.FindLast(macroGuiCcontrol => macroGuiCcontrol.ToString() == string.Format("{0}.{1}", prop.AssemblyName, prop.TypeName));
var instance = PluginManager.Current.CreateInstance(m);
if (instance != null)
{
if (!string.IsNullOrEmpty(prop.Value))
{
instance.Value = HttpUtility.HtmlDecode(prop.Value);
}
var macroControl = instance as Control;
if (macroControl != null)
{
macroControl.ID = uniqueId;
return macroControl;
}
}
return null;
}
}
}