Moves PartialView save/delete to the FileService

This commit is contained in:
Sebastiaan Janssen
2014-08-18 17:47:55 +02:00
parent 1ccee3f305
commit 65a2b79189
4 changed files with 221 additions and 122 deletions

View File

@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using Umbraco.Core.IO;
namespace Umbraco.Core.Models
{
/// <summary>
/// Represents a Partial View file
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
internal class PartialView : File
{
private readonly Regex _headerMatch = new Regex("^@inherits\\s+?.*$", RegexOptions.Multiline | RegexOptions.Compiled);
public PartialView(string path)
: base(path)
{
base.Path = path;
}
/// <summary>
/// Boolean indicating whether the file could be validated
/// </summary>
/// <returns>True if file is valid, otherwise false</returns>
public override bool IsValid()
{
//Validate extension
var validExtension = IOHelper.VerifyFileExtension(Path, new List<string> { "cshtml" });
return validExtension;
}
public string FileName { get; set; }
public string SnippetName { get; set; }
public bool CreateMacro { get; set; }
public string CodeHeader { get; set; }
public string ParentFolderName { get; set; }
public string AssignedApp { get; set; }
public string EditViewFile { get; set; }
public string BasePath { get; set; }
public string ReturnUrl { get; set; }
public bool SaveSucceeded { get; set; }
internal Regex HeaderMatch
{
get
{
return _headerMatch;
}
}
internal Attempt<string> TryGetSnippetPath(string fileName)
{
var partialViewsFileSystem = new PhysicalFileSystem(BasePath);
var snippetPath = IOHelper.MapPath(string.Format("{0}/PartialViewMacros/Templates/{1}", SystemDirectories.Umbraco, fileName));
return partialViewsFileSystem.FileExists(snippetPath)
? Attempt<string>.Succeed(snippetPath)
: Attempt<string>.Fail();
}
}
}