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.Persistence.UmbracoGlass/Properties/AssemblyInfo.cs b/Src/Commons.Persistence.UmbracoGlass/Properties/AssemblyInfo.cs index dc1cac4..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("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/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);; diff --git a/Src/Commons/Helpers/AppDomainHelper.cs b/Src/Commons/Helpers/AppDomainHelper.cs index 06586e8..f4debb2 100644 --- a/Src/Commons/Helpers/AppDomainHelper.cs +++ b/Src/Commons/Helpers/AppDomainHelper.cs @@ -96,29 +96,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; } } @@ -127,6 +109,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 fbb4990..b707781 100644 --- a/Src/Commons/Initializer.cs +++ b/Src/Commons/Initializer.cs @@ -48,10 +48,18 @@ public static void Execute(IDependencyResolver dependencyResolver, params IAppDo return; lock (initializer_lock) { - if (Executed) - return; - IoC.InitializeWith(dependencyResolver, appDomainHelpers); - new Bootstrapper(dependencyResolver, appDomainHelpers).Run(); + if (appDomainHelpers != null) + { + foreach (var appDomainHelper in appDomainHelpers) + { + dependencyResolver.RegisterInstance(appDomainHelper); + } + } + + IoC.InitializeWith(dependencyResolver); + var bootstrapper = dependencyResolver.Resolve(); + if (bootstrapper != null) + bootstrapper.Run(); Executed = true; }