Fixes: U4-6088 Publicize all partial view methods on IFileService & U4-6087 Fix Partial View macro repository usage so that when a macro is created from the FileService, the MacroService events are raised
Conflicts: src/Umbraco.Core/Umbraco.Core.csproj
This commit is contained in:
7
src/Umbraco.Core/Models/IPartialView.cs
Normal file
7
src/Umbraco.Core/Models/IPartialView.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
public interface IPartialView : IFile
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ using System.Runtime.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models.EntityBase;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
{
|
||||
@@ -48,7 +49,7 @@ namespace Umbraco.Core.Models
|
||||
Id = id;
|
||||
UseInEditor = useInEditor;
|
||||
CacheDuration = cacheDuration;
|
||||
Alias = alias;
|
||||
Alias = alias.ToCleanString(CleanStringType.Alias);
|
||||
Name = name;
|
||||
ControlType = controlType;
|
||||
ControlAssembly = controlAssembly;
|
||||
@@ -87,7 +88,7 @@ namespace Umbraco.Core.Models
|
||||
{
|
||||
UseInEditor = useInEditor;
|
||||
CacheDuration = cacheDuration;
|
||||
Alias = alias;
|
||||
Alias = alias.ToCleanString(CleanStringType.Alias);
|
||||
Name = name;
|
||||
ControlType = controlType;
|
||||
ControlAssembly = controlAssembly;
|
||||
@@ -207,7 +208,7 @@ namespace Umbraco.Core.Models
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
_alias = value;
|
||||
_alias = value.ToCleanString(CleanStringType.Alias);
|
||||
return _alias;
|
||||
}, _alias, AliasSelector);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[DataContract(IsReference = true)]
|
||||
internal class PartialView : File
|
||||
public class PartialView : File, IPartialView
|
||||
{
|
||||
//public PartialView(): base(string.Empty)
|
||||
//{
|
||||
|
||||
@@ -33,12 +33,12 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
get { return _fileSystem; }
|
||||
}
|
||||
|
||||
internal virtual void AddFolder(string folderPath)
|
||||
public virtual void AddFolder(string folderPath)
|
||||
{
|
||||
_work.RegisterAdded(new Folder(folderPath), this);
|
||||
}
|
||||
|
||||
internal virtual void DeleteFolder(string folderPath)
|
||||
public virtual void DeleteFolder(string folderPath)
|
||||
{
|
||||
_work.RegisterRemoved(new Folder(folderPath), this);
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
internal interface IPartialViewMacroRepository : IPartialViewRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds or Updates an associated macro
|
||||
/// </summary>
|
||||
/// <param name="macro"></param>
|
||||
void AddOrUpdate(IMacro macro);
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
internal interface IPartialViewRepository : IRepository<string, PartialView>
|
||||
internal interface IPartialViewRepository : IRepository<string, IPartialView>
|
||||
{
|
||||
|
||||
void AddFolder(string folderPath);
|
||||
void DeleteFolder(string folderPath);
|
||||
}
|
||||
}
|
||||
@@ -5,37 +5,18 @@ using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
internal class PartialViewMacroRepository : PartialViewRepository, IPartialViewMacroRepository
|
||||
internal class PartialViewMacroRepository : PartialViewRepository
|
||||
{
|
||||
private readonly IMacroRepository _macroRepository;
|
||||
|
||||
public PartialViewMacroRepository(IUnitOfWork work, IMacroRepository macroRepository)
|
||||
: this(work, new PhysicalFileSystem(SystemDirectories.MvcViews + "/MacroPartials/"), macroRepository)
|
||||
public PartialViewMacroRepository(IUnitOfWork work)
|
||||
: this(work, new PhysicalFileSystem(SystemDirectories.MvcViews + "/MacroPartials/"))
|
||||
{
|
||||
}
|
||||
|
||||
public PartialViewMacroRepository(IUnitOfWork work, IFileSystem fileSystem, IMacroRepository macroRepository)
|
||||
public PartialViewMacroRepository(IUnitOfWork work, IFileSystem fileSystem)
|
||||
: base(work, fileSystem)
|
||||
{
|
||||
_macroRepository = macroRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure the macro repo is disposed which contains a database UOW
|
||||
/// </summary>
|
||||
protected override void DisposeResources()
|
||||
{
|
||||
base.DisposeResources();
|
||||
_macroRepository.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds or updates a macro associated with the partial view
|
||||
/// </summary>
|
||||
/// <param name="macro"></param>
|
||||
public void AddOrUpdate(IMacro macro)
|
||||
{
|
||||
_macroRepository.AddOrUpdate(macro);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using Umbraco.Core.Persistence.UnitOfWork;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
internal class PartialViewRepository : FileRepository<string, PartialView>, IPartialViewRepository
|
||||
internal class PartialViewRepository : FileRepository<string, IPartialView>, IPartialViewRepository
|
||||
{
|
||||
public PartialViewRepository(IUnitOfWork work)
|
||||
: this(work, new PhysicalFileSystem(SystemDirectories.MvcViews + "/Partials/"))
|
||||
@@ -20,7 +20,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
}
|
||||
|
||||
public override PartialView Get(string id)
|
||||
public override IPartialView Get(string id)
|
||||
{
|
||||
if (FileSystem.FileExists(id) == false)
|
||||
{
|
||||
@@ -59,7 +59,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
return script;
|
||||
}
|
||||
|
||||
public override IEnumerable<PartialView> GetAll(params string[] ids)
|
||||
public override IEnumerable<IPartialView> GetAll(params string[] ids)
|
||||
{
|
||||
//ensure they are de-duplicated, easy win if people don't do this as this can cause many excess queries
|
||||
ids = ids.Distinct().ToArray();
|
||||
|
||||
@@ -149,9 +149,9 @@ namespace Umbraco.Core.Persistence
|
||||
return new PartialViewRepository(uow);
|
||||
}
|
||||
|
||||
internal virtual IPartialViewMacroRepository CreatePartialViewMacroRepository(IUnitOfWork uow, IDatabaseUnitOfWork duow)
|
||||
internal virtual IPartialViewRepository CreatePartialViewMacroRepository(IUnitOfWork uow)
|
||||
{
|
||||
return new PartialViewMacroRepository(uow, CreateMacroRepository(duow));
|
||||
return new PartialViewMacroRepository(uow);
|
||||
}
|
||||
|
||||
public virtual IStylesheetRepository CreateStylesheetRepository(IUnitOfWork uow, IDatabaseUnitOfWork db)
|
||||
|
||||
@@ -388,7 +388,7 @@ namespace Umbraco.Core.Services
|
||||
|
||||
#region Partial Views
|
||||
|
||||
internal IEnumerable<string> GetPartialViewSnippetNames(params string[] filterNames)
|
||||
public IEnumerable<string> GetPartialViewSnippetNames(params string[] filterNames)
|
||||
{
|
||||
var snippetPath = IOHelper.MapPath(string.Format("{0}/PartialViewMacros/Templates/", SystemDirectories.Umbraco));
|
||||
var files = Directory.GetFiles(snippetPath, "*.cshtml")
|
||||
@@ -404,7 +404,7 @@ namespace Umbraco.Core.Services
|
||||
return empty.Union(files.Except(empty));
|
||||
}
|
||||
|
||||
internal void DeletePartialViewFolder(string folderPath)
|
||||
public void DeletePartialViewFolder(string folderPath)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreatePartialViewRepository(uow))
|
||||
@@ -414,18 +414,17 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
internal void DeletePartialViewMacroFolder(string folderPath)
|
||||
public void DeletePartialViewMacroFolder(string folderPath)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
var duow = _dataUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreatePartialViewMacroRepository(uow, duow))
|
||||
using (var repository = _repositoryFactory.CreatePartialViewMacroRepository(uow))
|
||||
{
|
||||
((PartialViewMacroRepository)repository).DeleteFolder(folderPath);
|
||||
uow.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
internal PartialView GetPartialView(string path)
|
||||
public IPartialView GetPartialView(string path)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreatePartialViewRepository(_fileUowProvider.GetUnitOfWork()))
|
||||
{
|
||||
@@ -433,20 +432,44 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
internal PartialView GetPartialViewMacro(string path)
|
||||
public IPartialView GetPartialViewMacro(string path)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreatePartialViewMacroRepository(
|
||||
_fileUowProvider.GetUnitOfWork(),
|
||||
_dataUowProvider.GetUnitOfWork()))
|
||||
using (var repository = _repositoryFactory.CreatePartialViewMacroRepository(_fileUowProvider.GetUnitOfWork()))
|
||||
{
|
||||
return repository.Get(path);
|
||||
}
|
||||
}
|
||||
|
||||
internal Attempt<PartialView> CreatePartialView(PartialView partialView, string snippetName = null, int userId = 0)
|
||||
public Attempt<IPartialView> CreatePartialView(IPartialView partialView, string snippetName = null, int userId = 0)
|
||||
{
|
||||
if (CreatingPartialView.IsRaisedEventCancelled(new NewEventArgs<PartialView>(partialView, true, partialView.Alias, -1), this))
|
||||
return Attempt<PartialView>.Fail();
|
||||
return CreatePartialViewMacro(partialView, PartialViewType.PartialView, snippetName, userId);
|
||||
}
|
||||
|
||||
public Attempt<IPartialView> CreatePartialViewMacro(IPartialView partialView, string snippetName = null, int userId = 0)
|
||||
{
|
||||
return CreatePartialViewMacro(partialView, PartialViewType.PartialViewMacro, snippetName, userId);
|
||||
}
|
||||
|
||||
private Attempt<IPartialView> CreatePartialViewMacro(IPartialView partialView, PartialViewType partialViewType, string snippetName = null, int userId = 0)
|
||||
{
|
||||
if (CreatingPartialView.IsRaisedEventCancelled(new NewEventArgs<IPartialView>(partialView, true, partialView.Alias, -1), this))
|
||||
return Attempt<IPartialView>.Fail();
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
string partialViewHeader = null;
|
||||
IPartialViewRepository repository;
|
||||
switch (partialViewType)
|
||||
{
|
||||
case PartialViewType.PartialView:
|
||||
repository = _repositoryFactory.CreatePartialViewRepository(uow);
|
||||
partialViewHeader = PartialViewHeader;
|
||||
break;
|
||||
case PartialViewType.PartialViewMacro:
|
||||
default:
|
||||
repository = _repositoryFactory.CreatePartialViewMacroRepository(uow);
|
||||
partialViewHeader = PartialViewMacroHeader;
|
||||
break;
|
||||
}
|
||||
|
||||
if (snippetName.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
@@ -463,213 +486,114 @@ namespace Umbraco.Core.Services
|
||||
|
||||
//strip the @inherits if it's there
|
||||
snippetContent = StripPartialViewHeader(snippetContent);
|
||||
|
||||
var content = string.Format("{0}{1}{2}", PartialViewHeader, Environment.NewLine, snippetContent);
|
||||
|
||||
var content = string.Format("{0}{1}{2}",
|
||||
partialViewHeader,
|
||||
Environment.NewLine, snippetContent);
|
||||
partialView.Content = content;
|
||||
}
|
||||
}
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreatePartialViewRepository(uow))
|
||||
using (repository)
|
||||
{
|
||||
repository.AddOrUpdate(partialView);
|
||||
uow.Commit();
|
||||
|
||||
CreatedPartialView.RaiseEvent(new NewEventArgs<PartialView>(partialView, false, partialView.Alias, -1), this);
|
||||
CreatedPartialView.RaiseEvent(new NewEventArgs<IPartialView>(partialView, false, partialView.Alias, -1), this);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save PartialView performed by user"), userId, -1);
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save {0} performed by user", partialViewType), userId, -1);
|
||||
|
||||
return Attempt<PartialView>.Succeed(partialView);
|
||||
return Attempt<IPartialView>.Succeed(partialView);
|
||||
}
|
||||
|
||||
internal Attempt<PartialView> CreatePartialViewMacro(PartialView partialView, bool createMacro, string snippetName = null, int userId = 0)
|
||||
public bool DeletePartialView(string path, int userId = 0)
|
||||
{
|
||||
if (CreatingPartialView.IsRaisedEventCancelled(new NewEventArgs<PartialView>(partialView, true, partialView.Alias, -1), this))
|
||||
return Attempt<PartialView>.Fail();
|
||||
|
||||
if (snippetName.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
//create the file
|
||||
var snippetPathAttempt = TryGetSnippetPath(snippetName);
|
||||
if (snippetPathAttempt.Success == false)
|
||||
{
|
||||
throw new InvalidOperationException("Could not load snippet with name " + snippetName);
|
||||
}
|
||||
|
||||
using (var snippetFile = new StreamReader(System.IO.File.OpenRead(snippetPathAttempt.Result)))
|
||||
{
|
||||
var snippetContent = snippetFile.ReadToEnd().Trim();
|
||||
|
||||
//strip the @inherits if it's there
|
||||
snippetContent = StripPartialViewHeader(snippetContent);
|
||||
|
||||
var content = string.Format("{0}{1}{2}", PartialViewMacroHeader, Environment.NewLine, snippetContent);
|
||||
partialView.Content = content;
|
||||
}
|
||||
}
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
var duow = _dataUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreatePartialViewMacroRepository(uow, duow))
|
||||
{
|
||||
repository.AddOrUpdate(partialView);
|
||||
|
||||
if (createMacro)
|
||||
{
|
||||
var name = Path.GetFileNameWithoutExtension(partialView.Path)
|
||||
.SplitPascalCasing()
|
||||
.ToFirstUpperInvariant()
|
||||
.ToSafeAlias(false);
|
||||
|
||||
//The partial view path to be saved with the macro must be a fully qualified virtual path
|
||||
var virtualPath = string.Format("{0}/{1}/{2}", SystemDirectories.MvcViews, "MacroPartials", partialView.Path);
|
||||
|
||||
repository.AddOrUpdate(new Macro(name, name) { ScriptPath = virtualPath });
|
||||
}
|
||||
|
||||
//commit both - ensure that the macro is created if one was added
|
||||
uow.Commit();
|
||||
duow.Commit();
|
||||
|
||||
CreatedPartialView.RaiseEvent(new NewEventArgs<PartialView>(partialView, false, partialView.Alias, -1), this);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save PartialViewMacro performed by user"), userId, -1);
|
||||
|
||||
return Attempt<PartialView>.Succeed(partialView);
|
||||
return DeletePartialViewMacro(path, PartialViewType.PartialView, userId);
|
||||
}
|
||||
|
||||
internal bool DeletePartialView(string path, int userId = 0)
|
||||
public bool DeletePartialViewMacro(string path, int userId = 0)
|
||||
{
|
||||
return DeletePartialViewMacro(path, PartialViewType.PartialViewMacro, userId);
|
||||
}
|
||||
|
||||
private bool DeletePartialViewMacro(string path, PartialViewType partialViewType, int userId = 0)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreatePartialViewRepository(uow))
|
||||
|
||||
IPartialViewRepository repository;
|
||||
switch (partialViewType)
|
||||
{
|
||||
case PartialViewType.PartialView:
|
||||
repository = _repositoryFactory.CreatePartialViewRepository(uow);
|
||||
break;
|
||||
case PartialViewType.PartialViewMacro:
|
||||
default:
|
||||
repository = _repositoryFactory.CreatePartialViewMacroRepository(uow);
|
||||
break;
|
||||
}
|
||||
|
||||
using (repository)
|
||||
{
|
||||
var partialView = repository.Get(path);
|
||||
if (partialView == null)
|
||||
return true;
|
||||
|
||||
if (DeletingPartialView.IsRaisedEventCancelled(new DeleteEventArgs<PartialView>(partialView), this))
|
||||
if (DeletingPartialView.IsRaisedEventCancelled(new DeleteEventArgs<IPartialView>(partialView), this))
|
||||
return false;
|
||||
|
||||
repository.Delete(partialView);
|
||||
uow.Commit();
|
||||
|
||||
DeletedPartialView.RaiseEvent(new DeleteEventArgs<PartialView>(partialView, false), this);
|
||||
DeletedPartialView.RaiseEvent(new DeleteEventArgs<IPartialView>(partialView, false), this);
|
||||
|
||||
Audit.Add(AuditTypes.Delete, string.Format("Delete PartialView performed by user"), userId, -1);
|
||||
Audit.Add(AuditTypes.Delete, string.Format("Delete {0} performed by user", partialViewType), userId, -1);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
internal bool DeletePartialViewMacro(string path, int userId = 0)
|
||||
public Attempt<IPartialView> SavePartialView(IPartialView partialView, int userId = 0)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
var duow = _dataUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreatePartialViewMacroRepository(uow, duow))
|
||||
{
|
||||
var partialView = repository.Get(path);
|
||||
if (partialView == null)
|
||||
return true;
|
||||
|
||||
if (DeletingPartialView.IsRaisedEventCancelled(new DeleteEventArgs<PartialView>(partialView), this))
|
||||
return false;
|
||||
|
||||
repository.Delete(partialView);
|
||||
|
||||
//commit both (though in the case of deleting, there's no db changes)
|
||||
uow.Commit();
|
||||
duow.Commit();
|
||||
|
||||
DeletedPartialView.RaiseEvent(new DeleteEventArgs<PartialView>(partialView, false), this);
|
||||
|
||||
Audit.Add(AuditTypes.Delete, string.Format("Delete PartialViewMacro performed by user"), userId, -1);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
return SavePartialView(partialView, PartialViewType.PartialView, userId);
|
||||
}
|
||||
|
||||
internal Attempt<PartialView> SavePartialView(PartialView partialView, int userId = 0)
|
||||
public Attempt<IPartialView> SavePartialViewMacro(IPartialView partialView, int userId = 0)
|
||||
{
|
||||
if (SavingPartialView.IsRaisedEventCancelled(new SaveEventArgs<PartialView>(partialView), this))
|
||||
return Attempt<PartialView>.Fail();
|
||||
return SavePartialView(partialView, PartialViewType.PartialViewMacro, userId);
|
||||
}
|
||||
|
||||
private Attempt<IPartialView> SavePartialView(IPartialView partialView, PartialViewType partialViewType, int userId = 0)
|
||||
{
|
||||
if (SavingPartialView.IsRaisedEventCancelled(new SaveEventArgs<IPartialView>(partialView), this))
|
||||
return Attempt<IPartialView>.Fail();
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreatePartialViewRepository(uow))
|
||||
|
||||
IPartialViewRepository repository;
|
||||
switch (partialViewType)
|
||||
{
|
||||
case PartialViewType.PartialView:
|
||||
repository = _repositoryFactory.CreatePartialViewRepository(uow);
|
||||
break;
|
||||
case PartialViewType.PartialViewMacro:
|
||||
default:
|
||||
repository = _repositoryFactory.CreatePartialViewMacroRepository(uow);
|
||||
break;
|
||||
}
|
||||
|
||||
using (repository)
|
||||
{
|
||||
repository.AddOrUpdate(partialView);
|
||||
uow.Commit();
|
||||
|
||||
SavedPartialView.RaiseEvent(new SaveEventArgs<PartialView>(partialView, false), this);
|
||||
SavedPartialView.RaiseEvent(new SaveEventArgs<IPartialView>(partialView, false), this);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save PartialView performed by user"), userId, -1);
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save {0} performed by user", partialViewType), userId, -1);
|
||||
|
||||
////NOTE: I've left the below here just for informational purposes. If we save a file this way, then the UTF8
|
||||
//// BOM mucks everything up, strangely, if we use WriteAllText everything is ok!
|
||||
//// http://issues.umbraco.org/issue/U4-2118
|
||||
////using (var sw = System.IO.File.CreateText(savePath))
|
||||
////{
|
||||
//// sw.Write(val);
|
||||
////}
|
||||
|
||||
//System.IO.File.WriteAllText(partialView.Path, partialView.Content, Encoding.UTF8);
|
||||
////deletes the old file
|
||||
//if (partialView.FileName != partialView.OldFileName)
|
||||
//{
|
||||
// // Create a new PartialView class so that we can set the FileName of the file that needs deleting
|
||||
// var deletePartial = partialView;
|
||||
// deletePartial.FileName = partialView.OldFileName;
|
||||
// DeletePartialView(deletePartial, userId);
|
||||
//}
|
||||
|
||||
//SavedPartialView.RaiseEvent(new SaveEventArgs<PartialView>(partialView), this);
|
||||
|
||||
return Attempt.Succeed(partialView);
|
||||
}
|
||||
|
||||
internal Attempt<PartialView> SavePartialViewMacro(PartialView partialView, int userId = 0)
|
||||
{
|
||||
if (SavingPartialView.IsRaisedEventCancelled(new SaveEventArgs<PartialView>(partialView), this))
|
||||
return Attempt<PartialView>.Fail();
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
var duow = _dataUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreatePartialViewMacroRepository(uow, duow))
|
||||
{
|
||||
repository.AddOrUpdate(partialView);
|
||||
|
||||
//commit both (though in the case of updating, there's no db changes)
|
||||
uow.Commit();
|
||||
duow.Commit();
|
||||
|
||||
SavedPartialView.RaiseEvent(new SaveEventArgs<PartialView>(partialView, false), this);
|
||||
}
|
||||
|
||||
Audit.Add(AuditTypes.Save, string.Format("Save PartialViewMacro performed by user"), userId, -1);
|
||||
|
||||
////NOTE: I've left the below here just for informational purposes. If we save a file this way, then the UTF8
|
||||
//// BOM mucks everything up, strangely, if we use WriteAllText everything is ok!
|
||||
//// http://issues.umbraco.org/issue/U4-2118
|
||||
////using (var sw = System.IO.File.CreateText(savePath))
|
||||
////{
|
||||
//// sw.Write(val);
|
||||
////}
|
||||
|
||||
//System.IO.File.WriteAllText(partialView.Path, partialView.Content, Encoding.UTF8);
|
||||
////deletes the old file
|
||||
//if (partialView.FileName != partialView.OldFileName)
|
||||
//{
|
||||
// // Create a new PartialView class so that we can set the FileName of the file that needs deleting
|
||||
// var deletePartial = partialView;
|
||||
// deletePartial.FileName = partialView.OldFileName;
|
||||
// DeletePartialView(deletePartial, userId);
|
||||
//}
|
||||
|
||||
//SavedPartialView.RaiseEvent(new SaveEventArgs<PartialView>(partialView), this);
|
||||
SavedPartialView.RaiseEvent(new SaveEventArgs<IPartialView>(partialView), this);
|
||||
|
||||
return Attempt.Succeed(partialView);
|
||||
}
|
||||
@@ -696,7 +620,14 @@ namespace Umbraco.Core.Services
|
||||
return System.IO.File.Exists(snippetPath)
|
||||
? Attempt<string>.Succeed(snippetPath)
|
||||
: Attempt<string>.Fail();
|
||||
}
|
||||
}
|
||||
|
||||
private enum PartialViewType
|
||||
{
|
||||
PartialView,
|
||||
PartialViewMacro
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//TODO Method to change name and/or alias of view/masterpage template
|
||||
@@ -765,32 +696,32 @@ namespace Umbraco.Core.Services
|
||||
/// <summary>
|
||||
/// Occurs before Save
|
||||
/// </summary>
|
||||
internal static event TypedEventHandler<IFileService, SaveEventArgs<PartialView>> SavingPartialView;
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<IPartialView>> SavingPartialView;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Save
|
||||
/// </summary>
|
||||
internal static event TypedEventHandler<IFileService, SaveEventArgs<PartialView>> SavedPartialView;
|
||||
public static event TypedEventHandler<IFileService, SaveEventArgs<IPartialView>> SavedPartialView;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Create
|
||||
/// </summary>
|
||||
internal static event TypedEventHandler<IFileService, NewEventArgs<PartialView>> CreatingPartialView;
|
||||
public static event TypedEventHandler<IFileService, NewEventArgs<IPartialView>> CreatingPartialView;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Create
|
||||
/// </summary>
|
||||
internal static event TypedEventHandler<IFileService, NewEventArgs<PartialView>> CreatedPartialView;
|
||||
public static event TypedEventHandler<IFileService, NewEventArgs<IPartialView>> CreatedPartialView;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs before Delete
|
||||
/// </summary>
|
||||
internal static event TypedEventHandler<IFileService, DeleteEventArgs<PartialView>> DeletingPartialView;
|
||||
public static event TypedEventHandler<IFileService, DeleteEventArgs<IPartialView>> DeletingPartialView;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs after Delete
|
||||
/// </summary>
|
||||
internal static event TypedEventHandler<IFileService, DeleteEventArgs<PartialView>> DeletedPartialView;
|
||||
public static event TypedEventHandler<IFileService, DeleteEventArgs<IPartialView>> DeletedPartialView;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -8,6 +8,18 @@ namespace Umbraco.Core.Services
|
||||
/// </summary>
|
||||
public interface IFileService : IService
|
||||
{
|
||||
IEnumerable<string> GetPartialViewSnippetNames(params string[] filterNames);
|
||||
void DeletePartialViewFolder(string folderPath);
|
||||
void DeletePartialViewMacroFolder(string folderPath);
|
||||
IPartialView GetPartialView(string path);
|
||||
IPartialView GetPartialViewMacro(string path);
|
||||
Attempt<IPartialView> CreatePartialView(IPartialView partialView, string snippetName = null, int userId = 0);
|
||||
Attempt<IPartialView> CreatePartialViewMacro(IPartialView partialView, string snippetName = null, int userId = 0);
|
||||
bool DeletePartialView(string path, int userId = 0);
|
||||
bool DeletePartialViewMacro(string path, int userId = 0);
|
||||
Attempt<IPartialView> SavePartialView(IPartialView partialView, int userId = 0);
|
||||
Attempt<IPartialView> SavePartialViewMacro(IPartialView partialView, int userId = 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all <see cref="Stylesheet"/> objects
|
||||
/// </summary>
|
||||
|
||||
@@ -209,5 +209,7 @@ namespace Umbraco.Core.Services
|
||||
/// </summary>
|
||||
public static event TypedEventHandler<IMacroService, SaveEventArgs<IMacro>> Saved;
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -316,6 +316,7 @@
|
||||
<Compile Include="IDisposeOnRequestEnd.cs" />
|
||||
<Compile Include="IO\ResizedImage.cs" />
|
||||
<Compile Include="IO\UmbracoMediaFile.cs" />
|
||||
<Compile Include="Models\IPartialView.cs" />
|
||||
<Compile Include="Services\LocalizedTextService.cs" />
|
||||
<Compile Include="Services\ILocalizedTextService.cs" />
|
||||
<Compile Include="Macros\XsltExtension.cs" />
|
||||
@@ -403,7 +404,6 @@
|
||||
<Compile Include="Persistence\Migrations\Upgrades\TargetVersionSixTwoZero\ChangePasswordColumn.cs" />
|
||||
<Compile Include="Persistence\Migrations\Upgrades\TargetVersionSixTwoZero\UpdateToNewMemberPropertyAliases.cs" />
|
||||
<Compile Include="Persistence\DbConnectionExtensions.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IPartialViewMacroRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IPartialViewRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Interfaces\IRecycleBinRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\PartialViewMacroRepository.cs" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Umbraco.Core.CodeAnnotations;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
@@ -43,9 +44,10 @@ namespace umbraco
|
||||
{
|
||||
fileName += ".cshtml";
|
||||
}
|
||||
|
||||
|
||||
var model = new PartialView(fileName);
|
||||
var fileService = (FileService)ApplicationContext.Current.Services.FileService;
|
||||
var macroService = ApplicationContext.Current.Services.MacroService;
|
||||
|
||||
if (IsPartialViewMacro == false)
|
||||
{
|
||||
@@ -59,8 +61,15 @@ namespace umbraco
|
||||
return attempt.Success;
|
||||
}
|
||||
else
|
||||
{
|
||||
var attempt = fileService.CreatePartialViewMacro(model, ParentID == 1, snippetName, User.Id);
|
||||
{
|
||||
|
||||
var attempt = fileService.CreatePartialViewMacro(model, /*ParentID == 1,*/ snippetName, User.Id);
|
||||
if (attempt)
|
||||
{
|
||||
//The partial view path to be saved with the macro must be a fully qualified virtual path
|
||||
var virtualPath = string.Format("{0}/{1}/{2}", SystemDirectories.MvcViews, "MacroPartials", attempt.Result.Path);
|
||||
macroService.Save(new Macro(attempt.Result.Alias, attempt.Result.Alias) { ScriptPath = virtualPath });
|
||||
}
|
||||
|
||||
//TODO: We currently need to hack this because we are using the same editor for views, partial views, partial view macros and
|
||||
// the editor is using normal UI whereas the partial view repo and these classes are using IFileSystem with relative references
|
||||
@@ -69,13 +78,13 @@ namespace umbraco
|
||||
_returnUrl = string.Format("settings/views/EditView.aspx?treeType=partialViewMacros&file={0}", model.Path.TrimStart('/').EnsureStartsWith("MacroPartials/"));
|
||||
return attempt.Success;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override bool PerformDelete()
|
||||
{
|
||||
var fileService = (FileService)ApplicationContext.Current.Services.FileService;
|
||||
|
||||
|
||||
if (IsPartialViewMacro == false)
|
||||
{
|
||||
if (Alias.Contains(".") == false)
|
||||
|
||||
Reference in New Issue
Block a user