Merge branch 'dev-v7' into 7.4.0
This commit is contained in:
@@ -682,14 +682,16 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
public RenderingEngine DetermineTemplateRenderingEngine(ITemplate template)
|
||||
{
|
||||
var engine = _templateConfig.DefaultRenderingEngine;
|
||||
|
||||
if (template.Content.IsNullOrWhiteSpace() == false && MasterPageHelper.IsMasterPageSyntax(template.Content))
|
||||
var viewHelper = new ViewHelper(_viewsFileSystem);
|
||||
if (!viewHelper.ViewExists(template))
|
||||
{
|
||||
//there is a design but its definitely a webforms design
|
||||
return RenderingEngine.WebForms;
|
||||
if (template.Content.IsNullOrWhiteSpace() == false && MasterPageHelper.IsMasterPageSyntax(template.Content))
|
||||
{
|
||||
//there is a design but its definitely a webforms design and we haven't got a MVC view already for it
|
||||
return RenderingEngine.WebForms;
|
||||
}
|
||||
}
|
||||
|
||||
var viewHelper = new ViewHelper(_viewsFileSystem);
|
||||
var masterPageHelper = new MasterPageHelper(_masterpagesFileSystem);
|
||||
|
||||
switch (engine)
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace Umbraco.Core.Persistence
|
||||
|
||||
public override void OnException(Exception x)
|
||||
{
|
||||
_logger.Info<UmbracoDatabase>(x.StackTrace);
|
||||
_logger.Error<UmbracoDatabase>("Database exception occurred", x);
|
||||
base.OnException(x);
|
||||
}
|
||||
|
||||
|
||||
51
src/Umbraco.Core/ThreadExtensions.cs
Normal file
51
src/Umbraco.Core/ThreadExtensions.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
static class ThreadExtensions
|
||||
{
|
||||
public static void SanitizeThreadCulture(this Thread thread)
|
||||
{
|
||||
// get the current culture
|
||||
var currentCulture = CultureInfo.CurrentCulture;
|
||||
|
||||
// at the top of any culture should be the invariant culture - find it
|
||||
// doing an .Equals comparison ensure that we *will* find it and not loop
|
||||
// endlessly
|
||||
var invariantCulture = currentCulture;
|
||||
while (invariantCulture.Equals(CultureInfo.InvariantCulture) == false)
|
||||
invariantCulture = invariantCulture.Parent;
|
||||
|
||||
// now that invariant culture should be the same object as CultureInfo.InvariantCulture
|
||||
// yet for some reasons, sometimes it is not - and this breaks anything that loops on
|
||||
// culture.Parent until a reference equality to CultureInfo.InvariantCulture. See, for
|
||||
// example, the following code in PerformanceCounterLib.IsCustomCategory:
|
||||
//
|
||||
// CultureInfo culture = CultureInfo.CurrentCulture;
|
||||
// while (culture != CultureInfo.InvariantCulture)
|
||||
// {
|
||||
// library = GetPerformanceCounterLib(machine, culture);
|
||||
// if (library.IsCustomCategory(category))
|
||||
// return true;
|
||||
// culture = culture.Parent;
|
||||
// }
|
||||
//
|
||||
// The reference comparisons never succeeds, hence the loop never ends, and the
|
||||
// application hangs.
|
||||
//
|
||||
// granted, that comparison should probably be a .Equals comparison, but who knows
|
||||
// how many times the framework assumes that it can do a reference comparison? So,
|
||||
// better fix the cultures.
|
||||
|
||||
if (ReferenceEquals(invariantCulture, CultureInfo.InvariantCulture))
|
||||
return;
|
||||
|
||||
// if we do not have equality, fix cultures by replacing them with a culture with
|
||||
// the same name, but obtained here and now, with a proper invariant top culture
|
||||
|
||||
thread.CurrentCulture = CultureInfo.GetCultureInfo(thread.CurrentCulture.Name);
|
||||
thread.CurrentUICulture = CultureInfo.GetCultureInfo(thread.CurrentUICulture.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1290,6 +1290,7 @@
|
||||
<Compile Include="Sync\ApplicationUrlHelper.cs" />
|
||||
<Compile Include="Sync\RefreshMethodType.cs" />
|
||||
<Compile Include="Sync\ServerMessengerBase.cs" />
|
||||
<Compile Include="ThreadExtensions.cs" />
|
||||
<Compile Include="TopologicalSorter.cs" />
|
||||
<Compile Include="Strings\DefaultUrlSegmentProvider.cs" />
|
||||
<Compile Include="Strings\IUrlSegmentProvider.cs" />
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using log4net;
|
||||
@@ -64,6 +65,7 @@ namespace Umbraco.Core
|
||||
/// <param name="e"></param>
|
||||
protected void Application_Start(object sender, EventArgs e)
|
||||
{
|
||||
Thread.CurrentThread.SanitizeThreadCulture();
|
||||
StartApplication(sender, e);
|
||||
}
|
||||
|
||||
|
||||
109
src/Umbraco.Tests/Templates/TemplateRepositoryTests.cs
Normal file
109
src/Umbraco.Tests/Templates/TemplateRepositoryTests.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Tests.Templates
|
||||
{
|
||||
[TestFixture]
|
||||
public class TemplateRepositoryTests
|
||||
{
|
||||
private readonly Mock<IDatabaseUnitOfWork> _unitOfWorkMock = new Mock<IDatabaseUnitOfWork>();
|
||||
private readonly Mock<CacheHelper> _cacheMock = new Mock<CacheHelper>();
|
||||
private TemplateRepository _templateRepository;
|
||||
private readonly Mock<IFileSystem> _viewFileSystemMock = new Mock<IFileSystem>();
|
||||
private readonly Mock<IFileSystem> _masterpageFileSystemMock = new Mock<IFileSystem>();
|
||||
private readonly Mock<ITemplatesSection> _templateConfigMock = new Mock<Core.Configuration.UmbracoSettings.ITemplatesSection>();
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var loggerMock = new Mock<ILogger>();
|
||||
var sqlSyntaxMock = new Mock<ISqlSyntaxProvider>();
|
||||
_templateRepository = new TemplateRepository(_unitOfWorkMock.Object, _cacheMock.Object, loggerMock.Object, sqlSyntaxMock.Object, _masterpageFileSystemMock.Object, _viewFileSystemMock.Object, _templateConfigMock.Object);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DetermineTemplateRenderingEngine_Returns_MVC_When_ViewFile_Exists_And_Content_Has_Webform_Markup()
|
||||
{
|
||||
// Project in MVC mode
|
||||
_templateConfigMock.Setup(x => x.DefaultRenderingEngine).Returns(RenderingEngine.Mvc);
|
||||
|
||||
// Template has masterpage content
|
||||
var templateMock = new Mock<ITemplate>();
|
||||
templateMock.Setup(x => x.Alias).Returns("Something");
|
||||
templateMock.Setup(x => x.Content).Returns("<asp:Content />");
|
||||
|
||||
// but MVC View already exists
|
||||
_viewFileSystemMock.Setup(x => x.FileExists(It.IsAny<string>())).Returns(true);
|
||||
|
||||
var res = _templateRepository.DetermineTemplateRenderingEngine(templateMock.Object);
|
||||
Assert.AreEqual(RenderingEngine.Mvc, res);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DetermineTemplateRenderingEngine_Returns_WebForms_When_ViewFile_Doesnt_Exist_And_Content_Has_Webform_Markup()
|
||||
{
|
||||
// Project in MVC mode
|
||||
_templateConfigMock.Setup(x => x.DefaultRenderingEngine).Returns(RenderingEngine.Mvc);
|
||||
|
||||
// Template has masterpage content
|
||||
var templateMock = new Mock<ITemplate>();
|
||||
templateMock.Setup(x => x.Alias).Returns("Something");
|
||||
templateMock.Setup(x => x.Content).Returns("<asp:Content />");
|
||||
|
||||
// MVC View doesn't exist
|
||||
_viewFileSystemMock.Setup(x => x.FileExists(It.IsAny<string>())).Returns(false);
|
||||
|
||||
var res = _templateRepository.DetermineTemplateRenderingEngine(templateMock.Object);
|
||||
Assert.AreEqual(RenderingEngine.WebForms, res);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DetermineTemplateRenderingEngine_Returns_WebForms_When_MasterPage_Exists_And_In_Mvc_Mode()
|
||||
{
|
||||
// Project in MVC mode
|
||||
_templateConfigMock.Setup(x => x.DefaultRenderingEngine).Returns(RenderingEngine.Mvc);
|
||||
|
||||
var templateMock = new Mock<ITemplate>();
|
||||
templateMock.Setup(x => x.Alias).Returns("Something");
|
||||
|
||||
// but masterpage already exists
|
||||
_viewFileSystemMock.Setup(x => x.FileExists(It.IsAny<string>())).Returns(false);
|
||||
_masterpageFileSystemMock.Setup(x => x.FileExists(It.IsAny<string>())).Returns(true);
|
||||
|
||||
var res = _templateRepository.DetermineTemplateRenderingEngine(templateMock.Object);
|
||||
Assert.AreEqual(RenderingEngine.WebForms, res);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DetermineTemplateRenderingEngine_Returns_Mvc_When_ViewPage_Exists_And_In_Webforms_Mode()
|
||||
{
|
||||
// Project in WebForms mode
|
||||
_templateConfigMock.Setup(x => x.DefaultRenderingEngine).Returns(RenderingEngine.WebForms);
|
||||
|
||||
var templateMock = new Mock<ITemplate>();
|
||||
templateMock.Setup(x => x.Alias).Returns("Something");
|
||||
|
||||
// but MVC View already exists
|
||||
_viewFileSystemMock.Setup(x => x.FileExists(It.IsAny<string>())).Returns(true);
|
||||
_masterpageFileSystemMock.Setup(x => x.FileExists(It.IsAny<string>())).Returns(false);
|
||||
|
||||
var res = _templateRepository.DetermineTemplateRenderingEngine(templateMock.Object);
|
||||
Assert.AreEqual(RenderingEngine.Mvc, res);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -362,6 +362,7 @@
|
||||
<Compile Include="Services\MacroServiceTests.cs" />
|
||||
<Compile Include="Services\UserServiceTests.cs" />
|
||||
<Compile Include="Manifest\ManifestParserTests.cs" />
|
||||
<Compile Include="Templates\TemplateRepositoryTests.cs" />
|
||||
<Compile Include="TestHelpers\BaseSeleniumTest.cs" />
|
||||
<Compile Include="Integration\InstallPackage.cs" />
|
||||
<Compile Include="CoreXml\NavigableNavigatorTests.cs" />
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace Umbraco.Web.Scheduling
|
||||
|
||||
try
|
||||
{
|
||||
var result = await wc.SendAsync(request, token);
|
||||
var result = await wc.SendAsync(request, token).ConfigureAwait(false); // ConfigureAwait(false) is recommended? http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html
|
||||
return result.StatusCode == HttpStatusCode.OK;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -195,46 +195,7 @@ namespace Umbraco.Web.Security.Identity
|
||||
|
||||
public static void SanitizeThreadCulture(this IAppBuilder app)
|
||||
{
|
||||
// get the current culture
|
||||
var currentCulture = CultureInfo.CurrentCulture;
|
||||
|
||||
// at the top of any culture should be the invariant culture - find it
|
||||
// doing an .Equals comparison ensure that we *will* find it and not loop
|
||||
// endlessly
|
||||
var invariantCulture = currentCulture;
|
||||
while (invariantCulture.Equals(CultureInfo.InvariantCulture) == false)
|
||||
invariantCulture = invariantCulture.Parent;
|
||||
|
||||
// now that invariant culture should be the same object as CultureInfo.InvariantCulture
|
||||
// yet for some reasons, sometimes it is not - and this breaks anything that loops on
|
||||
// culture.Parent until a reference equality to CultureInfo.InvariantCulture. See, for
|
||||
// example, the following code in PerformanceCounterLib.IsCustomCategory:
|
||||
//
|
||||
// CultureInfo culture = CultureInfo.CurrentCulture;
|
||||
// while (culture != CultureInfo.InvariantCulture)
|
||||
// {
|
||||
// library = GetPerformanceCounterLib(machine, culture);
|
||||
// if (library.IsCustomCategory(category))
|
||||
// return true;
|
||||
// culture = culture.Parent;
|
||||
// }
|
||||
//
|
||||
// The reference comparisons never succeeds, hence the loop never ends, and the
|
||||
// application hangs.
|
||||
//
|
||||
// granted, that comparison should probably be a .Equals comparison, but who knows
|
||||
// how many times the framework assumes that it can do a reference comparison? So,
|
||||
// better fix the cultures.
|
||||
|
||||
if (ReferenceEquals(invariantCulture, CultureInfo.InvariantCulture))
|
||||
return;
|
||||
|
||||
// if we do not have equality, fix cultures by replacing them with a culture with
|
||||
// the same name, but obtained here and now, with a proper invariant top culture
|
||||
|
||||
var thread = Thread.CurrentThread;
|
||||
thread.CurrentCulture = CultureInfo.GetCultureInfo(thread.CurrentCulture.Name);
|
||||
thread.CurrentUICulture = CultureInfo.GetCultureInfo(thread.CurrentUICulture.Name);
|
||||
Thread.CurrentThread.SanitizeThreadCulture();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user