Merge remote-tracking branch 'origin/6.2.0' into 7.0.2

Conflicts:
	src/Umbraco.Core/Profiling/ProfilingViewEngine.cs
This commit is contained in:
Shannon
2013-12-19 12:53:32 +11:00
9 changed files with 176 additions and 26 deletions

View File

@@ -4,12 +4,12 @@ namespace Umbraco.Core.Profiling
{ {
public class ProfilingViewEngine: IViewEngine public class ProfilingViewEngine: IViewEngine
{ {
private readonly IViewEngine _inner; internal readonly IViewEngine Inner;
private readonly string _name; private readonly string _name;
public ProfilingViewEngine(IViewEngine inner) public ProfilingViewEngine(IViewEngine inner)
{ {
_inner = inner; Inner = inner;
_name = inner.GetType().Name; _name = inner.GetType().Name;
} }
@@ -17,7 +17,7 @@ namespace Umbraco.Core.Profiling
{ {
using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.FindPartialView, {1}, {2}", _name, partialViewName, useCache))) using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.FindPartialView, {1}, {2}", _name, partialViewName, useCache)))
{ {
return WrapResult(_inner.FindPartialView(controllerContext, partialViewName, useCache)); return WrapResult(Inner.FindPartialView(controllerContext, partialViewName, useCache));
} }
} }
@@ -25,7 +25,7 @@ namespace Umbraco.Core.Profiling
{ {
using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.FindView, {1}, {2}, {3}", _name, viewName, masterName, useCache))) using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.FindView, {1}, {2}, {3}", _name, viewName, masterName, useCache)))
{ {
return WrapResult(_inner.FindView(controllerContext, viewName, masterName, useCache)); return WrapResult(Inner.FindView(controllerContext, viewName, masterName, useCache));
} }
} }
@@ -41,7 +41,7 @@ namespace Umbraco.Core.Profiling
{ {
using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.ReleaseView, {1}", _name, view.GetType().Name))) using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.ReleaseView, {1}", _name, view.GetType().Name)))
{ {
_inner.ReleaseView(controllerContext, view); Inner.ReleaseView(controllerContext, view);
} }
} }
} }

View File

@@ -0,0 +1,78 @@
using System.Collections.Generic;
using System.Web.Mvc;
using Microsoft.Web.Mvc;
using NUnit.Framework;
using Umbraco.Core.Profiling;
using Umbraco.Web;
using Umbraco.Web.Mvc;
namespace Umbraco.Tests.BootManagers
{
[TestFixture]
public class WebBootManagerTests
{
[Test]
public void WrapViewEngines_HasEngines_WrapsAll()
{
IList<IViewEngine> engines = new List<IViewEngine>
{
new FixedWebFormViewEngine(),
new FixedRazorViewEngine(),
new RenderViewEngine(),
new PluginViewEngine()
};
WebBootManager.WrapViewEngines(engines);
Assert.That(engines.Count, Is.EqualTo(4));
Assert.That(engines[0], Is.InstanceOf<ProfilingViewEngine>());
Assert.That(engines[1], Is.InstanceOf<ProfilingViewEngine>());
Assert.That(engines[2], Is.InstanceOf<ProfilingViewEngine>());
Assert.That(engines[3], Is.InstanceOf<ProfilingViewEngine>());
}
[Test]
public void WrapViewEngines_HasEngines_KeepsSortOrder()
{
IList<IViewEngine> engines = new List<IViewEngine>
{
new FixedWebFormViewEngine(),
new FixedRazorViewEngine(),
new RenderViewEngine(),
new PluginViewEngine()
};
WebBootManager.WrapViewEngines(engines);
Assert.That(engines.Count, Is.EqualTo(4));
Assert.That(((ProfilingViewEngine)engines[0]).Inner, Is.InstanceOf<FixedWebFormViewEngine>());
Assert.That(((ProfilingViewEngine)engines[1]).Inner, Is.InstanceOf<FixedRazorViewEngine>());
Assert.That(((ProfilingViewEngine)engines[2]).Inner, Is.InstanceOf<RenderViewEngine>());
Assert.That(((ProfilingViewEngine)engines[3]).Inner, Is.InstanceOf<PluginViewEngine>());
}
[Test]
public void WrapViewEngines_HasProfiledEngine_AddsSameInstance()
{
var profiledEngine = new ProfilingViewEngine(new FixedRazorViewEngine());
IList<IViewEngine> engines = new List<IViewEngine>
{
profiledEngine
};
WebBootManager.WrapViewEngines(engines);
Assert.That(engines[0], Is.SameAs(profiledEngine));
}
[Test]
public void WrapViewEngines_CollectionIsNull_DoesNotThrow()
{
IList<IViewEngine> engines = null;
Assert.DoesNotThrow(() => WebBootManager.WrapViewEngines(engines));
Assert.That(engines, Is.Null);
}
}
}

