deploy-150 - wire GetSize in services

This commit is contained in:
Stephan
2017-01-09 17:49:12 +01:00
parent 844d6c9972
commit cfd8435d68
13 changed files with 152 additions and 11 deletions

View File

@@ -38,13 +38,12 @@ namespace Umbraco.Core.IO
}
// GetSize has been added to IFileSystem2 but not IFileSystem
// this is implementing GetSize for IFileSystem, the old way
public static long GetSize(this IFileSystem fs, string path)
{
// if we reach this point, fs is *not* IFileSystem2
// so it's not FileSystemWrapper nor shadow nor anything we know
// so... fall back to the old & inefficient method
var fs2 = fs as IFileSystem2;
if (fs2 != null) return fs2.GetSize(path);
// this is implementing GetSize for IFileSystem, the old way
using (var file = fs.OpenFile(path))
{
return file.Length;

View File

@@ -234,13 +234,28 @@ namespace Umbraco.Core.Persistence.Repositories
}
}
/// <summary>
/// Dispose any disposable properties
/// </summary>
/// <remarks>
/// Dispose the unit of work
/// </remarks>
protected override void DisposeResources()
public long GetFileSize(string filename)
{
if (FileSystem.FileExists(filename) == false)
return -1;
try
{
return FileSystem.GetSize(filename);
}
catch
{
return -1; // deal with race conds
}
}
/// <summary>
/// Dispose any disposable properties
/// </summary>
/// <remarks>
/// Dispose the unit of work
/// </remarks>
protected override void DisposeResources()
{
_work.DisposeIfDisposable();
}

View File

@@ -10,5 +10,6 @@ namespace Umbraco.Core.Persistence.Repositories
bool ValidatePartialView(IPartialView partialView);
Stream GetFileContentStream(string filepath);
void SetFileContent(string filepath, Stream content);
long GetFileSize(string filepath);
}
}

View File

@@ -8,5 +8,6 @@ namespace Umbraco.Core.Persistence.Repositories
bool ValidateScript(Script script);
Stream GetFileContentStream(string filepath);
void SetFileContent(string filepath, Stream content);
long GetFileSize(string filepath);
}
}

View File

@@ -8,5 +8,6 @@ namespace Umbraco.Core.Persistence.Repositories
bool ValidateStylesheet(Stylesheet stylesheet);
Stream GetFileContentStream(string filepath);
void SetFileContent(string filepath, Stream content);
long GetFileSize(string filepath);
}
}

View File

@@ -72,5 +72,7 @@ namespace Umbraco.Core.Persistence.Repositories
/// <param name="filepath">The filesystem path to the template.</param>
/// <param name="content">The content of the template.</param>
void SetFileContent(string filepath, Stream content);
long GetFileSize(string filepath);
}
}

View File

@@ -8,5 +8,6 @@ namespace Umbraco.Core.Persistence.Repositories
bool ValidateXsltFile(XsltFile xsltFile);
Stream GetFileContentStream(string filepath);
void SetFileContent(string filepath, Stream content);
long GetFileSize(string filepath);
}
}

View File

@@ -144,6 +144,20 @@ namespace Umbraco.Core.Persistence.Repositories
FileSystem.AddFile(filepath, content, true);
}
public long GetFileSize(string filepath)
{
if (FileSystem.FileExists(filepath) == false) return -1;
try
{
return FileSystem.GetSize(filepath);
}
catch
{
return -1; // deal with race conds
}
}
#endregion
}
}

View File

@@ -513,6 +513,11 @@ namespace Umbraco.Core.Persistence.Repositories
GetFileSystem(filepath).AddFile(filepath, content, true);
}
public long GetFileSize(string filepath)
{
return GetFileSystem(filepath).GetSize(filepath);
}
private IFileSystem GetFileSystem(string filepath)
{
var ext = Path.GetExtension(filepath);

View File

@@ -569,6 +569,14 @@ namespace Umbraco.Core.Services
}
}
public long GetTemplateFileSize(string filepath)
{
using (var repository = RepositoryFactory.CreateTemplateRepository(UowProvider.GetUnitOfWork()))
{
return repository.GetFileSize(filepath);
}
}
#endregion
public Stream GetStylesheetFileContentStream(string filepath)
@@ -587,6 +595,14 @@ namespace Umbraco.Core.Services
}
}
public long GetStylesheetFileSize(string filepath)
{
using (var repository = RepositoryFactory.CreateStylesheetRepository(UowProvider.GetUnitOfWork()))
{
return repository.GetFileSize(filepath);
}
}
public Stream GetScriptFileContentStream(string filepath)
{
using (var repository = RepositoryFactory.CreateScriptRepository(UowProvider.GetUnitOfWork()))
@@ -603,6 +619,14 @@ namespace Umbraco.Core.Services
}
}
public long GetScriptFileSize(string filepath)
{
using (var repository = RepositoryFactory.CreateScriptRepository(UowProvider.GetUnitOfWork()))
{
return repository.GetFileSize(filepath);
}
}
public Stream GetXsltFileContentStream(string filepath)
{
using (var repository = RepositoryFactory.CreateXsltFileRepository(UowProvider.GetUnitOfWork()))
@@ -619,6 +643,14 @@ namespace Umbraco.Core.Services
}
}
public long GetXsltFileSize(string filepath)
{
using (var repository = RepositoryFactory.CreateXsltFileRepository(UowProvider.GetUnitOfWork()))
{
return repository.GetFileSize(filepath);
}
}
#region Partial Views
public IEnumerable<string> GetPartialViewSnippetNames(params string[] filterNames)
@@ -890,6 +922,14 @@ namespace Umbraco.Core.Services
}
}
public long GetPartialViewMacroFileSize(string filepath)
{
using (var repository = GetPartialViewRepository(PartialViewType.PartialViewMacro, UowProvider.GetUnitOfWork()))
{
return repository.GetFileSize(filepath);
}
}
public Stream GetPartialViewFileContentStream(string filepath)
{
using (var repository = GetPartialViewRepository(PartialViewType.PartialView, UowProvider.GetUnitOfWork()))
@@ -906,6 +946,14 @@ namespace Umbraco.Core.Services
}
}
public long GetPartialViewFileSize(string filepath)
{
using (var repository = GetPartialViewRepository(PartialViewType.PartialView, UowProvider.GetUnitOfWork()))
{
return repository.GetFileSize(filepath);
}
}
#endregion
private void Audit(AuditType type, string message, int userId, int objectId)

