2012-12-10 13:49:20 -01:00
|
|
|
using System;
|
2012-11-07 13:56:52 -01:00
|
|
|
using System.Collections.Generic;
|
2014-08-18 17:47:55 +02:00
|
|
|
using System.IO;
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
using System.Linq;
|
2014-08-19 12:51:07 +02:00
|
|
|
using System.Runtime.Remoting.Messaging;
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
using System.Text.RegularExpressions;
|
2014-08-18 17:47:55 +02:00
|
|
|
using System.Web;
|
2012-12-10 13:49:20 -01:00
|
|
|
using Umbraco.Core.Auditing;
|
2012-12-15 10:43:03 +05:00
|
|
|
using Umbraco.Core.Events;
|
2014-08-18 17:47:55 +02:00
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
using Umbraco.Core.Logging;
|
2012-10-24 11:29:51 -02:00
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
using Umbraco.Core.Persistence;
|
2014-11-20 19:51:42 +11:00
|
|
|
using Umbraco.Core.Persistence.Querying;
|
2014-01-09 18:08:13 +11:00
|
|
|
using Umbraco.Core.Persistence.Repositories;
|
2012-10-24 11:29:51 -02:00
|
|
|
using Umbraco.Core.Persistence.UnitOfWork;
|
|
|
|
|
|
2012-11-12 07:40:11 -01:00
|
|
|
namespace Umbraco.Core.Services
|
2012-10-24 11:29:51 -02:00
|
|
|
{
|
2012-10-30 09:25:28 -01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Represents the File Service, which is an easy access to operations involving <see cref="IFile"/> objects like Scripts, Stylesheets and Templates
|
|
|
|
|
/// </summary>
|
2012-10-24 11:29:51 -02:00
|
|
|
public class FileService : IFileService
|
|
|
|
|
{
|
2013-12-16 18:10:44 +11:00
|
|
|
private readonly RepositoryFactory _repositoryFactory;
|
2012-12-14 12:59:47 -01:00
|
|
|
private readonly IUnitOfWorkProvider _fileUowProvider;
|
|
|
|
|
private readonly IDatabaseUnitOfWorkProvider _dataUowProvider;
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
|
|
|
|
|
private const string PartialViewHeader = "@inherits Umbraco.Web.Mvc.UmbracoTemplatePage";
|
|
|
|
|
private const string PartialViewMacroHeader = "@inherits Umbraco.Web.Macros.PartialViewMacroPage";
|
2012-10-24 11:29:51 -02:00
|
|
|
|
2012-12-14 13:27:10 -01:00
|
|
|
public FileService()
|
|
|
|
|
: this(new RepositoryFactory())
|
2013-12-16 18:10:44 +11:00
|
|
|
{ }
|
2012-12-14 13:27:10 -01:00
|
|
|
|
2012-12-14 08:22:42 +05:00
|
|
|
public FileService(RepositoryFactory repositoryFactory)
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
: this(new FileUnitOfWorkProvider(), new PetaPocoUnitOfWorkProvider(), repositoryFactory)
|
2012-10-24 11:29:51 -02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
public FileService(IUnitOfWorkProvider fileProvider, IDatabaseUnitOfWorkProvider dataProvider, RepositoryFactory repositoryFactory)
|
2012-10-24 11:29:51 -02:00
|
|
|
{
|
2013-12-16 18:10:44 +11:00
|
|
|
_repositoryFactory = repositoryFactory;
|
|
|
|
|
_fileUowProvider = fileProvider;
|
|
|
|
|
_dataUowProvider = dataProvider;
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
|
|
|
|
|
#region Stylesheets
|
|
|
|
|
|
2012-10-24 11:29:51 -02:00
|
|
|
/// <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)
|
|
|
|
|
{
|
2013-10-29 09:24:05 -04:00
|
|
|
using (var repository = _repositoryFactory.CreateStylesheetRepository(_fileUowProvider.GetUnitOfWork(), _dataUowProvider.GetUnitOfWork()))
|
2012-12-14 12:59:47 -01:00
|
|
|
{
|
|
|
|
|
return repository.GetAll(names);
|
|
|
|
|
}
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2013-10-29 09:24:05 -04:00
|
|
|
using (var repository = _repositoryFactory.CreateStylesheetRepository(_fileUowProvider.GetUnitOfWork(), _dataUowProvider.GetUnitOfWork()))
|
2012-12-14 12:59:47 -01:00
|
|
|
{
|
|
|
|
|
return repository.Get(name);
|
|
|
|
|
}
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves a <see cref="Stylesheet"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stylesheet"><see cref="Stylesheet"/> to save</param>
|
2012-12-10 13:49:20 -01:00
|
|
|
/// <param name="userId"></param>
|
2013-01-25 08:58:21 -01:00
|
|
|
public void SaveStylesheet(Stylesheet stylesheet, int userId = 0)
|
2012-10-24 11:29:51 -02:00
|
|
|
{
|
2013-12-16 18:10:44 +11:00
|
|
|
if (SavingStylesheet.IsRaisedEventCancelled(new SaveEventArgs<Stylesheet>(stylesheet), this))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
2013-10-29 09:24:05 -04:00
|
|
|
using (var repository = _repositoryFactory.CreateStylesheetRepository(uow, _dataUowProvider.GetUnitOfWork()))
|
2013-12-16 18:10:44 +11:00
|
|
|
{
|
|
|
|
|
repository.AddOrUpdate(stylesheet);
|
|
|
|
|
uow.Commit();
|
2012-12-15 21:04:17 +05:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
SavedStylesheet.RaiseEvent(new SaveEventArgs<Stylesheet>(stylesheet, false), this);
|
|
|
|
|
}
|
2012-12-15 21:04:17 +05:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
Audit.Add(AuditTypes.Save, string.Format("Save Stylesheet performed by user"), userId, -1);
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes a stylesheet by its name
|
|
|
|
|
/// </summary>
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
/// <param name="path">Name incl. extension of the Stylesheet to delete</param>
|
2012-12-10 13:49:20 -01:00
|
|
|
/// <param name="userId"></param>
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
public void DeleteStylesheet(string path, int userId = 0)
|
2012-10-24 11:29:51 -02:00
|
|
|
{
|
2012-12-14 12:59:47 -01:00
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
2013-10-29 09:24:05 -04:00
|
|
|
using (var repository = _repositoryFactory.CreateStylesheetRepository(uow, _dataUowProvider.GetUnitOfWork()))
|
2012-12-14 12:59:47 -01:00
|
|
|
{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
var stylesheet = repository.Get(path);
|
|
|
|
|
if (stylesheet == null) return;
|
2012-12-10 13:49:20 -01:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
if (DeletingStylesheet.IsRaisedEventCancelled(new DeleteEventArgs<Stylesheet>(stylesheet), this))
|
|
|
|
|
return;
|
2012-12-10 13:49:20 -01:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
repository.Delete(stylesheet);
|
|
|
|
|
uow.Commit();
|
2012-12-10 13:49:20 -01:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
DeletedStylesheet.RaiseEvent(new DeleteEventArgs<Stylesheet>(stylesheet, false), this);
|
2012-12-10 13:49:20 -01:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
Audit.Add(AuditTypes.Delete, string.Format("Delete Stylesheet performed by user"), userId, -1);
|
2012-12-10 13:49:20 -01:00
|
|
|
}
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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();
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
}
|
|
|
|
|
#endregion
|
2012-10-24 11:29:51 -02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
#region Scripts
|
2012-10-24 11:29:51 -02:00
|
|
|
/// <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)
|
|
|
|
|
{
|
2012-12-14 12:59:47 -01:00
|
|
|
using (var repository = _repositoryFactory.CreateScriptRepository(_fileUowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
|
|
|
|
return repository.GetAll(names);
|
|
|
|
|
}
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2012-12-14 12:59:47 -01:00
|
|
|
using (var repository = _repositoryFactory.CreateScriptRepository(_fileUowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
|
|
|
|
return repository.Get(name);
|
|
|
|
|
}
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves a <see cref="Script"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="script"><see cref="Script"/> to save</param>
|
2012-12-10 13:49:20 -01:00
|
|
|
/// <param name="userId"></param>
|
2013-01-25 08:58:21 -01:00
|
|
|
public void SaveScript(Script script, int userId = 0)
|
2012-10-24 11:29:51 -02:00
|
|
|
{
|
2013-12-16 18:10:44 +11:00
|
|
|
if (SavingScript.IsRaisedEventCancelled(new SaveEventArgs<Script>(script), this))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreateScriptRepository(uow))
|
|
|
|
|
{
|
|
|
|
|
repository.AddOrUpdate(script);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
|
|
|
|
|
SavedScript.RaiseEvent(new SaveEventArgs<Script>(script, false), this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Audit.Add(AuditTypes.Save, string.Format("Save Script performed by user"), userId, -1);
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes a script by its name
|
|
|
|
|
/// </summary>
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
/// <param name="path">Name incl. extension of the Script to delete</param>
|
2012-12-10 13:49:20 -01:00
|
|
|
/// <param name="userId"></param>
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
public void DeleteScript(string path, int userId = 0)
|
2012-10-24 11:29:51 -02:00
|
|
|
{
|
2012-12-14 12:59:47 -01:00
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreateScriptRepository(uow))
|
|
|
|
|
{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
var script = repository.Get(path);
|
|
|
|
|
if (script == null) return;
|
2012-12-10 13:49:20 -01:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
if (DeletingScript.IsRaisedEventCancelled(new DeleteEventArgs<Script>(script), this))
|
|
|
|
|
return; ;
|
|
|
|
|
|
|
|
|
|
repository.Delete(script);
|
|
|
|
|
uow.Commit();
|
2012-12-10 13:49:20 -01:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
DeletedScript.RaiseEvent(new DeleteEventArgs<Script>(script, false), this);
|
2012-12-10 13:49:20 -01:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
Audit.Add(AuditTypes.Delete, string.Format("Delete Script performed by user"), userId, -1);
|
2012-12-10 13:49:20 -01:00
|
|
|
}
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-09 18:08:13 +11:00
|
|
|
public void CreateScriptFolder(string folderPath)
|
|
|
|
|
{
|
|
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreateScriptRepository(uow))
|
|
|
|
|
{
|
|
|
|
|
((ScriptRepository)repository).AddFolder(folderPath);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteScriptFolder(string folderPath)
|
|
|
|
|
{
|
|
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreateScriptRepository(uow))
|
|
|
|
|
{
|
|
|
|
|
((ScriptRepository)repository).DeleteFolder(folderPath);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Templates
|
2014-11-25 18:48:19 +11:00
|
|
|
|
|
|
|
|
public ITemplate CreateTemplateWithIdentity(string name, string content, ITemplate masterTemplate = null, int userId = 0)
|
|
|
|
|
{
|
|
|
|
|
var template = new Template(name, name)
|
|
|
|
|
{
|
|
|
|
|
Content = content
|
|
|
|
|
};
|
|
|
|
|
if (masterTemplate != null)
|
|
|
|
|
{
|
|
|
|
|
template.SetMasterTemplate(masterTemplate);
|
|
|
|
|
}
|
|
|
|
|
SaveTemplate(template, userId);
|
|
|
|
|
return template;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-24 11:29:51 -02:00
|
|
|
/// <summary>
|
2012-11-11 12:20:14 -01:00
|
|
|
/// Gets a list of all <see cref="ITemplate"/> objects
|
2012-10-24 11:29:51 -02:00
|
|
|
/// </summary>
|
2012-11-11 12:20:14 -01:00
|
|
|
/// <returns>An enumerable list of <see cref="ITemplate"/> objects</returns>
|
|
|
|
|
public IEnumerable<ITemplate> GetTemplates(params string[] aliases)
|
2012-10-24 11:29:51 -02:00
|
|
|
{
|
2012-12-14 12:59:47 -01:00
|
|
|
using (var repository = _repositoryFactory.CreateTemplateRepository(_dataUowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
2014-11-25 18:02:17 +11:00
|
|
|
return repository.GetAll(aliases).OrderBy(x => x.Name);
|
2012-12-14 12:59:47 -01:00
|
|
|
}
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
2014-11-20 19:51:42 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a list of all <see cref="ITemplate"/> objects
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>An enumerable list of <see cref="ITemplate"/> objects</returns>
|
|
|
|
|
public IEnumerable<ITemplate> GetTemplates(int masterTemplateId)
|
|
|
|
|
{
|
|
|
|
|
using (var repository = _repositoryFactory.CreateTemplateRepository(_dataUowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
2014-11-25 18:02:17 +11:00
|
|
|
return repository.GetChildren(masterTemplateId).OrderBy(x => x.Name);
|
2014-11-20 19:51:42 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-24 11:29:51 -02:00
|
|
|
/// <summary>
|
2012-11-11 12:20:14 -01:00
|
|
|
/// Gets a <see cref="ITemplate"/> object by its alias
|
2012-10-24 11:29:51 -02:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alias">Alias of the template</param>
|
|
|
|
|
/// <returns>A <see cref="Template"/> object</returns>
|
2012-12-12 15:17:48 -01:00
|
|
|
public ITemplate GetTemplate(string alias)
|
2012-10-24 11:29:51 -02:00
|
|
|
{
|
2012-12-14 12:59:47 -01:00
|
|
|
using (var repository = _repositoryFactory.CreateTemplateRepository(_dataUowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
|
|
|
|
return repository.Get(alias);
|
2012-12-17 11:16:09 -01:00
|
|
|
}
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
2012-12-12 15:17:48 -01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a <see cref="ITemplate"/> object by its alias
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">Id of the template</param>
|
|
|
|
|
/// <returns>A <see cref="ITemplate"/> object</returns>
|
|
|
|
|
public ITemplate GetTemplate(int id)
|
|
|
|
|
{
|
2012-12-17 11:16:09 -01:00
|
|
|
using (var repository = _repositoryFactory.CreateTemplateRepository(_dataUowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
|
|
|
|
return repository.Get(id);
|
2012-12-14 12:59:47 -01:00
|
|
|
}
|
2012-12-12 15:17:48 -01:00
|
|
|
}
|
|
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a template as a template node which can be traversed (parent, children)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alias"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public TemplateNode GetTemplateNode(string alias)
|
|
|
|
|
{
|
|
|
|
|
using (var repository = _repositoryFactory.CreateTemplateRepository(_dataUowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
|
|
|
|
return repository.GetTemplateNode(alias);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Given a template node in a tree, this will find the template node with the given alias if it is found in the hierarchy, otherwise null
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="anyNode"></param>
|
|
|
|
|
/// <param name="alias"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public TemplateNode FindTemplateInTree(TemplateNode anyNode, string alias)
|
|
|
|
|
{
|
|
|
|
|
using (var repository = _repositoryFactory.CreateTemplateRepository(_dataUowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
|
|
|
|
return repository.FindTemplateInTree(anyNode, alias);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-24 11:29:51 -02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Saves a <see cref="Template"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="template"><see cref="Template"/> to save</param>
|
2012-12-10 13:49:20 -01:00
|
|
|
/// <param name="userId"></param>
|
2013-01-25 08:58:21 -01:00
|
|
|
public void SaveTemplate(ITemplate template, int userId = 0)
|
2012-10-24 11:29:51 -02:00
|
|
|
{
|
2013-12-16 18:10:44 +11:00
|
|
|
if (SavingTemplate.IsRaisedEventCancelled(new SaveEventArgs<ITemplate>(template), this))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var uow = _dataUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreateTemplateRepository(uow))
|
|
|
|
|
{
|
|
|
|
|
repository.AddOrUpdate(template);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
|
|
|
|
|
SavedTemplate.RaiseEvent(new SaveEventArgs<ITemplate>(template, false), this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Audit.Add(AuditTypes.Save, string.Format("Save Template performed by user"), userId, template.Id);
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
2013-03-20 20:31:44 -01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Saves a collection of <see cref="Template"/> objects
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="templates">List of <see cref="Template"/> to save</param>
|
|
|
|
|
/// <param name="userId">Optional id of the user</param>
|
|
|
|
|
public void SaveTemplate(IEnumerable<ITemplate> templates, int userId = 0)
|
|
|
|
|
{
|
|
|
|
|
if (SavingTemplate.IsRaisedEventCancelled(new SaveEventArgs<ITemplate>(templates), this))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var uow = _dataUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreateTemplateRepository(uow))
|
|
|
|
|
{
|
|
|
|
|
foreach (var template in templates)
|
|
|
|
|
{
|
|
|
|
|
repository.AddOrUpdate(template);
|
|
|
|
|
}
|
|
|
|
|
uow.Commit();
|
|
|
|
|
|
|
|
|
|
SavedTemplate.RaiseEvent(new SaveEventArgs<ITemplate>(templates, false), this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Audit.Add(AuditTypes.Save, string.Format("Save Template performed by user"), userId, -1);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-24 11:29:51 -02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes a template by its alias
|
|
|
|
|
/// </summary>
|
2012-11-11 12:20:14 -01:00
|
|
|
/// <param name="alias">Alias of the <see cref="ITemplate"/> to delete</param>
|
2012-12-10 13:49:20 -01:00
|
|
|
/// <param name="userId"></param>
|
2013-01-25 08:58:21 -01:00
|
|
|
public void DeleteTemplate(string alias, int userId = 0)
|
2012-10-24 11:29:51 -02:00
|
|
|
{
|
2012-12-14 12:59:47 -01:00
|
|
|
var uow = _dataUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreateTemplateRepository(uow))
|
|
|
|
|
{
|
|
|
|
|
var template = repository.Get(alias);
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
if (template == null) return;
|
2012-12-10 13:49:20 -01:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
if (DeletingTemplate.IsRaisedEventCancelled(new DeleteEventArgs<ITemplate>(template), this))
|
|
|
|
|
return;
|
2012-12-10 13:49:20 -01:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
repository.Delete(template);
|
|
|
|
|
uow.Commit();
|
2012-12-10 13:49:20 -01:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
DeletedTemplate.RaiseEvent(new DeleteEventArgs<ITemplate>(template, false), this);
|
2012-12-10 13:49:20 -01:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
Audit.Add(AuditTypes.Delete, string.Format("Delete Template performed by user"), userId, template.Id);
|
2012-12-10 13:49:20 -01:00
|
|
|
}
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2012-11-11 12:20:14 -01:00
|
|
|
/// Validates a <see cref="ITemplate"/>
|
2012-10-24 11:29:51 -02:00
|
|
|
/// </summary>
|
2012-11-11 12:20:14 -01:00
|
|
|
/// <param name="template"><see cref="ITemplate"/> to validate</param>
|
2012-10-24 11:29:51 -02:00
|
|
|
/// <returns>True if Script is valid, otherwise false</returns>
|
2012-11-11 12:20:14 -01:00
|
|
|
public bool ValidateTemplate(ITemplate template)
|
2012-10-24 11:29:51 -02:00
|
|
|
{
|
|
|
|
|
return template.IsValid();
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Partial Views
|
|
|
|
|
|
|
|
|
|
internal IEnumerable<string> GetPartialViewSnippetNames(params string[] filterNames)
|
|
|
|
|
{
|
|
|
|
|
var snippetPath = IOHelper.MapPath(string.Format("{0}/PartialViewMacros/Templates/", SystemDirectories.Umbraco));
|
2014-11-19 11:09:45 +11:00
|
|
|
var files = Directory.GetFiles(snippetPath, "*.cshtml")
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
.Select(Path.GetFileNameWithoutExtension)
|
|
|
|
|
.Except(filterNames, StringComparer.InvariantCultureIgnoreCase)
|
|
|
|
|
.ToArray();
|
2014-11-19 11:09:45 +11:00
|
|
|
|
|
|
|
|
//Ensure the ones that are called 'Empty' are at the top
|
|
|
|
|
var empty = files.Where(x => Path.GetFileName(x).InvariantStartsWith("Empty"))
|
|
|
|
|
.OrderBy(x => x.Length)
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
return empty.Union(files.Except(empty));
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void DeletePartialViewFolder(string folderPath)
|
|
|
|
|
{
|
|
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreatePartialViewRepository(uow))
|
|
|
|
|
{
|
|
|
|
|
((PartialViewRepository)repository).DeleteFolder(folderPath);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
}
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
2012-11-11 06:53:02 -01:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
internal void DeletePartialViewMacroFolder(string folderPath)
|
2014-08-18 17:47:55 +02:00
|
|
|
{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
|
|
|
|
var duow = _dataUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreatePartialViewMacroRepository(uow, duow))
|
|
|
|
|
{
|
|
|
|
|
((PartialViewMacroRepository)repository).DeleteFolder(folderPath);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-18 17:47:55 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
internal PartialView GetPartialView(string path)
|
|
|
|
|
{
|
|
|
|
|
using (var repository = _repositoryFactory.CreatePartialViewRepository(_fileUowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
|
|
|
|
return repository.Get(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal PartialView GetPartialViewMacro(string path)
|
|
|
|
|
{
|
|
|
|
|
using (var repository = _repositoryFactory.CreatePartialViewMacroRepository(
|
|
|
|
|
_fileUowProvider.GetUnitOfWork(),
|
|
|
|
|
_dataUowProvider.GetUnitOfWork()))
|
|
|
|
|
{
|
|
|
|
|
return repository.Get(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-18 17:47:55 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
internal Attempt<PartialView> CreatePartialView(PartialView partialView, string snippetName = null, int userId = 0)
|
|
|
|
|
{
|
2014-08-18 17:47:55 +02:00
|
|
|
if (CreatingPartialView.IsRaisedEventCancelled(new NewEventArgs<PartialView>(partialView, true, partialView.Alias, -1), this))
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
return Attempt<PartialView>.Fail();
|
|
|
|
|
|
|
|
|
|
if (snippetName.IsNullOrWhiteSpace() == false)
|
2014-08-18 17:47:55 +02:00
|
|
|
{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
//create the file
|
|
|
|
|
var snippetPathAttempt = TryGetSnippetPath(snippetName);
|
|
|
|
|
if (snippetPathAttempt.Success == false)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Could not load snippet with name " + snippetName);
|
|
|
|
|
}
|
2014-08-19 12:51:07 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
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);
|
2014-08-19 12:51:07 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
var content = string.Format("{0}{1}{2}", PartialViewHeader, Environment.NewLine, snippetContent);
|
|
|
|
|
partialView.Content = content;
|
|
|
|
|
}
|
2014-08-18 17:47:55 +02:00
|
|
|
}
|
|
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreatePartialViewRepository(uow))
|
2014-08-18 17:47:55 +02:00
|
|
|
{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
repository.AddOrUpdate(partialView);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
|
|
|
|
|
CreatedPartialView.RaiseEvent(new NewEventArgs<PartialView>(partialView, false, partialView.Alias, -1), this);
|
2014-08-18 17:47:55 +02:00
|
|
|
}
|
|
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
Audit.Add(AuditTypes.Save, string.Format("Save PartialView performed by user"), userId, -1);
|
|
|
|
|
|
|
|
|
|
return Attempt<PartialView>.Succeed(partialView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal Attempt<PartialView> CreatePartialViewMacro(PartialView partialView, bool createMacro, string snippetName = null, int userId = 0)
|
|
|
|
|
{
|
|
|
|
|
if (CreatingPartialView.IsRaisedEventCancelled(new NewEventArgs<PartialView>(partialView, true, partialView.Alias, -1), this))
|
|
|
|
|
return Attempt<PartialView>.Fail();
|
|
|
|
|
|
|
|
|
|
if (snippetName.IsNullOrWhiteSpace() == false)
|
2014-08-18 17:47:55 +02:00
|
|
|
{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
//create the file
|
|
|
|
|
var snippetPathAttempt = TryGetSnippetPath(snippetName);
|
|
|
|
|
if (snippetPathAttempt.Success == false)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Could not load snippet with name " + snippetName);
|
|
|
|
|
}
|
2014-08-18 17:47:55 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
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);
|
2014-08-18 17:47:55 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
var content = string.Format("{0}{1}{2}", PartialViewMacroHeader, Environment.NewLine, snippetContent);
|
|
|
|
|
partialView.Content = content;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-18 17:47:55 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
|
|
|
|
var duow = _dataUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreatePartialViewMacroRepository(uow, duow))
|
|
|
|
|
{
|
|
|
|
|
repository.AddOrUpdate(partialView);
|
|
|
|
|
|
|
|
|
|
if (createMacro)
|
2014-08-19 10:21:01 +02:00
|
|
|
{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
var name = Path.GetFileNameWithoutExtension(partialView.Path)
|
|
|
|
|
.SplitPascalCasing()
|
|
|
|
|
.ToFirstUpperInvariant()
|
|
|
|
|
.ToSafeAlias(false);
|
|
|
|
|
|
2014-11-19 11:09:45 +11:00
|
|
|
//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 });
|
2014-08-19 10:21:01 +02:00
|
|
|
}
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
|
|
|
|
|
//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);
|
2014-08-18 17:47:55 +02:00
|
|
|
}
|
|
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
Audit.Add(AuditTypes.Save, string.Format("Save PartialViewMacro performed by user"), userId, -1);
|
2014-08-18 17:47:55 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
return Attempt<PartialView>.Succeed(partialView);
|
2014-08-18 17:47:55 +02:00
|
|
|
}
|
|
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
internal bool DeletePartialView(string path, int userId = 0)
|
2014-08-18 17:47:55 +02:00
|
|
|
{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreatePartialViewRepository(uow))
|
|
|
|
|
{
|
|
|
|
|
var partialView = repository.Get(path);
|
|
|
|
|
if (partialView == null)
|
|
|
|
|
return true;
|
2014-08-18 17:47:55 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
if (DeletingPartialView.IsRaisedEventCancelled(new DeleteEventArgs<PartialView>(partialView), this))
|
|
|
|
|
return false;
|
2014-08-18 17:47:55 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
repository.Delete(partialView);
|
|
|
|
|
uow.Commit();
|
2014-08-18 17:47:55 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
DeletedPartialView.RaiseEvent(new DeleteEventArgs<PartialView>(partialView, false), this);
|
2014-08-18 17:47:55 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
Audit.Add(AuditTypes.Delete, string.Format("Delete PartialView performed by user"), userId, -1);
|
2014-08-18 17:47:55 +02:00
|
|
|
}
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal bool DeletePartialViewMacro(string path, int userId = 0)
|
|
|
|
|
{
|
|
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
|
|
|
|
var duow = _dataUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreatePartialViewMacroRepository(uow, duow))
|
2014-08-18 17:47:55 +02:00
|
|
|
{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
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();
|
2014-08-18 17:47:55 +02:00
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
DeletedPartialView.RaiseEvent(new DeleteEventArgs<PartialView>(partialView, false), this);
|
|
|
|
|
|
|
|
|
|
Audit.Add(AuditTypes.Delete, string.Format("Delete PartialViewMacro performed by user"), userId, -1);
|
|
|
|
|
}
|
2014-08-18 17:47:55 +02:00
|
|
|
|
|
|
|
|
return true;
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
|
2014-08-18 17:47:55 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-19 12:51:07 +02:00
|
|
|
internal Attempt<PartialView> SavePartialView(PartialView partialView, int userId = 0)
|
|
|
|
|
{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
if (SavingPartialView.IsRaisedEventCancelled(new SaveEventArgs<PartialView>(partialView), this))
|
|
|
|
|
return Attempt<PartialView>.Fail();
|
|
|
|
|
|
|
|
|
|
var uow = _fileUowProvider.GetUnitOfWork();
|
|
|
|
|
using (var repository = _repositoryFactory.CreatePartialViewRepository(uow))
|
2014-08-19 12:51:07 +02:00
|
|
|
{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
repository.AddOrUpdate(partialView);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
|
|
|
|
|
SavedPartialView.RaiseEvent(new SaveEventArgs<PartialView>(partialView, false), this);
|
2014-08-19 12:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
Audit.Add(AuditTypes.Save, string.Format("Save PartialView 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)
|
2014-08-19 12:51:07 +02:00
|
|
|
//{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
// // 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);
|
2014-08-19 12:51:07 +02:00
|
|
|
//}
|
|
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
//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))
|
2014-08-19 12:51:07 +02:00
|
|
|
{
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
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);
|
2014-08-19 12:51:07 +02:00
|
|
|
}
|
|
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
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);
|
2014-08-19 12:51:07 +02:00
|
|
|
|
|
|
|
|
return Attempt.Succeed(partialView);
|
|
|
|
|
}
|
|
|
|
|
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
internal bool ValidatePartialView(PartialView partialView)
|
|
|
|
|
{
|
|
|
|
|
return partialView.IsValid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal string StripPartialViewHeader(string contents)
|
|
|
|
|
{
|
|
|
|
|
var headerMatch = new Regex("^@inherits\\s+?.*$", RegexOptions.Multiline);
|
|
|
|
|
return headerMatch.Replace(contents, string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal Attempt<string> TryGetSnippetPath(string fileName)
|
|
|
|
|
{
|
|
|
|
|
if (fileName.EndsWith(".cshtml") == false)
|
|
|
|
|
{
|
|
|
|
|
fileName += ".cshtml";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var snippetPath = IOHelper.MapPath(string.Format("{0}/PartialViewMacros/Templates/{1}", SystemDirectories.Umbraco, fileName));
|
|
|
|
|
return System.IO.File.Exists(snippetPath)
|
|
|
|
|
? Attempt<string>.Succeed(snippetPath)
|
|
|
|
|
: Attempt<string>.Fail();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2012-11-11 06:53:02 -01:00
|
|
|
//TODO Method to change name and/or alias of view/masterpage template
|
2012-12-10 13:49:20 -01:00
|
|
|
|
|
|
|
|
#region Event Handlers
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs before Delete
|
2012-12-16 07:43:03 +05:00
|
|
|
/// </summary>
|
2013-12-16 18:10:44 +11:00
|
|
|
public static event TypedEventHandler<IFileService, DeleteEventArgs<ITemplate>> DeletingTemplate;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs after Delete
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event TypedEventHandler<IFileService, DeleteEventArgs<ITemplate>> DeletedTemplate;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs before Delete
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event TypedEventHandler<IFileService, DeleteEventArgs<Script>> DeletingScript;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs after Delete
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event TypedEventHandler<IFileService, DeleteEventArgs<Script>> DeletedScript;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs before Delete
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event TypedEventHandler<IFileService, DeleteEventArgs<Stylesheet>> DeletingStylesheet;
|
2012-12-10 13:49:20 -01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs after Delete
|
|
|
|
|
/// </summary>
|
2013-12-16 18:10:44 +11:00
|
|
|
public static event TypedEventHandler<IFileService, DeleteEventArgs<Stylesheet>> DeletedStylesheet;
|
2012-12-16 07:43:03 +05:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs before Save
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event TypedEventHandler<IFileService, SaveEventArgs<ITemplate>> SavingTemplate;
|
2012-12-16 07:43:03 +05:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs after Save
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event TypedEventHandler<IFileService, SaveEventArgs<ITemplate>> SavedTemplate;
|
2012-12-16 07:43:03 +05:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs before Save
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event TypedEventHandler<IFileService, SaveEventArgs<Script>> SavingScript;
|
2012-12-16 07:43:03 +05:00
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs after Save
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static event TypedEventHandler<IFileService, SaveEventArgs<Script>> SavedScript;
|
2012-12-10 13:49:20 -01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs before Save
|
|
|
|
|
/// </summary>
|
2013-12-16 18:10:44 +11:00
|
|
|
public static event TypedEventHandler<IFileService, SaveEventArgs<Stylesheet>> SavingStylesheet;
|
2012-12-10 13:49:20 -01:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs after Save
|
|
|
|
|
/// </summary>
|
2013-12-16 18:10:44 +11:00
|
|
|
public static event TypedEventHandler<IFileService, SaveEventArgs<Stylesheet>> SavedStylesheet;
|
2012-12-15 21:04:17 +05:00
|
|
|
|
2014-08-19 12:51:07 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs before Save
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal static event TypedEventHandler<IFileService, SaveEventArgs<PartialView>> SavingPartialView;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs after Save
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal static event TypedEventHandler<IFileService, SaveEventArgs<PartialView>> SavedPartialView;
|
Updates PartialView & PartialViewMacros models/services/repositories, streamlines their operations, fixes up other underlying problems with the FileRepository, fixes tree syncing for partial views, partial view macros and scripts, fixes scripts being created in folders, allows partial views and partial view macros to be managed and created in folders, fixes FileUnitOfWork to use a queue, publicizes some internal test classes, fixes tree syncing when dealing with invariant case, adds correct validation to the create dialogs of scripts and partial views (and partial view macros)
2014-10-22 16:44:45 +10:00
|
|
|
|
2014-08-18 17:47:55 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs before Create
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal static event TypedEventHandler<IFileService, NewEventArgs<PartialView>> CreatingPartialView;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs after Create
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal static event TypedEventHandler<IFileService, NewEventArgs<PartialView>> CreatedPartialView;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs before Delete
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal static event TypedEventHandler<IFileService, DeleteEventArgs<PartialView>> DeletingPartialView;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Occurs after Delete
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal static event TypedEventHandler<IFileService, DeleteEventArgs<PartialView>> DeletedPartialView;
|
|
|
|
|
|
2012-12-10 13:49:20 -01:00
|
|
|
#endregion
|
2014-08-19 12:51:07 +02:00
|
|
|
|
2014-11-25 18:48:19 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-24 11:29:51 -02:00
|
|
|
}
|
|
|
|
|
}
|