Adds Script repository and some edits to the Script model U4-965
Refactoring RepositoryResolver to use the base repository instead of the Queryable repo.
This commit is contained in:
@@ -34,15 +34,15 @@ namespace Umbraco.Core.Models
|
||||
//See codeEditorSave.asmx.cs for reference.
|
||||
|
||||
var exts = UmbracoSettings.ScriptFileTypes.Split(',').ToList();
|
||||
if (UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc)
|
||||
/*if (UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc)
|
||||
{
|
||||
exts.Add("cshtml");
|
||||
exts.Add("vbhtml");
|
||||
}
|
||||
}*/
|
||||
|
||||
var dirs = SystemDirectories.Scripts;
|
||||
if (UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc)
|
||||
dirs += "," + SystemDirectories.MvcViews;
|
||||
/*if (UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc)
|
||||
dirs += "," + SystemDirectories.MvcViews;*/
|
||||
|
||||
//Validate file
|
||||
var validFile = IOHelper.ValidateEditPath(Path, dirs.Split(','));
|
||||
|
||||
100
src/Umbraco.Core/Persistence/Repositories/ScriptRepository.cs
Normal file
100
src/Umbraco.Core/Persistence/Repositories/ScriptRepository.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
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 Script Repository
|
||||
/// </summary>
|
||||
internal class ScriptRepository : IScriptRepository
|
||||
{
|
||||
private IUnitOfWork _work;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
public ScriptRepository(IUnitOfWork work)
|
||||
{
|
||||
_work = work;
|
||||
_fileSystem = FileSystemProviderManager.Current.GetFileSystemProvider("script");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Unit of Work added to the repository
|
||||
/// </summary>
|
||||
protected IUnitOfWork UnitOfWork
|
||||
{
|
||||
get { return _work; }
|
||||
}
|
||||
|
||||
#region Implementation of IRepository<string,Script>
|
||||
|
||||
public void AddOrUpdate(Script entity)
|
||||
{
|
||||
var stream = new MemoryStream(Encoding.UTF8.GetBytes(entity.Content));
|
||||
_fileSystem.AddFile(entity.Name, stream, true);
|
||||
}
|
||||
|
||||
public void Delete(Script entity)
|
||||
{
|
||||
if (_fileSystem.FileExists(entity.Name))
|
||||
{
|
||||
_fileSystem.DeleteFile(entity.Name);
|
||||
}
|
||||
}
|
||||
|
||||
public Script 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 script = new Script(path) {Content = content};
|
||||
return script;
|
||||
}
|
||||
|
||||
public IEnumerable<Script> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Exists(string id)
|
||||
{
|
||||
return _fileSystem.FileExists(id);
|
||||
}
|
||||
|
||||
public void SetUnitOfWork(IUnitOfWork work)
|
||||
{
|
||||
_work = work;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Configuration.Repositories;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
@@ -23,8 +22,8 @@ namespace Umbraco.Core.Persistence
|
||||
//- If type exists check dependencies, create new object, add it to dictionary and return it
|
||||
//If we have come this far the correct types wasn't found and we throw an exception
|
||||
internal static TRepository ResolveByType<TRepository, TEntity, TId>(IUnitOfWork unitOfWork)
|
||||
where TRepository : class, IRepositoryQueryable<TId, TEntity>
|
||||
where TEntity : class, IAggregateRoot
|
||||
where TRepository : class, IRepository<TId, TEntity>
|
||||
where TEntity : class
|
||||
{
|
||||
//Initialize the provider's default value
|
||||
TRepository repository = default(TRepository);
|
||||
@@ -36,7 +35,7 @@ namespace Umbraco.Core.Persistence
|
||||
if (Repositories.ContainsKey(interfaceShortName))
|
||||
{
|
||||
repository = (TRepository)Repositories[interfaceShortName];
|
||||
if (unitOfWork != null && repository.GetType().IsSubclassOf(typeof(IRepositoryQueryable<TId, TEntity>)))
|
||||
if (unitOfWork != null && repository.GetType().IsSubclassOf(typeof(IRepository<TId, TEntity>)))
|
||||
{
|
||||
repository.SetUnitOfWork(unitOfWork);
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@
|
||||
<Compile Include="Persistence\Repositories\RelationRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\RelationTypeRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\RepositoryBase.cs" />
|
||||
<Compile Include="Persistence\Repositories\ScriptRepository.cs" />
|
||||
<Compile Include="Persistence\RepositoryResolver.cs" />
|
||||
<Compile Include="Persistence\TransactionType.cs" />
|
||||
<Compile Include="Persistence\UnitOfWork\FileUnitOfWork.cs" />
|
||||
|
||||
Reference in New Issue
Block a user