mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Slightly refactor IAppDataFolder
Remove the "SetBasePath" method, introduce IAppDataFolderRoot as replacement. --HG-- branch : dev
This commit is contained in:
@@ -10,6 +10,7 @@ using Orchard.FileSystems.VirtualPath;
|
|||||||
using Orchard.Indexing;
|
using Orchard.Indexing;
|
||||||
using Orchard.Core.Indexing.Lucene;
|
using Orchard.Core.Indexing.Lucene;
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
|
using Orchard.Tests.Environment.Configuration;
|
||||||
|
|
||||||
namespace Orchard.Tests.Indexing {
|
namespace Orchard.Tests.Indexing {
|
||||||
public class DefaultIndexProviderTests {
|
public class DefaultIndexProviderTests {
|
||||||
@@ -31,8 +32,7 @@ namespace Orchard.Tests.Indexing {
|
|||||||
}
|
}
|
||||||
Directory.CreateDirectory(_basePath);
|
Directory.CreateDirectory(_basePath);
|
||||||
|
|
||||||
_appDataFolder = new AppDataFolder(new DefaultVirtualPathMonitor(new Clock()));
|
_appDataFolder = AppDataFolderTests.CreateAppDataFolder(_basePath);
|
||||||
_appDataFolder.SetBasePath(_basePath);
|
|
||||||
|
|
||||||
var builder = new ContainerBuilder();
|
var builder = new ContainerBuilder();
|
||||||
builder.RegisterType<DefaultIndexProvider>().As<IIndexProvider>();
|
builder.RegisterType<DefaultIndexProvider>().As<IIndexProvider>();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using Orchard.FileSystems.VirtualPath;
|
|||||||
using Orchard.Indexing;
|
using Orchard.Indexing;
|
||||||
using Orchard.Core.Indexing.Lucene;
|
using Orchard.Core.Indexing.Lucene;
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
|
using Orchard.Tests.Environment.Configuration;
|
||||||
|
|
||||||
namespace Orchard.Tests.Indexing {
|
namespace Orchard.Tests.Indexing {
|
||||||
public class DefaultSearchBuilderTests {
|
public class DefaultSearchBuilderTests {
|
||||||
@@ -31,9 +32,7 @@ namespace Orchard.Tests.Indexing {
|
|||||||
}
|
}
|
||||||
Directory.CreateDirectory(_basePath);
|
Directory.CreateDirectory(_basePath);
|
||||||
|
|
||||||
|
_appDataFolder = AppDataFolderTests.CreateAppDataFolder(_basePath);
|
||||||
_appDataFolder = new AppDataFolder(new DefaultVirtualPathMonitor(new Clock()));
|
|
||||||
_appDataFolder.SetBasePath(_basePath);
|
|
||||||
|
|
||||||
var builder = new ContainerBuilder();
|
var builder = new ContainerBuilder();
|
||||||
builder.RegisterType<DefaultIndexProvider>().As<IIndexProvider>();
|
builder.RegisterType<DefaultIndexProvider>().As<IIndexProvider>();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using Orchard.Environment.Descriptor.Models;
|
|||||||
using Orchard.FileSystems.AppData;
|
using Orchard.FileSystems.AppData;
|
||||||
using Orchard.FileSystems.VirtualPath;
|
using Orchard.FileSystems.VirtualPath;
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
|
using Orchard.Tests.Environment.Configuration;
|
||||||
|
|
||||||
namespace Orchard.Tests.Environment.Blueprint {
|
namespace Orchard.Tests.Environment.Blueprint {
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
@@ -21,8 +22,9 @@ namespace Orchard.Tests.Environment.Blueprint {
|
|||||||
_tempFolder = Path.GetTempFileName();
|
_tempFolder = Path.GetTempFileName();
|
||||||
File.Delete(_tempFolder);
|
File.Delete(_tempFolder);
|
||||||
Directory.CreateDirectory(_tempFolder);
|
Directory.CreateDirectory(_tempFolder);
|
||||||
_appDataFolder = new AppDataFolder(new DefaultVirtualPathMonitor(new Clock()));
|
|
||||||
_appDataFolder.SetBasePath(_tempFolder);
|
_appDataFolder = AppDataFolderTests.CreateAppDataFolder(_tempFolder);
|
||||||
|
|
||||||
var builder = new ContainerBuilder();
|
var builder = new ContainerBuilder();
|
||||||
builder.RegisterInstance(_appDataFolder).As<IAppDataFolder>();
|
builder.RegisterInstance(_appDataFolder).As<IAppDataFolder>();
|
||||||
builder.RegisterType<ShellDescriptorCache>().As<IShellDescriptorCache>();
|
builder.RegisterType<ShellDescriptorCache>().As<IShellDescriptorCache>();
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.Environment;
|
|
||||||
using Orchard.FileSystems.AppData;
|
using Orchard.FileSystems.AppData;
|
||||||
using Orchard.FileSystems.VirtualPath;
|
using Orchard.FileSystems.VirtualPath;
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
@@ -12,6 +11,16 @@ namespace Orchard.Tests.Environment.Configuration {
|
|||||||
private string _tempFolder;
|
private string _tempFolder;
|
||||||
private IAppDataFolder _appDataFolder;
|
private IAppDataFolder _appDataFolder;
|
||||||
|
|
||||||
|
public class StubAppDataFolderRoot : IAppDataFolderRoot {
|
||||||
|
public string RootPath { get; set; }
|
||||||
|
public string RootFolder { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IAppDataFolder CreateAppDataFolder(string tempFolder) {
|
||||||
|
var folderRoot = new StubAppDataFolderRoot {RootPath = "~/App_Data", RootFolder = tempFolder};
|
||||||
|
return new AppDataFolder(folderRoot, new DefaultVirtualPathMonitor(new Clock()));
|
||||||
|
}
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Init() {
|
public void Init() {
|
||||||
_tempFolder = Path.GetTempFileName();
|
_tempFolder = Path.GetTempFileName();
|
||||||
@@ -21,8 +30,7 @@ namespace Orchard.Tests.Environment.Configuration {
|
|||||||
File.WriteAllText(Path.Combine(_tempFolder, "alpha\\gamma.txt"), "gamma-content");
|
File.WriteAllText(Path.Combine(_tempFolder, "alpha\\gamma.txt"), "gamma-content");
|
||||||
Directory.CreateDirectory(Path.Combine(_tempFolder, "alpha\\omega"));
|
Directory.CreateDirectory(Path.Combine(_tempFolder, "alpha\\omega"));
|
||||||
|
|
||||||
_appDataFolder = new AppDataFolder(new DefaultVirtualPathMonitor(new Clock()));
|
_appDataFolder = CreateAppDataFolder(_tempFolder);
|
||||||
_appDataFolder.SetBasePath(_tempFolder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TearDown]
|
[TearDown]
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ namespace Orchard.Tests.Environment.Configuration {
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class DefaultTenantManagerTests {
|
public class DefaultTenantManagerTests {
|
||||||
private string _tempFolder;
|
private string _tempFolder;
|
||||||
private AppDataFolder _appData;
|
private IAppDataFolder _appData;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Init() {
|
public void Init() {
|
||||||
_appData = new AppDataFolder(new DefaultVirtualPathMonitor(new Clock()));
|
|
||||||
_tempFolder = Path.GetTempFileName();
|
_tempFolder = Path.GetTempFileName();
|
||||||
File.Delete(_tempFolder);
|
File.Delete(_tempFolder);
|
||||||
_appData.SetBasePath(_tempFolder);
|
|
||||||
|
_appData = AppDataFolderTests.CreateAppDataFolder(_tempFolder);
|
||||||
}
|
}
|
||||||
[TearDown]
|
[TearDown]
|
||||||
public void Term() {
|
public void Term() {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Autofac;
|
|||||||
using Autofac.Integration.Web;
|
using Autofac.Integration.Web;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using Orchard.Caching;
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
using Orchard.Environment.AutofacUtil;
|
using Orchard.Environment.AutofacUtil;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
@@ -22,6 +23,7 @@ using Orchard.FileSystems.AppData;
|
|||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
using Orchard.Mvc.ModelBinders;
|
using Orchard.Mvc.ModelBinders;
|
||||||
using Orchard.Mvc.Routes;
|
using Orchard.Mvc.Routes;
|
||||||
|
using Orchard.Tests.Environment.Configuration;
|
||||||
using Orchard.Tests.Environment.TestDependencies;
|
using Orchard.Tests.Environment.TestDependencies;
|
||||||
using Orchard.Tests.Stubs;
|
using Orchard.Tests.Stubs;
|
||||||
using Orchard.Tests.Utility;
|
using Orchard.Tests.Utility;
|
||||||
@@ -38,6 +40,12 @@ namespace Orchard.Tests.Environment {
|
|||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Init() {
|
public void Init() {
|
||||||
|
var temp = Path.GetTempFileName();
|
||||||
|
File.Delete(temp);
|
||||||
|
Directory.CreateDirectory(temp);
|
||||||
|
|
||||||
|
var appDataFolder = AppDataFolderTests.CreateAppDataFolder(temp);
|
||||||
|
|
||||||
_controllerBuilder = new ControllerBuilder();
|
_controllerBuilder = new ControllerBuilder();
|
||||||
_routeCollection = new RouteCollection();
|
_routeCollection = new RouteCollection();
|
||||||
_modelBinderDictionary = new ModelBinderDictionary();
|
_modelBinderDictionary = new ModelBinderDictionary();
|
||||||
@@ -51,6 +59,7 @@ namespace Orchard.Tests.Environment {
|
|||||||
builder.RegisterType<ModelBinderPublisher>().As<IModelBinderPublisher>();
|
builder.RegisterType<ModelBinderPublisher>().As<IModelBinderPublisher>();
|
||||||
builder.RegisterType<ShellContextFactory>().As<IShellContextFactory>();
|
builder.RegisterType<ShellContextFactory>().As<IShellContextFactory>();
|
||||||
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
|
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
|
||||||
|
builder.RegisterInstance(appDataFolder);
|
||||||
builder.RegisterInstance(_controllerBuilder);
|
builder.RegisterInstance(_controllerBuilder);
|
||||||
builder.RegisterInstance(_routeCollection);
|
builder.RegisterInstance(_routeCollection);
|
||||||
builder.RegisterInstance(_modelBinderDictionary);
|
builder.RegisterInstance(_modelBinderDictionary);
|
||||||
@@ -75,13 +84,6 @@ namespace Orchard.Tests.Environment {
|
|||||||
_container.Mock<IOrchardShellEvents>()
|
_container.Mock<IOrchardShellEvents>()
|
||||||
.Setup(e=>e.Activated());
|
.Setup(e=>e.Activated());
|
||||||
|
|
||||||
var temp = Path.GetTempFileName();
|
|
||||||
File.Delete(temp);
|
|
||||||
Directory.CreateDirectory(temp);
|
|
||||||
|
|
||||||
_container.Resolve<IAppDataFolder>()
|
|
||||||
.SetBasePath(temp);
|
|
||||||
|
|
||||||
var updater = new ContainerUpdater();
|
var updater = new ContainerUpdater();
|
||||||
updater.RegisterInstance(_container).SingleInstance();
|
updater.RegisterInstance(_container).SingleInstance();
|
||||||
updater.Update(_lifetime);
|
updater.Update(_lifetime);
|
||||||
@@ -120,6 +122,10 @@ namespace Orchard.Tests.Environment {
|
|||||||
public void UninstallExtension(string extensionType, string extensionName) {
|
public void UninstallExtension(string extensionType, string extensionName) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Monitor(Action<IVolatileToken> monitor) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StubShellSettingsLoader : IShellSettingsManager {
|
public class StubShellSettingsLoader : IShellSettingsManager {
|
||||||
|
|||||||
@@ -72,11 +72,14 @@ namespace Orchard.Data {
|
|||||||
private ISessionFactory BuildSessionFactory(bool createDatabase, bool updateSchema) {
|
private ISessionFactory BuildSessionFactory(bool createDatabase, bool updateSchema) {
|
||||||
Logger.Debug("Building session factory");
|
Logger.Debug("Building session factory");
|
||||||
|
|
||||||
var shellPath = _appDataFolder.CreateDirectory(Path.Combine("Sites", _shellSettings.Name));
|
var shellPath = _appDataFolder.Combine("Sites", _shellSettings.Name);
|
||||||
|
_appDataFolder.CreateDirectory(shellPath);
|
||||||
|
|
||||||
|
var shellFolder = _appDataFolder.MapPath(shellPath);
|
||||||
|
|
||||||
var sessionFactory = _sessionFactoryBuilder.BuildSessionFactory(new SessionFactoryParameters {
|
var sessionFactory = _sessionFactoryBuilder.BuildSessionFactory(new SessionFactoryParameters {
|
||||||
Provider = _shellSettings.DataProvider,
|
Provider = _shellSettings.DataProvider,
|
||||||
DataFolder = shellPath,
|
DataFolder = shellFolder,
|
||||||
ConnectionString = _shellSettings.DataConnectionString,
|
ConnectionString = _shellSettings.DataConnectionString,
|
||||||
CreateDatabase = createDatabase,
|
CreateDatabase = createDatabase,
|
||||||
UpdateSchema = updateSchema,
|
UpdateSchema = updateSchema,
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ namespace Orchard.Environment {
|
|||||||
builder.RegisterType<DefaultHostEnvironment>().As<IHostEnvironment>().SingleInstance();
|
builder.RegisterType<DefaultHostEnvironment>().As<IHostEnvironment>().SingleInstance();
|
||||||
builder.RegisterType<DefaultBuildManager>().As<IBuildManager>().SingleInstance();
|
builder.RegisterType<DefaultBuildManager>().As<IBuildManager>().SingleInstance();
|
||||||
builder.RegisterType<WebFormsExtensionsVirtualPathProvider>().As<ICustomVirtualPathProvider>().SingleInstance();
|
builder.RegisterType<WebFormsExtensionsVirtualPathProvider>().As<ICustomVirtualPathProvider>().SingleInstance();
|
||||||
|
builder.RegisterType<AppDataFolderRoot>().As<IAppDataFolderRoot>().SingleInstance();
|
||||||
|
|
||||||
RegisterVolatileProvider<WebSiteFolder, IWebSiteFolder>(builder);
|
RegisterVolatileProvider<WebSiteFolder, IWebSiteFolder>(builder);
|
||||||
RegisterVolatileProvider<AppDataFolder, IAppDataFolder>(builder);
|
RegisterVolatileProvider<AppDataFolder, IAppDataFolder>(builder);
|
||||||
|
|||||||
@@ -1,32 +1,50 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
using Orchard.Caching;
|
using Orchard.Caching;
|
||||||
using Orchard.Environment;
|
|
||||||
using Orchard.FileSystems.VirtualPath;
|
using Orchard.FileSystems.VirtualPath;
|
||||||
|
|
||||||
namespace Orchard.FileSystems.AppData {
|
namespace Orchard.FileSystems.AppData {
|
||||||
public class AppDataFolder : IAppDataFolder {
|
public class AppDataFolder : IAppDataFolder {
|
||||||
|
private readonly IAppDataFolderRoot _root;
|
||||||
private readonly IVirtualPathMonitor _virtualPathMonitor;
|
private readonly IVirtualPathMonitor _virtualPathMonitor;
|
||||||
protected string _basePath;
|
|
||||||
|
|
||||||
public AppDataFolder(IVirtualPathMonitor virtualPathMonitor) {
|
public AppDataFolder(IAppDataFolderRoot root, IVirtualPathMonitor virtualPathMonitor) {
|
||||||
|
_root = root;
|
||||||
_virtualPathMonitor = virtualPathMonitor;
|
_virtualPathMonitor = virtualPathMonitor;
|
||||||
_basePath = HostingEnvironment.MapPath("~/App_Data");
|
}
|
||||||
|
|
||||||
|
public string RootFolder {
|
||||||
|
get {
|
||||||
|
return _root.RootFolder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string _appDataPath {
|
||||||
|
get {
|
||||||
|
return _root.RootPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Combine a set of virtual paths into a physical path based at "_basePath"
|
/// Combine a set of virtual paths relative to "~/App_Data" into an absolute physical path
|
||||||
|
/// starting with "_basePath".
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private string CombineToPhysicalPath(params string[] paths) {
|
private string CombineToPhysicalPath(params string[] paths) {
|
||||||
return Path.Combine(_basePath, Path.Combine(paths))
|
return Path.Combine(RootFolder, Path.Combine(paths))
|
||||||
.Replace('/', Path.DirectorySeparatorChar);
|
.Replace('/', Path.DirectorySeparatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Combine a set of virtual paths into a virtual path relative to "~/App_Data"
|
||||||
|
/// </summary>
|
||||||
|
public string Combine(params string[] paths) {
|
||||||
|
return Path.Combine(paths).Replace(Path.DirectorySeparatorChar, '/');
|
||||||
|
}
|
||||||
|
|
||||||
public IVolatileToken WhenPathChanges(string path) {
|
public IVolatileToken WhenPathChanges(string path) {
|
||||||
var replace = Path.Combine("~/App_Data", path).Replace(Path.DirectorySeparatorChar, '/');
|
var replace = Combine(_appDataPath, path);
|
||||||
return _virtualPathMonitor.WhenPathChanges(replace);
|
return _virtualPathMonitor.WhenPathChanges(replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,12 +77,7 @@ namespace Orchard.FileSystems.AppData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool FileExists(string path) {
|
public bool FileExists(string path) {
|
||||||
var filePath = CombineToPhysicalPath(path);
|
return File.Exists(CombineToPhysicalPath(path));
|
||||||
return File.Exists(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Combine(params string[] paths) {
|
|
||||||
return Path.Combine(paths).Replace(Path.DirectorySeparatorChar, '/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> ListFiles(string path) {
|
public IEnumerable<string> ListFiles(string path) {
|
||||||
@@ -93,15 +106,8 @@ namespace Orchard.FileSystems.AppData {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public string CreateDirectory(string path) {
|
public void CreateDirectory(string path) {
|
||||||
var directory = CombineToPhysicalPath(path);
|
Directory.CreateDirectory(CombineToPhysicalPath(path));
|
||||||
if (!Directory.Exists(directory))
|
|
||||||
Directory.CreateDirectory(directory);
|
|
||||||
return directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetBasePath(string basePath) {
|
|
||||||
_basePath = basePath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string MapPath(string path) {
|
public string MapPath(string path) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
@@ -5,9 +6,8 @@ using Orchard.Caching;
|
|||||||
|
|
||||||
namespace Orchard.FileSystems.AppData {
|
namespace Orchard.FileSystems.AppData {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstraction of App_Data folder
|
/// Abstraction of App_Data folder. All virtual paths passed in or returned are relative to "~/App_Data".
|
||||||
/// Expected to work on physical filesystem, but decouples core
|
/// Expected to work on physical filesystem, but decouples core system from web hosting apis
|
||||||
/// system from web hosting apis
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IAppDataFolder : IVolatileProvider {
|
public interface IAppDataFolder : IVolatileProvider {
|
||||||
IEnumerable<string> ListFiles(string path);
|
IEnumerable<string> ListFiles(string path);
|
||||||
@@ -24,15 +24,10 @@ namespace Orchard.FileSystems.AppData {
|
|||||||
|
|
||||||
void DeleteFile(string path);
|
void DeleteFile(string path);
|
||||||
|
|
||||||
string CreateDirectory(string path);
|
void CreateDirectory(string path);
|
||||||
|
|
||||||
IVolatileToken WhenPathChanges(string path);
|
IVolatileToken WhenPathChanges(string path);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// May be called to initialize component when not in a hosting environment
|
|
||||||
/// app domain
|
|
||||||
/// </summary>
|
|
||||||
void SetBasePath(string basePath);
|
|
||||||
string MapPath(string path);
|
string MapPath(string path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
29
src/Orchard/FileSystems/AppData/IAppDataFolderRoot.cs
Normal file
29
src/Orchard/FileSystems/AppData/IAppDataFolderRoot.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Web.Hosting;
|
||||||
|
|
||||||
|
namespace Orchard.FileSystems.AppData {
|
||||||
|
/// <summary>
|
||||||
|
/// Abstraction over the root location of "~/App_Data", mainly to enable
|
||||||
|
/// unit testing of AppDataFolder.
|
||||||
|
/// </summary>
|
||||||
|
public interface IAppDataFolderRoot : ISingletonDependency {
|
||||||
|
/// <summary>
|
||||||
|
/// Virtual path of root ("~/App_Data")
|
||||||
|
/// </summary>
|
||||||
|
string RootPath { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Physical path of root (typically: MapPath(RootPath))
|
||||||
|
/// </summary>
|
||||||
|
string RootFolder { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AppDataFolderRoot : IAppDataFolderRoot {
|
||||||
|
public string RootPath {
|
||||||
|
get { return "~/App_Data"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string RootFolder {
|
||||||
|
get { return HostingEnvironment.MapPath(RootPath); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,36 +5,25 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Orchard.Caching;
|
using Orchard.Caching;
|
||||||
using Orchard.Environment.Extensions;
|
|
||||||
using Orchard.FileSystems.AppData;
|
using Orchard.FileSystems.AppData;
|
||||||
using Orchard.FileSystems.WebSite;
|
|
||||||
|
|
||||||
namespace Orchard.FileSystems.Dependencies {
|
namespace Orchard.FileSystems.Dependencies {
|
||||||
public class DefaultDependenciesFolder : IDependenciesFolder {
|
public class DefaultDependenciesFolder : IDependenciesFolder {
|
||||||
private readonly string _basePath = "Dependencies";
|
private readonly string _basePath = "Dependencies";
|
||||||
|
private readonly string _persistanceFileName = "dependencies.xml";
|
||||||
private readonly ICacheManager _cacheManager;
|
private readonly ICacheManager _cacheManager;
|
||||||
private readonly IWebSiteFolder _webSiteFolder;
|
|
||||||
private readonly IAppDataFolder _appDataFolder;
|
private readonly IAppDataFolder _appDataFolder;
|
||||||
private readonly IExtensionManagerEvents _events;
|
|
||||||
private readonly InvalidationToken _writeThroughToken;
|
private readonly InvalidationToken _writeThroughToken;
|
||||||
|
|
||||||
public DefaultDependenciesFolder(ICacheManager cacheManager, IWebSiteFolder webSiteFolder, IAppDataFolder appDataFolder, IExtensionManagerEvents events) {
|
public DefaultDependenciesFolder(ICacheManager cacheManager, IAppDataFolder appDataFolder) {
|
||||||
_cacheManager = cacheManager;
|
_cacheManager = cacheManager;
|
||||||
_webSiteFolder = webSiteFolder;
|
|
||||||
_appDataFolder = appDataFolder;
|
_appDataFolder = appDataFolder;
|
||||||
_events = events;
|
|
||||||
_writeThroughToken = new InvalidationToken();
|
_writeThroughToken = new InvalidationToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string BasePath {
|
|
||||||
get {
|
|
||||||
return _basePath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private string PersistencePath {
|
private string PersistencePath {
|
||||||
get {
|
get {
|
||||||
return _appDataFolder.Combine(BasePath, "dependencies.xml");
|
return _appDataFolder.Combine(_basePath, _persistanceFileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,10 +31,12 @@ namespace Orchard.FileSystems.Dependencies {
|
|||||||
get {
|
get {
|
||||||
return _cacheManager.Get(PersistencePath,
|
return _cacheManager.Get(PersistencePath,
|
||||||
ctx => {
|
ctx => {
|
||||||
|
_appDataFolder.CreateDirectory(_basePath);
|
||||||
|
|
||||||
ctx.Monitor(_appDataFolder.WhenPathChanges(ctx.Key));
|
ctx.Monitor(_appDataFolder.WhenPathChanges(ctx.Key));
|
||||||
ctx.Monitor(_writeThroughToken);
|
ctx.Monitor(_writeThroughToken);
|
||||||
|
|
||||||
_appDataFolder.CreateDirectory(BasePath);
|
_appDataFolder.CreateDirectory(_basePath);
|
||||||
return ReadDependencies(ctx.Key).ToList();
|
return ReadDependencies(ctx.Key).ToList();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -55,36 +46,14 @@ namespace Orchard.FileSystems.Dependencies {
|
|||||||
public bool IsCurrent { get; set; }
|
public bool IsCurrent { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//public void StoreReferencedAssembly(string moduleName) {
|
|
||||||
// if (Descriptors.Any(d => d.ModuleName == moduleName)) {
|
|
||||||
// // Remove the moduleName from the list of assemblies in the dependency folder
|
|
||||||
// var newDescriptors = Descriptors.Where(d => d.ModuleName != moduleName);
|
|
||||||
|
|
||||||
// WriteDependencies(PersistencePath, newDescriptors);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public void StoreBuildProviderAssembly(string moduleName, string virtualPath, Assembly assembly) {
|
|
||||||
// var descriptor = new DependencyDescriptor {
|
|
||||||
// ModuleName = moduleName,
|
|
||||||
// IsFromBuildProvider = true,
|
|
||||||
// VirtualPath = virtualPath,
|
|
||||||
// FileName = assembly.Location
|
|
||||||
// };
|
|
||||||
|
|
||||||
// StoreDepencyInformation(descriptor);
|
|
||||||
|
|
||||||
// _webSiteFolder.WhenPathChanges(virtualPath, () => _events.ModuleChanged(moduleName));
|
|
||||||
//}
|
|
||||||
|
|
||||||
public void StorePrecompiledAssembly(string moduleModuleName, string virtualPath, string loaderName) {
|
public void StorePrecompiledAssembly(string moduleModuleName, string virtualPath, string loaderName) {
|
||||||
_appDataFolder.CreateDirectory(BasePath);
|
_appDataFolder.CreateDirectory(_basePath);
|
||||||
|
|
||||||
// Only store assembly if it's more recent that what we have stored already (if anything)
|
// Only store assembly if it's more recent that what we have stored already (if anything)
|
||||||
var assemblyFileName = _appDataFolder.MapPath(virtualPath);
|
var assemblyFileName = _appDataFolder.MapPath(virtualPath);
|
||||||
if (IsNewerAssembly(moduleModuleName, assemblyFileName)) {
|
if (IsNewerAssembly(moduleModuleName, assemblyFileName)) {
|
||||||
var destinationFileName = Path.GetFileName(assemblyFileName);
|
var destinationFileName = Path.GetFileName(assemblyFileName);
|
||||||
var destinationPath = _appDataFolder.MapPath(_appDataFolder.Combine(BasePath, destinationFileName));
|
var destinationPath = _appDataFolder.MapPath(_appDataFolder.Combine(_basePath, destinationFileName));
|
||||||
File.Copy(assemblyFileName, destinationPath, true);
|
File.Copy(assemblyFileName, destinationPath, true);
|
||||||
|
|
||||||
StoreDepencyInformation(new DependencyDescriptor {
|
StoreDepencyInformation(new DependencyDescriptor {
|
||||||
@@ -119,7 +88,7 @@ namespace Orchard.FileSystems.Dependencies {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var existingFileName = _appDataFolder.MapPath(_appDataFolder.Combine(BasePath, dependency.FileName));
|
var existingFileName = _appDataFolder.MapPath(_appDataFolder.Combine(_basePath, dependency.FileName));
|
||||||
if (!File.Exists(existingFileName)) {
|
if (!File.Exists(existingFileName)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -141,13 +110,13 @@ namespace Orchard.FileSystems.Dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Assembly LoadAssembly(string moduleName) {
|
public Assembly LoadAssembly(string moduleName) {
|
||||||
_appDataFolder.CreateDirectory(BasePath);
|
_appDataFolder.CreateDirectory(_basePath);
|
||||||
|
|
||||||
var dependency = Descriptors.SingleOrDefault(d => d.ModuleName == moduleName);
|
var dependency = Descriptors.SingleOrDefault(d => d.ModuleName == moduleName);
|
||||||
if (dependency == null)
|
if (dependency == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (!_appDataFolder.FileExists(_appDataFolder.Combine(BasePath, dependency.FileName)))
|
if (!_appDataFolder.FileExists(_appDataFolder.Combine(_basePath, dependency.FileName)))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return Assembly.Load(Path.GetFileNameWithoutExtension(dependency.FileName));
|
return Assembly.Load(Path.GetFileNameWithoutExtension(dependency.FileName));
|
||||||
@@ -158,7 +127,7 @@ namespace Orchard.FileSystems.Dependencies {
|
|||||||
if (dependency == null)
|
if (dependency == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!_appDataFolder.FileExists(_appDataFolder.Combine(BasePath, dependency.FileName)))
|
if (!_appDataFolder.FileExists(_appDataFolder.Combine(_basePath, dependency.FileName)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -353,6 +353,7 @@
|
|||||||
<Compile Include="Data\DataModule.cs" />
|
<Compile Include="Data\DataModule.cs" />
|
||||||
<Compile Include="Data\Orderable.cs" />
|
<Compile Include="Data\Orderable.cs" />
|
||||||
<Compile Include="Environment\DefaultOrchardShell.cs" />
|
<Compile Include="Environment\DefaultOrchardShell.cs" />
|
||||||
|
<Compile Include="FileSystems\AppData\IAppDataFolderRoot.cs" />
|
||||||
<Compile Include="FileSystems\Dependencies\DefaultDependenciesFolder.cs" />
|
<Compile Include="FileSystems\Dependencies\DefaultDependenciesFolder.cs" />
|
||||||
<Compile Include="FileSystems\VirtualPath\DefaultVirtualPathMonitor.cs" />
|
<Compile Include="FileSystems\VirtualPath\DefaultVirtualPathMonitor.cs" />
|
||||||
<Compile Include="FileSystems\VirtualPath\DefaultVirtualPathProvider.cs" />
|
<Compile Include="FileSystems\VirtualPath\DefaultVirtualPathProvider.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user