Adds Stylesheet repository implementation U4-966
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public interface IStylesheetRepository : IRepository<string, Stylesheet>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the Stylesheet Repository
|
||||
/// </summary>
|
||||
internal class StylesheetRepository : FileRepository<string, Stylesheet>, IStylesheetRepository
|
||||
{
|
||||
public StylesheetRepository(IUnitOfWork work)
|
||||
: base(work, FileSystemProviderManager.Current.GetFileSystemProvider("stylesheet"))
|
||||
{
|
||||
}
|
||||
|
||||
#region Overrides of FileRepository<string,Stylesheet>
|
||||
|
||||
public override Stylesheet Get(string id)
|
||||
{
|
||||
if (!FileSystem.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);
|
||||
|
||||
var path = FileSystem.GetRelativePath(id);
|
||||
|
||||
var stylesheet = new Stylesheet(path) { Content = content };
|
||||
return stylesheet;
|
||||
}
|
||||
|
||||
public override IEnumerable<Stylesheet> GetAll(params string[] ids)
|
||||
{
|
||||
if (ids.Any())
|
||||
{
|
||||
foreach (var id in ids)
|
||||
{
|
||||
yield return Get(id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var files = FileSystem.GetFiles("", "*");
|
||||
foreach (var file in files)
|
||||
{
|
||||
yield return Get(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,12 @@ using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the Template Repository
|
||||
/// </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)
|
||||
public TemplateRepository(IUnitOfWork work)
|
||||
: base(work, FileSystemProviderManager.Current.GetFileSystemProvider("template"))
|
||||
{
|
||||
|
||||
@@ -134,6 +134,7 @@
|
||||
<Compile Include="Persistence\Relators\TabPropertyTypeRelator.cs" />
|
||||
<Compile Include="Persistence\Repositories\IScriptRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\IRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\IStylesheetRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\ITemplateRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\LanguageRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\MacroRepository.cs" />
|
||||
@@ -142,6 +143,7 @@
|
||||
<Compile Include="Persistence\Repositories\RelationTypeRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\RepositoryBase.cs" />
|
||||
<Compile Include="Persistence\Repositories\ScriptRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\StylesheetRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\TemplateRepository.cs" />
|
||||
<Compile Include="Persistence\RepositoryResolver.cs" />
|
||||
<Compile Include="Persistence\TransactionType.cs" />
|
||||
|
||||
Reference in New Issue
Block a user