2012-08-01 22:06:15 +06:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using Umbraco.Core.Logging;
|
2012-08-10 13:18:13 +06:00
|
|
|
|
using Umbraco.Core.ObjectResolution;
|
2012-08-18 11:39:18 +06:00
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A bootstrapper for the Umbraco application which initializes all objects for the Core of the application
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// This does not provide any startup functionality relating to web objects
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
internal class CoreBootManager : IBootManager
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
private DisposableTimer _timer;
|
2012-08-07 21:40:34 +06:00
|
|
|
|
private bool _isInitialized = false;
|
|
|
|
|
|
private bool _isStarted = false;
|
|
|
|
|
|
private bool _isComplete = false;
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2012-08-14 12:03:34 +06:00
|
|
|
|
protected ApplicationContext ApplicationContext { get; private set; }
|
|
|
|
|
|
|
2012-08-01 22:06:15 +06:00
|
|
|
|
public virtual IBootManager Initialize()
|
|
|
|
|
|
{
|
2012-08-07 21:40:34 +06:00
|
|
|
|
if (_isInitialized)
|
|
|
|
|
|
throw new InvalidOperationException("The boot manager has already been initialized");
|
|
|
|
|
|
|
2012-08-01 22:06:15 +06:00
|
|
|
|
LogHelper.Info<CoreBootManager>("Umbraco application starting");
|
|
|
|
|
|
_timer = DisposableTimer.Start(x => LogHelper.Info<CoreBootManager>("Umbraco application startup complete" + " (took " + x + "ms)"));
|
|
|
|
|
|
|
|
|
|
|
|
//create the ApplicationContext
|
2012-09-28 11:11:47 -02:00
|
|
|
|
ApplicationContext = ApplicationContext.Current = new ApplicationContext();
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2012-11-05 09:03:48 -01:00
|
|
|
|
//initialize the DatabaseContext
|
|
|
|
|
|
DatabaseContext.Current.Initialize();
|
2012-10-29 09:49:31 -01:00
|
|
|
|
|
2012-08-01 22:06:15 +06:00
|
|
|
|
InitializeResolvers();
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
|
|
|
|
|
_isInitialized = true;
|
|
|
|
|
|
|
2012-08-01 22:06:15 +06:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fires after initialization and calls the callback to allow for customizations to occur
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="afterStartup"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public virtual IBootManager Startup(Action<ApplicationContext> afterStartup)
|
|
|
|
|
|
{
|
2012-08-07 21:40:34 +06:00
|
|
|
|
if (_isStarted)
|
|
|
|
|
|
throw new InvalidOperationException("The boot manager has already been initialized");
|
|
|
|
|
|
|
2012-08-01 22:46:13 +06:00
|
|
|
|
if (afterStartup != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
afterStartup(ApplicationContext.Current);
|
2012-08-07 21:40:34 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_isStarted = true;
|
|
|
|
|
|
|
2012-08-01 22:06:15 +06:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fires after startup and calls the callback once customizations are locked
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="afterComplete"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public virtual IBootManager Complete(Action<ApplicationContext> afterComplete)
|
|
|
|
|
|
{
|
2012-08-07 21:40:34 +06:00
|
|
|
|
if (_isComplete)
|
|
|
|
|
|
throw new InvalidOperationException("The boot manager has already been completed");
|
|
|
|
|
|
|
2012-08-01 22:06:15 +06:00
|
|
|
|
//freeze resolution to not allow Resolvers to be modified
|
|
|
|
|
|
Resolution.Freeze();
|
|
|
|
|
|
|
|
|
|
|
|
//stop the timer and log the output
|
|
|
|
|
|
_timer.Dispose();
|
|
|
|
|
|
|
2012-08-01 22:46:13 +06:00
|
|
|
|
if (afterComplete != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
afterComplete(ApplicationContext.Current);
|
|
|
|
|
|
}
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
|
|
|
|
|
_isComplete = true;
|
|
|
|
|
|
|
2012-08-01 22:06:15 +06:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create the resolvers
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected virtual void InitializeResolvers()
|
|
|
|
|
|
{
|
|
|
|
|
|
CacheRefreshersResolver.Current = new CacheRefreshersResolver(
|
|
|
|
|
|
PluginManager.Current.ResolveCacheRefreshers());
|
|
|
|
|
|
|
|
|
|
|
|
DataTypesResolver.Current = new DataTypesResolver(
|
|
|
|
|
|
PluginManager.Current.ResolveDataTypes());
|
2012-08-01 22:46:13 +06:00
|
|
|
|
|
|
|
|
|
|
MacroFieldEditorsResolver.Current = new MacroFieldEditorsResolver(
|
|
|
|
|
|
PluginManager.Current.ResolveMacroRenderings());
|
2012-08-01 23:03:26 +06:00
|
|
|
|
|
|
|
|
|
|
PackageActionsResolver.Current = new PackageActionsResolver(
|
|
|
|
|
|
PluginManager.Current.ResolvePackageActions());
|
2012-08-01 23:30:37 +06:00
|
|
|
|
|
|
|
|
|
|
ActionsResolver.Current = new ActionsResolver(
|
|
|
|
|
|
PluginManager.Current.ResolveActions());
|
2012-08-18 11:39:18 +06:00
|
|
|
|
|
2012-10-30 09:25:28 -01:00
|
|
|
|
MacroPropertyTypeResolver.Current = new MacroPropertyTypeResolver(
|
|
|
|
|
|
PluginManager.Current.ResolveMacroPropertyTypes());
|
|
|
|
|
|
|
2012-08-18 11:39:18 +06:00
|
|
|
|
PropertyEditorValueConvertersResolver.Current = new PropertyEditorValueConvertersResolver(
|
2012-11-05 06:14:44 +06:00
|
|
|
|
PluginManager.Current.ResolvePropertyEditorValueConverters());
|
|
|
|
|
|
//add the internal ones, these are not public currently so need to add them manually
|
|
|
|
|
|
PropertyEditorValueConvertersResolver.Current.AddType<DatePickerPropertyEditorValueConverter>();
|
|
|
|
|
|
PropertyEditorValueConvertersResolver.Current.AddType<TinyMcePropertyEditorValueConverter>();
|
|
|
|
|
|
PropertyEditorValueConvertersResolver.Current.AddType<YesNoPropertyEditorValueConverter>();
|
2012-08-01 22:06:15 +06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|