2012-08-01 22:06:15 +06:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
2012-12-15 08:41:46 +05:00
|
|
|
|
using Umbraco.Core.Configuration;
|
2012-08-01 22:06:15 +06:00
|
|
|
|
using Umbraco.Core.Logging;
|
2012-08-10 13:18:13 +06:00
|
|
|
|
using Umbraco.Core.ObjectResolution;
|
2012-12-09 09:01:00 +05:00
|
|
|
|
using Umbraco.Core.Persistence;
|
2012-12-29 18:53:13 -01:00
|
|
|
|
using Umbraco.Core.Persistence.Mappers;
|
2013-01-10 04:33:30 +03:00
|
|
|
|
using Umbraco.Core.Persistence.Migrations;
|
2012-12-14 08:06:32 +05:00
|
|
|
|
using Umbraco.Core.Persistence.UnitOfWork;
|
2012-08-18 11:39:18 +06:00
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
2012-12-14 08:06:32 +05:00
|
|
|
|
using Umbraco.Core.Publishing;
|
|
|
|
|
|
using Umbraco.Core.Services;
|
2013-01-10 04:33:30 +03:00
|
|
|
|
using MigrationsVersionSixth = Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSixth;
|
|
|
|
|
|
using MigrationsVersionFourNineZero = Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionFourNineZero;
|
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>
|
2012-12-12 20:10:50 +05:00
|
|
|
|
public class CoreBootManager : IBootManager
|
2012-08-01 22:06:15 +06:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
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)"));
|
|
|
|
|
|
|
2012-12-14 08:06:32 +05:00
|
|
|
|
//create database and service contexts for the app context
|
2012-12-15 08:41:46 +05:00
|
|
|
|
var dbFactory = new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName);
|
2013-01-10 04:33:30 +03:00
|
|
|
|
Database.Mapper = new PetaPocoMapper();
|
2012-12-15 08:41:46 +05:00
|
|
|
|
var dbContext = new DatabaseContext(dbFactory);
|
|
|
|
|
|
var serviceContext = new ServiceContext(
|
|
|
|
|
|
new PetaPocoUnitOfWorkProvider(dbFactory),
|
|
|
|
|
|
new FileUnitOfWorkProvider(),
|
|
|
|
|
|
new PublishingStrategy());
|
2012-12-14 08:06:32 +05:00
|
|
|
|
|
2012-08-01 22:06:15 +06:00
|
|
|
|
//create the ApplicationContext
|
2012-12-14 08:06:32 +05:00
|
|
|
|
ApplicationContext = ApplicationContext.Current = new ApplicationContext(dbContext, serviceContext);
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2012-11-05 09:03:48 -01:00
|
|
|
|
//initialize the DatabaseContext
|
2012-12-14 08:06:32 +05:00
|
|
|
|
dbContext.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()
|
|
|
|
|
|
{
|
2012-12-10 02:58:23 +05:00
|
|
|
|
RepositoryResolver.Current = new RepositoryResolver(
|
|
|
|
|
|
new RepositoryFactory());
|
2012-12-09 09:01:00 +05:00
|
|
|
|
|
2012-08-01 22:06:15 +06:00
|
|
|
|
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>();
|
2013-01-10 04:33:30 +03:00
|
|
|
|
|
|
|
|
|
|
//the database migration objects
|
|
|
|
|
|
MigrationResolver.Current = new MigrationResolver(new List<Type>
|
|
|
|
|
|
{
|
|
|
|
|
|
typeof (MigrationsVersionFourNineZero.RemoveUmbracoAppConstraints),
|
|
|
|
|
|
typeof (MigrationsVersionSixth.DeleteAppTables),
|
|
|
|
|
|
typeof (MigrationsVersionSixth.EnsureAppsTreesUpdated),
|
|
|
|
|
|
typeof (MigrationsVersionSixth.MoveMasterContentTypeData),
|
|
|
|
|
|
typeof (MigrationsVersionSixth.NewCmsContentType2ContentTypeTable),
|
|
|
|
|
|
typeof (MigrationsVersionSixth.RemoveMasterContentTypeColumn),
|
|
|
|
|
|
typeof (MigrationsVersionSixth.RenameCmsTabTable),
|
|
|
|
|
|
typeof (MigrationsVersionSixth.RenameTabIdColumn),
|
|
|
|
|
|
typeof (MigrationsVersionSixth.UpdateCmsContentTypeAllowedContentTypeTable),
|
|
|
|
|
|
typeof (MigrationsVersionSixth.UpdateCmsContentTypeTable),
|
|
|
|
|
|
typeof (MigrationsVersionSixth.UpdateCmsContentVersionTable),
|
|
|
|
|
|
typeof (MigrationsVersionSixth.UpdateCmsPropertyTypeGroupTable)
|
|
|
|
|
|
});
|
2012-08-01 22:06:15 +06:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|