diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 34be23e1f1..bc860705a2 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -249,6 +249,32 @@ namespace Umbraco.Core.IO return _rootDir; } + internal static string GetRootDirectoryBinFolder() + { + string binFolder = string.Empty; + if (string.IsNullOrEmpty(_rootDir)) + { + binFolder = Assembly.GetExecutingAssembly().GetAssemblyFile().Directory.FullName; + return binFolder; + } + + binFolder = Path.Combine(GetRootDirectorySafe(), "bin"); + +#if DEBUG + var debugFolder = Path.Combine(binFolder, "debug"); + if (Directory.Exists(debugFolder)) + return debugFolder; +#endif + var releaseFolder = Path.Combine(binFolder, "release"); + if (Directory.Exists(releaseFolder)) + return releaseFolder; + + if (Directory.Exists(binFolder)) + return binFolder; + + return _rootDir; + } + /// /// Allows you to overwrite RootDirectory, which would otherwise be resolved /// automatically upon application start. diff --git a/src/Umbraco.Core/Standalone/ServiceContextManager.cs b/src/Umbraco.Core/Standalone/ServiceContextManager.cs index 29a2945edd..ea9464242b 100644 --- a/src/Umbraco.Core/Standalone/ServiceContextManager.cs +++ b/src/Umbraco.Core/Standalone/ServiceContextManager.cs @@ -1,4 +1,6 @@ using System; +using System.Diagnostics; +using System.Reflection; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Persistence.UnitOfWork; @@ -14,12 +16,18 @@ namespace Umbraco.Core.Standalone private ServiceContext _serviceContext; private readonly StandaloneCoreApplication _application; - public ServiceContextManager(string connectionString, string providerName) + public ServiceContextManager(string connectionString, string providerName, string baseDirectory) { _connectionString = connectionString; _providerName = providerName; - _application = StandaloneCoreApplication.GetApplication(); + Trace.WriteLine("ServiceContextManager-Current AppDomain: " + AppDomain.CurrentDomain.FriendlyName); + Trace.WriteLine("ServiceContextManager-Current AppDomain: " + AppDomain.CurrentDomain.BaseDirectory); + + var examineEventHandlerToRemove = Type.GetType("Umbraco.Web.Search.ExamineEvents, Umbraco.Web"); + + _application = StandaloneCoreApplication.GetApplication(baseDirectory); + _application.WithoutApplicationEventHandler(examineEventHandlerToRemove); _application.Start(); } diff --git a/src/Umbraco.Core/Standalone/StandaloneCoreApplication.cs b/src/Umbraco.Core/Standalone/StandaloneCoreApplication.cs index 0e0081d948..c22a648478 100644 --- a/src/Umbraco.Core/Standalone/StandaloneCoreApplication.cs +++ b/src/Umbraco.Core/Standalone/StandaloneCoreApplication.cs @@ -8,7 +8,10 @@ namespace Umbraco.Core.Standalone /// /// Initializes a new instance of the class. /// - protected StandaloneCoreApplication() { } + protected StandaloneCoreApplication(string baseDirectory) + { + _baseDirectory = baseDirectory; + } /// /// Provides the application boot manager. @@ -16,11 +19,12 @@ namespace Umbraco.Core.Standalone /// An application boot manager. protected override IBootManager GetBootManager() { - return new StandaloneCoreBootManager(this, _handlersToAdd, _handlersToRemove); + return new StandaloneCoreBootManager(this, _handlersToAdd, _handlersToRemove, _baseDirectory); } #region Application + private readonly string _baseDirectory; private static StandaloneCoreApplication _application; private static bool _started; private static readonly object AppLock = new object(); @@ -28,11 +32,11 @@ namespace Umbraco.Core.Standalone /// /// Gets the instance of the standalone Umbraco application. /// - public static StandaloneCoreApplication GetApplication() + public static StandaloneCoreApplication GetApplication(string baseDirectory) { lock (AppLock) { - return _application ?? (_application = new StandaloneCoreApplication()); + return _application ?? (_application = new StandaloneCoreApplication(baseDirectory)); } } diff --git a/src/Umbraco.Core/Standalone/StandaloneCoreBootManager.cs b/src/Umbraco.Core/Standalone/StandaloneCoreBootManager.cs index 46871e2055..84c73f95b7 100644 --- a/src/Umbraco.Core/Standalone/StandaloneCoreBootManager.cs +++ b/src/Umbraco.Core/Standalone/StandaloneCoreBootManager.cs @@ -10,12 +10,16 @@ namespace Umbraco.Core.Standalone { private readonly IEnumerable _handlersToAdd; private readonly IEnumerable _handlersToRemove; + private readonly string _baseDirectory; - public StandaloneCoreBootManager(UmbracoApplicationBase umbracoApplication, IEnumerable handlersToAdd, IEnumerable handlersToRemove) + public StandaloneCoreBootManager(UmbracoApplicationBase umbracoApplication, IEnumerable handlersToAdd, IEnumerable handlersToRemove, string baseDirectory) : base(umbracoApplication) { _handlersToAdd = handlersToAdd; _handlersToRemove = handlersToRemove; + _baseDirectory = baseDirectory; + + base.InitializeApplicationRootPath(_baseDirectory); // this is only here to ensure references to the assemblies needed for // the DataTypesResolver otherwise they won't be loaded into the AppDomain. @@ -25,8 +29,10 @@ namespace Umbraco.Core.Standalone protected override void InitializeApplicationEventsResolver() { base.InitializeApplicationEventsResolver(); + foreach (var type in _handlersToAdd) ApplicationEventsResolver.Current.AddType(type); + foreach (var type in _handlersToRemove) ApplicationEventsResolver.Current.RemoveType(type); } @@ -36,7 +42,7 @@ namespace Umbraco.Core.Standalone base.InitializeResolvers(); //Mappers are not resolved, which could be because of a known TypeMapper issue - MappingResolver.Reset(); + /*MappingResolver.Reset(); MappingResolver.Current = new MappingResolver( () => new List @@ -47,7 +53,7 @@ namespace Umbraco.Core.Standalone typeof (MediaTypeMapper), typeof (DataTypeDefinitionMapper), typeof (UmbracoEntityMapper) - }); + });*/ } } } \ No newline at end of file diff --git a/src/Umbraco.Core/TypeFinder.cs b/src/Umbraco.Core/TypeFinder.cs index 81be7564c0..c6b943b008 100644 --- a/src/Umbraco.Core/TypeFinder.cs +++ b/src/Umbraco.Core/TypeFinder.cs @@ -73,8 +73,10 @@ namespace Umbraco.Core { //NOTE: we cannot use AppDomain.CurrentDomain.GetAssemblies() because this only returns assemblies that have // already been loaded in to the app domain, instead we will look directly into the bin folder and load each one. - var binFolder = Assembly.GetExecutingAssembly().GetAssemblyFile().Directory; - var binAssemblyFiles = Directory.GetFiles(binFolder.FullName, "*.dll", SearchOption.TopDirectoryOnly).ToList(); + var binFolder = IOHelper.GetRootDirectoryBinFolder(); + var binAssemblyFiles = Directory.GetFiles(binFolder, "*.dll", SearchOption.TopDirectoryOnly).ToList(); + //var binFolder = Assembly.GetExecutingAssembly().GetAssemblyFile().Directory; + //var binAssemblyFiles = Directory.GetFiles(binFolder.FullName, "*.dll", SearchOption.TopDirectoryOnly).ToList(); assemblies = new List(); foreach (var a in binAssemblyFiles) { diff --git a/src/Umbraco.Web/Standalone/ServiceContextManager.cs b/src/Umbraco.Web/Standalone/ServiceContextManager.cs index badd77d21b..aa53b586ee 100644 --- a/src/Umbraco.Web/Standalone/ServiceContextManager.cs +++ b/src/Umbraco.Web/Standalone/ServiceContextManager.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using Umbraco.Core; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; @@ -15,12 +16,15 @@ namespace Umbraco.Web.Standalone private ServiceContext _serviceContext; private readonly StandaloneApplication _application; - public ServiceContextManager(string connectionString, string providerName) + public ServiceContextManager(string connectionString, string providerName, string baseDirectory) { _connectionString = connectionString; _providerName = providerName; - _application = StandaloneApplication.GetApplication(); + Trace.WriteLine("Current AppDomain: " + AppDomain.CurrentDomain.FriendlyName); + Trace.WriteLine("Current AppDomain: " + AppDomain.CurrentDomain.BaseDirectory); + + _application = StandaloneApplication.GetApplication(baseDirectory); _application.Start(); } diff --git a/src/Umbraco.Web/Standalone/StandaloneApplication.cs b/src/Umbraco.Web/Standalone/StandaloneApplication.cs index a1fd0249a7..cdaf8718c1 100644 --- a/src/Umbraco.Web/Standalone/StandaloneApplication.cs +++ b/src/Umbraco.Web/Standalone/StandaloneApplication.cs @@ -14,7 +14,10 @@ namespace Umbraco.Web.Standalone /// /// Initializes a new instance of the class. /// - protected StandaloneApplication(){ } + protected StandaloneApplication(string baseDirectory) + { + _baseDirectory = baseDirectory; + } /// /// Provides the application boot manager. @@ -22,23 +25,24 @@ namespace Umbraco.Web.Standalone /// An application boot manager. protected override IBootManager GetBootManager() { - return new StandaloneBootManager(this, _handlersToAdd, _handlersToRemove); + return new StandaloneBootManager(this, _handlersToAdd, _handlersToRemove, _baseDirectory); } #region Application private static StandaloneApplication _application; + private readonly string _baseDirectory; private static bool _started; private static readonly object AppLock = new object(); /// /// Gets the instance of the standalone Umbraco application. /// - public static StandaloneApplication GetApplication() + public static StandaloneApplication GetApplication(string baseDirectory) { lock (AppLock) { - return _application ?? (_application = new StandaloneApplication()); + return _application ?? (_application = new StandaloneApplication(baseDirectory)); } } diff --git a/src/Umbraco.Web/Standalone/StandaloneBootManager.cs b/src/Umbraco.Web/Standalone/StandaloneBootManager.cs index 1215ab89a7..cf2e8f7c11 100644 --- a/src/Umbraco.Web/Standalone/StandaloneBootManager.cs +++ b/src/Umbraco.Web/Standalone/StandaloneBootManager.cs @@ -20,12 +20,16 @@ namespace Umbraco.Web.Standalone private readonly IEnumerable _handlersToAdd; private readonly IEnumerable _handlersToRemove; + private readonly string _baseDirectory; - public StandaloneBootManager(UmbracoApplicationBase umbracoApplication, IEnumerable handlersToAdd, IEnumerable handlersToRemove) + public StandaloneBootManager(UmbracoApplicationBase umbracoApplication, IEnumerable handlersToAdd, IEnumerable handlersToRemove, string baseDirectory) : base(umbracoApplication) { _handlersToAdd = handlersToAdd; _handlersToRemove = handlersToRemove; + _baseDirectory = baseDirectory; + + base.InitializeApplicationRootPath(_baseDirectory); // this is only here to ensure references to the assemblies needed for // the DataTypesResolver otherwise they won't be loaded into the AppDomain. @@ -63,7 +67,7 @@ namespace Umbraco.Web.Standalone typeof (ContentFinderByPageIdQuery), typeof (ContentFinderByNiceUrl), typeof (ContentFinderByIdPath), - typeof(ContentFinderByNotFoundHandlers) + typeof (ContentFinderByNotFoundHandlers) ); // fixme - what else?