From 7088a59d87d51a6b1cf4e708fb35e1f763fc4507 Mon Sep 17 00:00:00 2001 From: Ralf van den Burg Date: Mon, 4 Aug 2014 09:54:35 +0200 Subject: [PATCH 01/10] NULL's checks --- Src/Commons/Helpers/AppDomainHelper.cs | 53 +++++++++++++++----------- Src/Commons/Initializer.cs | 4 +- Src/Commons/InversionOfControl/IoC.cs | 35 ++++++++++------- 3 files changed, 55 insertions(+), 37 deletions(-) diff --git a/Src/Commons/Helpers/AppDomainHelper.cs b/Src/Commons/Helpers/AppDomainHelper.cs index 53b0b15..aa6f6f3 100644 --- a/Src/Commons/Helpers/AppDomainHelper.cs +++ b/Src/Commons/Helpers/AppDomainHelper.cs @@ -85,29 +85,11 @@ private void EnsureLoaded() var filters = FileFilter.Split('|'); foreach (var path in paths) { - try - { - loadedAssemblies.AddRange( - filters.SelectMany(s => Directory.GetFiles(path, s)).Select(Assembly.LoadFrom)); - Loaded = true; - } - // Files should always exists but don't blow up here if they don't - catch (FileNotFoundException) - { - } - // File was found but could not be loaded - catch (FileLoadException) - { - } - // Dlls that contain native code are not loaded, but do not invalidate the Directory - catch (BadImageFormatException) - { - } - // Dlls that have missing Managed dependencies are not loaded, but do not invalidate the Directory - catch (ReflectionTypeLoadException) - { - } - + loadedAssemblies.AddRange( + filters.SelectMany(s => Directory.GetFiles(path, s)) + .Select(TryLoadAssembly) + .Where(it => it != null )); + Loaded = true; } } @@ -116,6 +98,31 @@ private void EnsureLoaded() } + private Assembly TryLoadAssembly(String path) + { + try + { + return Assembly.LoadFrom(path); + } + // Files should always exists but don't blow up here if they don't + catch (FileNotFoundException) + { + } + // File was found but could not be loaded + catch (FileLoadException) + { + } + // Dlls that contain native code are not loaded, but do not invalidate the Directory + catch (BadImageFormatException) + { + } + // Dlls that have missing Managed dependencies are not loaded, but do not invalidate the Directory + catch (ReflectionTypeLoadException) + { + } + + return null; + } /// /// Releases the unmanaged resources used by the and /// optionally releases the managed resources. diff --git a/Src/Commons/Initializer.cs b/Src/Commons/Initializer.cs index e2c9ad2..bd32deb 100644 --- a/Src/Commons/Initializer.cs +++ b/Src/Commons/Initializer.cs @@ -58,7 +58,9 @@ public static void Execute(IDependencyResolver dependencyResolver, params IAppDo } IoC.InitializeWith(dependencyResolver); - dependencyResolver.Resolve().Run(); + var bootstrapper = dependencyResolver.Resolve(); + if (bootstrapper != null) + bootstrapper.Run(); Executed = true; } diff --git a/Src/Commons/InversionOfControl/IoC.cs b/Src/Commons/InversionOfControl/IoC.cs index c987a21..69c9c9a 100644 --- a/Src/Commons/InversionOfControl/IoC.cs +++ b/Src/Commons/InversionOfControl/IoC.cs @@ -50,7 +50,7 @@ public static void Reset() private static void RunContainerInitializers(IDependencyResolver dependencyResolver) { var appdomainHelpers = dependencyResolver.ResolveAll(); - if (appdomainHelpers == null || appdomainHelpers.Count() == 0) + if (appdomainHelpers == null || ! appdomainHelpers.Any()) { appdomainHelpers = new[] {AppDomainHelper.CreateDefault()}; } @@ -64,20 +64,29 @@ private static void RunContainerInitializers(IDependencyResolver dependencyResol dependencyResolver.RegisterType(typeof(IContainerInitializer), taskType); } //run them: - var allTasks = dependencyResolver.ResolveAll(); - if (allTasks != null) + var allTasks = dependencyResolver.ResolveAll() + .Where( it=> it != null ) + .ToList(); + //first user's tasks: + foreach (var task in allTasks.Where(t => !NamespaceStartsWith (t , "BoC."))) { - //first user's tasks: - foreach (var task in allTasks.Where(t => !t.GetType().Namespace.StartsWith("BoC."))) - { - task.Execute(); - } - //now ours: - foreach (var task in allTasks.Where(t => t.GetType().Namespace.StartsWith("BoC."))) - { - task.Execute(); - } + task.Execute(); + } + //now ours: + foreach (var task in allTasks.Where(t => NamespaceStartsWith(t,"BoC."))) + { + task.Execute(); } } + + private static bool NamespaceStartsWith(IContainerInitializer initializer, String startsWidth ) + { + if (initializer == null) return false; + + var typeofInitializerNameSpace = initializer.GetType().Namespace; + if (String.IsNullOrEmpty(typeofInitializerNameSpace)) return false; + + return typeofInitializerNameSpace.StartsWith(startsWidth); + } } } \ No newline at end of file From 4a4969e4358e73980a0fbf4e791acbf29be4af7f Mon Sep 17 00:00:00 2001 From: Chris van de Steeg Date: Wed, 15 Jul 2015 18:12:11 +0200 Subject: [PATCH 02/10] Some small new sitecore features --- .../App_Start/GlassMapperScCustom.BoC.cs.pp | 8 +-- .../BoC.Persistence.SitecoreGlass.csproj | 29 +++++++++ .../BoC.Persistence.SitecoreGlass.nuspec | 3 +- .../DataContext/SitecoreDataContext.cs | 2 +- .../RegisterValueProvider.cs | 22 +++++++ .../Properties/AssemblyInfo.cs | 4 +- .../TemplateParametersValueProviderFactory.cs | 65 +++++++++++++++++++ .../packages.config | 3 + .../Properties/AssemblyInfo.cs | 4 +- .../SitecoreValueProvider.cs | 6 ++ 10 files changed, 136 insertions(+), 10 deletions(-) create mode 100644 Src/Commons.Persistence.Sitecore/DefaultSetupTasks/RegisterValueProvider.cs create mode 100644 Src/Commons.Persistence.Sitecore/TemplateParametersValueProviderFactory.cs diff --git a/Src/Commons.Persistence.Sitecore/App_Start/GlassMapperScCustom.BoC.cs.pp b/Src/Commons.Persistence.Sitecore/App_Start/GlassMapperScCustom.BoC.cs.pp index c78291c..c3f5312 100644 --- a/Src/Commons.Persistence.Sitecore/App_Start/GlassMapperScCustom.BoC.cs.pp +++ b/Src/Commons.Persistence.Sitecore/App_Start/GlassMapperScCustom.BoC.cs.pp @@ -16,9 +16,9 @@ public static class GlassMapperScCustom { public static IDependencyResolver CreateResolver(){ - BoC.Persistence.SitecoreGlass.Initialize.InitBoc.Start(); + global::BoC.Persistence.SitecoreGlass.Initialize.InitBoc.Start(); - var config = new Glass.Mapper.Sc.Config(); + var config = new global::Glass.Mapper.Sc.Config(); var resolver = new DependencyResolver(config); //trigger addtypes @@ -43,13 +43,13 @@ * */ - return IoC.Resolver.ResolveAll().ToArray(); + return global::BoC.InversionOfControl.IoC.Resolver.ResolveAll().ToArray(); } public static void PostLoad(){ //Set config property to true in Glass.Mapper.Sc.CodeFirst.config to enable codefirst if (!global::Sitecore.Configuration.Settings.GetBoolSetting("Glass.CodeFirst", false)) return; - var dbs = Sitecore.Configuration.Factory.GetDatabases(); + var dbs = global::Sitecore.Configuration.Factory.GetDatabases(); foreach (var db in dbs) { var provider = db.GetDataProviders().FirstOrDefault(x => x is GlassDataProvider) as GlassDataProvider; diff --git a/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.csproj b/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.csproj index 75f2da4..8348408 100644 --- a/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.csproj +++ b/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.csproj @@ -99,6 +99,30 @@ + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll + + + False + ..\..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll + + + False + ..\..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll + + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll + + + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll + True + + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll + @@ -113,6 +137,10 @@ + + + + @@ -128,6 +156,7 @@ + diff --git a/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.nuspec b/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.nuspec index 044766f..c421c9c 100644 --- a/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.nuspec +++ b/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.nuspec @@ -14,7 +14,8 @@ Copyright 2014 BoC,Persistence,Glass,Mapper,ORM,Repository,Sitecore - + + diff --git a/Src/Commons.Persistence.Sitecore/DataContext/SitecoreDataContext.cs b/Src/Commons.Persistence.Sitecore/DataContext/SitecoreDataContext.cs index dee14f8..9ff5bd3 100644 --- a/Src/Commons.Persistence.Sitecore/DataContext/SitecoreDataContext.cs +++ b/Src/Commons.Persistence.Sitecore/DataContext/SitecoreDataContext.cs @@ -66,7 +66,7 @@ public CultureInfo GetCultureInfo() { return ((SitecoreDataContext) OuterDataContext).GetCultureInfo(); } - return Context.Culture; + return Context.Language.CultureInfo; } diff --git a/Src/Commons.Persistence.Sitecore/DefaultSetupTasks/RegisterValueProvider.cs b/Src/Commons.Persistence.Sitecore/DefaultSetupTasks/RegisterValueProvider.cs new file mode 100644 index 0000000..3b83a98 --- /dev/null +++ b/Src/Commons.Persistence.Sitecore/DefaultSetupTasks/RegisterValueProvider.cs @@ -0,0 +1,22 @@ +using System.Linq; +using System.Web.Mvc; +using BoC.Tasks; + +namespace BoC.Persistence.SitecoreGlass.DefaultSetupTasks +{ + public class RegisterValueProvider : IBootstrapperTask + { + public void Execute() + { + var index = ValueProviderFactories.Factories.FirstOrDefault(f => f is ChildActionValueProviderFactory); + if (index != null) + { + ValueProviderFactories.Factories.Insert(ValueProviderFactories.Factories.IndexOf(index) + 1, new ParametersTemplateValueProviderFactory()); + } + else + { + ValueProviderFactories.Factories.Add(new ParametersTemplateValueProviderFactory()); + } + } + } +} \ No newline at end of file diff --git a/Src/Commons.Persistence.Sitecore/Properties/AssemblyInfo.cs b/Src/Commons.Persistence.Sitecore/Properties/AssemblyInfo.cs index e412433..30c20ba 100644 --- a/Src/Commons.Persistence.Sitecore/Properties/AssemblyInfo.cs +++ b/Src/Commons.Persistence.Sitecore/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("4.0.2.0")] -[assembly: AssemblyFileVersion("4.0.2.0")] +[assembly: AssemblyVersion("4.0.7.0")] +[assembly: AssemblyFileVersion("4.0.7.0")] diff --git a/Src/Commons.Persistence.Sitecore/TemplateParametersValueProviderFactory.cs b/Src/Commons.Persistence.Sitecore/TemplateParametersValueProviderFactory.cs new file mode 100644 index 0000000..5c7eb6b --- /dev/null +++ b/Src/Commons.Persistence.Sitecore/TemplateParametersValueProviderFactory.cs @@ -0,0 +1,65 @@ +using System; +using System.Globalization; +using System.Reflection; +using System.Web.Mvc; +using Glass.Mapper.Sc; +using Sitecore.Mvc.Presentation; + +namespace BoC.Persistence.SitecoreGlass +{ + public class ParametersTemplateValueProviderFactory : ValueProviderFactory + { + public override IValueProvider GetValueProvider(ControllerContext controllerContext) + { + return new ParametersTemplateValueProvider(); + } + + private class ParametersTemplateValueProvider : IValueProvider + { + public bool ContainsPrefix(string prefix) + { + return "renderingParameters".Equals(prefix, StringComparison.OrdinalIgnoreCase); + } + + public ValueProviderResult GetValue(string key) + { + var context = RenderingContext.CurrentOrNull; + if (context == null) return null; + + var keyval = key.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); + var prefix = keyval[0]; + switch (prefix.ToLowerInvariant()) + { + case "renderingparameters": + if (RenderingContext.CurrentOrNull == null) + return new ValueProviderResult(null, "renderingParameters", CultureInfo.CurrentCulture); + return new ParametersTemplateValueProviderResult(RenderingContext.CurrentOrNull.Rendering[GlassHtml.Parameters], CultureInfo.CurrentCulture); + default: + return null; + } + } + + } + } + + internal class ParametersTemplateValueProviderResult : ValueProviderResult + { + private readonly string _parameters; + + public ParametersTemplateValueProviderResult(string parameters, CultureInfo cultureInfo): base(parameters, parameters, cultureInfo) + { + _parameters = parameters; + } + + static MethodInfo method = typeof(GlassHtml).GetMethod("GetRenderingParameters", BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(string) }, null); + public override object ConvertTo(Type type, CultureInfo culture) + { + if (String.IsNullOrEmpty(_parameters)) + return null; + + var glassHtml = new GlassHtml(SitecoreContext.GetFromHttpContext()); + var genericMethod = method.MakeGenericMethod(type); + return genericMethod.Invoke(glassHtml, new object[]{_parameters}) ?? base.ConvertTo(type, culture); + } + } +} diff --git a/Src/Commons.Persistence.Sitecore/packages.config b/Src/Commons.Persistence.Sitecore/packages.config index 44d0b34..3eee48c 100644 --- a/Src/Commons.Persistence.Sitecore/packages.config +++ b/Src/Commons.Persistence.Sitecore/packages.config @@ -4,6 +4,9 @@ + + + diff --git a/Src/Commons.Sitecore.Mvc/Properties/AssemblyInfo.cs b/Src/Commons.Sitecore.Mvc/Properties/AssemblyInfo.cs index 906f557..c5f614b 100644 --- a/Src/Commons.Sitecore.Mvc/Properties/AssemblyInfo.cs +++ b/Src/Commons.Sitecore.Mvc/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("4.0.0.0")] -[assembly: AssemblyFileVersion("4.0.0.0")] +[assembly: AssemblyVersion("4.0.3.0")] +[assembly: AssemblyFileVersion("4.0.3.0")] diff --git a/Src/Commons.Sitecore.Mvc/SitecoreValueProvider.cs b/Src/Commons.Sitecore.Mvc/SitecoreValueProvider.cs index 388cafa..288590e 100644 --- a/Src/Commons.Sitecore.Mvc/SitecoreValueProvider.cs +++ b/Src/Commons.Sitecore.Mvc/SitecoreValueProvider.cs @@ -25,6 +25,7 @@ public bool ContainsPrefix(string prefix) return "contextItem".Equals(prefix, StringComparison.OrdinalIgnoreCase) || "renderingItem".Equals(prefix, StringComparison.OrdinalIgnoreCase) + || "pageContextItem".Equals(prefix, StringComparison.OrdinalIgnoreCase) || "dataSource".Equals(prefix, StringComparison.OrdinalIgnoreCase); } @@ -43,6 +44,11 @@ public ValueProviderResult GetValue(string key) return new ValueProviderResult(null, "contextitem", CultureInfo.CurrentCulture); return GetValueResult(context.ContextItem, property); + case "pagecontextitem": + if (context.PageContext == null || context.PageContext.Item == null) + return new ValueProviderResult(null, "contextitem", CultureInfo.CurrentCulture); + return GetValueResult(context.PageContext.Item, property); + case "renderingitem": if (context.Rendering == null || context.Rendering.RenderingItem == null) return new ValueProviderResult(null, "renderingitem", CultureInfo.CurrentCulture);; From 1b82e95b7e19f5afb3758c389e2c7ea5daab61e6 Mon Sep 17 00:00:00 2001 From: Ralf van den Burg Date: Fri, 3 Jul 2015 14:13:03 +0200 Subject: [PATCH 03/10] Prevent Collection modified exception while running initializers --- Src/Commons/InversionOfControl/IoC.cs | 69 +++++++++++++++++---------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/Src/Commons/InversionOfControl/IoC.cs b/Src/Commons/InversionOfControl/IoC.cs index f9e76a1..27cd1d0 100644 --- a/Src/Commons/InversionOfControl/IoC.cs +++ b/Src/Commons/InversionOfControl/IoC.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using BoC.Helpers; @@ -8,9 +9,11 @@ public static class IoC { private static readonly object resolverLock = new object(); - public static void InitializeWith(IDependencyResolver resolver) + public static void InitializeWith(IDependencyResolver resolver, params IAppDomainHelper[] appDomainHelpers) { Check.Argument.IsNotNull(resolver, "resolver"); + if (IoC.Resolver != null) + throw new ApplicationException("IoC already initialized"); lock (resolverLock) { if (IoC.Resolver != null) @@ -18,7 +21,7 @@ public static void InitializeWith(IDependencyResolver resolver) IoC.Resolver = resolver; resolver.RegisterInstance(resolver); - RunContainerInitializers(resolver); + RunContainerInitializers(resolver, appDomainHelpers); } } @@ -48,46 +51,64 @@ public static void Reset() } } - private static void RunContainerInitializers(IDependencyResolver dependencyResolver) + private static void RunContainerInitializers(IDependencyResolver dependencyResolver, IAppDomainHelper[] appdomainHelpers) { - var appdomainHelpers = dependencyResolver.ResolveAll(); - if (appdomainHelpers == null || ! appdomainHelpers.Any()) + if (appdomainHelpers == null || appdomainHelpers.Any() ) { - appdomainHelpers = new[] {AppDomainHelper.CreateDefault()}; + var helper = AppDomainHelper.CreateDefault(); + appdomainHelpers = new[] {helper}; } - var initTasks = - appdomainHelpers.SelectMany(helper => helper.GetTypes( - t => t.IsClass && !t.IsAbstract && typeof (IContainerInitializer).IsAssignableFrom(t))); - //register them: - foreach (var taskType in initTasks) + if (!dependencyResolver.IsRegistered(typeof (IAppDomainHelper))) { - dependencyResolver.RegisterType(typeof(IContainerInitializer), taskType); + foreach (var helper in appdomainHelpers) + { + dependencyResolver.RegisterInstance(helper); + } } + + var allTasks = + appdomainHelpers.SelectMany(helper => helper.GetTypes( + t => t.IsClass && !t.IsAbstract && typeof (IContainerInitializer).IsAssignableFrom(t))); //run them: - var allTasks = dependencyResolver.ResolveAll() - .Where( it=> it != null ) - .ToList(); + var allTasksList = allTasks as IList ?? allTasks.ToList(); + + var nonbocHelpers = allTasksList.Where(t => t.Namespace != null && !t.Namespace.StartsWith("BoC.")); + var bocHelpers = allTasksList.Where(t => t.Namespace != null && t.Namespace.StartsWith("BoC.")); + //first user's tasks: - foreach (var task in allTasks.Where(t => !NamespaceStartsWith (t , "BoC."))) + foreach (var type in nonbocHelpers) { + var task = CreateTask(dependencyResolver, type, appdomainHelpers); task.Execute(); } //now ours: - foreach (var task in allTasks.Where(t => NamespaceStartsWith(t,"BoC."))) + foreach (var type in bocHelpers ) { + var task = CreateTask(dependencyResolver, type, appdomainHelpers); task.Execute(); } } - private static bool NamespaceStartsWith(IContainerInitializer initializer, String startsWidth ) + private static IContainerInitializer CreateTask(IDependencyResolver dependencyResolver, Type type, IAppDomainHelper[] appDomainHelpers) { - if (initializer == null) return false; - - var typeofInitializerNameSpace = initializer.GetType().Namespace; - if (String.IsNullOrEmpty(typeofInitializerNameSpace)) return false; - - return typeofInitializerNameSpace.StartsWith(startsWidth); + var constructor = type.GetConstructors().First(); + var parameters = constructor.GetParameters(); + if (!parameters.Any()) + return Activator.CreateInstance(type) as IContainerInitializer; + var parameterValues = new object[parameters.Length]; + for (var i=0;i Date: Mon, 6 Jul 2015 09:47:50 +0200 Subject: [PATCH 04/10] Enabled by default --- .../Web/UnitOfWorkPerRequestHttpModule.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Src/Commons/Web/UnitOfWorkPerRequestHttpModule.cs b/Src/Commons/Web/UnitOfWorkPerRequestHttpModule.cs index b1cf707..4772ecd 100644 --- a/Src/Commons/Web/UnitOfWorkPerRequestHttpModule.cs +++ b/Src/Commons/Web/UnitOfWorkPerRequestHttpModule.cs @@ -2,17 +2,17 @@ using System.Web; using BoC.EventAggregator; using BoC.Tasks; -using BoC.UnitOfWork; +using BoC.DataContext; using BoC.Web.Events; namespace BoC.Web { //we have to use an httpmodule instead of subscribing to our own eventmanager, since this absolutely has to be started //immediately after the request starts. - public class UnitOfWorkPerRequestHttpModule : IHttpModule + public class DataContextPerRequestHttpModule : IHttpModule { - private const string unitofworkkey = "BoC.UnitOfWork.Web.OuterUnitOfWork"; - public static bool Enabled = false; + private const string DataContextkey = "BoC.DataContext.Web.OuterDataContext"; + public static bool Enabled = true; public void Init(HttpApplication context) { @@ -31,18 +31,18 @@ private void OnEndRequest(object sender, EventArgs eventArgs) return; } - var unitOfWork = ((HttpApplication)sender).Context.Items[unitofworkkey] as IUnitOfWork; - if (unitOfWork != null) + var DataContext = ((HttpApplication)sender).Context.Items[DataContextkey] as IDataContext; + if (DataContext != null) { - unitOfWork.Dispose(); + DataContext.Dispose(); } - ((HttpApplication)sender).Context.Items.Remove(unitofworkkey); + ((HttpApplication)sender).Context.Items.Remove(DataContextkey); } private void OnBeginRequest(object sender, EventArgs eventArgs) { if (Enabled) - ((HttpApplication)sender).Context.Items[unitofworkkey] = UnitOfWork.UnitOfWork.BeginUnitOfWork(); + ((HttpApplication)sender).Context.Items[DataContextkey] = DataContext.DataContext.BeginDataContext(); } } From 5e865a9baccb7e69ed4dbc48bc9c9776da51936a Mon Sep 17 00:00:00 2001 From: Chris van de Steeg Date: Mon, 6 Jul 2015 09:48:13 +0200 Subject: [PATCH 05/10] Version update --- .../BoC.Persistence.SitecoreGlass.csproj | 98 +++++++++++-------- .../BoC.Persistence.SitecoreGlass.nuspec | 30 ++++++ .../Properties/AssemblyInfo.cs | 6 +- .../packages.config | 12 ++- Src/Commons/Properties/AssemblyInfo.cs | 6 +- 5 files changed, 102 insertions(+), 50 deletions(-) create mode 100644 Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.nuspec diff --git a/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.csproj b/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.csproj index 07f6903..75f2da4 100644 --- a/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.csproj +++ b/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.csproj @@ -35,28 +35,45 @@ false - + False - ..\..\lib\Glass.mapper\Glass.Mapper.dll + ..\..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll - + False - ..\..\lib\Glass.mapper\Glass.Mapper.Sc.dll + ..\..\packages\BoC.Glass.Mapper.Sc.4.0.0\lib\Glass.Mapper.dll - - ..\..\lib\Glass.mapper\Glass.Mapper.Sc.ContentSearch.dll + + False + ..\..\packages\BoC.Glass.Mapper.Sc.4.0.0\lib\80\Glass.Mapper.Sc.dll + + + False + ..\..\packages\BoC.Glass.Mapper.Sc.ContentSearch.LuceneProvider.4.0.0\lib\80\Glass.Mapper.Sc.ContentSearch.dll - - ..\..\lib\Glass.mapper\Glass.Mapper.Sc.ContentSearch.LuceneProvider.dll + + False + ..\..\packages\BoC.Glass.Mapper.Sc.ContentSearch.LuceneProvider.4.0.0\lib\80\Glass.Mapper.Sc.ContentSearch.LuceneProvider.dll - + False - ..\..\lib\Sitecore\Lucene.Net.dll + ..\..\packages\BoC.Glass.Mapper.Sc.4.0.0\lib\Mvc5\Glass.Mapper.Sc.Mvc.dll + + + False + ..\..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll + + + False + ..\..\packages\Lucene.Net.3.0.3\lib\NET40\Lucene.Net.dll True ..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + + ..\..\packages\ReadOnlyCollectionInterfaces.1.0.0\lib\NET45\ReadOnlyCollectionsInterfaces.dll + ..\..\lib\Sitecore\Sitecore.ContentSearch.dll @@ -71,42 +88,33 @@ ..\..\lib\Sitecore\Sitecore.Mvc.dll - - - - - False - ..\..\packages\Microsoft.AspNet.WebPages.3.1.2\lib\net45\System.Web.Helpers.dll - - - False - ..\..\packages\Microsoft.AspNet.Mvc.5.1.2\lib\net45\System.Web.Mvc.dll - - + False - ..\..\packages\Microsoft.AspNet.Razor.3.1.2\lib\net45\System.Web.Razor.dll + ..\..\packages\Microsoft.Bcl.Immutable.1.0.34\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - - False - ..\..\packages\Microsoft.AspNet.WebPages.3.1.2\lib\net45\System.Web.WebPages.dll - - - False - ..\..\packages\Microsoft.AspNet.WebPages.3.1.2\lib\net45\System.Web.WebPages.Deployment.dll - - - False - ..\..\packages\Microsoft.AspNet.WebPages.3.1.2\lib\net45\System.Web.WebPages.Razor.dll + + ..\..\packages\System.Collections.Immutable.Net40.1.0.30.17\lib\net40\System.Collections.Immutable.Net40.dll + + + + + + False + ..\..\packages\WebActivatorEx.2.0.6\lib\net40\WebActivatorEx.dll + + - + + + @@ -114,16 +122,21 @@ + + - + + + + - - - - - + + + + + @@ -132,6 +145,9 @@ + + + diff --git a/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.nuspec b/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.nuspec new file mode 100644 index 0000000..044766f --- /dev/null +++ b/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.nuspec @@ -0,0 +1,30 @@ + + + + $id$ + $version$ + $title$ + Chris van de Steeg + Chris van de Steeg + https://github.com/csteeg/BoC/blob/master/LICENSE + https://github.com/csteeg/boc + false + $description$ + Summary of changes made in this release of the package. + Copyright 2014 + BoC,Persistence,Glass,Mapper,ORM,Repository,Sitecore + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/Commons.Persistence.Sitecore/Properties/AssemblyInfo.cs b/Src/Commons.Persistence.Sitecore/Properties/AssemblyInfo.cs index 2a8703c..bb77f5d 100644 --- a/Src/Commons.Persistence.Sitecore/Properties/AssemblyInfo.cs +++ b/Src/Commons.Persistence.Sitecore/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("BoC.Persistence.Sitecore")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyDescription("Persistence layer for sitecore using glass.mapper")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("BoC.Persistence.Sitecore")] @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.0.0")] -[assembly: AssemblyFileVersion("1.5.0.0")] +[assembly: AssemblyVersion("4.0.2.0")] +[assembly: AssemblyFileVersion("4.0.2.0")] diff --git a/Src/Commons.Persistence.Sitecore/packages.config b/Src/Commons.Persistence.Sitecore/packages.config index b3afa51..44d0b34 100644 --- a/Src/Commons.Persistence.Sitecore/packages.config +++ b/Src/Commons.Persistence.Sitecore/packages.config @@ -1,7 +1,13 @@  - - - + + + + + + + + + \ No newline at end of file diff --git a/Src/Commons/Properties/AssemblyInfo.cs b/Src/Commons/Properties/AssemblyInfo.cs index af8b217..2330f8c 100644 --- a/Src/Commons/Properties/AssemblyInfo.cs +++ b/Src/Commons/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Chris van de Steeg")] [assembly: AssemblyProduct("BoC")] -[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyCopyright("Copyright © 2012-2014")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,7 +32,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.0.0")] -[assembly: AssemblyFileVersion("1.5.0.0")] +[assembly: AssemblyVersion("4.0.1.0")] +[assembly: AssemblyFileVersion("4.0.1.0")] [assembly: AssemblyKeyFileAttribute("../../BoC.snk")] \ No newline at end of file From 8333b99ebf0cf3ea515830564c4199d54d206b18 Mon Sep 17 00:00:00 2001 From: Chris van de Steeg Date: Thu, 9 Jul 2015 13:04:46 +0200 Subject: [PATCH 06/10] Update and rename README to README.md --- README => README.md | 4 ++++ 1 file changed, 4 insertions(+) rename README => README.md (75%) diff --git a/README b/README.md similarity index 75% rename from README rename to README.md index 699fa06..a7a410e 100644 --- a/README +++ b/README.md @@ -5,3 +5,7 @@ -Bootstrapper and Background task pattern implementation -Logging wrapper (see BoC.Logging.log4net for implementation) -Persistence repository and service pattern implementation (see other BoC packages like BoC.Persistence.NHibernate for implementations) + +'BoC and Sitecore +If you would like to get started with the BoC and Sitecore, follow this excellent tutorial by Guido van Tricht: +http://guidovtricht.nl/2015/07/sitecore-mvc-musicstore-part-1/ From e63d2eb0ea18a03838b7350f0410e6aec850f397 Mon Sep 17 00:00:00 2001 From: Chris van de Steeg Date: Thu, 9 Jul 2015 13:05:08 +0200 Subject: [PATCH 07/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a7a410e..a665915 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,6 @@ -Logging wrapper (see BoC.Logging.log4net for implementation) -Persistence repository and service pattern implementation (see other BoC packages like BoC.Persistence.NHibernate for implementations) -'BoC and Sitecore +#BoC and Sitecore If you would like to get started with the BoC and Sitecore, follow this excellent tutorial by Guido van Tricht: http://guidovtricht.nl/2015/07/sitecore-mvc-musicstore-part-1/ From f87f101bd079e5a33a031b85e61902d8fd1fdbe0 Mon Sep 17 00:00:00 2001 From: Chris van de Steeg Date: Thu, 9 Jul 2015 13:06:01 +0200 Subject: [PATCH 08/10] Update README.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a665915..feb2c5f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -BoC needs some documentation, but contains lots of usefull stuff like --EventAggregator pattern implementation --Inversion of Control wrapper (see other BoC packages like BoC.InversionOfControl.Unity for implementations) --UnitOfWork pattern implementation (see other BoC packages like BoC.Persistence.NHibernate for implementations) --Bootstrapper and Background task pattern implementation --Logging wrapper (see BoC.Logging.log4net for implementation) --Persistence repository and service pattern implementation (see other BoC packages like BoC.Persistence.NHibernate for implementations) +BoC needs some documentation, but contains lots of usefull stuff like +*EventAggregator pattern implementation +*Inversion of Control wrapper (although being an anti-pattern, still very usefull. see other BoC packages like BoC.InversionOfControl.Unity for implementations) +*UnitOfWork pattern implementation (see other BoC packages like BoC.Persistence.NHibernate for implementations) +*Bootstrapper and Background task pattern implementation +*Logging wrapper (see BoC.Logging.log4net for implementation) +*Persistence repository and service pattern implementation (see other BoC packages like BoC.Persistence.NHibernate for implementations) #BoC and Sitecore If you would like to get started with the BoC and Sitecore, follow this excellent tutorial by Guido van Tricht: From 2dd3dc1f86dd442597bde58fd44aaf93adb5186a Mon Sep 17 00:00:00 2001 From: Chris van de Steeg Date: Thu, 9 Jul 2015 13:06:21 +0200 Subject: [PATCH 09/10] Update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index feb2c5f..8bd70c3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ BoC needs some documentation, but contains lots of usefull stuff like -*EventAggregator pattern implementation -*Inversion of Control wrapper (although being an anti-pattern, still very usefull. see other BoC packages like BoC.InversionOfControl.Unity for implementations) -*UnitOfWork pattern implementation (see other BoC packages like BoC.Persistence.NHibernate for implementations) -*Bootstrapper and Background task pattern implementation -*Logging wrapper (see BoC.Logging.log4net for implementation) -*Persistence repository and service pattern implementation (see other BoC packages like BoC.Persistence.NHibernate for implementations) +* EventAggregator pattern implementation +* Inversion of Control wrapper (although being an anti-pattern, still very usefull. see other BoC packages like BoC.InversionOfControl.Unity for implementations) +* UnitOfWork pattern implementation (see other BoC packages like BoC.Persistence.NHibernate for implementations) +* Bootstrapper and Background task pattern implementation +* Logging wrapper (see BoC.Logging.log4net for implementation) +* Persistence repository and service pattern implementation (see other BoC packages like BoC.Persistence.NHibernate for implementations) #BoC and Sitecore If you would like to get started with the BoC and Sitecore, follow this excellent tutorial by Guido van Tricht: From 0a9c8bb621dea96d25d8979cf84cf5462b0e899b Mon Sep 17 00:00:00 2001 From: Chris van de Steeg Date: Wed, 15 Jul 2015 18:12:11 +0200 Subject: [PATCH 10/10] Some small new sitecore features --- .../App_Start/GlassMapperScCustom.BoC.cs.pp | 71 ++++++++++++++ .../BoC.Persistence.SitecoreGlass.csproj | 29 ++++++ .../BoC.Persistence.SitecoreGlass.nuspec | 3 +- .../DataContext/SitecoreDataContext.cs | 92 +++++++++++++++++++ .../RegisterValueProvider.cs | 11 ++- .../Mvc/SitecoreValueProvider.cs | 10 +- .../Properties/AssemblyInfo.cs | 4 +- .../TemplateParametersValueProviderFactory.cs | 65 +++++++++++++ .../packages.config | 3 + .../Properties/AssemblyInfo.cs | 16 ++-- 10 files changed, 287 insertions(+), 17 deletions(-) create mode 100644 Src/Commons.Persistence.Sitecore/App_Start/GlassMapperScCustom.BoC.cs.pp create mode 100644 Src/Commons.Persistence.Sitecore/DataContext/SitecoreDataContext.cs create mode 100644 Src/Commons.Persistence.Sitecore/TemplateParametersValueProviderFactory.cs diff --git a/Src/Commons.Persistence.Sitecore/App_Start/GlassMapperScCustom.BoC.cs.pp b/Src/Commons.Persistence.Sitecore/App_Start/GlassMapperScCustom.BoC.cs.pp new file mode 100644 index 0000000..c3f5312 --- /dev/null +++ b/Src/Commons.Persistence.Sitecore/App_Start/GlassMapperScCustom.BoC.cs.pp @@ -0,0 +1,71 @@ +using System.Linq; +using BoC.InversionOfControl; +using Glass.Mapper.Configuration; +using Glass.Mapper.IoC; +using Glass.Mapper.Maps; +using Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CacheCheck; +using Glass.Mapper.Sc.CodeFirst; +using Glass.Mapper.Sc.ContentSearch.Pipelines.ObjectConstruction.Tasks.SearchProxy; +using Glass.Mapper.Sc.IoC; +using Sitecore.SecurityModel; +using IDependencyResolver = Glass.Mapper.Sc.IoC.IDependencyResolver; + +namespace $rootnamespace$.App_Start +{ + //Comment out all code in glass.mapper's original GlassMapperScCustom.cs and move your custom code to here. This version has a different CreateResolver() for contentsearch support + public static class GlassMapperScCustom + { + public static IDependencyResolver CreateResolver(){ + global::BoC.Persistence.SitecoreGlass.Initialize.InitBoc.Start(); + + var config = new global::Glass.Mapper.Sc.Config(); + + var resolver = new DependencyResolver(config); + //trigger addtypes + var items = resolver.ObjectConstructionFactory.GetItems().ToArray(); + var index = 0; + for (var i=0;i new SearchProxyWrapperTask()); + return resolver; + } + + public static IConfigurationLoader[] GlassLoaders(){ + + /* Register any ConfigurationLoader you use (eg fluent) in the IoC.Resolver. + * + * If you are using Attribute Configuration or automapping/on-demand mapping you don't need to do anything! + * + */ + + return global::BoC.InversionOfControl.IoC.Resolver.ResolveAll().ToArray(); + } + public static void PostLoad(){ + //Set config property to true in Glass.Mapper.Sc.CodeFirst.config to enable codefirst + if (!global::Sitecore.Configuration.Settings.GetBoolSetting("Glass.CodeFirst", false)) return; + + var dbs = global::Sitecore.Configuration.Factory.GetDatabases(); + foreach (var db in dbs) + { + var provider = db.GetDataProviders().FirstOrDefault(x => x is GlassDataProvider) as GlassDataProvider; + if (provider != null) + { + using (new SecurityDisabler()) + { + provider.Initialise(db); + } + } + } + } + public static void AddMaps(IConfigFactory mapsConfigFactory) + { + // Add maps here + // mapsConfigFactory.Add(() => new SeoMap()); + } + } +} diff --git a/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.csproj b/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.csproj index 75f2da4..8348408 100644 --- a/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.csproj +++ b/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.csproj @@ -99,6 +99,30 @@ + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll + + + False + ..\..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll + + + False + ..\..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll + + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll + + + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll + True + + + False + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll + @@ -113,6 +137,10 @@ + + + + @@ -128,6 +156,7 @@ + diff --git a/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.nuspec b/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.nuspec index 044766f..c421c9c 100644 --- a/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.nuspec +++ b/Src/Commons.Persistence.Sitecore/BoC.Persistence.SitecoreGlass.nuspec @@ -14,7 +14,8 @@ Copyright 2014 BoC,Persistence,Glass,Mapper,ORM,Repository,Sitecore - + + diff --git a/Src/Commons.Persistence.Sitecore/DataContext/SitecoreDataContext.cs b/Src/Commons.Persistence.Sitecore/DataContext/SitecoreDataContext.cs new file mode 100644 index 0000000..9ff5bd3 --- /dev/null +++ b/Src/Commons.Persistence.Sitecore/DataContext/SitecoreDataContext.cs @@ -0,0 +1,92 @@ +using System.Globalization; +using BoC.DataContext; +using Sitecore; +using Sitecore.ContentSearch; +using Sitecore.Data; +using Sitecore.Search; + +namespace BoC.Persistence.SitecoreGlass.DataContext +{ + public class SitecoreDataContext : BaseThreadSafeSingleDataContext + { + private readonly IIndexNameProvider _indexNameProvider; + protected IProviderSearchContext _index; + private string _database; + private CultureInfo _cultureInfo; + + public SitecoreDataContext(IIndexNameProvider indexNameProvider): base() + { + _indexNameProvider = indexNameProvider; + } + + public static SitecoreDataContext BeginDataContext(IIndexNameProvider indexNameProvider = null, string database = null, CultureInfo cultureInfo = null) + { + return new SitecoreDataContext(indexNameProvider) + { + _database = database, + _cultureInfo = cultureInfo + }; + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (_index != null) + { + try + { + _index.Dispose(); + } + finally + { + _index = null; + } + } + } + + protected override void CleanUpOuterDataContext() + { + + } + + public virtual Database GetDatabase() + { + if (!string.IsNullOrEmpty(_database)) + return Database.GetDatabase(_database); + if (OuterDataContext != this && OuterDataContext is SitecoreDataContext) + return ((SitecoreDataContext) OuterDataContext).GetDatabase(); + return Context.Database ?? Context.ContentDatabase; + } + + public CultureInfo GetCultureInfo() + { + if (_cultureInfo != null) + return _cultureInfo; + if (OuterDataContext != this && OuterDataContext is SitecoreDataContext) + { + return ((SitecoreDataContext) OuterDataContext).GetCultureInfo(); + } + return Context.Language.CultureInfo; + } + + + public virtual IProviderSearchContext IndexSearchContext + { + get + { + if (OuterDataContext == this || !(OuterDataContext is SitecoreDataContext) || ((SitecoreDataContext)OuterDataContext)._indexNameProvider.GetIndexName() != (_indexNameProvider == null ? null : _indexNameProvider.GetIndexName())) + { + if (_indexNameProvider != null) + return _index ?? + (_index = ContentSearchManager.GetIndex(_indexNameProvider.GetIndexName()).CreateSearchContext()); + } + else if (OuterDataContext is SitecoreDataContext) + { + return ((SitecoreDataContext)OuterDataContext).IndexSearchContext; + } + return null; + } + } + + } +} diff --git a/Src/Commons.Persistence.Sitecore/DefaultSetupTasks/RegisterValueProvider.cs b/Src/Commons.Persistence.Sitecore/DefaultSetupTasks/RegisterValueProvider.cs index 26262dc..7601e6d 100644 --- a/Src/Commons.Persistence.Sitecore/DefaultSetupTasks/RegisterValueProvider.cs +++ b/Src/Commons.Persistence.Sitecore/DefaultSetupTasks/RegisterValueProvider.cs @@ -1,6 +1,5 @@ -using System.Linq; +using System.Linq; using System.Web.Mvc; -using BoC.Persistence.SitecoreGlass.Mvc; using BoC.Tasks; namespace BoC.Persistence.SitecoreGlass.DefaultSetupTasks @@ -11,9 +10,13 @@ public void Execute() { var index = ValueProviderFactories.Factories.FirstOrDefault(f => f is ChildActionValueProviderFactory); if (index != null) - ValueProviderFactories.Factories.Insert(ValueProviderFactories.Factories.IndexOf(index) + 1, new SitecoreValueProviderFactory()); + { + ValueProviderFactories.Factories.Insert(ValueProviderFactories.Factories.IndexOf(index) + 1, new ParametersTemplateValueProviderFactory()); + } else - ValueProviderFactories.Factories.Add(new SitecoreValueProviderFactory()); + { + ValueProviderFactories.Factories.Add(new ParametersTemplateValueProviderFactory()); + } } } } \ No newline at end of file diff --git a/Src/Commons.Persistence.Sitecore/Mvc/SitecoreValueProvider.cs b/Src/Commons.Persistence.Sitecore/Mvc/SitecoreValueProvider.cs index 7157f31..713868c 100644 --- a/Src/Commons.Persistence.Sitecore/Mvc/SitecoreValueProvider.cs +++ b/Src/Commons.Persistence.Sitecore/Mvc/SitecoreValueProvider.cs @@ -1,15 +1,15 @@ using System; using System.Globalization; using System.Linq; -using System.Web; using System.Web.Mvc; using BoC.InversionOfControl; +using BoC.Persistence; using BoC.Services; using Sitecore.Data; using Sitecore.Data.Items; using Sitecore.Mvc.Presentation; -namespace BoC.Persistence.SitecoreGlass.Mvc +namespace BoC.Sitecore.Mvc { public class SitecoreValueProviderFactory : ValueProviderFactory { @@ -25,6 +25,7 @@ public bool ContainsPrefix(string prefix) return "contextItem".Equals(prefix, StringComparison.OrdinalIgnoreCase) || "renderingItem".Equals(prefix, StringComparison.OrdinalIgnoreCase) + || "pageContextItem".Equals(prefix, StringComparison.OrdinalIgnoreCase) || "dataSource".Equals(prefix, StringComparison.OrdinalIgnoreCase); } @@ -43,6 +44,11 @@ public ValueProviderResult GetValue(string key) return new ValueProviderResult(null, "contextitem", CultureInfo.CurrentCulture); return GetValueResult(context.ContextItem, property); + case "pagecontextitem": + if (context.PageContext == null || context.PageContext.Item == null) + return new ValueProviderResult(null, "contextitem", CultureInfo.CurrentCulture); + return GetValueResult(context.PageContext.Item, property); + case "renderingitem": if (context.Rendering == null || context.Rendering.RenderingItem == null) return new ValueProviderResult(null, "renderingitem", CultureInfo.CurrentCulture);; diff --git a/Src/Commons.Persistence.Sitecore/Properties/AssemblyInfo.cs b/Src/Commons.Persistence.Sitecore/Properties/AssemblyInfo.cs index bb77f5d..e5b2424 100644 --- a/Src/Commons.Persistence.Sitecore/Properties/AssemblyInfo.cs +++ b/Src/Commons.Persistence.Sitecore/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("4.0.2.0")] -[assembly: AssemblyFileVersion("4.0.2.0")] +[assembly: AssemblyVersion("4.0.7.0")] +[assembly: AssemblyFileVersion("4.0.7.0")] diff --git a/Src/Commons.Persistence.Sitecore/TemplateParametersValueProviderFactory.cs b/Src/Commons.Persistence.Sitecore/TemplateParametersValueProviderFactory.cs new file mode 100644 index 0000000..5c7eb6b --- /dev/null +++ b/Src/Commons.Persistence.Sitecore/TemplateParametersValueProviderFactory.cs @@ -0,0 +1,65 @@ +using System; +using System.Globalization; +using System.Reflection; +using System.Web.Mvc; +using Glass.Mapper.Sc; +using Sitecore.Mvc.Presentation; + +namespace BoC.Persistence.SitecoreGlass +{ + public class ParametersTemplateValueProviderFactory : ValueProviderFactory + { + public override IValueProvider GetValueProvider(ControllerContext controllerContext) + { + return new ParametersTemplateValueProvider(); + } + + private class ParametersTemplateValueProvider : IValueProvider + { + public bool ContainsPrefix(string prefix) + { + return "renderingParameters".Equals(prefix, StringComparison.OrdinalIgnoreCase); + } + + public ValueProviderResult GetValue(string key) + { + var context = RenderingContext.CurrentOrNull; + if (context == null) return null; + + var keyval = key.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); + var prefix = keyval[0]; + switch (prefix.ToLowerInvariant()) + { + case "renderingparameters": + if (RenderingContext.CurrentOrNull == null) + return new ValueProviderResult(null, "renderingParameters", CultureInfo.CurrentCulture); + return new ParametersTemplateValueProviderResult(RenderingContext.CurrentOrNull.Rendering[GlassHtml.Parameters], CultureInfo.CurrentCulture); + default: + return null; + } + } + + } + } + + internal class ParametersTemplateValueProviderResult : ValueProviderResult + { + private readonly string _parameters; + + public ParametersTemplateValueProviderResult(string parameters, CultureInfo cultureInfo): base(parameters, parameters, cultureInfo) + { + _parameters = parameters; + } + + static MethodInfo method = typeof(GlassHtml).GetMethod("GetRenderingParameters", BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(string) }, null); + public override object ConvertTo(Type type, CultureInfo culture) + { + if (String.IsNullOrEmpty(_parameters)) + return null; + + var glassHtml = new GlassHtml(SitecoreContext.GetFromHttpContext()); + var genericMethod = method.MakeGenericMethod(type); + return genericMethod.Invoke(glassHtml, new object[]{_parameters}) ?? base.ConvertTo(type, culture); + } + } +} diff --git a/Src/Commons.Persistence.Sitecore/packages.config b/Src/Commons.Persistence.Sitecore/packages.config index 44d0b34..3eee48c 100644 --- a/Src/Commons.Persistence.Sitecore/packages.config +++ b/Src/Commons.Persistence.Sitecore/packages.config @@ -4,6 +4,9 @@ + + + diff --git a/Src/Commons.Persistence.UmbracoGlass/Properties/AssemblyInfo.cs b/Src/Commons.Persistence.UmbracoGlass/Properties/AssemblyInfo.cs index 4356ff4..c5f614b 100644 --- a/Src/Commons.Persistence.UmbracoGlass/Properties/AssemblyInfo.cs +++ b/Src/Commons.Persistence.UmbracoGlass/Properties/AssemblyInfo.cs @@ -5,12 +5,12 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("BoC.Persistence.UmbracoGlass")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyTitle("BoC.Sitecore.Mvc")] +[assembly: AssemblyDescription("Mvc stuff for sitecore")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("BoC.Persistence.UmbracoGlass")] -[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyCompany("Chris van de Steeg")] +[assembly: AssemblyProduct("BoC.Sitecore.Mvc")] +[assembly: AssemblyCopyright("Copyright © 2015")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -20,7 +20,7 @@ [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("679867b2-0cc4-493a-85ca-d25266a6702f")] +[assembly: Guid("13d89bef-9ca9-46eb-899c-dda310cddb55")] // Version information for an assembly consists of the following four values: // @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("4.0.3.0")] +[assembly: AssemblyFileVersion("4.0.3.0")]