View File

@@ -78,6 +78,9 @@
<Private>True</Private> <Private>True</Private>
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath> <HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference> </Reference>
<Reference Include="Microsoft.Web.Mvc.FixedDisplayModes">
<HintPath>..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.1\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll</HintPath>
</Reference>
<Reference Include="Moq"> <Reference Include="Moq">
<HintPath>..\packages\Moq.4.1.1309.0919\lib\net40\Moq.dll</HintPath> <HintPath>..\packages\Moq.4.1.1309.0919\lib\net40\Moq.dll</HintPath>
</Reference> </Reference>
@@ -135,17 +138,17 @@
<Private>True</Private> <Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll</HintPath> <HintPath>..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="System.Web.Razor">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll</HintPath> <HintPath>..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private> <Private>True</Private>
</Reference>
<Reference Include="System.Web.WebPages">
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.dll</HintPath> <HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private> <Private>True</Private>
</Reference>
<Reference Include="System.Web.WebPages.Deployment">
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Deployment.dll</HintPath> <HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Deployment.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private> <Private>True</Private>
@@ -171,6 +174,7 @@
<Compile Include="Mvc\UmbracoViewPageTests.cs" /> <Compile Include="Mvc\UmbracoViewPageTests.cs" />
<Compile Include="Persistence\Auditing\AuditTests.cs" /> <Compile Include="Persistence\Auditing\AuditTests.cs" />
<Compile Include="BootManagers\CoreBootManagerTests.cs" /> <Compile Include="BootManagers\CoreBootManagerTests.cs" />
<Compile Include="BootManagers\WebBootManagerTests.cs" />
<Compile Include="BusinessLogic\DictionaryTest.cs" /> <Compile Include="BusinessLogic\DictionaryTest.cs" />
<Compile Include="Cache\ObjectCacheProviderTests.cs" /> <Compile Include="Cache\ObjectCacheProviderTests.cs" />
<Compile Include="Cache\CacheProviderTests.cs" /> <Compile Include="Cache\CacheProviderTests.cs" />

View File

@@ -0,0 +1,55 @@
<?xml version="1.0"?>
<configuration>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="Umbraco.Web" />
<add namespace="Umbraco.Core" />
<add namespace="Umbraco.Core.Models" />
<add namespace="Umbraco.Web.Mvc" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>

View File

@@ -6,6 +6,7 @@
<package id="log4net-mediumtrust" version="2.0.0" targetFramework="net40" /> <package id="log4net-mediumtrust" version="2.0.0" targetFramework="net40" />
<package id="Lucene.Net" version="2.9.4.1" targetFramework="net40" /> <package id="Lucene.Net" version="2.9.4.1" targetFramework="net40" />
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net40" /> <package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.1" targetFramework="net40" />
<package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net40" /> <package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi" version="4.0.30506.0" targetFramework="net40" /> <package id="Microsoft.AspNet.WebApi" version="4.0.30506.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.30506.0" targetFramework="net40" /> <package id="Microsoft.AspNet.WebApi.Client" version="4.0.30506.0" targetFramework="net40" />

View File

