2012-08-01 22:06:15 +06:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2015-03-19 13:53:15 +11:00
|
|
|
|
using System.IO;
|
2013-07-01 14:23:56 +10:00
|
|
|
|
using System.Linq;
|
2015-07-09 14:31:59 +02:00
|
|
|
|
using System.Threading;
|
2013-07-02 17:47:20 +10:00
|
|
|
|
using System.Web;
|
2013-07-01 14:23:56 +10:00
|
|
|
|
using AutoMapper;
|
2013-08-09 11:37:57 +10:00
|
|
|
|
using Umbraco.Core.Cache;
|
2012-12-15 08:41:46 +05:00
|
|
|
|
using Umbraco.Core.Configuration;
|
2015-07-09 14:31:59 +02:00
|
|
|
|
using Umbraco.Core.Exceptions;
|
2015-03-19 13:53:15 +11:00
|
|
|
|
using Umbraco.Core.IO;
|
2012-08-01 22:06:15 +06:00
|
|
|
|
using Umbraco.Core.Logging;
|
2013-07-01 14:23:56 +10:00
|
|
|
|
using Umbraco.Core.Models.Mapping;
|
2013-09-13 21:15:40 +02:00
|
|
|
|
using Umbraco.Core.Models.PublishedContent;
|
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;
|
2013-01-18 12:00:29 -01:00
|
|
|
|
using Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix;
|
2013-02-28 14:54:42 -01:00
|
|
|
|
using Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSixZeroOne;
|
2013-03-09 10:43:34 -01:00
|
|
|
|
using Umbraco.Core.Persistence.SqlSyntax;
|
2012-12-14 08:06:32 +05:00
|
|
|
|
using Umbraco.Core.Persistence.UnitOfWork;
|
2013-05-12 15:25:46 -10:00
|
|
|
|
using Umbraco.Core.Profiling;
|
2012-08-18 11:39:18 +06:00
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
2013-09-23 16:30:24 +02:00
|
|
|
|
using Umbraco.Core.PropertyEditors.ValueConverters;
|
2012-12-14 08:06:32 +05:00
|
|
|
|
using Umbraco.Core.Publishing;
|
2013-01-16 13:31:04 -01:00
|
|
|
|
using Umbraco.Core.Macros;
|
2015-03-19 13:53:15 +11:00
|
|
|
|
using Umbraco.Core.Manifest;
|
2012-12-14 08:06:32 +05:00
|
|
|
|
using Umbraco.Core.Services;
|
2013-02-11 20:07:23 +06:00
|
|
|
|
using Umbraco.Core.Sync;
|
2013-02-07 13:30:50 -01:00
|
|
|
|
using Umbraco.Core.Strings;
|
2013-01-10 04:33:30 +03:00
|
|
|
|
using MigrationsVersionFourNineZero = Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionFourNineZero;
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core
|
|
|
|
|
|
{
|
2013-06-20 10:05:51 +10:00
|
|
|
|
/// <summary>
|
2015-01-07 17:23:24 +11:00
|
|
|
|
/// 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>
|
|
|
|
|
|
public class CoreBootManager : IBootManager
|
|
|
|
|
|
{
|
2015-01-16 12:29:27 +11:00
|
|
|
|
private ProfilingLogger _profilingLogger;
|
2015-01-07 17:23:24 +11:00
|
|
|
|
private DisposableTimer _timer;
|
|
|
|
|
|
private bool _isInitialized = false;
|
|
|
|
|
|
private bool _isStarted = false;
|
|
|
|
|
|
private bool _isComplete = false;
|
2015-01-16 15:47:44 +11:00
|
|
|
|
private readonly IServiceProvider _serviceProvider = new ActivatorServiceProvider();
|
2013-01-29 09:45:12 +06:00
|
|
|
|
private readonly UmbracoApplicationBase _umbracoApplication;
|
2015-01-07 17:23:24 +11:00
|
|
|
|
protected ApplicationContext ApplicationContext { get; set; }
|
2013-07-02 17:47:20 +10:00
|
|
|
|
protected CacheHelper ApplicationCache { get; set; }
|
2015-01-16 15:47:44 +11:00
|
|
|
|
protected PluginManager PluginManager { get; private set; }
|
2012-08-14 12:03:34 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
protected UmbracoApplicationBase UmbracoApplication
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _umbracoApplication; }
|
|
|
|
|
|
}
|
2013-01-29 09:45:12 +06:00
|
|
|
|
|
2015-01-16 15:47:44 +11:00
|
|
|
|
protected IServiceProvider ServiceProvider
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _serviceProvider; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
public CoreBootManager(UmbracoApplicationBase umbracoApplication)
|
|
|
|
|
|
{
|
2013-01-29 09:45:12 +06:00
|
|
|
|
if (umbracoApplication == null) throw new ArgumentNullException("umbracoApplication");
|
|
|
|
|
|
_umbracoApplication = umbracoApplication;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
public virtual IBootManager Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_isInitialized)
|
|
|
|
|
|
throw new InvalidOperationException("The boot manager has already been initialized");
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
InitializeLoggerResolver();
|
|
|
|
|
|
InitializeProfilerResolver();
|
2013-05-13 21:11:03 -10:00
|
|
|
|
|
2015-01-16 12:29:27 +11:00
|
|
|
|
_profilingLogger = new ProfilingLogger(LoggerResolver.Current.Logger, ProfilerResolver.Current.Profiler);
|
|
|
|
|
|
|
2015-07-03 16:34:41 +02:00
|
|
|
|
_timer = _profilingLogger.TraceDuration<CoreBootManager>(
|
2015-07-13 22:45:37 +02:00
|
|
|
|
string.Format("Umbraco {0} application starting on {1}", UmbracoVersion.GetSemanticVersion().ToSemanticString(), NetworkHelper.MachineName),
|
2015-07-03 16:34:41 +02:00
|
|
|
|
"Umbraco application startup complete");
|
2015-01-07 17:23:24 +11:00
|
|
|
|
|
|
|
|
|
|
CreateApplicationCache();
|
2013-07-02 17:47:20 +10:00
|
|
|
|
|
2015-01-16 15:47:44 +11:00
|
|
|
|
//create and set the plugin manager (I'd much prefer to not use this singleton anymore but many things are using it unfortunately and
|
|
|
|
|
|
// the way that it is setup, there must only ever be one per app so without IoC it would be hard to make this not a singleton)
|
|
|
|
|
|
PluginManager = new PluginManager(ServiceProvider, ApplicationCache.RuntimeCache, _profilingLogger);
|
|
|
|
|
|
PluginManager.Current = PluginManager;
|
|
|
|
|
|
|
2013-09-09 15:57:22 +10:00
|
|
|
|
//Create the legacy prop-eds mapping
|
|
|
|
|
|
LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors();
|
2013-10-30 14:36:07 +11:00
|
|
|
|
LegacyParameterEditorAliasConverter.CreateMappingsForCoreEditors();
|
2013-09-09 15:57:22 +10:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
//create database and service contexts for the app context
|
2015-01-09 15:27:47 +11:00
|
|
|
|
var dbFactory = new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName, LoggerResolver.Current.Logger);
|
2015-01-07 17:23:24 +11:00
|
|
|
|
Database.Mapper = new PetaPocoMapper();
|
2015-01-13 18:19:52 +11:00
|
|
|
|
|
|
|
|
|
|
var dbContext = new DatabaseContext(
|
|
|
|
|
|
dbFactory,
|
|
|
|
|
|
LoggerResolver.Current.Logger,
|
|
|
|
|
|
SqlSyntaxProviders.CreateDefault(LoggerResolver.Current.Logger));
|
|
|
|
|
|
|
|
|
|
|
|
//initialize the DatabaseContext
|
|
|
|
|
|
dbContext.Initialize();
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
var serviceContext = new ServiceContext(
|
2015-01-13 18:19:52 +11:00
|
|
|
|
new RepositoryFactory(ApplicationCache, LoggerResolver.Current.Logger, dbContext.SqlSyntax, UmbracoConfig.For.UmbracoSettings()),
|
2015-01-07 17:23:24 +11:00
|
|
|
|
new PetaPocoUnitOfWorkProvider(dbFactory),
|
|
|
|
|
|
new FileUnitOfWorkProvider(),
|
|
|
|
|
|
new PublishingStrategy(),
|
2015-01-09 10:51:15 +11:00
|
|
|
|
ApplicationCache,
|
|
|
|
|
|
LoggerResolver.Current.Logger);
|
2013-03-11 23:46:47 +06:00
|
|
|
|
|
|
|
|
|
|
CreateApplicationContext(dbContext, serviceContext);
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2013-01-29 09:45:12 +06:00
|
|
|
|
InitializeApplicationEventsResolver();
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
InitializeResolvers();
|
2013-03-09 10:43:34 -01:00
|
|
|
|
|
2015-01-13 18:19:52 +11:00
|
|
|
|
|
2013-03-09 10:43:34 -01:00
|
|
|
|
|
2013-06-18 17:22:01 +10:00
|
|
|
|
InitializeModelMappers();
|
|
|
|
|
|
|
2015-07-14 10:49:43 +02:00
|
|
|
|
using (_profilingLogger.DebugDuration<CoreBootManager>(
|
|
|
|
|
|
string.Format("Executing {0} IApplicationEventHandler.OnApplicationInitialized", ApplicationEventsResolver.Current.ApplicationEventHandlers.Count()),
|
|
|
|
|
|
"Finished executing IApplicationEventHandler.OnApplicationInitialized"))
|
2015-07-08 16:45:34 +02:00
|
|
|
|
{
|
|
|
|
|
|
//now we need to call the initialize methods
|
|
|
|
|
|
ApplicationEventsResolver.Current.ApplicationEventHandlers
|
|
|
|
|
|
.ForEach(x =>
|
2015-07-08 16:27:06 +02:00
|
|
|
|
{
|
2015-07-08 16:45:34 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
x.OnApplicationInitialized(UmbracoApplication, ApplicationContext);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2015-07-14 10:49:43 +02:00
|
|
|
|
_profilingLogger.Logger.Error<CoreBootManager>("An error occurred running OnApplicationInitialized for handler " + x.GetType(), ex);
|
2015-07-08 16:45:34 +02:00
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2013-01-29 09:45:12 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
_isInitialized = true;
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2013-03-11 23:46:47 +06:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates and assigns the application context singleton
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dbContext"></param>
|
|
|
|
|
|
/// <param name="serviceContext"></param>
|
|
|
|
|
|
protected virtual void CreateApplicationContext(DatabaseContext dbContext, ServiceContext serviceContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
//create the ApplicationContext
|
2015-01-16 12:29:27 +11:00
|
|
|
|
ApplicationContext = ApplicationContext.Current = new ApplicationContext(dbContext, serviceContext, ApplicationCache, _profilingLogger);
|
2013-07-02 17:47:20 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates and assigns the ApplicationCache based on a new instance of System.Web.Caching.Cache
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected virtual void CreateApplicationCache()
|
|
|
|
|
|
{
|
2013-08-09 11:37:57 +10:00
|
|
|
|
var cacheHelper = new CacheHelper(
|
|
|
|
|
|
new ObjectCacheRuntimeCacheProvider(),
|
|
|
|
|
|
new StaticCacheProvider(),
|
2015-01-07 17:23:24 +11:00
|
|
|
|
//we have no request based cache when not running in web-based context
|
2013-08-09 11:37:57 +10:00
|
|
|
|
new NullCacheProvider());
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationCache = cacheHelper;
|
2013-03-11 23:46:47 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-06-18 17:22:01 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This method allows for configuration of model mappers
|
|
|
|
|
|
/// </summary>
|
2013-07-01 14:23:56 +10:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// Model mappers MUST be defined on ApplicationEventHandler instances with the interface IMapperConfiguration.
|
|
|
|
|
|
/// This allows us to search for less types on startup.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
protected void InitializeModelMappers()
|
2013-06-18 17:22:01 +10:00
|
|
|
|
{
|
2013-07-01 14:23:56 +10:00
|
|
|
|
Mapper.Initialize(configuration =>
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var m in ApplicationEventsResolver.Current.ApplicationEventHandlers.OfType<IMapperConfiguration>())
|
|
|
|
|
|
{
|
2013-07-25 15:31:26 +10:00
|
|
|
|
m.ConfigureMappings(configuration, ApplicationContext);
|
2013-07-01 14:23:56 +10:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2013-06-18 17:22:01 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Special method to initialize the LoggerResolver
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected virtual void InitializeLoggerResolver()
|
|
|
|
|
|
{
|
2015-01-09 10:51:15 +11:00
|
|
|
|
LoggerResolver.Current = new LoggerResolver(Logger.CreateWithDefaultLog4NetConfiguration())
|
2015-01-07 17:23:24 +11:00
|
|
|
|
{
|
|
|
|
|
|
//This is another special resolver that needs to be resolvable before resolution is frozen
|
|
|
|
|
|
//since it is used for profiling the application startup
|
|
|
|
|
|
CanResolveBeforeFrozen = true
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-05-13 21:11:03 -10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Special method to initialize the ProfilerResolver
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected virtual void InitializeProfilerResolver()
|
|
|
|
|
|
{
|
|
|
|
|
|
//By default we'll initialize the Log profiler (in the web project, we'll override with the web profiler)
|
2015-01-07 17:23:24 +11:00
|
|
|
|
ProfilerResolver.Current = new ProfilerResolver(new LogProfiler(LoggerResolver.Current.Logger))
|
|
|
|
|
|
{
|
|
|
|
|
|
//This is another special resolver that needs to be resolvable before resolution is frozen
|
|
|
|
|
|
//since it is used for profiling the application startup
|
|
|
|
|
|
CanResolveBeforeFrozen = true
|
|
|
|
|
|
};
|
2013-05-13 21:11:03 -10:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-01-29 09:45:12 +06:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Special method to initialize the ApplicationEventsResolver and any modifications required for it such
|
|
|
|
|
|
/// as adding custom types to the resolver.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected virtual void InitializeApplicationEventsResolver()
|
|
|
|
|
|
{
|
|
|
|
|
|
//find and initialize the application startup handlers, we need to initialize this resolver here because
|
|
|
|
|
|
//it is a special resolver where they need to be instantiated first before any other resolvers in order to bind to
|
|
|
|
|
|
//events and to call their events during bootup.
|
|
|
|
|
|
//ApplicationStartupHandler.RegisterHandlers();
|
|
|
|
|
|
//... and set the special flag to let us resolve before frozen resolution
|
|
|
|
|
|
ApplicationEventsResolver.Current = new ApplicationEventsResolver(
|
2015-01-16 15:47:44 +11:00
|
|
|
|
ServiceProvider,
|
|
|
|
|
|
LoggerResolver.Current.Logger,
|
|
|
|
|
|
PluginManager.ResolveApplicationStartupHandlers())
|
2013-01-29 09:45:12 +06:00
|
|
|
|
{
|
|
|
|
|
|
CanResolveBeforeFrozen = true
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-05-22 07:48:42 -02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Special method to extend the use of Umbraco by enabling the consumer to overwrite
|
|
|
|
|
|
/// the absolute path to the root of an Umbraco site/solution, which is used for stuff
|
|
|
|
|
|
/// like Umbraco.Core.IO.IOHelper.MapPath etc.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="rootPath">Absolute</param>
|
|
|
|
|
|
protected virtual void InitializeApplicationRootPath(string rootPath)
|
|
|
|
|
|
{
|
2015-07-14 10:49:43 +02:00
|
|
|
|
IOHelper.SetRootDirectory(rootPath);
|
2013-05-22 07:48:42 -02:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fires after initialization and calls the callback to allow for customizations to occur &
|
2013-01-29 09:45:12 +06:00
|
|
|
|
/// Ensure that the OnApplicationStarting methods of the IApplicationEvents are called
|
2015-01-07 17:23:24 +11:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="afterStartup"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public virtual IBootManager Startup(Action<ApplicationContext> afterStartup)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_isStarted)
|
|
|
|
|
|
throw new InvalidOperationException("The boot manager has already been initialized");
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
2015-07-14 10:49:43 +02:00
|
|
|
|
using (_profilingLogger.DebugDuration<CoreBootManager>(
|
|
|
|
|
|
string.Format("Executing {0} IApplicationEventHandler.OnApplicationStarting", ApplicationEventsResolver.Current.ApplicationEventHandlers.Count()),
|
|
|
|
|
|
"Finished executing IApplicationEventHandler.OnApplicationStarting"))
|
2015-07-08 16:45:34 +02:00
|
|
|
|
{
|
|
|
|
|
|
//call OnApplicationStarting of each application events handler
|
|
|
|
|
|
ApplicationEventsResolver.Current.ApplicationEventHandlers
|
|
|
|
|
|
.ForEach(x =>
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
x.OnApplicationStarting(UmbracoApplication, ApplicationContext);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2015-07-14 10:49:43 +02:00
|
|
|
|
_profilingLogger.Logger.Error<CoreBootManager>("An error occurred running OnApplicationStarting for handler " + x.GetType(), ex);
|
2015-07-08 16:45:34 +02:00
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (afterStartup != null)
|
2013-02-14 23:05:58 +06:00
|
|
|
|
{
|
|
|
|
|
|
afterStartup(ApplicationContext.Current);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
_isStarted = true;
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11: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)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_isComplete)
|
|
|
|
|
|
throw new InvalidOperationException("The boot manager has already been completed");
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
FreezeResolution();
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
2015-07-09 14:31:59 +02:00
|
|
|
|
//Here we need to make sure the db can be connected to
|
|
|
|
|
|
EnsureDatabaseConnection();
|
|
|
|
|
|
|
2015-07-14 10:49:43 +02:00
|
|
|
|
using (_profilingLogger.DebugDuration<CoreBootManager>(
|
|
|
|
|
|
string.Format("Executing {0} IApplicationEventHandler.OnApplicationStarted", ApplicationEventsResolver.Current.ApplicationEventHandlers.Count()),
|
|
|
|
|
|
"Finished executing IApplicationEventHandler.OnApplicationStarted"))
|
2015-07-08 16:45:34 +02:00
|
|
|
|
{
|
|
|
|
|
|
//call OnApplicationStarting of each application events handler
|
|
|
|
|
|
ApplicationEventsResolver.Current.ApplicationEventHandlers
|
|
|
|
|
|
.ForEach(x =>
|
2015-07-08 16:27:06 +02:00
|
|
|
|
{
|
2015-07-08 16:45:34 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
x.OnApplicationStarted(UmbracoApplication, ApplicationContext);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2015-07-14 10:49:43 +02:00
|
|
|
|
_profilingLogger.Logger.Error<CoreBootManager>("An error occurred running OnApplicationStarted for handler " + x.GetType(), ex);
|
2015-07-08 16:45:34 +02:00
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2013-01-29 09:45:12 +06:00
|
|
|
|
|
2013-02-14 23:05:58 +06:00
|
|
|
|
//Now, startup all of our legacy startup handler
|
2013-04-16 04:27:03 -02:00
|
|
|
|
ApplicationEventsResolver.Current.InstantiateLegacyStartupHandlers();
|
2013-02-14 23:05:58 +06:00
|
|
|
|
|
|
|
|
|
|
if (afterComplete != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
afterComplete(ApplicationContext.Current);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
_isComplete = true;
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
2013-01-29 09:45:12 +06:00
|
|
|
|
// we're ready to serve content!
|
|
|
|
|
|
ApplicationContext.IsReady = true;
|
|
|
|
|
|
|
2013-11-28 10:51:54 +11:00
|
|
|
|
//stop the timer and log the output
|
|
|
|
|
|
_timer.Dispose();
|
2015-01-07 17:23:24 +11:00
|
|
|
|
return this;
|
2012-08-01 22:06:15 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-07-09 14:31:59 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// We cannot continue if the db cannot be connected to
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void EnsureDatabaseConnection()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ApplicationContext.IsConfigured == false) return;
|
|
|
|
|
|
if (ApplicationContext.DatabaseContext.IsDatabaseConfigured == false) return;
|
|
|
|
|
|
|
|
|
|
|
|
var currentTry = 0;
|
|
|
|
|
|
while (currentTry < 5)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ApplicationContext.DatabaseContext.CanConnect)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
//wait and retry
|
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
currentTry++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (currentTry == 5)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new UmbracoStartupFailedException("Umbraco cannot start. A connection string is configured but the Umbraco cannot connect to the database.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
}
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2013-03-12 00:21:10 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Freeze resolution to not allow Resolvers to be modified
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected virtual void FreezeResolution()
|
|
|
|
|
|
{
|
|
|
|
|
|
Resolution.Freeze();
|
|
|
|
|
|
}
|
2015-01-07 17:23:24 +11:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create the resolvers
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected virtual void InitializeResolvers()
|
|
|
|
|
|
{
|
2015-03-19 13:53:15 +11:00
|
|
|
|
var builder = new ManifestBuilder(
|
|
|
|
|
|
ApplicationCache.RuntimeCache,
|
|
|
|
|
|
new ManifestParser(new DirectoryInfo(IOHelper.MapPath("~/App_Plugins")), ApplicationCache.RuntimeCache));
|
|
|
|
|
|
|
2015-03-19 17:42:57 +11:00
|
|
|
|
PropertyEditorResolver.Current = new PropertyEditorResolver(ServiceProvider, LoggerResolver.Current.Logger, () => PluginManager.ResolvePropertyEditors(), builder);
|
|
|
|
|
|
ParameterEditorResolver.Current = new ParameterEditorResolver(ServiceProvider, LoggerResolver.Current.Logger, () => PluginManager.ResolveParameterEditors(), builder);
|
2013-09-19 17:34:57 +10:00
|
|
|
|
|
2013-05-23 22:15:52 -10:00
|
|
|
|
//setup the validators resolver with our predefined validators
|
2015-01-16 15:47:44 +11:00
|
|
|
|
ValidatorsResolver.Current = new ValidatorsResolver(
|
|
|
|
|
|
ServiceProvider, LoggerResolver.Current.Logger, new[]
|
2013-05-23 22:15:52 -10:00
|
|
|
|
{
|
2013-08-28 13:30:05 +10:00
|
|
|
|
new Lazy<Type>(() => typeof (RequiredManifestValueValidator)),
|
|
|
|
|
|
new Lazy<Type>(() => typeof (RegexValidator)),
|
2013-12-12 18:28:45 +11:00
|
|
|
|
new Lazy<Type>(() => typeof (DelimitedManifestValueValidator)),
|
|
|
|
|
|
new Lazy<Type>(() => typeof (EmailValidator)),
|
|
|
|
|
|
new Lazy<Type>(() => typeof (IntegerValidator)),
|
2013-05-23 22:15:52 -10:00
|
|
|
|
});
|
2013-05-13 20:10:28 -10:00
|
|
|
|
|
2015-07-17 11:09:31 +02:00
|
|
|
|
//by default we'll use the db server registrar unless the developer has the legacy
|
|
|
|
|
|
// dist calls enabled, in which case we'll use the config server registrar
|
|
|
|
|
|
if (UmbracoConfig.For.UmbracoSettings().DistributedCall.Enabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
ServerRegistrarResolver.Current = new ServerRegistrarResolver(new ConfigServerRegistrar());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ServerRegistrarResolver.Current = new ServerRegistrarResolver(
|
|
|
|
|
|
new DatabaseServerRegistrar(
|
|
|
|
|
|
new Lazy<IServerRegistrationService>(() => ApplicationContext.Services.ServerRegistrationService),
|
|
|
|
|
|
new DatabaseServerRegistrarOptions()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-02-12 03:46:27 +06:00
|
|
|
|
|
2015-07-15 17:27:01 +02:00
|
|
|
|
//by default we'll use the database server messenger with default options (no callbacks),
|
|
|
|
|
|
// this will be overridden in the web startup
|
2013-02-12 03:46:27 +06:00
|
|
|
|
ServerMessengerResolver.Current = new ServerMessengerResolver(
|
2015-07-15 17:27:01 +02:00
|
|
|
|
new DatabaseServerMessenger(ApplicationContext, true, new DatabaseServerMessengerOptions()));
|
2013-02-11 20:07:23 +06:00
|
|
|
|
|
2013-03-13 01:09:29 +04:00
|
|
|
|
MappingResolver.Current = new MappingResolver(
|
2015-01-16 15:47:44 +11:00
|
|
|
|
ServiceProvider, LoggerResolver.Current.Logger,
|
|
|
|
|
|
() => PluginManager.ResolveAssignedMapperTypes());
|
2013-03-13 01:09:29 +04:00
|
|
|
|
|
2015-01-13 18:19:52 +11:00
|
|
|
|
|
|
|
|
|
|
//RepositoryResolver.Current = new RepositoryResolver(
|
|
|
|
|
|
// new RepositoryFactory(ApplicationCache));
|
2013-03-09 10:43:34 -01:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
CacheRefreshersResolver.Current = new CacheRefreshersResolver(
|
2015-01-16 15:47:44 +11:00
|
|
|
|
ServiceProvider, LoggerResolver.Current.Logger,
|
|
|
|
|
|
() => PluginManager.ResolveCacheRefreshers());
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
DataTypesResolver.Current = new DataTypesResolver(
|
2015-01-16 15:47:44 +11:00
|
|
|
|
ServiceProvider, LoggerResolver.Current.Logger,
|
|
|
|
|
|
() => PluginManager.ResolveDataTypes());
|
2012-08-01 22:46:13 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
MacroFieldEditorsResolver.Current = new MacroFieldEditorsResolver(
|
2015-01-16 15:47:44 +11:00
|
|
|
|
ServiceProvider, LoggerResolver.Current.Logger,
|
|
|
|
|
|
() => PluginManager.ResolveMacroRenderings());
|
2012-08-01 23:03:26 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
PackageActionsResolver.Current = new PackageActionsResolver(
|
2015-01-16 15:47:44 +11:00
|
|
|
|
ServiceProvider, LoggerResolver.Current.Logger,
|
|
|
|
|
|
() => PluginManager.ResolvePackageActions());
|
2012-08-01 23:30:37 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
ActionsResolver.Current = new ActionsResolver(
|
2015-01-16 15:47:44 +11:00
|
|
|
|
ServiceProvider, LoggerResolver.Current.Logger,
|
|
|
|
|
|
() => PluginManager.ResolveActions());
|
2012-08-18 11:39:18 +06:00
|
|
|
|
|
2013-02-13 03:29:32 +06:00
|
|
|
|
//the database migration objects
|
|
|
|
|
|
MigrationResolver.Current = new MigrationResolver(
|
2015-04-01 17:43:27 +11:00
|
|
|
|
LoggerResolver.Current.Logger,
|
2015-01-16 15:47:44 +11:00
|
|
|
|
() => PluginManager.ResolveTypes<IMigration>());
|
2013-01-18 12:05:00 -01:00
|
|
|
|
|
2013-09-23 16:55:59 +02:00
|
|
|
|
// todo: remove once we drop IPropertyEditorValueConverter support.
|
2013-09-05 17:47:13 +02:00
|
|
|
|
PropertyEditorValueConvertersResolver.Current = new PropertyEditorValueConvertersResolver(
|
2015-01-16 15:47:44 +11:00
|
|
|
|
ServiceProvider, LoggerResolver.Current.Logger,
|
|
|
|
|
|
PluginManager.ResolvePropertyEditorValueConverters());
|
2013-02-07 13:30:50 -01:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
// need to filter out the ones we dont want!!
|
|
|
|
|
|
PropertyValueConvertersResolver.Current = new PropertyValueConvertersResolver(
|
2015-01-16 15:47:44 +11:00
|
|
|
|
ServiceProvider, LoggerResolver.Current.Logger,
|
|
|
|
|
|
PluginManager.ResolveTypes<IPropertyValueConverter>());
|
2013-09-09 15:17:33 +10:00
|
|
|
|
|
2013-12-13 12:06:56 +01:00
|
|
|
|
// use the new DefaultShortStringHelper
|
2013-03-22 17:39:35 -01:00
|
|
|
|
ShortStringHelperResolver.Current = new ShortStringHelperResolver(
|
2013-12-13 12:06:56 +01:00
|
|
|
|
//new LegacyShortStringHelper());
|
2015-07-15 16:28:50 +02:00
|
|
|
|
new DefaultShortStringHelper(UmbracoConfig.For.UmbracoSettings()).WithDefaultConfig());
|
2013-03-22 17:39:35 -01:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
UrlSegmentProviderResolver.Current = new UrlSegmentProviderResolver(
|
2015-01-16 15:47:44 +11:00
|
|
|
|
ServiceProvider, LoggerResolver.Current.Logger,
|
2015-01-07 17:23:24 +11:00
|
|
|
|
typeof(DefaultUrlSegmentProvider));
|
2013-09-13 21:15:40 +02:00
|
|
|
|
|
2014-05-19 13:15:47 +02:00
|
|
|
|
// by default, no factory is activated
|
2015-01-07 17:23:24 +11:00
|
|
|
|
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-08-01 22:06:15 +06:00
|
|
|
|
}
|