Implements IFileService for U4-939
Updates TemplateRepository to treat the passed in string as an alias for a template that could be a master or a view.
This commit is contained in:
@@ -63,9 +63,11 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
public override Template Get(string id)
|
||||
{
|
||||
if (!FileSystem.FileExists(id) && !_viewsFileSystem.FileExists(id))
|
||||
string masterpageName = string.Concat(id, ".master");
|
||||
string viewName = string.Concat(id, ".cshtml");
|
||||
if (!FileSystem.FileExists(masterpageName) && !_viewsFileSystem.FileExists(viewName))
|
||||
{
|
||||
throw new Exception(string.Format("The file {0} was not found", id));
|
||||
throw new Exception(string.Format("The file with alias: '{0}' was not found", id));
|
||||
}
|
||||
|
||||
string content = string.Empty;
|
||||
@@ -74,28 +76,28 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
DateTime updated = new DateTime();
|
||||
string name = string.Empty;
|
||||
|
||||
if(FileSystem.FileExists(id))
|
||||
if (FileSystem.FileExists(masterpageName))
|
||||
{
|
||||
var stream = FileSystem.OpenFile(id);
|
||||
var stream = FileSystem.OpenFile(masterpageName);
|
||||
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);
|
||||
path = FileSystem.GetRelativePath(masterpageName);
|
||||
created = FileSystem.GetCreated(path).UtcDateTime;
|
||||
updated = FileSystem.GetLastModified(path).UtcDateTime;
|
||||
name = new FileInfo(path).Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
var stream = _viewsFileSystem.OpenFile(id);
|
||||
var stream = _viewsFileSystem.OpenFile(viewName);
|
||||
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);
|
||||
path = _viewsFileSystem.GetRelativePath(viewName);
|
||||
created = FileSystem.GetCreated(path).UtcDateTime;
|
||||
updated = FileSystem.GetLastModified(path).UtcDateTime;
|
||||
name = new FileInfo(path).Name;
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace Umbraco.Web.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the IDataType specified by it's unique ID
|
||||
/// Gets the <see cref="IDataType"/> specified by it's unique ID
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the DataType, which corresponds to the Guid Id of the control</param>
|
||||
/// <returns><see cref="IDataType"/> object</returns>
|
||||
@@ -131,7 +131,7 @@ namespace Umbraco.Web.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a complete list of all registered IDataType's
|
||||
/// Gets a complete list of all registered <see cref="IDataType"/>'s
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="IDataType"/> objects</returns>
|
||||
public IEnumerable<IDataType> GetAllDataTypes()
|
||||
|
||||
196
src/Umbraco.Web/Services/FileService.cs
Normal file
196
src/Umbraco.Web/Services/FileService.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
public class FileService : IFileService
|
||||
{
|
||||
private readonly IUnitOfWorkProvider _provider;
|
||||
|
||||
public FileService() : this(new PetaPocoUnitOfWorkProvider())
|
||||
{
|
||||
}
|
||||
|
||||
public FileService(IUnitOfWorkProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all <see cref="Stylesheet"/> objects
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="Stylesheet"/> objects</returns>
|
||||
public IEnumerable<Stylesheet> GetStylesheets(params string[] names)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<IStylesheetRepository, Stylesheet, string>(unitOfWork);
|
||||
return repository.GetAll(names);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Stylesheet"/> object by its name
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the stylesheet incl. extension</param>
|
||||
/// <returns>A <see cref="Stylesheet"/> object</returns>
|
||||
public Stylesheet GetStylesheetByName(string name)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<IStylesheetRepository, Stylesheet, string>(unitOfWork);
|
||||
return repository.Get(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a <see cref="Stylesheet"/>
|
||||
/// </summary>
|
||||
/// <param name="stylesheet"><see cref="Stylesheet"/> to save</param>
|
||||
public void SaveStylesheet(Stylesheet stylesheet)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<IStylesheetRepository, Stylesheet, string>(unitOfWork);
|
||||
repository.AddOrUpdate(stylesheet);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a stylesheet by its name
|
||||
/// </summary>
|
||||
/// <param name="name">Name incl. extension of the Stylesheet to delete</param>
|
||||
public void DeleteStylesheet(string name)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<IStylesheetRepository, Stylesheet, string>(unitOfWork);
|
||||
var stylesheet = repository.Get(name);
|
||||
repository.Delete(stylesheet);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates a <see cref="Stylesheet"/>
|
||||
/// </summary>
|
||||
/// <param name="stylesheet"><see cref="Stylesheet"/> to validate</param>
|
||||
/// <returns>True if Stylesheet is valid, otherwise false</returns>
|
||||
public bool ValidateStylesheet(Stylesheet stylesheet)
|
||||
{
|
||||
return stylesheet.IsValid() && stylesheet.IsFileValidCss();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all <see cref="Script"/> objects
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="Script"/> objects</returns>
|
||||
public IEnumerable<Script> GetScripts(params string[] names)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<IScriptRepository, Script, string>(unitOfWork);
|
||||
return repository.GetAll(names);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Script"/> object by its name
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the script incl. extension</param>
|
||||
/// <returns>A <see cref="Script"/> object</returns>
|
||||
public Script GetScriptByName(string name)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<IScriptRepository, Script, string>(unitOfWork);
|
||||
return repository.Get(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a <see cref="Script"/>
|
||||
/// </summary>
|
||||
/// <param name="script"><see cref="Script"/> to save</param>
|
||||
public void SaveScript(Script script)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<IScriptRepository, Script, string>(unitOfWork);
|
||||
repository.AddOrUpdate(script);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a script by its name
|
||||
/// </summary>
|
||||
/// <param name="name">Name incl. extension of the Script to delete</param>
|
||||
public void DeleteScript(string name)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<IScriptRepository, Script, string>(unitOfWork);
|
||||
var script = repository.Get(name);
|
||||
repository.Delete(script);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates a <see cref="Script"/>
|
||||
/// </summary>
|
||||
/// <param name="script"><see cref="Script"/> to validate</param>
|
||||
/// <returns>True if Script is valid, otherwise false</returns>
|
||||
public bool ValidateScript(Script script)
|
||||
{
|
||||
return script.IsValid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all <see cref="Template"/> objects
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="Template"/> objects</returns>
|
||||
public IEnumerable<Template> GetTemplates(params string[] aliases)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<ITemplateRepository, Template, string>(unitOfWork);
|
||||
return repository.GetAll(aliases);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Template"/> object by its alias
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias of the template</param>
|
||||
/// <returns>A <see cref="Template"/> object</returns>
|
||||
public Template GetTemplateByAlias(string alias)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<ITemplateRepository, Template, string>(unitOfWork);
|
||||
return repository.Get(alias);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a <see cref="Template"/>
|
||||
/// </summary>
|
||||
/// <param name="template"><see cref="Template"/> to save</param>
|
||||
public void SaveTemplate(Template template)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<ITemplateRepository, Template, string>(unitOfWork);
|
||||
repository.AddOrUpdate(template);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a template by its alias
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias of the <see cref="Template"/> to delete</param>
|
||||
public void DeleteTemplate(string alias)
|
||||
{
|
||||
var unitOfWork = _provider.GetUnitOfWork();
|
||||
var repository = RepositoryResolver.ResolveByType<ITemplateRepository, Template, string>(unitOfWork);
|
||||
var template = repository.Get(alias);
|
||||
repository.Delete(template);
|
||||
unitOfWork.Commit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates a <see cref="Template"/>
|
||||
/// </summary>
|
||||
/// <param name="template"><see cref="Template"/> to validate</param>
|
||||
/// <returns>True if Script is valid, otherwise false</returns>
|
||||
public bool ValidateTemplate(Template template)
|
||||
{
|
||||
return template.IsValid();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,14 +50,14 @@ namespace Umbraco.Web.Services
|
||||
void Delete(IDataTypeDefinition dataTypeDefinition, int userId);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the IDataType specified by it's unique ID
|
||||
/// Gets the <see cref="IDataType"/> specified by it's unique ID
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the DataType, which corresponds to the Guid Id of the control</param>
|
||||
/// <returns><see cref="IDataType"/> object</returns>
|
||||
IDataType GetDataTypeById(Guid id);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a complete list of all registered IDataType's
|
||||
/// Gets a complete list of all registered <see cref="IDataType"/>'s
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="IDataType"/> objects</returns>
|
||||
IEnumerable<IDataType> GetAllDataTypes();
|
||||
|
||||
107
src/Umbraco.Web/Services/IFileService.cs
Normal file
107
src/Umbraco.Web/Services/IFileService.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the File Service, which is an easy access to operations involving <see cref="IFile"/> objects like Scripts, Stylesheets and Templates
|
||||
/// </summary>
|
||||
public interface IFileService : IService
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a list of all <see cref="Stylesheet"/> objects
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="Stylesheet"/> objects</returns>
|
||||
IEnumerable<Stylesheet> GetStylesheets(params string[] names);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Stylesheet"/> object by its name
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the stylesheet incl. extension</param>
|
||||
/// <returns>A <see cref="Stylesheet"/> object</returns>
|
||||
Stylesheet GetStylesheetByName(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Saves a <see cref="Stylesheet"/>
|
||||
/// </summary>
|
||||
/// <param name="stylesheet"><see cref="Stylesheet"/> to save</param>
|
||||
void SaveStylesheet(Stylesheet stylesheet);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a stylesheet by its name
|
||||
/// </summary>
|
||||
/// <param name="name">Name incl. extension of the Stylesheet to delete</param>
|
||||
void DeleteStylesheet(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Validates a <see cref="Stylesheet"/>
|
||||
/// </summary>
|
||||
/// <param name="stylesheet"><see cref="Stylesheet"/> to validate</param>
|
||||
/// <returns>True if Stylesheet is valid, otherwise false</returns>
|
||||
bool ValidateStylesheet(Stylesheet stylesheet);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all <see cref="Script"/> objects
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="Script"/> objects</returns>
|
||||
IEnumerable<Script> GetScripts(params string[] names);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Script"/> object by its name
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the script incl. extension</param>
|
||||
/// <returns>A <see cref="Script"/> object</returns>
|
||||
Script GetScriptByName(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Saves a <see cref="Script"/>
|
||||
/// </summary>
|
||||
/// <param name="script"><see cref="Script"/> to save</param>
|
||||
void SaveScript(Script script);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a script by its name
|
||||
/// </summary>
|
||||
/// <param name="name">Name incl. extension of the Script to delete</param>
|
||||
void DeleteScript(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Validates a <see cref="Script"/>
|
||||
/// </summary>
|
||||
/// <param name="script"><see cref="Script"/> to validate</param>
|
||||
/// <returns>True if Script is valid, otherwise false</returns>
|
||||
bool ValidateScript(Script script);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all <see cref="Template"/> objects
|
||||
/// </summary>
|
||||
/// <returns>An enumerable list of <see cref="Template"/> objects</returns>
|
||||
IEnumerable<Template> GetTemplates(params string[] aliases);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Template"/> object by its alias
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias of the template</param>
|
||||
/// <returns>A <see cref="Template"/> object</returns>
|
||||
Template GetTemplateByAlias(string alias);
|
||||
|
||||
/// <summary>
|
||||
/// Saves a <see cref="Template"/>
|
||||
/// </summary>
|
||||
/// <param name="template"><see cref="Template"/> to save</param>
|
||||
void SaveTemplate(Template template);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a template by its alias
|
||||
/// </summary>
|
||||
/// <param name="alias">Alias of the <see cref="Template"/> to delete</param>
|
||||
void DeleteTemplate(string alias);
|
||||
|
||||
/// <summary>
|
||||
/// Validates a <see cref="Template"/>
|
||||
/// </summary>
|
||||
/// <param name="template"><see cref="Template"/> to validate</param>
|
||||
/// <returns>True if Script is valid, otherwise false</returns>
|
||||
bool ValidateTemplate(Template template);
|
||||
}
|
||||
}
|
||||
10
src/Umbraco.Web/Services/ILocalizationService.cs
Normal file
10
src/Umbraco.Web/Services/ILocalizationService.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the Localization Service, which is an easy access to operations involving Languages and Dictionary
|
||||
/// </summary>
|
||||
public interface ILocalizationService : IService
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using Umbraco.Core.Models;
|
||||
namespace Umbraco.Web.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the MediaService, which is an easy access to operations involving <see cref="IMedia"/>
|
||||
/// Defines the Media Service, which is an easy access to operations involving <see cref="IMedia"/>
|
||||
/// </summary>
|
||||
public interface IMediaService : IService
|
||||
{
|
||||
|
||||
@@ -316,9 +316,12 @@
|
||||
<Compile Include="Services\ContentService.cs" />
|
||||
<Compile Include="Services\ContentTypeService.cs" />
|
||||
<Compile Include="Services\DataTypeService.cs" />
|
||||
<Compile Include="Services\FileService.cs" />
|
||||
<Compile Include="Services\IContentService.cs" />
|
||||
<Compile Include="Services\IContentTypeService.cs" />
|
||||
<Compile Include="Services\IDataTypeService.cs" />
|
||||
<Compile Include="Services\IFileService.cs" />
|
||||
<Compile Include="Services\ILocalizationService.cs" />
|
||||
<Compile Include="Services\IMediaService.cs" />
|
||||
<Compile Include="Services\IService.cs" />
|
||||
<Compile Include="Services\MediaService.cs" />
|
||||
|
||||
Reference in New Issue
Block a user