@@ -12,7 +12,7 @@ namespace Umbraco.Web
/// <summary> /// <summary>
/// Extension methods for the cache helper /// Extension methods for the cache helper
/// </summary> /// </summary>
internal static class CacheHelperExtensions public static class CacheHelperExtensions
{ {
public const string PartialViewCacheKey = "Umbraco.Web.PartialViewCacheKey"; public const string PartialViewCacheKey = "Umbraco.Web.PartialViewCacheKey";
@@ -54,4 +54,4 @@ namespace Umbraco.Web
cacheHelper.ClearCacheByKeySearch(PartialViewCacheKey); cacheHelper.ClearCacheByKeySearch(PartialViewCacheKey);
} }
} }
} }

View File

@@ -83,7 +83,8 @@ namespace Umbraco.Web
int cachedSeconds, int cachedSeconds,
bool cacheByPage = false, bool cacheByPage = false,
bool cacheByMember = false, bool cacheByMember = false,
ViewDataDictionary viewData = null) ViewDataDictionary viewData = null,
Func<object, ViewDataDictionary, string> contextualKeyBuilder = null)
{ {
var cacheKey = new StringBuilder(partialViewName); var cacheKey = new StringBuilder(partialViewName);
if (cacheByPage) if (cacheByPage)
@@ -98,7 +99,12 @@ namespace Umbraco.Web
{ {
var currentMember = Member.GetCurrentMember(); var currentMember = Member.GetCurrentMember();
cacheKey.AppendFormat("m{0}-", currentMember == null ? 0 : currentMember.Id); cacheKey.AppendFormat("m{0}-", currentMember == null ? 0 : currentMember.Id);
} }
if (contextualKeyBuilder != null)
{
var contextualKey = contextualKeyBuilder(model, viewData);
cacheKey.AppendFormat("c{0}-", contextualKey);
}
return ApplicationContext.Current.ApplicationCache.CachedPartialView(htmlHelper, partialViewName, model, cachedSeconds, cacheKey.ToString(), viewData); return ApplicationContext.Current.ApplicationCache.CachedPartialView(htmlHelper, partialViewName, model, cachedSeconds, cacheKey.ToString(), viewData);
} }
@@ -814,4 +820,4 @@ namespace Umbraco.Web
#endregion #endregion
} }
} }

View File

@@ -140,13 +140,7 @@ namespace Umbraco.Web
public override IBootManager Complete(Action<ApplicationContext> afterComplete) public override IBootManager Complete(Action<ApplicationContext> afterComplete)
{ {
//Wrap viewengines in the profiling engine //Wrap viewengines in the profiling engine
IViewEngine[] engines = ViewEngines.Engines.Select(e => e).ToArray(); WrapViewEngines(ViewEngines.Engines);
ViewEngines.Engines.Clear();
foreach (var engine in engines)
{
var wrappedEngine = engine is ProfilingViewEngine ? engine : new ProfilingViewEngine(engine);
ViewEngines.Engines.Add(wrappedEngine);
}
//set routes //set routes
CreateRoutes(); CreateRoutes();
@@ -159,7 +153,20 @@ namespace Umbraco.Web
return this; return this;
} }
/// <summary> internal static void WrapViewEngines(IList<IViewEngine> viewEngines)
{
if (viewEngines == null || viewEngines.Count == 0) return;
var originalEngines = viewEngines.Select(e => e).ToArray();
viewEngines.Clear();
foreach (var engine in originalEngines)
{
var wrappedEngine = engine is ProfilingViewEngine ? engine : new ProfilingViewEngine(engine);
viewEngines.Add(wrappedEngine);
}
}
/// <summary>
/// Creates the application cache based on the HttpRuntime cache /// Creates the application cache based on the HttpRuntime cache
/// </summary> /// </summary>
protected override void CreateApplicationCache() protected override void CreateApplicationCache()

View File

@@ -151,8 +151,7 @@ namespace umbraco.cms.businesslogic.web
() => () =>
{ {
var result = new List<Domain>(); var result = new List<Domain>();
using (var dr = SqlHelper.ExecuteReader( using (var dr = SqlHelper.ExecuteReader("SELECT id, domainName FROM umbracoDomains ORDER BY id"))
"select id, domainName from umbracoDomains"))
{ {
while (dr.Read()) while (dr.Read())
{ {