diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index 328db6c9cd..e02f41e809 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -179,6 +179,7 @@ namespace Umbraco.Core //ModelMappers container.RegisterFrom(); + //TODO: Don't think we'll need this when the resolvers are all container resolvers container.RegisterSingleton(); container.RegisterSingleton(factory => PluginManager); diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 60f72ed19c..4a69f8f127 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -36,6 +36,7 @@ namespace Umbraco.Core.IO string tempDir = unPackDirectory; Directory.CreateDirectory(tempDir); + //TODO: Get rid of SharpZipLib library using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFilePath))) { ZipEntry theEntry; diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index a5cf5797c4..13f48bb2bf 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -60,50 +60,6 @@ ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll True - - ..\packages\Lucene.Net.3.0.3\lib\NET40\Lucene.Net.dll - True - - - ..\packages\Lucene.Net.Contrib.3.0.3\lib\net40\Lucene.Net.Contrib.Analyzers.dll - True - - - ..\packages\Lucene.Net.Contrib.3.0.3\lib\net40\Lucene.Net.Contrib.Core.dll - True - - - ..\packages\Lucene.Net.Contrib.3.0.3\lib\net40\Lucene.Net.Contrib.FastVectorHighlighter.dll - True - - - ..\packages\Lucene.Net.Contrib.3.0.3\lib\net40\Lucene.Net.Contrib.Highlighter.dll - True - - - ..\packages\Lucene.Net.Contrib.3.0.3\lib\net40\Lucene.Net.Contrib.Memory.dll - True - - - ..\packages\Lucene.Net.Contrib.3.0.3\lib\net40\Lucene.Net.Contrib.Queries.dll - True - - - ..\packages\Lucene.Net.Contrib.3.0.3\lib\net40\Lucene.Net.Contrib.Regex.dll - True - - - ..\packages\Lucene.Net.Contrib.3.0.3\lib\net40\Lucene.Net.Contrib.SimpleFacetedSearch.dll - True - - - ..\packages\Lucene.Net.Contrib.3.0.3\lib\net40\Lucene.Net.Contrib.Snowball.dll - True - - - ..\packages\Lucene.Net.Contrib.3.0.3\lib\net40\Lucene.Net.Contrib.SpellChecker.dll - True - False ..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll diff --git a/src/Umbraco.Core/packages.config b/src/Umbraco.Core/packages.config index e439a612e1..80fe5b3e37 100644 --- a/src/Umbraco.Core/packages.config +++ b/src/Umbraco.Core/packages.config @@ -5,8 +5,6 @@ - - diff --git a/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs b/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs index 731377d778..efb5079ed9 100644 --- a/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs +++ b/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; +using Examine; using LightInject; using Moq; using NUnit.Framework; @@ -13,9 +14,11 @@ using Umbraco.Core.ObjectResolution; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Tests.TestHelpers; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.DependencyInjection; using Umbraco.Core.Persistence; using Umbraco.Core.Profiling; using Umbraco.Core.Services; +using UmbracoExamine; namespace Umbraco.Tests.BootManagers { @@ -69,6 +72,15 @@ namespace Umbraco.Tests.BootManagers container.Register(factory => new DatabaseContext( factory.GetInstance(), factory.GetInstance()), new PerContainerLifetime()); + container.RegisterSingleton(); + } + + public class TestIndexCollectionAccessor : IExamineIndexCollectionAccessor + { + public IReadOnlyDictionary Indexes + { + get { return new Dictionary(); } + } } } diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index 7f12b9b727..8c4b891aa0 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -79,7 +79,7 @@ namespace Umbraco.Tests.TestHelpers get { return _disabledCacheHelper ?? (_disabledCacheHelper = CacheHelper.CreateDisabledCacheHelper()); } } - protected override void SetupApplicationContext() + protected override ApplicationContext CreateApplicationContext() { var sqlSyntaxProviders = new[] { new SqlCeSyntaxProvider() }; @@ -138,7 +138,7 @@ namespace Umbraco.Tests.TestHelpers // application is ready _appContext.IsReady = true; - ApplicationContext.Current = _appContext; + return _appContext; } /// diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs index 90cf7afde6..1d5a898868 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs @@ -200,16 +200,16 @@ namespace Umbraco.Tests.TestHelpers { return CacheHelper.CreateDisabledCacheHelper(); } - - /// - /// Inheritors can override this if they wish to create a custom application context - /// - protected virtual void SetupApplicationContext() + + private void SetupApplicationContext() { var applicationContext = CreateApplicationContext(); ApplicationContext.Current = applicationContext; } + /// + /// Inheritors can override this if they wish to create a custom application context + /// protected virtual ApplicationContext CreateApplicationContext() { var evtMsgs = new TransientEventMessagesFactory(); diff --git a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs index 3ace05d220..5eb3769e4d 100644 --- a/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/GridPropertyEditor.cs @@ -1,47 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Text; -using System.Threading.Tasks; using Umbraco.Core.Logging; using Examine; using Lucene.Net.Documents; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Core; -using Umbraco.Core.Logging; -using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; -using Umbraco.Core.Services; using Umbraco.Core.Xml; using UmbracoExamine; namespace Umbraco.Web.PropertyEditors { [PropertyEditor(Core.Constants.PropertyEditors.GridAlias, "Grid layout", "grid", HideLabel = true, IsParameterEditor = false, ValueType = PropertyEditorValueTypes.Json, Group="rich content", Icon="icon-layout")] - public class GridPropertyEditor : PropertyEditor + public class GridPropertyEditor : PropertyEditor, IApplicationEventHandler { - /// - /// We're going to bind to the Examine events so we can ensure grid data is index nicely - /// - /// - /// I think this kind of logic belongs on this property editor, putting this inside of the indexer certainly doesn't seem right - /// - static GridPropertyEditor() - { - foreach (var i in ExamineManager.Instance.IndexProviderCollection.OfType()) - { - i.DocumentWriting += DocumentWriting; - } - } + private readonly IExamineIndexCollectionAccessor _indexCollection; /// - /// The constructor will setup the property editor based on the attribute if one is found - /// - public GridPropertyEditor(ILogger logger) : base(logger) + /// Constructor + /// + public GridPropertyEditor(ILogger logger, IExamineIndexCollectionAccessor indexCollection) : base(logger) { + _indexCollection = indexCollection; } - + private static void DocumentWriting(object sender, Examine.LuceneEngine.DocumentWritingEventArgs e) { var indexer = (BaseUmbracoIndexer)sender; @@ -147,6 +130,27 @@ namespace Umbraco.Web.PropertyEditors [PreValueField("rte", "Rich text editor", "views/propertyeditors/rte/rte.prevalues.html", Description = "Rich text editor configuration")] public string Rte { get; set; } } + + #region Application event handler, used to bind to events on startup + public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + } + + public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + } + + /// + /// We're going to bind to the Examine events so we can ensure grid data is index nicely. + /// + public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + foreach (var i in _indexCollection.Indexes.Values.OfType()) + { + i.DocumentWriting += DocumentWriting; + } + } + #endregion } diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 39bd43fd18..60529f2cb3 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -43,6 +43,7 @@ using Umbraco.Web.Editors; using Umbraco.Core.DependencyInjection; using Umbraco.Web.DependencyInjection; using Umbraco.Web._Legacy.Actions; +using UmbracoExamine; using Action = System.Action; using GlobalSettings = Umbraco.Core.Configuration.GlobalSettings; using ProfilingViewEngine = Umbraco.Core.Profiling.ProfilingViewEngine; @@ -346,6 +347,8 @@ namespace Umbraco.Web container.Register(); container.RegisterSingleton(); container.RegisterSingleton(); + + container.RegisterSingleton(); } /// diff --git a/src/UmbracoExamine/BaseUmbracoIndexer.cs b/src/UmbracoExamine/BaseUmbracoIndexer.cs index 1fe1e8b7af..0ac59c79e2 100644 --- a/src/UmbracoExamine/BaseUmbracoIndexer.cs +++ b/src/UmbracoExamine/BaseUmbracoIndexer.cs @@ -25,7 +25,6 @@ using Directory = Lucene.Net.Store.Directory; namespace UmbracoExamine { - /// /// An abstract provider containing the basic functionality to be able to query against /// Umbraco data. diff --git a/src/UmbracoExamine/ExamineIndexCollectionAccessor.cs b/src/UmbracoExamine/ExamineIndexCollectionAccessor.cs new file mode 100644 index 0000000000..f2e30fe5d0 --- /dev/null +++ b/src/UmbracoExamine/ExamineIndexCollectionAccessor.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using Examine; + +namespace UmbracoExamine +{ + /// + /// Default implementation of IExamineIndexCollectionAccessor to return indexes from Examinemanager + /// + public class ExamineIndexCollectionAccessor : IExamineIndexCollectionAccessor + { + public IReadOnlyDictionary Indexes => ExamineManager.Instance.IndexProviders; + } +} \ No newline at end of file diff --git a/src/UmbracoExamine/IExamineIndexCollectionAccessor.cs b/src/UmbracoExamine/IExamineIndexCollectionAccessor.cs new file mode 100644 index 0000000000..7edb93719c --- /dev/null +++ b/src/UmbracoExamine/IExamineIndexCollectionAccessor.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using Examine; + +namespace UmbracoExamine +{ + /// + /// Returns a collection of IExamineIndexer + /// + public interface IExamineIndexCollectionAccessor + { + IReadOnlyDictionary Indexes { get; } + } +} \ No newline at end of file diff --git a/src/UmbracoExamine/UmbracoExamine.csproj b/src/UmbracoExamine/UmbracoExamine.csproj index f08ff1f287..149bcb11c5 100644 --- a/src/UmbracoExamine/UmbracoExamine.csproj +++ b/src/UmbracoExamine/UmbracoExamine.csproj @@ -163,6 +163,8 @@ + +