2017-07-20 11:21:28 +02:00
|
|
|
|
using System;
|
2012-11-07 13:56:52 -01:00
|
|
|
|
using System.Collections.Generic;
|
2016-01-06 19:27:15 +01:00
|
|
|
|
using System.ComponentModel;
|
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;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
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-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>
|
2017-05-12 14:49:44 +02:00
|
|
|
|
public class FileService : ScopeRepositoryService, IFileService
|
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
|
|
|
|
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
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
public FileService(IScopeUnitOfWorkProvider uowProvider, ILogger logger, IEventMessagesFactory eventMessagesFactory)
|
|
|
|
|
|
: base(uowProvider, logger, eventMessagesFactory)
|
|
|
|
|
|
{ }
|
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)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2012-12-14 12:59:47 -01:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IStylesheetRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetAll(names);
|
2012-12-14 12:59:47 -01:00
|
|
|
|
}
|
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)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2012-12-14 12:59:47 -01:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IStylesheetRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.Get(name);
|
2012-12-14 12:59:47 -01:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2013-12-16 18:10:44 +11:00
|
|
|
|
{
|
2017-09-18 15:33:13 +02:00
|
|
|
|
var saveEventArgs = new SaveEventArgs<Stylesheet>(stylesheet);
|
|
|
|
|
|
if (uow.Events.DispatchCancelable(SavingStylesheet, this, saveEventArgs))
|
2017-05-12 14:49:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IStylesheetRepository>();
|
2013-12-16 18:10:44 +11:00
|
|
|
|
repository.AddOrUpdate(stylesheet);
|
2017-09-18 15:33:13 +02:00
|
|
|
|
saveEventArgs.CanCancel = false;
|
|
|
|
|
|
uow.Events.Dispatch(SavedStylesheet, this, saveEventArgs);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
Audit(uow, AuditType.Save, "Save Stylesheet performed by user", userId, -1);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
2013-12-16 18:10:44 +11:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2012-12-14 12:59:47 -01:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IStylesheetRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var stylesheet = repository.Get(path);
|
2016-05-18 10:55:19 +02:00
|
|
|
|
if (stylesheet == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2012-12-10 13:49:20 -01:00
|
|
|
|
|
2017-09-18 15:33:13 +02:00
|
|
|
|
var deleteEventArgs = new DeleteEventArgs<Stylesheet>(stylesheet);
|
|
|
|
|
|
if (uow.Events.DispatchCancelable(DeletingStylesheet, this, deleteEventArgs))
|
2017-05-12 14:49:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
2016-05-18 10:55:19 +02:00
|
|
|
|
return; // causes rollback
|
2017-05-12 14:49:44 +02:00
|
|
|
|
}
|
2012-12-10 13:49:20 -01:00
|
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
|
repository.Delete(stylesheet);
|
2017-09-18 15:33:13 +02:00
|
|
|
|
deleteEventArgs.CanCancel = false;
|
|
|
|
|
|
uow.Events.Dispatch(DeletedStylesheet, this, deleteEventArgs);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
Audit(uow, AuditType.Delete, "Delete Stylesheet performed by user", userId, -1);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
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)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-01-14 12:09:30 +11:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IStylesheetRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.ValidateStylesheet(stylesheet);
|
2015-01-14 12:09:30 +11:00
|
|
|
|
}
|
2015-09-07 12:38:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-03 10:31:44 +01:00
|
|
|
|
public Stream GetStylesheetFileContentStream(string filepath)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2016-11-03 10:31:44 +01:00
|
|
|
|
{
|
|
|
|
|
|
var repository = uow.CreateRepository<IStylesheetRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetFileContentStream(filepath);
|
2016-11-03 10:31:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-01-14 12:09:30 +11:00
|
|
|
|
|
2016-11-03 10:31:44 +01:00
|
|
|
|
public void SetStylesheetFileContent(string filepath, Stream content)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2015-01-14 12:09:30 +11:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
var repository = uow.CreateRepository<IStylesheetRepository>();
|
|
|
|
|
|
repository.SetFileContent(filepath, content);
|
|
|
|
|
|
uow.Complete();
|
2015-01-14 12:09:30 +11:00
|
|
|
|
}
|
2015-09-07 12:38:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
public long GetStylesheetFileSize(string filepath)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = uow.CreateRepository<IStylesheetRepository>();
|
|
|
|
|
|
return repository.GetFileSize(filepath);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
2016-11-03 10:31:44 +01:00
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2012-12-14 12:59:47 -01:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IScriptRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetAll(names);
|
2012-12-14 12:59:47 -01:00
|
|
|
|
}
|
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)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2012-12-14 12:59:47 -01:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IScriptRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.Get(name);
|
2012-12-14 12:59:47 -01:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2013-12-16 18:10:44 +11:00
|
|
|
|
{
|
2017-09-18 15:33:13 +02:00
|
|
|
|
var saveEventArgs = new SaveEventArgs<Script>(script);
|
|
|
|
|
|
if (uow.Events.DispatchCancelable(SavingScript, this, saveEventArgs))
|
2017-05-12 14:49:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IScriptRepository>();
|
2013-12-16 18:10:44 +11:00
|
|
|
|
repository.AddOrUpdate(script);
|
2017-09-18 15:33:13 +02:00
|
|
|
|
saveEventArgs.CanCancel = false;
|
|
|
|
|
|
uow.Events.Dispatch(SavedScript, this, saveEventArgs);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
Audit(uow, AuditType.Save, "Save Script performed by user", userId, -1);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
2013-12-16 18:10:44 +11:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2012-12-14 12:59:47 -01:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IScriptRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var script = repository.Get(path);
|
2016-05-18 10:55:19 +02:00
|
|
|
|
if (script == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2012-12-10 13:49:20 -01:00
|
|
|
|
|
2017-09-18 15:33:13 +02:00
|
|
|
|
var deleteEventArgs = new DeleteEventArgs<Script>(script);
|
|
|
|
|
|
if (uow.Events.DispatchCancelable(DeletingScript, this, deleteEventArgs))
|
2017-05-12 14:49:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2013-12-16 18:10:44 +11:00
|
|
|
|
|
|
|
|
|
|
repository.Delete(script);
|
2017-09-18 15:33:13 +02:00
|
|
|
|
deleteEventArgs.CanCancel = false;
|
|
|
|
|
|
uow.Events.Dispatch(DeletedScript, this, deleteEventArgs);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
Audit(uow, AuditType.Delete, "Delete Script performed by user", userId, -1);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
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)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-01-14 12:09:30 +11:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IScriptRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.ValidateScript(script);
|
2015-01-14 12:09:30 +11:00
|
|
|
|
}
|
2012-10-24 11:29:51 -02:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-01-09 18:08:13 +11:00
|
|
|
|
public void CreateScriptFolder(string folderPath)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2014-01-09 18:08:13 +11:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IScriptRepository>();
|
2016-05-02 12:12:21 +02:00
|
|
|
|
((ScriptRepository) repository).AddFolder(folderPath);
|
|
|
|
|
|
uow.Complete();
|
2014-01-09 18:08:13 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DeleteScriptFolder(string folderPath)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2014-01-09 18:08:13 +11:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IScriptRepository>();
|
2016-05-02 12:12:21 +02:00
|
|
|
|
((ScriptRepository) repository).DeleteFolder(folderPath);
|
|
|
|
|
|
uow.Complete();
|
2014-01-09 18:08:13 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-03 10:31:44 +01:00
|
|
|
|
public Stream GetScriptFileContentStream(string filepath)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2014-01-09 18:08:13 +11:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
var repository = uow.CreateRepository<IScriptRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetFileContentStream(filepath);
|
2016-11-03 10:31:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetScriptFileContent(string filepath, Stream content)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = uow.CreateRepository<IScriptRepository>();
|
|
|
|
|
|
repository.SetFileContent(filepath, content);
|
|
|
|
|
|
uow.Complete();
|
2014-01-09 18:08:13 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
public long GetScriptFileSize(string filepath)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = uow.CreateRepository<IScriptRepository>();
|
|
|
|
|
|
return repository.GetFileSize(filepath);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-01-19 21:38:11 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates a template for a content type
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="contentTypeAlias"></param>
|
|
|
|
|
|
/// <param name="contentTypeName"></param>
|
|
|
|
|
|
/// <param name="userId"></param>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// The template created
|
|
|
|
|
|
/// </returns>
|
2016-05-18 10:55:19 +02:00
|
|
|
|
public Attempt<OperationStatus<OperationStatusType, ITemplate>> CreateTemplateForContentType(string contentTypeAlias, string contentTypeName, int userId = 0)
|
2016-01-19 21:38:11 +01:00
|
|
|
|
{
|
2016-02-16 14:20:29 +01:00
|
|
|
|
var template = new Template(contentTypeName,
|
|
|
|
|
|
//NOTE: We are NOT passing in the content type alias here, we want to use it's name since we don't
|
|
|
|
|
|
// want to save template file names as camelCase, the Template ctor will clean the alias as
|
|
|
|
|
|
// `alias.ToCleanString(CleanStringType.UnderscoreAlias)` which has been the default.
|
|
|
|
|
|
// This fixes: http://issues.umbraco.org/issue/U4-7953
|
|
|
|
|
|
contentTypeName);
|
2016-01-19 21:38:11 +01:00
|
|
|
|
|
|
|
|
|
|
var evtMsgs = EventMessagesFactory.Get();
|
|
|
|
|
|
|
2016-01-20 11:19:04 +01:00
|
|
|
|
//NOTE: This isn't pretty but we need to maintain backwards compatibility so we cannot change
|
|
|
|
|
|
// the event args here. The other option is to create a different event with different event
|
|
|
|
|
|
// args specifically for this method... which also isn't pretty. So for now, we'll use this
|
|
|
|
|
|
// dictionary approach to store 'additional data' in.
|
|
|
|
|
|
var additionalData = new Dictionary<string, object>
|
|
|
|
|
|
{
|
2016-01-20 14:47:32 +01:00
|
|
|
|
{"CreateTemplateForContentType", true},
|
|
|
|
|
|
{"ContentTypeAlias", contentTypeAlias},
|
2016-01-20 11:19:04 +01:00
|
|
|
|
};
|
2016-01-19 21:38:11 +01:00
|
|
|
|
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2016-01-19 21:38:11 +01:00
|
|
|
|
{
|
2017-09-18 15:33:13 +02:00
|
|
|
|
var saveEventArgs = new SaveEventArgs<ITemplate>(template, true, evtMsgs, additionalData);
|
|
|
|
|
|
if (uow.Events.DispatchCancelable(SavingTemplate, this, saveEventArgs))
|
2017-05-12 14:49:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
return OperationStatus.Attempt.Fail<OperationStatusType, ITemplate>(OperationStatusType.FailedCancelledByEvent, evtMsgs, template);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2016-01-19 21:38:11 +01:00
|
|
|
|
repository.AddOrUpdate(template);
|
2017-09-18 15:33:13 +02:00
|
|
|
|
saveEventArgs.CanCancel = false;
|
|
|
|
|
|
uow.Events.Dispatch(SavedTemplate, this, saveEventArgs);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
Audit(uow, AuditType.Save, "Save Template performed by user", userId, template.Id);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
2016-01-19 21:38:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-18 10:55:19 +02:00
|
|
|
|
return OperationStatus.Attempt.Succeed<OperationStatusType, ITemplate>(OperationStatusType.Success, evtMsgs, template);
|
2016-01-19 21:38:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2012-12-14 12:59:47 -01:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02: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)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2014-11-20 19:51:42 +11:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02: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>
|
2015-11-03 14:07:05 +01:00
|
|
|
|
/// Gets a <see cref="ITemplate"/> object by its alias.
|
2012-10-24 11:29:51 -02:00
|
|
|
|
/// </summary>
|
2015-11-03 14:07:05 +01:00
|
|
|
|
/// <param name="alias">The alias of the template.</param>
|
|
|
|
|
|
/// <returns>The <see cref="ITemplate"/> object matching the alias, or null.</returns>
|
2012-12-12 15:17:48 -01:00
|
|
|
|
public ITemplate GetTemplate(string alias)
|
2012-10-24 11:29:51 -02:00
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2012-12-14 12:59:47 -01:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
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>
|
2015-11-03 14:07:05 +01:00
|
|
|
|
/// Gets a <see cref="ITemplate"/> object by its identifier.
|
2012-12-12 15:17:48 -01:00
|
|
|
|
/// </summary>
|
2015-11-03 14:07:05 +01:00
|
|
|
|
/// <param name="id">The identifer of the template.</param>
|
|
|
|
|
|
/// <returns>The <see cref="ITemplate"/> object matching the identifier, or null.</returns>
|
2012-12-12 15:17:48 -01:00
|
|
|
|
public ITemplate GetTemplate(int id)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2012-12-17 11:16:09 -01:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.Get(id);
|
2012-12-14 12:59:47 -01:00
|
|
|
|
}
|
2012-12-12 15:17:48 -01:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-11-03 14:07:05 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a <see cref="ITemplate"/> object by its guid identifier.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id">The guid identifier of the template.</param>
|
|
|
|
|
|
/// <returns>The <see cref="ITemplate"/> object matching the identifier, or null.</returns>
|
|
|
|
|
|
public ITemplate GetTemplate(Guid id)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-11-03 14:07:05 +01:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-09-22 18:28:21 +02:00
|
|
|
|
var query = Query<ITemplate>().Where(x => x.Key == id);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetByQuery(query).SingleOrDefault();
|
2015-11-03 14:07:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-08-05 11:50:20 +02:00
|
|
|
|
public IEnumerable<ITemplate> GetTemplateDescendants(string alias)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-08-05 11:50:20 +02:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetDescendants(alias);
|
2015-08-05 11:50:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the template descendants
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="masterTemplateId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public IEnumerable<ITemplate> GetTemplateDescendants(int masterTemplateId)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-08-05 11:50:20 +02:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetDescendants(masterTemplateId);
|
2015-08-05 11:50:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the template children
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="alias"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public IEnumerable<ITemplate> GetTemplateChildren(string alias)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-08-05 11:50:20 +02:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetChildren(alias);
|
2015-08-05 11:50:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the template children
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="masterTemplateId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public IEnumerable<ITemplate> GetTemplateChildren(int masterTemplateId)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-08-05 11:50:20 +02:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetChildren(masterTemplateId);
|
2015-08-05 11:50:20 +02: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>
|
2016-01-06 19:27:15 +01:00
|
|
|
|
[Obsolete("Use GetDescendants instead")]
|
|
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
2013-12-16 18:10:44 +11:00
|
|
|
|
public TemplateNode GetTemplateNode(string alias)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2013-12-16 18:10:44 +11:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetTemplateNode(alias);
|
2013-12-16 18:10:44 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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>
|
2016-01-06 19:27:15 +01:00
|
|
|
|
[Obsolete("Use GetDescendants instead")]
|
|
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
2013-12-16 18:10:44 +11:00
|
|
|
|
public TemplateNode FindTemplateInTree(TemplateNode anyNode, string alias)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2013-12-16 18:10:44 +11:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.FindTemplateInTree(anyNode, alias);
|
2013-12-16 18:10:44 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2013-12-16 18:10:44 +11:00
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
if (uow.Events.DispatchCancelable(SavingTemplate, this, new SaveEventArgs<ITemplate>(template)))
|
|
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2013-12-16 18:10:44 +11:00
|
|
|
|
repository.AddOrUpdate(template);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
uow.Events.Dispatch(SavedTemplate, this, new SaveEventArgs<ITemplate>(template, false));
|
|
|
|
|
|
|
|
|
|
|
|
Audit(uow, AuditType.Save, "Save Template performed by user", userId, template.Id);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
2013-12-16 18:10:44 +11:00
|
|
|
|
}
|
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)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var templatesA = templates.ToArray();
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2013-03-20 20:31:44 -01:00
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
if (uow.Events.DispatchCancelable(SavingTemplate, this, new SaveEventArgs<ITemplate>(templatesA)))
|
|
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
foreach (var template in templatesA)
|
2013-03-20 20:31:44 -01:00
|
|
|
|
repository.AddOrUpdate(template);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
uow.Events.Dispatch(SavedTemplate, this, new SaveEventArgs<ITemplate>(templatesA, false));
|
|
|
|
|
|
|
|
|
|
|
|
Audit(uow, AuditType.Save, "Save Template performed by user", userId, -1);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
2013-03-20 20:31:44 -01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-14 12:09:30 +11:00
|
|
|
|
/// <summary>
|
2016-05-02 12:12:21 +02:00
|
|
|
|
/// This checks what the default rendering engine is set in config but then also ensures that there isn't already
|
|
|
|
|
|
/// a template that exists in the opposite rendering engine's template folder, then returns the appropriate
|
2015-01-14 12:09:30 +11:00
|
|
|
|
/// rendering engine to use.
|
2016-05-02 12:12:21 +02:00
|
|
|
|
/// </summary>
|
2015-01-14 12:09:30 +11:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// The reason this is required is because for example, if you have a master page file already existing under ~/masterpages/Blah.aspx
|
2016-05-02 12:12:21 +02:00
|
|
|
|
/// and then you go to create a template in the tree called Blah and the default rendering engine is MVC, it will create a Blah.cshtml
|
|
|
|
|
|
/// empty template in ~/Views. This means every page that is using Blah will go to MVC and render an empty page.
|
|
|
|
|
|
/// This is mostly related to installing packages since packages install file templates to the file system and then create the
|
2015-01-14 12:09:30 +11:00
|
|
|
|
/// templates in business logic. Without this, it could cause the wrong rendering engine to be used for a package.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public RenderingEngine DetermineTemplateRenderingEngine(ITemplate template)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-01-14 12:09:30 +11:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.DetermineTemplateRenderingEngine(template);
|
2015-01-14 12:09:30 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2016-05-02 12:24:13 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2012-12-14 12:59:47 -01:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var template = repository.Get(alias);
|
2016-05-18 10:55:19 +02:00
|
|
|
|
if (template == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2012-12-10 13:49:20 -01:00
|
|
|
|
|
2017-09-18 15:33:13 +02:00
|
|
|
|
var args = new DeleteEventArgs<ITemplate>(template);
|
|
|
|
|
|
if (uow.Events.DispatchCancelable(DeletingTemplate, this, args))
|
2017-05-12 14:49:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-09-23 10:08:18 +02:00
|
|
|
|
|
2013-12-16 18:10:44 +11:00
|
|
|
|
repository.Delete(template);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2017-09-18 15:33:13 +02:00
|
|
|
|
args.CanCancel = false;
|
|
|
|
|
|
uow.Events.Dispatch(DeletedTemplate, this, args);
|
2017-09-23 10:08:18 +02:00
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
Audit(uow, AuditType.Delete, "Delete Template performed by user", userId, template.Id);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-01-14 12:09:30 +11:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.ValidateTemplate(template);
|
2015-01-14 12:09:30 +11:00
|
|
|
|
}
|
2015-09-07 12:38:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-09 09:26:29 +02:00
|
|
|
|
public Stream GetTemplateFileContentStream(string filepath)
|
2015-11-30 16:39:27 +01:00
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-11-30 16:39:27 +01:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetFileContentStream(filepath);
|
2015-12-08 12:53:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-15 13:25:11 +02:00
|
|
|
|
public void SetTemplateFileContent(string filepath, Stream content)
|
2015-12-08 12:53:11 +01:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2015-12-08 12:53:11 +01:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
2016-04-15 13:25:11 +02:00
|
|
|
|
repository.SetFileContent(filepath, content);
|
2016-11-03 10:31:44 +01:00
|
|
|
|
uow.Complete();
|
2015-11-30 16:39:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
public long GetTemplateFileSize(string filepath)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = uow.CreateRepository<ITemplateRepository>();
|
|
|
|
|
|
return repository.GetFileSize(filepath);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public IEnumerable<string> GetPartialViewSnippetNames(params string[] filterNames)
|
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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var snippetPath = IOHelper.MapPath($"{SystemDirectories.Umbraco}/PartialViewMacros/Templates/");
|
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));
|
2016-05-02 12:12:21 +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
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public void DeletePartialViewFolder(string folderPath)
|
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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
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
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IPartialViewRepository>();
|
|
|
|
|
|
((PartialViewRepository) repository).DeleteFolder(folderPath);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
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
|
|
|
|
}
|
2012-10-24 11:29:51 -02:00
|
|
|
|
}
|
2012-11-11 06:53:02 -01:00
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public void DeletePartialViewMacroFolder(string folderPath)
|
2014-08-18 17:47:55 +02:00
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
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
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IPartialViewMacroRepository>();
|
|
|
|
|
|
((PartialViewMacroRepository) repository).DeleteFolder(folderPath);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
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
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public IPartialView GetPartialView(string path)
|
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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: 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
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IPartialViewRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.Get(path);
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public IPartialView GetPartialViewMacro(string path)
|
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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: 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
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IPartialViewMacroRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.Get(path);
|
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
|
|
|
|
|
2016-09-09 13:28:30 +02:00
|
|
|
|
public IEnumerable<IPartialView> GetPartialViewMacros(params string[] names)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2016-09-09 13:28:30 +02:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
var repository = uow.CreateRepository<IPartialViewMacroRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetAll(names).OrderBy(x => x.Name);
|
2016-09-09 13:28:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-09 13:33:14 +02:00
|
|
|
|
public IXsltFile GetXsltFile(string path)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2016-09-09 13:33:14 +02:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
var repository = uow.CreateRepository<IXsltFileRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.Get(path);
|
2016-09-09 13:33:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<IXsltFile> GetXsltFiles(params string[] names)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2016-09-09 13:33:14 +02:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
var repository = uow.CreateRepository<IXsltFileRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetAll(names).OrderBy(x => x.Name);
|
2016-09-09 13:33:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public Attempt<IPartialView> CreatePartialView(IPartialView partialView, string snippetName = null, 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
|
|
|
|
{
|
2015-01-09 18:39:44 +11:00
|
|
|
|
return CreatePartialViewMacro(partialView, PartialViewType.PartialView, snippetName, userId);
|
|
|
|
|
|
}
|
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
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public Attempt<IPartialView> CreatePartialViewMacro(IPartialView partialView, string snippetName = null, int userId = 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return CreatePartialViewMacro(partialView, PartialViewType.PartialViewMacro, snippetName, userId);
|
|
|
|
|
|
}
|
2014-08-19 12:51:07 +02:00
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
private Attempt<IPartialView> CreatePartialViewMacro(IPartialView partialView, PartialViewType partialViewType, string snippetName = null, int userId = 0)
|
|
|
|
|
|
{
|
2015-09-07 12:38:46 +02:00
|
|
|
|
string partialViewHeader;
|
2015-01-09 18:39:44 +11:00
|
|
|
|
switch (partialViewType)
|
2014-08-18 17:47:55 +02:00
|
|
|
|
{
|
2015-01-09 18:39:44 +11:00
|
|
|
|
case PartialViewType.PartialView:
|
|
|
|
|
|
partialViewHeader = PartialViewHeader;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case PartialViewType.PartialViewMacro:
|
|
|
|
|
|
partialViewHeader = PartialViewMacroHeader;
|
|
|
|
|
|
break;
|
2015-09-07 12:38:46 +02:00
|
|
|
|
default:
|
2017-05-12 14:49:44 +02:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(partialViewType));
|
2014-08-18 17:47:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
string partialViewContent = null;
|
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 (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);
|
2016-05-02 12:12:21 +02:00
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
partialViewContent = $"{partialViewHeader}{Environment.NewLine}{snippetContent}";
|
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
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
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
|
|
|
|
{
|
2017-09-18 15:33:13 +02:00
|
|
|
|
var newEventArgs = new NewEventArgs<IPartialView>(partialView, true, partialView.Alias, -1);
|
|
|
|
|
|
if (uow.Events.DispatchCancelable(CreatingPartialView, this, newEventArgs))
|
2017-05-12 14:49:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
return Attempt<IPartialView>.Fail();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-29 10:53:19 +02:00
|
|
|
|
var repository = uow.CreatePartialViewRepository(partialViewType);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
if (partialViewContent != null) partialView.Content = partialViewContent;
|
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);
|
2017-09-23 10:08:18 +02:00
|
|
|
|
|
2017-09-18 15:33:13 +02:00
|
|
|
|
newEventArgs.CanCancel = false;
|
|
|
|
|
|
uow.Events.Dispatch(CreatedPartialView, this, newEventArgs);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
|
|
|
|
|
Audit(uow, AuditType.Save, $"Save {partialViewType} performed by user", userId, -1);
|
|
|
|
|
|
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
2014-08-18 17:47:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
return Attempt<IPartialView>.Succeed(partialView);
|
2014-08-18 17:47:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public bool DeletePartialView(string path, int userId = 0)
|
2014-08-18 17:47:55 +02:00
|
|
|
|
{
|
2015-01-09 18:39:44 +11:00
|
|
|
|
return DeletePartialViewMacro(path, PartialViewType.PartialView, userId);
|
|
|
|
|
|
}
|
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
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public bool DeletePartialViewMacro(string path, int userId = 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return DeletePartialViewMacro(path, PartialViewType.PartialViewMacro, userId);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
private bool DeletePartialViewMacro(string path, PartialViewType partialViewType, 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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2016-05-02 12:12:21 +02:00
|
|
|
|
{
|
2016-04-29 10:53:19 +02:00
|
|
|
|
var repository = uow.CreatePartialViewRepository(partialViewType);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var partialView = repository.Get(path);
|
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 (partialView == null)
|
2016-05-18 10:55:19 +02:00
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
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;
|
2016-05-18 10:55:19 +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
|
|
|
|
|
2017-09-18 15:33:13 +02:00
|
|
|
|
var deleteEventArgs = new DeleteEventArgs<IPartialView>(partialView);
|
|
|
|
|
|
if (uow.Events.DispatchCancelable(DeletingPartialView, this, deleteEventArgs))
|
2017-05-12 14:49:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
2017-09-18 15:33:13 +02:00
|
|
|
|
return false;
|
2017-05-12 14:49:44 +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);
|
2017-09-18 15:33:13 +02:00
|
|
|
|
deleteEventArgs.CanCancel = false;
|
|
|
|
|
|
uow.Events.Dispatch(DeletedPartialView, this, deleteEventArgs);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
Audit(uow, AuditType.Delete, $"Delete {partialViewType} performed by user", userId, -1);
|
|
|
|
|
|
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
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
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public Attempt<IPartialView> SavePartialView(IPartialView partialView, int userId = 0)
|
2014-08-19 12:51:07 +02:00
|
|
|
|
{
|
2015-01-09 18:39:44 +11:00
|
|
|
|
return SavePartialView(partialView, PartialViewType.PartialView, userId);
|
|
|
|
|
|
}
|
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
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public Attempt<IPartialView> SavePartialViewMacro(IPartialView partialView, int userId = 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return SavePartialView(partialView, PartialViewType.PartialViewMacro, userId);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-09 18:39:44 +11:00
|
|
|
|
private Attempt<IPartialView> SavePartialView(IPartialView partialView, PartialViewType partialViewType, 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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2015-01-09 18:39:44 +11:00
|
|
|
|
{
|
2017-09-18 15:33:13 +02:00
|
|
|
|
var saveEventArgs = new SaveEventArgs<IPartialView>(partialView);
|
|
|
|
|
|
if (uow.Events.DispatchCancelable(SavingPartialView, this, saveEventArgs))
|
2017-05-12 14:49:44 +02:00
|
|
|
|
{
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
return Attempt<IPartialView>.Fail();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-29 10:53:19 +02:00
|
|
|
|
var repository = uow.CreatePartialViewRepository(partialViewType);
|
2015-01-09 18:39:44 +11:00
|
|
|
|
repository.AddOrUpdate(partialView);
|
2017-09-18 15:33:13 +02:00
|
|
|
|
saveEventArgs.CanCancel = false;
|
2017-05-12 14:49:44 +02:00
|
|
|
|
Audit(uow, AuditType.Save, $"Save {partialViewType} performed by user", userId, -1);
|
2017-09-18 15:33:13 +02:00
|
|
|
|
uow.Events.Dispatch(SavedPartialView, this, saveEventArgs);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
|
2016-05-02 12:12:21 +02:00
|
|
|
|
uow.Complete();
|
2014-08-19 12:51:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Attempt.Succeed(partialView);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-14 12:09:30 +11:00
|
|
|
|
public bool ValidatePartialView(PartialView 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
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-09-08 17:48:26 +02:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IPartialViewRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.ValidatePartialView(partialView);
|
2015-09-08 17:48:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-01-14 12:09:30 +11:00
|
|
|
|
|
2015-09-08 17:48:26 +02:00
|
|
|
|
public bool ValidatePartialViewMacro(PartialView partialView)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-09-08 17:48:26 +02:00
|
|
|
|
{
|
2016-04-28 08:48:59 +02:00
|
|
|
|
var repository = uow.CreateRepository<IPartialViewMacroRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.ValidatePartialView(partialView);
|
2015-09-08 17:48:26 +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 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";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var snippetPath = IOHelper.MapPath($"{SystemDirectories.Umbraco}/PartialViewMacros/Templates/{fileName}");
|
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 System.IO.File.Exists(snippetPath)
|
|
|
|
|
|
? Attempt<string>.Succeed(snippetPath)
|
|
|
|
|
|
: Attempt<string>.Fail();
|
2015-01-09 18:39:44 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-09 13:28:30 +02:00
|
|
|
|
public Stream GetPartialViewMacroFileContentStream(string filepath)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2016-09-09 13:28:30 +02:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
var repository = uow.CreatePartialViewRepository(PartialViewType.PartialViewMacro);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetFileContentStream(filepath);
|
2016-09-09 13:28:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetPartialViewMacroFileContent(string filepath, Stream content)
|
|
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2016-09-09 13:31:43 +02:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
var repository = uow.CreatePartialViewRepository(PartialViewType.PartialViewMacro);
|
2016-09-09 13:31:43 +02:00
|
|
|
|
repository.SetFileContent(filepath, content);
|
2016-11-03 10:31:44 +01:00
|
|
|
|
uow.Complete();
|
2016-09-09 13:31:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Stream GetPartialViewFileContentStream(string filepath)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2016-09-09 13:31:43 +02:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
var repository = uow.CreatePartialViewRepository(PartialViewType.PartialView);
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetFileContentStream(filepath);
|
2016-09-09 13:31:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetPartialViewFileContent(string filepath, Stream content)
|
|
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
2016-09-09 13:28:30 +02:00
|
|
|
|
{
|
2016-11-03 10:31:44 +01:00
|
|
|
|
var repository = uow.CreatePartialViewRepository(PartialViewType.PartialView);
|
2016-09-09 13:28:30 +02:00
|
|
|
|
repository.SetFileContent(filepath, content);
|
2016-11-03 10:31:44 +01:00
|
|
|
|
uow.Complete();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
public void CreatePartialViewFolder(string folderPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = uow.CreatePartialViewRepository(PartialViewType.PartialView);
|
|
|
|
|
|
((PartialViewRepository) repository).AddFolder(folderPath);
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void CreatePartialViewMacroFolder(string folderPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = uow.CreatePartialViewRepository(PartialViewType.PartialViewMacro);
|
|
|
|
|
|
((PartialViewMacroRepository) repository).AddFolder(folderPath);
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long GetPartialViewMacroFileSize(string filepath)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = uow.CreatePartialViewRepository(PartialViewType.PartialViewMacro);
|
|
|
|
|
|
return repository.GetFileSize(filepath);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long GetPartialViewFileSize(string filepath)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = uow.CreatePartialViewRepository(PartialViewType.PartialView);
|
|
|
|
|
|
return repository.GetFileSize(filepath);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Snippets
|
|
|
|
|
|
|
|
|
|
|
|
public string GetPartialViewSnippetContent(string snippetName)
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetPartialViewMacroSnippetContent(snippetName, PartialViewType.PartialView);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetPartialViewMacroSnippetContent(string snippetName)
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetPartialViewMacroSnippetContent(snippetName, PartialViewType.PartialViewMacro);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string GetPartialViewMacroSnippetContent(string snippetName, PartialViewType partialViewType)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (snippetName.IsNullOrWhiteSpace())
|
|
|
|
|
|
throw new ArgumentNullException(nameof(snippetName));
|
|
|
|
|
|
|
|
|
|
|
|
string partialViewHeader;
|
|
|
|
|
|
switch (partialViewType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case PartialViewType.PartialView:
|
|
|
|
|
|
partialViewHeader = PartialViewHeader;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case PartialViewType.PartialViewMacro:
|
|
|
|
|
|
partialViewHeader = PartialViewMacroHeader;
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(partialViewType));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Try and get the snippet path
|
|
|
|
|
|
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 = $"{partialViewHeader}{Environment.NewLine}{snippetContent}";
|
|
|
|
|
|
return content;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-03 10:31:44 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Xslt
|
|
|
|
|
|
|
|
|
|
|
|
public Stream GetXsltFileContentStream(string filepath)
|
|
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2016-11-03 10:31:44 +01:00
|
|
|
|
{
|
|
|
|
|
|
var repository = uow.CreateRepository<IXsltFileRepository>();
|
2017-05-12 14:49:44 +02:00
|
|
|
|
return repository.GetFileContentStream(filepath);
|
2016-09-09 13:28:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-03 10:31:44 +01:00
|
|
|
|
public void SetXsltFileContent(string filepath, Stream content)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork())
|
|
|
|
|
|
{
|
|
|
|
|
|
var repository = uow.CreateRepository<IXsltFileRepository>();
|
|
|
|
|
|
repository.SetFileContent(filepath, content);
|
|
|
|
|
|
uow.Complete();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-09-07 12:38:46 +02:00
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
public long GetXsltFileSize(string filepath)
|
2015-01-19 15:12:34 +11:00
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using (var uow = UowProvider.CreateUnitOfWork(readOnly: true))
|
2015-01-19 15:12:34 +11:00
|
|
|
|
{
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var repository = uow.CreateRepository<IXsltFileRepository>();
|
|
|
|
|
|
return repository.GetFileSize(filepath);
|
2015-01-19 15:12:34 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
private void Audit(IUnitOfWork uow, AuditType type, string message, int userId, int objectId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var repo = uow.CreateRepository<IAuditRepository>();
|
|
|
|
|
|
repo.AddOrUpdate(new AuditItem(objectId, message, type, userId));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
2016-05-02 12:12:21 +02: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
|
2016-05-02 12:12:21 +02:00
|
|
|
|
/// </summary>
|
2013-12-16 18:10:44 +11:00
|
|
|
|
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
|
2016-05-02 12:12:21 +02:00
|
|
|
|
/// </summary>
|
2013-12-16 18:10:44 +11:00
|
|
|
|
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>
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public static event TypedEventHandler<IFileService, SaveEventArgs<IPartialView>> SavingPartialView;
|
2014-08-19 12:51:07 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Occurs after Save
|
|
|
|
|
|
/// </summary>
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public static event TypedEventHandler<IFileService, SaveEventArgs<IPartialView>> SavedPartialView;
|
2016-05-02 12:12:21 +02:00
|
|
|
|
|
2014-08-18 17:47:55 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Occurs before Create
|
|
|
|
|
|
/// </summary>
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public static event TypedEventHandler<IFileService, NewEventArgs<IPartialView>> CreatingPartialView;
|
2014-08-18 17:47:55 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Occurs after Create
|
|
|
|
|
|
/// </summary>
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public static event TypedEventHandler<IFileService, NewEventArgs<IPartialView>> CreatedPartialView;
|
2014-08-18 17:47:55 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Occurs before Delete
|
|
|
|
|
|
/// </summary>
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public static event TypedEventHandler<IFileService, DeleteEventArgs<IPartialView>> DeletingPartialView;
|
2014-08-18 17:47:55 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Occurs after Delete
|
|
|
|
|
|
/// </summary>
|
2015-01-09 18:39:44 +11:00
|
|
|
|
public static event TypedEventHandler<IFileService, DeleteEventArgs<IPartialView>> DeletedPartialView;
|
2014-08-18 17:47:55 +02:00
|
|
|
|
|
2012-12-10 13:49:20 -01:00
|
|
|
|
#endregion
|
2012-10-24 11:29:51 -02:00
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|