Refactoring TemplateRepository and adding providers to the FileSystemPRoviders.config
This commit is contained in:
@@ -40,7 +40,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
FileSystem.AddFile(entity.Name, stream, true);
|
||||
}
|
||||
|
||||
public void Delete(TEntity entity)
|
||||
public virtual void Delete(TEntity entity)
|
||||
{
|
||||
if (_fileSystem.FileExists(entity.Name))
|
||||
{
|
||||
@@ -56,7 +56,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
public abstract IEnumerable<TEntity> GetAll(params TId[] ids);
|
||||
|
||||
public bool Exists(TId id)
|
||||
public virtual bool Exists(TId id)
|
||||
{
|
||||
return _fileSystem.FileExists(id.ToString());
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
private void EnsureDependencies()
|
||||
{
|
||||
_fileSystem = FileSystemProviderManager.Current.GetFileSystemProvider("macro");
|
||||
_fileSystem = FileSystemProviderManager.Current.GetFileSystemProvider("macros");
|
||||
var serviceStackSerializer = new ServiceStackJsonSerializer();
|
||||
_serializationService = new SerializationService(serviceStackSerializer);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
internal class ScriptRepository : FileRepository<string, Script>, IScriptRepository
|
||||
{
|
||||
public ScriptRepository(IUnitOfWork work)
|
||||
: base(work, FileSystemProviderManager.Current.GetFileSystemProvider("script"))
|
||||
: base(work, FileSystemProviderManager.Current.GetFileSystemProvider("scripts"))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
internal class StylesheetRepository : FileRepository<string, Stylesheet>, IStylesheetRepository
|
||||
{
|
||||
public StylesheetRepository(IUnitOfWork work)
|
||||
: base(work, FileSystemProviderManager.Current.GetFileSystemProvider("stylesheet"))
|
||||
: base(work, FileSystemProviderManager.Current.GetFileSystemProvider("stylesheets"))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
@@ -13,28 +15,82 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// </summary>
|
||||
internal class TemplateRepository : FileRepository<string, Template>, ITemplateRepository
|
||||
{
|
||||
//TODO: Figure out how to deal with templates in either Masterpages or Views folders (or in both folders)
|
||||
private readonly IFileSystem _viewsFileSystem;
|
||||
|
||||
public TemplateRepository(IUnitOfWork work)
|
||||
: base(work, FileSystemProviderManager.Current.GetFileSystemProvider("template"))
|
||||
: base(work, FileSystemProviderManager.Current.GetFileSystemProvider("masterpages"))
|
||||
{
|
||||
_viewsFileSystem = FileSystemProviderManager.Current.GetFileSystemProvider("views");
|
||||
}
|
||||
|
||||
#region Overrides of FileRepository<string,Template>
|
||||
|
||||
public override void AddOrUpdate(Template entity)
|
||||
{
|
||||
var stream = new MemoryStream(Encoding.UTF8.GetBytes(entity.Content));
|
||||
if (UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc)
|
||||
{
|
||||
_viewsFileSystem.AddFile(entity.Name, stream, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
FileSystem.AddFile(entity.Name, stream, true);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Delete(Template entity)
|
||||
{
|
||||
//Check for file under the Masterpages filesystem
|
||||
if (FileSystem.FileExists(entity.Name))
|
||||
{
|
||||
FileSystem.DeleteFile(entity.Name);
|
||||
}
|
||||
else if (FileSystem.FileExists(entity.Path))
|
||||
{
|
||||
FileSystem.DeleteFile(entity.Path);
|
||||
}
|
||||
|
||||
//Check for file under the Views/Mvc filesystem
|
||||
if (_viewsFileSystem.FileExists(entity.Name))
|
||||
{
|
||||
_viewsFileSystem.DeleteFile(entity.Name);
|
||||
}
|
||||
else if (_viewsFileSystem.FileExists(entity.Path))
|
||||
{
|
||||
_viewsFileSystem.DeleteFile(entity.Path);
|
||||
}
|
||||
}
|
||||
|
||||
public override Template Get(string id)
|
||||
{
|
||||
if (!FileSystem.FileExists(id))
|
||||
if (!FileSystem.FileExists(id) && !_viewsFileSystem.FileExists(id))
|
||||
{
|
||||
throw new Exception(string.Format("The file {0} was not found", id));
|
||||
}
|
||||
|
||||
var stream = FileSystem.OpenFile(id);
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
stream.Position = 0;
|
||||
stream.Read(bytes, 0, (int)stream.Length);
|
||||
var content = Encoding.UTF8.GetString(bytes);
|
||||
string content = string.Empty;
|
||||
string path = string.Empty;
|
||||
|
||||
var path = FileSystem.GetRelativePath(id);
|
||||
if(FileSystem.FileExists(id))
|
||||
{
|
||||
var stream = FileSystem.OpenFile(id);
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
stream.Position = 0;
|
||||
stream.Read(bytes, 0, (int)stream.Length);
|
||||
content = Encoding.UTF8.GetString(bytes);
|
||||
|
||||
path = FileSystem.GetRelativePath(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
var stream = _viewsFileSystem.OpenFile(id);
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
stream.Position = 0;
|
||||
stream.Read(bytes, 0, (int)stream.Length);
|
||||
content = Encoding.UTF8.GetString(bytes);
|
||||
|
||||
path = _viewsFileSystem.GetRelativePath(id);
|
||||
}
|
||||
|
||||
var template = new Template(path) { Content = content };
|
||||
return template;
|
||||
@@ -51,7 +107,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
}
|
||||
else
|
||||
{
|
||||
var files = FileSystem.GetFiles("", "*");
|
||||
var files = FileSystem.GetFiles("", "*").ToList();
|
||||
files.AddRange(_viewsFileSystem.GetFiles("", "*"));
|
||||
foreach (var file in files)
|
||||
{
|
||||
yield return Get(file);
|
||||
@@ -59,6 +116,11 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Exists(string id)
|
||||
{
|
||||
return FileSystem.FileExists(id) || _viewsFileSystem.FileExists(id);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,38 @@
|
||||
<add key="virtualRoot" value="~/media/" />
|
||||
</Parameters>
|
||||
</Provider>
|
||||
|
||||
<!-- Macros -->
|
||||
<Provider alias="macros" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
|
||||
<Parameters>
|
||||
<add key="virtualRoot" value="~/app_data/macros/" />
|
||||
</Parameters>
|
||||
</Provider>
|
||||
|
||||
<!-- Scripts -->
|
||||
<Provider alias="scripts" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
|
||||
<Parameters>
|
||||
<add key="virtualRoot" value="~/scripts/" />
|
||||
</Parameters>
|
||||
</Provider>
|
||||
|
||||
<!-- Stylesheets -->
|
||||
<Provider alias="stylesheets" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
|
||||
<Parameters>
|
||||
<add key="virtualRoot" value="~/css/" />
|
||||
</Parameters>
|
||||
</Provider>
|
||||
|
||||
<!-- Templates -->
|
||||
<Provider alias="masterpages" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
|
||||
<Parameters>
|
||||
<add key="virtualRoot" value="~/masterpages/" />
|
||||
</Parameters>
|
||||
</Provider>
|
||||
<Provider alias="views" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
|
||||
<Parameters>
|
||||
<add key="virtualRoot" value="~/views/" />
|
||||
</Parameters>
|
||||
</Provider>
|
||||
|
||||
</FileSystemProviders>
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Umbraco.Web.Publishing
|
||||
return doc.PublishWithResult(user);
|
||||
}
|
||||
|
||||
internal bool PublishWithChildrenWithResult(int userId, int contentId)
|
||||
internal bool PublishWithChildren(int userId, int contentId)
|
||||
{
|
||||
var doc = new Document(contentId, true);
|
||||
var user = new User(userId);
|
||||
|
||||
Reference in New Issue
Block a user