View File

@@ -254,6 +254,13 @@ namespace Umbraco.Core.Services
/// <param name="content">The content of the template.</param>
void SetTemplateFileContent(string filepath, Stream content);
/// <summary>
/// Gets the size of a template.
/// </summary>
/// <param name="filepath">The filesystem path to the template.</param>
/// <returns>The size of the template.</returns>
long GetTemplateFileSize(string filepath);
/// <summary>
/// Gets the content of a stylesheet as a stream.
/// </summary>
@@ -268,6 +275,13 @@ namespace Umbraco.Core.Services
/// <param name="content">The content of the stylesheet.</param>
void SetStylesheetFileContent(string filepath, Stream content);
/// <summary>
/// Gets the size of a stylesheet.
/// </summary>
/// <param name="filepath">The filesystem path to the stylesheet.</param>
/// <returns>The size of the stylesheet.</returns>
long GetStylesheetFileSize(string filepath);
/// <summary>
/// Gets the content of a script file as a stream.
/// </summary>
@@ -282,6 +296,13 @@ namespace Umbraco.Core.Services
/// <param name="content">The content of the script file.</param>
void SetScriptFileContent(string filepath, Stream content);
/// <summary>
/// Gets the size of a script file.
/// </summary>
/// <param name="filepath">The filesystem path to the script file.</param>
/// <returns>The size of the script file.</returns>
long GetScriptFileSize(string filepath);
/// <summary>
/// Gets the content of a XSLT file as a stream.
/// </summary>
@@ -296,6 +317,13 @@ namespace Umbraco.Core.Services
/// <param name="content">The content of the XSLT file.</param>
void SetXsltFileContent(string filepath, Stream content);
/// <summary>
/// Gets the size of a XSLT file.
/// </summary>
/// <param name="filepath">The filesystem path to the XSLT file.</param>
/// <returns>The size of the XSLT file.</returns>
long GetXsltFileSize(string filepath);
/// <summary>
/// Gets the content of a macro partial view as a stream.
/// </summary>
@@ -310,6 +338,13 @@ namespace Umbraco.Core.Services
/// <param name="content">The content of the macro partial view.</param>
void SetPartialViewMacroFileContent(string filepath, Stream content);
/// <summary>
/// Gets the size of a macro partial view.
/// </summary>
/// <param name="filepath">The filesystem path to the macro partial view.</param>
/// <returns>The size of the macro partial view.</returns>
long GetPartialViewMacroFileSize(string filepath);
/// <summary>
/// Gets the content of a partial view as a stream.
/// </summary>
@@ -323,5 +358,12 @@ namespace Umbraco.Core.Services
/// <param name="filepath">The filesystem path to the partial view.</param>
/// <param name="content">The content of the partial view.</param>
void SetPartialViewFileContent(string filepath, Stream content);
/// <summary>
/// Gets the size of a partial view.
/// </summary>
/// <param name="filepath">The filesystem path to the partial view.</param>
/// <returns>The size of the partial view.</returns>
long GetPartialViewFileSize(string filepath);
}
}

View File

@@ -430,6 +430,13 @@ namespace Umbraco.Core.Services
/// <param name="content">The content of the media.</param>
void SetMediaFileContent(string filepath, Stream content);
/// <summary>
/// Gets the size of a media.
/// </summary>
/// <param name="filepath">The filesystem path to the media.</param>
/// <returns>The size of the media.</returns>
long GetMediaFileSize(string filepath);
/// <summary>
/// Deletes a media file and all thumbnails.
/// </summary>

View File

@@ -1361,6 +1361,11 @@ namespace Umbraco.Core.Services
_mediaFileSystem.AddFile(filepath, stream, true);
}
public long GetMediaFileSize(string filepath)
{
return _mediaFileSystem.GetSize(filepath);
}
public void DeleteMediaFile(string filepath)
{
_mediaFileSystem.DeleteFile(filepath, true);