Introduced a IHostingEnvironment and one implemtation for AspNetHostingEnvironment
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
namespace Umbraco.Core.Hosting
|
||||
{
|
||||
public interface IHostingEnvironment
|
||||
{
|
||||
string SiteName { get; }
|
||||
string ApplicationId { get; }
|
||||
string ApplicationPhysicalPath { get; }
|
||||
|
||||
string LocalTempPath { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Core.Configuration
|
||||
{
|
||||
|
||||
public static class GlobalSettingsExtensions
|
||||
{
|
||||
private static string _localTempPath;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the location of temporary files.
|
||||
/// </summary>
|
||||
public static string LocalTempPath(this IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
{
|
||||
|
||||
if (_localTempPath != null)
|
||||
return _localTempPath;
|
||||
|
||||
switch (globalSettings.LocalTempStorageLocation)
|
||||
{
|
||||
case LocalTempStorage.AspNetTemp:
|
||||
return _localTempPath = System.IO.Path.Combine(HttpRuntime.CodegenDir, "UmbracoData");
|
||||
|
||||
case LocalTempStorage.EnvironmentTemp:
|
||||
|
||||
// environment temp is unique, we need a folder per site
|
||||
|
||||
// use a hash
|
||||
// combine site name and application id
|
||||
// site name is a Guid on Cloud
|
||||
// application id is eg /LM/W3SVC/123456/ROOT
|
||||
// the combination is unique on one server
|
||||
// and, if a site moves from worker A to B and then back to A...
|
||||
// hopefully it gets a new Guid or new application id?
|
||||
|
||||
var siteName = HostingEnvironment.SiteName;
|
||||
var applicationId = HostingEnvironment.ApplicationID; // ie HttpRuntime.AppDomainAppId
|
||||
|
||||
var hashString = siteName + "::" + applicationId;
|
||||
var hash = hashString.GenerateHash();
|
||||
var siteTemp = System.IO.Path.Combine(Environment.ExpandEnvironmentVariables("%temp%"), "UmbracoData", hash);
|
||||
|
||||
return _localTempPath = siteTemp;
|
||||
|
||||
//case LocalTempStorage.Default:
|
||||
//case LocalTempStorage.Unknown:
|
||||
default:
|
||||
return _localTempPath = ioHelper.MapPath("~/App_Data/TEMP");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.IO;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
|
||||
namespace Umbraco.Core.IO
|
||||
{
|
||||
@@ -9,9 +10,9 @@ namespace Umbraco.Core.IO
|
||||
public static string TinyMceConfig => Constants.SystemDirectories.Config + "/tinyMceConfig.config";
|
||||
|
||||
// TODO: Kill this off we don't have umbraco.config XML cache we now have NuCache
|
||||
public static string GetContentCacheXml(IGlobalSettings globalSettings)
|
||||
public static string GetContentCacheXml(IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
return Path.Combine(globalSettings.LocalTempPath(Current.IOHelper), "umbraco.config");
|
||||
return Path.Combine(hostingEnvironment.LocalTempPath, "umbraco.config");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Web.Hosting;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Core
|
||||
@@ -46,14 +47,14 @@ namespace Umbraco.Core
|
||||
#region Ctor
|
||||
|
||||
// initializes a new instance of MainDom
|
||||
public MainDom(ILogger logger)
|
||||
public MainDom(ILogger logger, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
var appId = string.Empty;
|
||||
// HostingEnvironment.ApplicationID is null in unit tests, making ReplaceNonAlphanumericChars fail
|
||||
if (HostingEnvironment.ApplicationID != null)
|
||||
appId = HostingEnvironment.ApplicationID.ReplaceNonAlphanumericChars(string.Empty);
|
||||
if (hostingEnvironment.ApplicationId != null)
|
||||
appId = hostingEnvironment.ApplicationId.ReplaceNonAlphanumericChars(string.Empty);
|
||||
|
||||
// combining with the physical path because if running on eg IIS Express,
|
||||
// two sites could have the same appId even though they are different.
|
||||
@@ -64,7 +65,7 @@ namespace Umbraco.Core
|
||||
// we *cannot* use the process ID here because when an AppPool restarts it is
|
||||
// a new process for the same application path
|
||||
|
||||
var appPath = HostingEnvironment.ApplicationPhysicalPath;
|
||||
var appPath = hostingEnvironment.ApplicationPhysicalPath;
|
||||
var hash = (appId + ":::" + appPath).GenerateHash<SHA1>();
|
||||
|
||||
var lockName = "UMBRACO-" + hash + "-MAINDOM-LCK";
|
||||
|
||||
@@ -4,6 +4,7 @@ using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Composing.CompositionExtensions;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Manifest;
|
||||
@@ -102,9 +103,10 @@ namespace Umbraco.Core.Runtime
|
||||
factory.GetInstance<IScopeProvider>(),
|
||||
factory.GetInstance<ISqlContext>(),
|
||||
factory.GetInstance<IProfilingLogger>(),
|
||||
factory.GetInstance<IGlobalSettings>(),
|
||||
true, new DatabaseServerMessengerOptions(),
|
||||
factory.GetInstance<IIOHelper>()));
|
||||
factory.GetInstance<IIOHelper>(),
|
||||
factory.GetInstance<IHostingEnvironment>()
|
||||
));
|
||||
|
||||
composition.WithCollectionBuilder<CacheRefresherCollectionBuilder>()
|
||||
.Add(() => composition.TypeLoader.GetCacheRefreshers());
|
||||
|
||||
@@ -6,6 +6,7 @@ using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
@@ -27,12 +28,13 @@ namespace Umbraco.Core.Runtime
|
||||
private readonly IUmbracoBootPermissionChecker _umbracoBootPermissionChecker;
|
||||
|
||||
|
||||
public CoreRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IUmbracoBootPermissionChecker umbracoBootPermissionChecker)
|
||||
public CoreRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IUmbracoBootPermissionChecker umbracoBootPermissionChecker, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
IOHelper = ioHelper;
|
||||
Configs = configs;
|
||||
UmbracoVersion = umbracoVersion ;
|
||||
Profiler = profiler;
|
||||
HostingEnvironment = hostingEnvironment;
|
||||
|
||||
_umbracoBootPermissionChecker = umbracoBootPermissionChecker;
|
||||
|
||||
@@ -74,6 +76,7 @@ namespace Umbraco.Core.Runtime
|
||||
/// Gets the <see cref="IIOHelper"/>
|
||||
/// </summary>
|
||||
protected IIOHelper IOHelper { get; }
|
||||
protected IHostingEnvironment HostingEnvironment { get; }
|
||||
protected Configs Configs { get; }
|
||||
protected IUmbracoVersion UmbracoVersion { get; }
|
||||
|
||||
@@ -142,10 +145,10 @@ namespace Umbraco.Core.Runtime
|
||||
var databaseFactory = GetDatabaseFactory();
|
||||
|
||||
// type finder/loader
|
||||
var typeLoader = new TypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, new DirectoryInfo(Configs.Global().LocalTempPath(IOHelper)), ProfilingLogger);
|
||||
var typeLoader = new TypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, new DirectoryInfo(HostingEnvironment.LocalTempPath), ProfilingLogger);
|
||||
|
||||
// main dom
|
||||
var mainDom = new MainDom(Logger);
|
||||
var mainDom = new MainDom(Logger, HostingEnvironment);
|
||||
|
||||
// create the composition
|
||||
composition = new Composition(register, typeLoader, ProfilingLogger, _state, Configs);
|
||||
|
||||
@@ -16,6 +16,7 @@ using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Scoping;
|
||||
|
||||
namespace Umbraco.Core.Sync
|
||||
@@ -35,6 +36,7 @@ namespace Umbraco.Core.Sync
|
||||
private readonly object _locko = new object();
|
||||
private readonly IProfilingLogger _profilingLogger;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly ISqlContext _sqlContext;
|
||||
private readonly Lazy<string> _distCacheFilePath;
|
||||
private int _lastId = -1;
|
||||
@@ -47,8 +49,8 @@ namespace Umbraco.Core.Sync
|
||||
public DatabaseServerMessengerOptions Options { get; }
|
||||
|
||||
public DatabaseServerMessenger(
|
||||
IRuntimeState runtime, IScopeProvider scopeProvider, ISqlContext sqlContext, IProfilingLogger proflog, IGlobalSettings globalSettings,
|
||||
bool distributedEnabled, DatabaseServerMessengerOptions options, IIOHelper ioHelper)
|
||||
IRuntimeState runtime, IScopeProvider scopeProvider, ISqlContext sqlContext, IProfilingLogger proflog,
|
||||
bool distributedEnabled, DatabaseServerMessengerOptions options, IIOHelper ioHelper, IHostingEnvironment hostingEnvironment)
|
||||
: base(distributedEnabled)
|
||||
{
|
||||
ScopeProvider = scopeProvider ?? throw new ArgumentNullException(nameof(scopeProvider));
|
||||
@@ -56,11 +58,12 @@ namespace Umbraco.Core.Sync
|
||||
_runtime = runtime;
|
||||
_profilingLogger = proflog ?? throw new ArgumentNullException(nameof(proflog));
|
||||
_ioHelper = ioHelper;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
Logger = proflog;
|
||||
Options = options ?? throw new ArgumentNullException(nameof(options));
|
||||
_lastPruned = _lastSync = DateTime.UtcNow;
|
||||
_syncIdle = new ManualResetEvent(true);
|
||||
_distCacheFilePath = new Lazy<string>(() => GetDistCacheFilePath(globalSettings));
|
||||
_distCacheFilePath = new Lazy<string>(() => GetDistCacheFilePath(hostingEnvironment));
|
||||
}
|
||||
|
||||
protected ILogger Logger { get; }
|
||||
@@ -532,11 +535,11 @@ namespace Umbraco.Core.Sync
|
||||
+ "/D" + AppDomain.CurrentDomain.Id // eg 22
|
||||
+ "] " + Guid.NewGuid().ToString("N").ToUpper(); // make it truly unique
|
||||
|
||||
private string GetDistCacheFilePath(IGlobalSettings globalSettings)
|
||||
private string GetDistCacheFilePath(IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
var fileName = HttpRuntime.AppDomainAppId.ReplaceNonAlphanumericChars(string.Empty) + "-lastsynced.txt";
|
||||
|
||||
var distCacheFilePath = Path.Combine(globalSettings.LocalTempPath(_ioHelper), "DistCache", fileName);
|
||||
var distCacheFilePath = Path.Combine(hostingEnvironment.LocalTempPath, "DistCache", fileName);
|
||||
|
||||
//ensure the folder exists
|
||||
var folder = Path.GetDirectoryName(distCacheFilePath);
|
||||
|
||||
@@ -149,7 +149,6 @@
|
||||
<Compile Include="Composing\CompositionExtensions\Services.cs" />
|
||||
<Compile Include="CompositionExtensions_Essentials.cs" />
|
||||
<Compile Include="CompositionExtensions_FileSystems.cs" />
|
||||
<Compile Include="Configuration\GlobalSettingsExtensions.cs" />
|
||||
<Compile Include="ConventionsHelper.cs" />
|
||||
<Compile Include="Deploy\IGridCellValueConnector.cs" />
|
||||
<Compile Include="Events\ContentPublishedEventArgs.cs" />
|
||||
|
||||
@@ -7,6 +7,7 @@ using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.LegacyXmlPublishedCache;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
@@ -64,7 +65,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
|
||||
_xml = new XmlDocument();
|
||||
_xml.LoadXml(GetXml());
|
||||
var xmlStore = new XmlStore(() => _xml, null, null, null);
|
||||
var xmlStore = new XmlStore(() => _xml, null, null, null, HostingEnvironment);
|
||||
var appCache = new DictionaryAppCache();
|
||||
var domainCache = new DomainCache(ServiceContext.DomainService, DefaultCultureAccessor);
|
||||
var publishedShapshot = new PublishedSnapshot(
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
var mChild2 = MakeNewMedia("Child2", mType, user, mRoot2.Id);
|
||||
|
||||
var ctx = GetUmbracoContext("/test");
|
||||
var cache = new PublishedMediaCache(new XmlStore((XmlDocument) null, null, null, null), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
var cache = new PublishedMediaCache(new XmlStore((XmlDocument) null, null, null, null, HostingEnvironment), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
var roots = cache.GetAtRoot();
|
||||
Assert.AreEqual(2, roots.Count());
|
||||
Assert.IsTrue(roots.Select(x => x.Id).ContainsAll(new[] {mRoot1.Id, mRoot2.Id}));
|
||||
@@ -97,7 +97,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
|
||||
//var publishedMedia = PublishedMediaTests.GetNode(mRoot.Id, GetUmbracoContext("/test", 1234));
|
||||
var umbracoContext = GetUmbracoContext("/test");
|
||||
var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null), Current.Services.MediaService, Current.Services.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null, HostingEnvironment), Current.Services.MediaService, Current.Services.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
var publishedMedia = cache.GetById(mRoot.Id);
|
||||
Assert.IsNotNull(publishedMedia);
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
|
||||
var result = new SearchResult("1234", 1, () => fields.ToDictionary(x => x.Key, x => new List<string> { x.Value }));
|
||||
|
||||
var store = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
var store = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null, HostingEnvironment), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
var doc = store.CreateFromCacheValues(store.ConvertFromSearchResult(result));
|
||||
|
||||
DoAssert(doc, 1234, key, null, 0, "/media/test.jpg", "Image", 23, "Shannon", "Shannon", 0, 0, "-1,1234", DateTime.Parse("2012-07-17T10:34:09"), DateTime.Parse("2012-07-16T10:34:09"), 2);
|
||||
@@ -224,7 +224,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
var xmlDoc = GetMediaXml();
|
||||
((XmlElement)xmlDoc.DocumentElement.FirstChild).SetAttribute("key", key.ToString());
|
||||
var navigator = xmlDoc.SelectSingleNode("/root/Image").CreateNavigator();
|
||||
var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null, HostingEnvironment), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
var doc = cache.CreateFromCacheValues(cache.ConvertFromXPathNavigator(navigator, true));
|
||||
|
||||
DoAssert(doc, 2000, key, null, 2, "image1", "Image", 23, "Shannon", "Shannon", 33, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1);
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -37,6 +38,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
private readonly ISiteDomainHelper _siteDomainHelper;
|
||||
private readonly IEntityXmlSerializer _entitySerializer;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
#region Constructors
|
||||
|
||||
@@ -51,6 +53,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
IDefaultCultureAccessor defaultCultureAccessor,
|
||||
ILogger logger,
|
||||
IGlobalSettings globalSettings,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
ISiteDomainHelper siteDomainHelper,
|
||||
IEntityXmlSerializer entitySerializer,
|
||||
MainDom mainDom,
|
||||
@@ -59,7 +62,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor,
|
||||
documentRepository, mediaRepository, memberRepository,
|
||||
defaultCultureAccessor,
|
||||
logger, globalSettings, siteDomainHelper, entitySerializer, null, mainDom, testing, enableRepositoryEvents)
|
||||
logger, globalSettings, hostingEnvironment, siteDomainHelper, entitySerializer, null, mainDom, testing, enableRepositoryEvents)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
}
|
||||
@@ -75,6 +78,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
IDefaultCultureAccessor defaultCultureAccessor,
|
||||
ILogger logger,
|
||||
IGlobalSettings globalSettings,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
ISiteDomainHelper siteDomainHelper,
|
||||
IEntityXmlSerializer entitySerializer,
|
||||
PublishedContentTypeCache contentTypeCache,
|
||||
@@ -89,7 +93,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
|
||||
_xmlStore = new XmlStore(serviceContext.ContentTypeService, serviceContext.ContentService, scopeProvider, _routesCache,
|
||||
_contentTypeCache, publishedSnapshotAccessor, mainDom, testing, enableRepositoryEvents,
|
||||
documentRepository, mediaRepository, memberRepository, globalSettings, entitySerializer);
|
||||
documentRepository, mediaRepository, memberRepository, globalSettings, entitySerializer, hostingEnvironment);
|
||||
|
||||
_domainService = serviceContext.DomainService;
|
||||
_memberService = serviceContext.MemberService;
|
||||
@@ -102,6 +106,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
_globalSettings = globalSettings;
|
||||
_siteDomainHelper = siteDomainHelper;
|
||||
_entitySerializer = entitySerializer;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
@@ -126,7 +131,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
}
|
||||
catch
|
||||
{
|
||||
errors = new[] { SystemFiles.GetContentCacheXml(_globalSettings) };
|
||||
errors = new[] { SystemFiles.GetContentCacheXml(_hostingEnvironment) };
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Xml;
|
||||
using NPoco;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -43,6 +44,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
private readonly IMemberRepository _memberRepository;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IEntityXmlSerializer _entitySerializer;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private XmlStoreFilePersister _persisterTask;
|
||||
private volatile bool _released;
|
||||
private bool _withRepositoryEvents;
|
||||
@@ -61,8 +63,8 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
/// </summary>
|
||||
/// <remarks>The default constructor will boot the cache, load data from file or database, /// wire events in order to manage changes, etc.</remarks>
|
||||
public XmlStore(IContentTypeService contentTypeService, IContentService contentService, IScopeProvider scopeProvider, RoutesCache routesCache, PublishedContentTypeCache contentTypeCache,
|
||||
IPublishedSnapshotAccessor publishedSnapshotAccessor, MainDom mainDom, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IGlobalSettings globalSettings, IEntityXmlSerializer entitySerializer)
|
||||
: this(contentTypeService, contentService, scopeProvider, routesCache, contentTypeCache, publishedSnapshotAccessor, mainDom, false, false, documentRepository, mediaRepository, memberRepository, globalSettings, entitySerializer)
|
||||
IPublishedSnapshotAccessor publishedSnapshotAccessor, MainDom mainDom, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IGlobalSettings globalSettings, IEntityXmlSerializer entitySerializer, IHostingEnvironment hostingEnvironment)
|
||||
: this(contentTypeService, contentService, scopeProvider, routesCache, contentTypeCache, publishedSnapshotAccessor, mainDom, false, false, documentRepository, mediaRepository, memberRepository, globalSettings, entitySerializer, hostingEnvironment)
|
||||
{ }
|
||||
|
||||
// internal for unit tests
|
||||
@@ -70,7 +72,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
// TODO: er, we DO have a DB?
|
||||
internal XmlStore(IContentTypeService contentTypeService, IContentService contentService, IScopeProvider scopeProvider, RoutesCache routesCache, PublishedContentTypeCache contentTypeCache,
|
||||
IPublishedSnapshotAccessor publishedSnapshotAccessor, MainDom mainDom,
|
||||
bool testing, bool enableRepositoryEvents, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IGlobalSettings globalSettings, IEntityXmlSerializer entitySerializer)
|
||||
bool testing, bool enableRepositoryEvents, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IGlobalSettings globalSettings, IEntityXmlSerializer entitySerializer, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
if (testing == false)
|
||||
EnsureConfigurationIsValid();
|
||||
@@ -86,7 +88,9 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
_memberRepository = memberRepository;
|
||||
_globalSettings = globalSettings;
|
||||
_entitySerializer = entitySerializer;
|
||||
_xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(_globalSettings));
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
|
||||
_xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(_hostingEnvironment));
|
||||
|
||||
if (testing)
|
||||
{
|
||||
@@ -103,28 +107,28 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
// internal for unit tests
|
||||
// initialize with an xml document
|
||||
// no events, no file nor db, no config check
|
||||
internal XmlStore(XmlDocument xmlDocument, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository)
|
||||
internal XmlStore(XmlDocument xmlDocument, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_xmlDocument = xmlDocument;
|
||||
_documentRepository = documentRepository;
|
||||
_mediaRepository = mediaRepository;
|
||||
_memberRepository = memberRepository;
|
||||
_xmlFileEnabled = false;
|
||||
_xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(Current.Configs.Global()));
|
||||
_xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(hostingEnvironment));
|
||||
// do not plug events, we may not have what it takes to handle them
|
||||
}
|
||||
|
||||
// internal for unit tests
|
||||
// initialize with a function returning an xml document
|
||||
// no events, no file nor db, no config check
|
||||
internal XmlStore(Func<XmlDocument> getXmlDocument, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository)
|
||||
internal XmlStore(Func<XmlDocument> getXmlDocument, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_documentRepository = documentRepository;
|
||||
_mediaRepository = mediaRepository;
|
||||
_memberRepository = memberRepository;
|
||||
GetXmlDocument = getXmlDocument ?? throw new ArgumentNullException(nameof(getXmlDocument));
|
||||
_xmlFileEnabled = false;
|
||||
_xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(Current.Configs.Global()));
|
||||
_xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(hostingEnvironment));
|
||||
// do not plug events, we may not have what it takes to handle them
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -58,6 +59,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var configs = TestHelper.GetConfigs();
|
||||
Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs);
|
||||
var globalSettings = new GlobalSettings(IOHelper.Default);
|
||||
var hostingEnvironment = Mock.Of<IHostingEnvironment>();
|
||||
configs.Add(SettingsForTests.GenerateMockUmbracoSettings);
|
||||
configs.Add<IGlobalSettings>(() => globalSettings);
|
||||
|
||||
@@ -162,7 +164,8 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Mock.Of<IEntityXmlSerializer>(),
|
||||
Mock.Of<IPublishedModelFactory>(),
|
||||
new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider() }),
|
||||
typeFinder);
|
||||
typeFinder,
|
||||
hostingEnvironment);
|
||||
|
||||
// invariant is the current default
|
||||
_variationAccesor.VariationContext = new VariationContext();
|
||||
|
||||
@@ -205,7 +205,8 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Mock.Of<IEntityXmlSerializer>(),
|
||||
Mock.Of<IPublishedModelFactory>(),
|
||||
new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider() }),
|
||||
typeFinder);
|
||||
typeFinder,
|
||||
TestHelper.GetHostingEnvironment());
|
||||
|
||||
// invariant is the current default
|
||||
_variationAccesor.VariationContext = new VariationContext();
|
||||
|
||||
@@ -14,6 +14,7 @@ using Umbraco.Core.Composing;
|
||||
using Current = Umbraco.Core.Composing.Current;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -44,11 +45,11 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Composition.RegisterUnique<IPublishedModelFactory>(f => new PublishedModelFactory(f.GetInstance<TypeLoader>().GetTypes<PublishedContentModel>()));
|
||||
}
|
||||
|
||||
protected override TypeLoader CreateTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, IGlobalSettings globalSettings, IProfilingLogger logger)
|
||||
protected override TypeLoader CreateTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache,IProfilingLogger logger, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
var baseLoader = base.CreateTypeLoader(ioHelper, typeFinder, runtimeCache, globalSettings, logger);
|
||||
var baseLoader = base.CreateTypeLoader(ioHelper, typeFinder, runtimeCache, logger, hostingEnvironment);
|
||||
|
||||
return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(globalSettings.LocalTempPath(ioHelper)), logger, false,
|
||||
return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(hostingEnvironment.LocalTempPath), logger, false,
|
||||
// this is so the model factory looks into the test assembly
|
||||
baseLoader.AssembliesToScan
|
||||
.Union(new[] {typeof(PublishedContentMoreTests).Assembly})
|
||||
|
||||
@@ -15,6 +15,7 @@ using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -87,11 +88,11 @@ namespace Umbraco.Tests.PublishedContent
|
||||
}
|
||||
|
||||
|
||||
protected override TypeLoader CreateTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, IGlobalSettings globalSettings, IProfilingLogger logger)
|
||||
protected override TypeLoader CreateTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, IProfilingLogger logger, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
var baseLoader = base.CreateTypeLoader(ioHelper, typeFinder, runtimeCache, globalSettings, logger);
|
||||
var baseLoader = base.CreateTypeLoader(ioHelper, typeFinder, runtimeCache, logger, hostingEnvironment);
|
||||
|
||||
return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(globalSettings.LocalTempPath(ioHelper)), logger, false,
|
||||
return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(hostingEnvironment.LocalTempPath), logger, false,
|
||||
// this is so the model factory looks into the test assembly
|
||||
baseLoader.AssembliesToScan
|
||||
.Union(new[] { typeof(PublishedContentTests).Assembly })
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
/// <returns></returns>
|
||||
internal IPublishedContent GetNode(int id, UmbracoContext umbracoContext)
|
||||
{
|
||||
var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null),
|
||||
var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null, HostingEnvironment),
|
||||
ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache,
|
||||
Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
var doc = cache.GetById(id);
|
||||
@@ -485,7 +485,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
</Image>");
|
||||
var node = xml.DescendantsAndSelf("Image").Single(x => (int)x.Attribute("id") == nodeId);
|
||||
|
||||
var publishedMedia = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
var publishedMedia = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null, HostingEnvironment), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
|
||||
var nav = node.CreateNavigator();
|
||||
|
||||
@@ -505,7 +505,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var errorXml = new XElement("error", string.Format("No media is maching '{0}'", 1234));
|
||||
var nav = errorXml.CreateNavigator();
|
||||
|
||||
var publishedMedia = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
var publishedMedia = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null, HostingEnvironment), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance<IEntityXmlSerializer>(), Factory.GetInstance<IUmbracoContextAccessor>());
|
||||
var converted = publishedMedia.ConvertFromXPathNodeIterator(nav.Select("/"), 1234);
|
||||
|
||||
Assert.IsNull(converted);
|
||||
|
||||
@@ -19,6 +19,7 @@ using Umbraco.Core.Strings;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Persistence;
|
||||
@@ -50,8 +51,8 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
public class TestRuntime : WebRuntime
|
||||
{
|
||||
public TestRuntime(UmbracoApplicationBase umbracoApplication, Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger)
|
||||
: base(umbracoApplication, configs, umbracoVersion, ioHelper, Mock.Of<ILogger>(), Mock.Of<IProfiler>())
|
||||
public TestRuntime(UmbracoApplicationBase umbracoApplication, Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IHostingEnvironment hostingEnvironment)
|
||||
: base(umbracoApplication, configs, umbracoVersion, ioHelper, Mock.Of<ILogger>(), Mock.Of<IProfiler>(), hostingEnvironment)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
@@ -20,6 +21,7 @@ using Umbraco.Core.Scoping;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Hosting;
|
||||
using Umbraco.Web.Runtime;
|
||||
|
||||
namespace Umbraco.Tests.Runtimes
|
||||
@@ -81,7 +83,7 @@ namespace Umbraco.Tests.Runtimes
|
||||
// test application
|
||||
public class TestUmbracoApplication : UmbracoApplicationBase
|
||||
{
|
||||
public TestUmbracoApplication() : base(new DebugDiagnosticsLogger(new MessageTemplates()), GetConfigs(), IOHelper.Default, GetProfiler())
|
||||
public TestUmbracoApplication() : base(new DebugDiagnosticsLogger(new MessageTemplates()), GetConfigs(), IOHelper.Default, GetProfiler(), new AspNetHostingEnvironment(GetConfigs().Global(), IOHelper.Default))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -100,17 +102,17 @@ namespace Umbraco.Tests.Runtimes
|
||||
|
||||
public IRuntime Runtime { get; private set; }
|
||||
|
||||
protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler)
|
||||
protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
return Runtime = new TestRuntime(configs, umbracoVersion, ioHelper, logger, profiler);
|
||||
return Runtime = new TestRuntime(configs, umbracoVersion, ioHelper, logger, profiler, hostingEnvironment);
|
||||
}
|
||||
}
|
||||
|
||||
// test runtime
|
||||
public class TestRuntime : CoreRuntime
|
||||
{
|
||||
public TestRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler)
|
||||
:base(configs, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker())
|
||||
public TestRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment)
|
||||
:base(configs, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Migrations.Install;
|
||||
@@ -63,6 +64,7 @@ namespace Umbraco.Tests.Runtimes
|
||||
var databaseFactory = new UmbracoDatabaseFactory(logger, new Lazy<IMapperCollection>(() => factory.GetInstance<IMapperCollection>()), TestHelper.GetConfigs());
|
||||
var typeFinder = new TypeFinder(logger);
|
||||
var ioHelper = IOHelper.Default;
|
||||
var hostingEnvironment = Mock.Of<IHostingEnvironment>();
|
||||
var typeLoader = new TypeLoader(ioHelper, typeFinder, appCaches.RuntimeCache, new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), profilingLogger);
|
||||
var mainDom = new SimpleMainDom();
|
||||
var umbracoVersion = TestHelper.GetUmbracoVersion();
|
||||
@@ -75,7 +77,7 @@ namespace Umbraco.Tests.Runtimes
|
||||
composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion);
|
||||
|
||||
// create the core runtime and have it compose itself
|
||||
var coreRuntime = new CoreRuntime(configs, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker());coreRuntime.Compose(composition);
|
||||
var coreRuntime = new CoreRuntime(configs, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment);coreRuntime.Compose(composition);
|
||||
|
||||
// determine actual runtime level
|
||||
runtimeState.DetermineRuntimeLevel(databaseFactory, logger);
|
||||
@@ -256,6 +258,7 @@ namespace Umbraco.Tests.Runtimes
|
||||
var ioHelper = IOHelper.Default;
|
||||
var typeLoader = new TypeLoader(ioHelper, typeFinder, appCaches.RuntimeCache, new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), profilingLogger);
|
||||
var runtimeState = Mock.Of<IRuntimeState>();
|
||||
var hostingEnvironment = Mock.Of<IHostingEnvironment>();
|
||||
Mock.Get(runtimeState).Setup(x => x.Level).Returns(RuntimeLevel.Run);
|
||||
var mainDom = Mock.Of<IMainDom>();
|
||||
Mock.Get(mainDom).Setup(x => x.IsMainDom).Returns(true);
|
||||
@@ -268,7 +271,7 @@ namespace Umbraco.Tests.Runtimes
|
||||
composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion);
|
||||
|
||||
// create the core runtime and have it compose itself
|
||||
var coreRuntime = new CoreRuntime(configs, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker());
|
||||
var coreRuntime = new CoreRuntime(configs, umbracoVersion, ioHelper, logger, profiler, new AspNetUmbracoBootPermissionChecker(), hostingEnvironment);
|
||||
coreRuntime.Compose(composition);
|
||||
|
||||
// get the components
|
||||
|
||||
@@ -81,6 +81,7 @@ namespace Umbraco.Tests.Scoping
|
||||
var documentRepository = Mock.Of<IDocumentRepository>();
|
||||
var mediaRepository = Mock.Of<IMediaRepository>();
|
||||
var memberRepository = Mock.Of<IMemberRepository>();
|
||||
var hostingEnvironment = TestHelper.GetHostingEnvironment();
|
||||
|
||||
var typeFinder = new TypeFinder(Mock.Of<ILogger>());
|
||||
|
||||
@@ -102,7 +103,8 @@ namespace Umbraco.Tests.Scoping
|
||||
Factory.GetInstance<IEntityXmlSerializer>(),
|
||||
Mock.Of<IPublishedModelFactory>(),
|
||||
new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider() }),
|
||||
typeFinder);
|
||||
typeFinder,
|
||||
hostingEnvironment);
|
||||
}
|
||||
|
||||
protected UmbracoContext GetUmbracoContextNu(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable<IUrlProvider> urlProviders = null)
|
||||
|
||||
@@ -8,6 +8,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
@@ -49,10 +50,12 @@ namespace Umbraco.Tests.Services
|
||||
var runtimeStateMock = new Mock<IRuntimeState>();
|
||||
runtimeStateMock.Setup(x => x.Level).Returns(() => RuntimeLevel.Run);
|
||||
|
||||
var contentTypeFactory = Factory.GetInstance<IPublishedContentTypeFactory>();
|
||||
var contentTypeFactory = Factory.GetInstance<IPublishedContentTypeFactory>();
|
||||
var documentRepository = Factory.GetInstance<IDocumentRepository>();
|
||||
var mediaRepository = Mock.Of<IMediaRepository>();
|
||||
var memberRepository = Mock.Of<IMemberRepository>();
|
||||
var hostingEnvironment = Mock.Of<IHostingEnvironment>();
|
||||
|
||||
|
||||
var typeFinder = new TypeFinder(Mock.Of<ILogger>());
|
||||
|
||||
@@ -74,7 +77,8 @@ namespace Umbraco.Tests.Services
|
||||
Factory.GetInstance<IEntityXmlSerializer>(),
|
||||
Mock.Of<IPublishedModelFactory>(),
|
||||
new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider() }),
|
||||
typeFinder);
|
||||
typeFinder,
|
||||
hostingEnvironment);
|
||||
}
|
||||
|
||||
public class LocalServerMessenger : ServerMessengerBase
|
||||
@@ -127,8 +131,8 @@ namespace Umbraco.Tests.Services
|
||||
[TestCase(ContentVariation.CultureAndSegment, ContentVariation.CultureAndSegment, false)]
|
||||
public void Change_Content_Type_Variation_Clears_Redirects(ContentVariation startingContentTypeVariation, ContentVariation changedContentTypeVariation, bool shouldUrlRedirectsBeCleared)
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateBasicContentType();
|
||||
contentType.Variations = startingContentTypeVariation;
|
||||
var contentType = MockedContentTypes.CreateBasicContentType();
|
||||
contentType.Variations = startingContentTypeVariation;
|
||||
ServiceContext.ContentTypeService.Save(contentType);
|
||||
var contentType2 = MockedContentTypes.CreateBasicContentType("test");
|
||||
ServiceContext.ContentTypeService.Save(contentType2);
|
||||
@@ -407,7 +411,7 @@ namespace Umbraco.Tests.Services
|
||||
Assert.AreEqual("hello world", doc.GetValue("title"));
|
||||
Assert.IsTrue(doc.IsCultureEdited("en-US")); //invariant prop changes show up on default lang
|
||||
Assert.IsTrue(doc.Edited);
|
||||
|
||||
|
||||
//change the property type to be variant
|
||||
contentType.PropertyTypes.First().Variations = variant;
|
||||
ServiceContext.ContentTypeService.Save(contentType);
|
||||
@@ -435,7 +439,7 @@ namespace Umbraco.Tests.Services
|
||||
{
|
||||
//create content type with a property type that varies by culture
|
||||
var contentType = MockedContentTypes.CreateBasicContentType();
|
||||
// content type supports all variations
|
||||
// content type supports all variations
|
||||
contentType.Variations = ContentVariation.Culture | ContentVariation.Segment;
|
||||
var properties = CreatePropertyCollection(("title", variant));
|
||||
contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" });
|
||||
@@ -472,7 +476,7 @@ namespace Umbraco.Tests.Services
|
||||
{
|
||||
//create content type with a property type that varies by culture
|
||||
var contentType = MockedContentTypes.CreateBasicContentType();
|
||||
// content type supports all variations
|
||||
// content type supports all variations
|
||||
contentType.Variations = ContentVariation.Culture | ContentVariation.Segment;
|
||||
var properties = CreatePropertyCollection(("title", variant));
|
||||
contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" });
|
||||
@@ -879,14 +883,14 @@ namespace Umbraco.Tests.Services
|
||||
// switch property type to Invariant
|
||||
contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = invariant;
|
||||
ServiceContext.ContentTypeService.Save(contentType); //This is going to have to re-normalize the "Edited" flag
|
||||
|
||||
|
||||
document = ServiceContext.ContentService.GetById(document.Id);
|
||||
Assert.IsTrue(document.IsCultureEdited("en")); //This will remain true because there is now a pending change for the invariant property data which is flagged under the default lang
|
||||
Assert.IsFalse(document.IsCultureEdited("fr")); //This will be false because nothing has changed for this culture and the property no longer reflects variant changes
|
||||
Assert.IsTrue(document.Edited);
|
||||
|
||||
//update the invariant value and publish
|
||||
document.SetValue("value1", "v1inv");
|
||||
document.SetValue("value1", "v1inv");
|
||||
ServiceContext.ContentService.SaveAndPublish(document);
|
||||
|
||||
document = ServiceContext.ContentService.GetById(document.Id);
|
||||
@@ -906,7 +910,7 @@ namespace Umbraco.Tests.Services
|
||||
// switch property back to Culture
|
||||
contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = variant;
|
||||
ServiceContext.ContentTypeService.Save(contentType);
|
||||
|
||||
|
||||
document = ServiceContext.ContentService.GetById(document.Id);
|
||||
Assert.AreEqual("v1inv", document.GetValue("value1", "en")); //The invariant property value gets copied over to the default language
|
||||
Assert.AreEqual("v1inv", document.GetValue("value1", "en", published: true));
|
||||
@@ -970,9 +974,9 @@ namespace Umbraco.Tests.Services
|
||||
Assert.AreEqual("doc1en", document.GetCultureName("en"));
|
||||
Assert.AreEqual("doc1fr", document.GetCultureName("fr"));
|
||||
Assert.AreEqual("v1en", document.GetValue("value1"));
|
||||
Assert.AreEqual("v1en-init", document.GetValue("value1", published: true));
|
||||
Assert.AreEqual("v1en-init", document.GetValue("value1", published: true));
|
||||
Assert.IsTrue(document.IsCultureEdited("en")); //This is true because the invariant property reflects changes on the default lang
|
||||
Assert.IsFalse(document.IsCultureEdited("fr"));
|
||||
Assert.IsFalse(document.IsCultureEdited("fr"));
|
||||
Assert.IsTrue(document.Edited);
|
||||
|
||||
// switch property type to Culture
|
||||
@@ -980,7 +984,7 @@ namespace Umbraco.Tests.Services
|
||||
ServiceContext.ContentTypeService.Save(contentType); //This is going to have to re-normalize the "Edited" flag
|
||||
|
||||
document = ServiceContext.ContentService.GetById(document.Id);
|
||||
Assert.IsTrue(document.IsCultureEdited("en")); //Remains true
|
||||
Assert.IsTrue(document.IsCultureEdited("en")); //Remains true
|
||||
Assert.IsFalse(document.IsCultureEdited("fr")); //False because no french property has ever been edited
|
||||
Assert.IsTrue(document.Edited);
|
||||
|
||||
@@ -1010,7 +1014,7 @@ namespace Umbraco.Tests.Services
|
||||
Assert.IsNull(document.GetValue("value1", "fr")); //The values are there but the business logic returns null
|
||||
Assert.IsNull(document.GetValue("value1", "fr", published: true)); //The values are there but the business logic returns null
|
||||
Assert.IsFalse(document.IsCultureEdited("en")); //The variant published AND edited values are copied over to the invariant
|
||||
Assert.IsFalse(document.IsCultureEdited("fr"));
|
||||
Assert.IsFalse(document.IsCultureEdited("fr"));
|
||||
Assert.IsFalse(document.Edited);
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -20,6 +21,7 @@ using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Sync;
|
||||
using Umbraco.Web.Hosting;
|
||||
using File = System.IO.File;
|
||||
|
||||
namespace Umbraco.Tests.TestHelpers
|
||||
@@ -296,5 +298,10 @@ namespace Umbraco.Tests.TestHelpers
|
||||
{
|
||||
return RegisterFactory.Create(GetConfigs().Global());
|
||||
}
|
||||
|
||||
public static IHostingEnvironment GetHostingEnvironment()
|
||||
{
|
||||
return new AspNetHostingEnvironment(SettingsForTests.GetDefaultGlobalSettings(), IOHelper.Default);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ using Umbraco.Web.Security;
|
||||
using Umbraco.Web.Routing;
|
||||
using File = System.IO.File;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Tests.Testing;
|
||||
@@ -60,6 +61,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
internal ScopeProvider ScopeProvider => Current.ScopeProvider as ScopeProvider;
|
||||
|
||||
protected ISqlContext SqlContext => Factory.GetInstance<ISqlContext>();
|
||||
protected IHostingEnvironment HostingEnvironment => Factory.GetInstance<IHostingEnvironment>();
|
||||
|
||||
public override void SetUp()
|
||||
{
|
||||
@@ -268,7 +270,9 @@ namespace Umbraco.Tests.TestHelpers
|
||||
Factory.GetInstance<IDocumentRepository>(), Factory.GetInstance<IMediaRepository>(), Factory.GetInstance<IMemberRepository>(),
|
||||
DefaultCultureAccessor,
|
||||
Logger,
|
||||
Factory.GetInstance<IGlobalSettings>(), new SiteDomainHelper(),
|
||||
Factory.GetInstance<IGlobalSettings>(),
|
||||
HostingEnvironment,
|
||||
new SiteDomainHelper(),
|
||||
Factory.GetInstance<IEntityXmlSerializer>(),
|
||||
ContentTypesCache,
|
||||
null, true, Options.PublishedRepositoryEvents);
|
||||
|
||||
@@ -36,9 +36,11 @@ using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Trees;
|
||||
using Umbraco.Core.Composing.CompositionExtensions;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Web.Composing.CompositionExtensions;
|
||||
using Umbraco.Web.Hosting;
|
||||
using Umbraco.Web.Sections;
|
||||
using Current = Umbraco.Core.Composing.Current;
|
||||
using FileSystems = Umbraco.Core.IO.FileSystems;
|
||||
@@ -140,8 +142,9 @@ namespace Umbraco.Tests.Testing
|
||||
TypeFinder = new TypeFinder(logger);
|
||||
var appCaches = GetAppCaches();
|
||||
var globalSettings = SettingsForTests.GetDefaultGlobalSettings();
|
||||
IHostingEnvironment hostingEnvironment = new AspNetHostingEnvironment(globalSettings, IOHelper);
|
||||
UmbracoVersion = new UmbracoVersion(globalSettings);
|
||||
var typeLoader = GetTypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, globalSettings, proflogger, Options.TypeLoader);
|
||||
var typeLoader = GetTypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, hostingEnvironment, proflogger, Options.TypeLoader);
|
||||
|
||||
var register = TestHelper.GetRegister();
|
||||
|
||||
@@ -156,6 +159,7 @@ namespace Umbraco.Tests.Testing
|
||||
Composition.RegisterUnique(profiler);
|
||||
Composition.RegisterUnique<IProfilingLogger>(proflogger);
|
||||
Composition.RegisterUnique(appCaches);
|
||||
Composition.RegisterUnique(hostingEnvironment);
|
||||
|
||||
TestObjects = new TestObjects(register);
|
||||
Compose();
|
||||
@@ -279,30 +283,30 @@ namespace Umbraco.Tests.Testing
|
||||
.ComposeWebMappingProfiles();
|
||||
}
|
||||
|
||||
protected virtual TypeLoader GetTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, IGlobalSettings globalSettings, IProfilingLogger logger, UmbracoTestOptions.TypeLoader option)
|
||||
protected virtual TypeLoader GetTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, IHostingEnvironment hostingEnvironment, IProfilingLogger logger, UmbracoTestOptions.TypeLoader option)
|
||||
{
|
||||
switch (option)
|
||||
{
|
||||
case UmbracoTestOptions.TypeLoader.Default:
|
||||
return _commonTypeLoader ?? (_commonTypeLoader = CreateCommonTypeLoader(ioHelper, typeFinder, runtimeCache, globalSettings, logger));
|
||||
return _commonTypeLoader ?? (_commonTypeLoader = CreateCommonTypeLoader(ioHelper, typeFinder, runtimeCache, logger, hostingEnvironment));
|
||||
case UmbracoTestOptions.TypeLoader.PerFixture:
|
||||
return _featureTypeLoader ?? (_featureTypeLoader = CreateTypeLoader(ioHelper, typeFinder, runtimeCache, globalSettings, logger));
|
||||
return _featureTypeLoader ?? (_featureTypeLoader = CreateTypeLoader(ioHelper, typeFinder, runtimeCache, logger, hostingEnvironment));
|
||||
case UmbracoTestOptions.TypeLoader.PerTest:
|
||||
return CreateTypeLoader(ioHelper, typeFinder, runtimeCache, globalSettings, logger);
|
||||
return CreateTypeLoader(ioHelper, typeFinder, runtimeCache, logger, hostingEnvironment);
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(option));
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual TypeLoader CreateTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, IGlobalSettings globalSettings, IProfilingLogger logger)
|
||||
protected virtual TypeLoader CreateTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, IProfilingLogger logger, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
return CreateCommonTypeLoader(ioHelper, typeFinder, runtimeCache, globalSettings, logger);
|
||||
return CreateCommonTypeLoader(ioHelper, typeFinder, runtimeCache, logger, hostingEnvironment);
|
||||
}
|
||||
|
||||
// common to all tests = cannot be overriden
|
||||
private static TypeLoader CreateCommonTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, IGlobalSettings globalSettings, IProfilingLogger logger)
|
||||
private static TypeLoader CreateCommonTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, IProfilingLogger logger, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(globalSettings.LocalTempPath(ioHelper)), logger, false, new[]
|
||||
return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(hostingEnvironment.LocalTempPath), logger, false, new[]
|
||||
{
|
||||
Assembly.Load("Umbraco.Core"),
|
||||
Assembly.Load("Umbraco.Web"),
|
||||
|
||||
@@ -425,7 +425,9 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
null, null,
|
||||
umbracoContextAccessor, null, null, null,
|
||||
new TestDefaultCultureAccessor(),
|
||||
Current.Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(),
|
||||
Current.Logger, TestObjects.GetGlobalSettings(),
|
||||
TestHelper.GetHostingEnvironment(),
|
||||
new SiteDomainHelper(),
|
||||
Factory.GetInstance<IEntityXmlSerializer>(),
|
||||
null, true, false
|
||||
); // no events
|
||||
|
||||
@@ -14,6 +14,7 @@ using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Web.Composing;
|
||||
using System.ComponentModel;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Web
|
||||
@@ -29,8 +30,8 @@ namespace Umbraco.Web
|
||||
private readonly IUmbracoDatabaseFactory _databaseFactory;
|
||||
|
||||
public BatchedDatabaseServerMessenger(
|
||||
IRuntimeState runtime, IUmbracoDatabaseFactory databaseFactory, IScopeProvider scopeProvider, ISqlContext sqlContext, IProfilingLogger proflog, IGlobalSettings globalSettings, DatabaseServerMessengerOptions options, IIOHelper ioHelper)
|
||||
: base(runtime, scopeProvider, sqlContext, proflog, globalSettings, true, options, ioHelper)
|
||||
IRuntimeState runtime, IUmbracoDatabaseFactory databaseFactory, IScopeProvider scopeProvider, ISqlContext sqlContext, IProfilingLogger proflog, DatabaseServerMessengerOptions options, IIOHelper ioHelper, IHostingEnvironment hostingEnvironment)
|
||||
: base(runtime, scopeProvider, sqlContext, proflog, true, options, ioHelper, hostingEnvironment )
|
||||
{
|
||||
_databaseFactory = databaseFactory;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Web.Hosting
|
||||
{
|
||||
public class AspNetHostingEnvironment : IHostingEnvironment
|
||||
{
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private string _localTempPath;
|
||||
|
||||
public AspNetHostingEnvironment(IGlobalSettings globalSettings, IIOHelper ioHelper)
|
||||
{
|
||||
_globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
|
||||
SiteName = HostingEnvironment.SiteName;
|
||||
ApplicationId = HostingEnvironment.ApplicationID;
|
||||
ApplicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath;
|
||||
}
|
||||
|
||||
public string SiteName { get; }
|
||||
public string ApplicationId { get; }
|
||||
public string ApplicationPhysicalPath { get; }
|
||||
|
||||
public string LocalTempPath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_localTempPath != null)
|
||||
return _localTempPath;
|
||||
|
||||
switch (_globalSettings.LocalTempStorageLocation)
|
||||
{
|
||||
case LocalTempStorage.AspNetTemp:
|
||||
return _localTempPath = System.IO.Path.Combine(HttpRuntime.CodegenDir, "UmbracoData");
|
||||
|
||||
case LocalTempStorage.EnvironmentTemp:
|
||||
|
||||
// environment temp is unique, we need a folder per site
|
||||
|
||||
// use a hash
|
||||
// combine site name and application id
|
||||
// site name is a Guid on Cloud
|
||||
// application id is eg /LM/W3SVC/123456/ROOT
|
||||
// the combination is unique on one server
|
||||
// and, if a site moves from worker A to B and then back to A...
|
||||
// hopefully it gets a new Guid or new application id?
|
||||
|
||||
var hashString = SiteName + "::" + ApplicationId;
|
||||
var hash = hashString.GenerateHash();
|
||||
var siteTemp = System.IO.Path.Combine(Environment.ExpandEnvironmentVariables("%temp%"), "UmbracoData", hash);
|
||||
|
||||
return _localTempPath = siteTemp;
|
||||
|
||||
//case LocalTempStorage.Default:
|
||||
//case LocalTempStorage.Unknown:
|
||||
default:
|
||||
return _localTempPath = _ioHelper.MapPath("~/App_Data/TEMP");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
@@ -48,6 +49,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
private readonly IDefaultCultureAccessor _defaultCultureAccessor;
|
||||
private readonly UrlSegmentProviderCollection _urlSegmentProviders;
|
||||
private readonly ITypeFinder _typeFinder;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
// volatile because we read it with no lock
|
||||
private volatile bool _isReady;
|
||||
@@ -80,7 +82,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
IEntityXmlSerializer entitySerializer,
|
||||
IPublishedModelFactory publishedModelFactory,
|
||||
UrlSegmentProviderCollection urlSegmentProviders,
|
||||
ITypeFinder typeFinder)
|
||||
ITypeFinder typeFinder,
|
||||
IHostingEnvironment hostingEnvironment)
|
||||
: base(publishedSnapshotAccessor, variationContextAccessor)
|
||||
{
|
||||
//if (Interlocked.Increment(ref _singletonCheck) > 1)
|
||||
@@ -98,6 +101,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
_globalSettings = globalSettings;
|
||||
_urlSegmentProviders = urlSegmentProviders;
|
||||
_typeFinder = typeFinder;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
|
||||
// we need an Xml serializer here so that the member cache can support XPath,
|
||||
// for members this is done by navigating the serialized-to-xml member
|
||||
@@ -299,7 +303,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
private string GetLocalFilesPath()
|
||||
{
|
||||
var path = Path.Combine(_globalSettings.LocalTempPath(Current.IOHelper), "NuCache");
|
||||
var path = Path.Combine(_hostingEnvironment.LocalTempPath, "NuCache");
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
@@ -14,6 +14,7 @@ using ClientDependency.Core.Config;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Install;
|
||||
using Umbraco.Web.JavaScript;
|
||||
@@ -30,13 +31,15 @@ namespace Umbraco.Web.Runtime
|
||||
private readonly SurfaceControllerTypeCollection _surfaceControllerTypes;
|
||||
private readonly UmbracoApiControllerTypeCollection _apiControllerTypes;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
public WebInitialComponent(IUmbracoContextAccessor umbracoContextAccessor, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, IGlobalSettings globalSettings)
|
||||
public WebInitialComponent(IUmbracoContextAccessor umbracoContextAccessor, SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes, IGlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_surfaceControllerTypes = surfaceControllerTypes;
|
||||
_apiControllerTypes = apiControllerTypes;
|
||||
_globalSettings = globalSettings;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
@@ -48,7 +51,7 @@ namespace Umbraco.Web.Runtime
|
||||
// want to access HttpContext.Current, which doesn't exist
|
||||
if (Current.IOHelper.IsHosted)
|
||||
{
|
||||
ConfigureClientDependency(_globalSettings);
|
||||
ConfigureClientDependency();
|
||||
}
|
||||
|
||||
// Disable the X-AspNetMvc-Version HTTP Header
|
||||
@@ -109,7 +112,7 @@ namespace Umbraco.Web.Runtime
|
||||
new NamespaceHttpControllerSelector(GlobalConfiguration.Configuration));
|
||||
}
|
||||
|
||||
private static void ConfigureClientDependency(IGlobalSettings globalSettings)
|
||||
private void ConfigureClientDependency()
|
||||
{
|
||||
// Backwards compatibility - set the path and URL type for ClientDependency 1.5.1 [LK]
|
||||
XmlFileMapper.FileMapDefaultFolder = Core.Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ClientDependency";
|
||||
@@ -117,9 +120,9 @@ namespace Umbraco.Web.Runtime
|
||||
|
||||
// Now we need to detect if we are running 'Umbraco.Core.LocalTempStorage' as EnvironmentTemp and in that case we want to change the CDF file
|
||||
// location to be there
|
||||
if (globalSettings.LocalTempStorageLocation == LocalTempStorage.EnvironmentTemp)
|
||||
if (_globalSettings.LocalTempStorageLocation == LocalTempStorage.EnvironmentTemp)
|
||||
{
|
||||
var cachePath = globalSettings.LocalTempPath(Current.IOHelper);
|
||||
var cachePath = _hostingEnvironment.LocalTempPath;
|
||||
|
||||
//set the file map and composite file default location to the %temp% location
|
||||
BaseCompositeFileProcessingProvider.CompositeFilePathDefaultFolder
|
||||
|
||||
@@ -8,6 +8,7 @@ using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Dashboards;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Migrations.PostMigrations;
|
||||
using Umbraco.Web.Migrations.PostMigrations;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
@@ -24,6 +25,7 @@ using Umbraco.Web.Dictionary;
|
||||
using Umbraco.Web.Editors;
|
||||
using Umbraco.Web.Features;
|
||||
using Umbraco.Web.HealthCheck;
|
||||
using Umbraco.Web.Hosting;
|
||||
using Umbraco.Web.Macros;
|
||||
using Umbraco.Web.Media.EmbedProviders;
|
||||
using Umbraco.Web.Models.PublishedContent;
|
||||
@@ -55,6 +57,7 @@ namespace Umbraco.Web.Runtime
|
||||
|
||||
composition.Register<UmbracoInjectedModule>();
|
||||
composition.Register<IIpResolver, IpResolver>();
|
||||
composition.Register<IHostingEnvironment, AspNetHostingEnvironment>();
|
||||
|
||||
composition.RegisterUnique<IHttpContextAccessor, AspNetHttpContextAccessor>(); // required for hybrid accessors
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Runtime;
|
||||
using Umbraco.Web.Cache;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Hosting;
|
||||
using Umbraco.Web.Logging;
|
||||
|
||||
namespace Umbraco.Web.Runtime
|
||||
@@ -26,8 +27,8 @@ namespace Umbraco.Web.Runtime
|
||||
/// Initializes a new instance of the <see cref="WebRuntime"/> class.
|
||||
/// </summary>
|
||||
/// <param name="umbracoApplication"></param>
|
||||
public WebRuntime(UmbracoApplicationBase umbracoApplication, Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler):
|
||||
base(configs, umbracoVersion, ioHelper, logger, profiler ,new AspNetUmbracoBootPermissionChecker())
|
||||
public WebRuntime(UmbracoApplicationBase umbracoApplication, Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment):
|
||||
base(configs, umbracoVersion, ioHelper, logger, profiler ,new AspNetUmbracoBootPermissionChecker(), hostingEnvironment)
|
||||
{
|
||||
_umbracoApplication = umbracoApplication;
|
||||
|
||||
@@ -63,7 +64,7 @@ namespace Umbraco.Web.Runtime
|
||||
{
|
||||
Logger.Info<CoreRuntime>("Booting site '{HostingSiteName}', app '{HostingApplicationID}', path '{HostingPhysicalPath}', server '{MachineName}'.",
|
||||
HostingEnvironment.SiteName,
|
||||
HostingEnvironment.ApplicationID,
|
||||
HostingEnvironment.ApplicationId,
|
||||
HostingEnvironment.ApplicationPhysicalPath,
|
||||
NetworkHelper.MachineName);
|
||||
Logger.Debug<CoreRuntime>("Runtime: {Runtime}", GetType().FullName);
|
||||
|
||||
@@ -163,6 +163,7 @@
|
||||
<Compile Include="Editors\MacrosController.cs" />
|
||||
<Compile Include="Editors\RelationTypeController.cs" />
|
||||
<Compile Include="Editors\TinyMceController.cs" />
|
||||
<Compile Include="Hosting\AspNetHostingEnvironment.cs" />
|
||||
<Compile Include="IpResolver.cs" />
|
||||
<Compile Include="IUmbracoContextFactory.cs" />
|
||||
<Compile Include="Install\ChangesMonitor.cs" />
|
||||
@@ -1263,7 +1264,6 @@
|
||||
<CachedSettingsPropName>umbraco_org_umbraco_update_CheckForUpgrade</CachedSettingsPropName>
|
||||
</WebReferenceUrl>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!--
|
||||
copied from Microsoft.CSharp.targets
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Web;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web.Runtime;
|
||||
@@ -13,9 +14,9 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
public class UmbracoApplication : UmbracoApplicationBase
|
||||
{
|
||||
protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler)
|
||||
protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
return new WebRuntime(this, configs, umbracoVersion, ioHelper, logger, profiler);
|
||||
return new WebRuntime(this, configs, umbracoVersion, ioHelper, logger, profiler, hostingEnvironment);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -6,9 +6,11 @@ using System.Web.Hosting;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Logging.Serilog;
|
||||
using Umbraco.Web.Hosting;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
@@ -23,6 +25,7 @@ namespace Umbraco.Web
|
||||
private readonly Configs _configs;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IProfiler _profiler;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
|
||||
protected UmbracoApplicationBase()
|
||||
{
|
||||
@@ -30,21 +33,23 @@ namespace Umbraco.Web
|
||||
_ioHelper = IOHelper.Default;
|
||||
_configs = new ConfigsFactory(_ioHelper).Create();
|
||||
_profiler = new LogProfiler(_logger);
|
||||
_hostingEnvironment = new AspNetHostingEnvironment(_configs.Global(), _ioHelper);
|
||||
}
|
||||
|
||||
protected UmbracoApplicationBase(ILogger logger, Configs configs, IIOHelper ioHelper, IProfiler profiler)
|
||||
protected UmbracoApplicationBase(ILogger logger, Configs configs, IIOHelper ioHelper, IProfiler profiler, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_logger = logger;
|
||||
_configs = configs;
|
||||
_ioHelper = ioHelper;
|
||||
_profiler = profiler;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a runtime.
|
||||
/// </summary>
|
||||
protected abstract IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler);
|
||||
protected abstract IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger, IProfiler profiler, IHostingEnvironment hostingEnvironment);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the application register.
|
||||
@@ -89,7 +94,7 @@ namespace Umbraco.Web
|
||||
// create the register for the application, and boot
|
||||
// the boot manager is responsible for registrations
|
||||
var register = GetRegister(globalSettings);
|
||||
_runtime = GetRuntime(_configs, umbracoVersion, _ioHelper, _logger, _profiler);
|
||||
_runtime = GetRuntime(_configs, umbracoVersion, _ioHelper, _logger, _profiler, _hostingEnvironment);
|
||||
_runtime.Boot(register);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user