deploy-30 - fixes

This commit is contained in:
Stephan
2016-04-15 13:25:11 +02:00
parent 523283acd0
commit 378e8f5cd9
23 changed files with 161 additions and 114 deletions

View File

@@ -450,11 +450,11 @@ namespace Umbraco.Core.Models
#region SetValue for setting file contents
/// <summary>
/// Sets and uploads the file from a HttpPostedFileBase object as the property value
/// Stores and sets an uploaded HttpPostedFileBase as a property value.
/// </summary>
/// <param name="content"><see cref="IContentBase"/> to add property value to</param>
/// <param name="propertyTypeAlias">Alias of the property to save the value on</param>
/// <param name="value">The <see cref="HttpPostedFileBase"/> containing the file that will be uploaded</param>
/// <param name="content"><see cref="IContentBase"/>A content item.</param>
/// <param name="propertyTypeAlias">The property alias.</param>
/// <param name="value">The uploaded <see cref="HttpPostedFileBase"/>.</param>
public static void SetValue(this IContentBase content, string propertyTypeAlias, HttpPostedFileBase value)
{
// ensure we get the filename without the path in IE in intranet mode
@@ -478,37 +478,37 @@ namespace Umbraco.Core.Models
}
/// <summary>
/// Sets and uploads the file from a HttpPostedFile object as the property value
/// Stores and sets an uploaded HttpPostedFile as a property value.
/// </summary>
/// <param name="content"><see cref="IContentBase"/> to add property value to</param>
/// <param name="propertyTypeAlias">Alias of the property to save the value on</param>
/// <param name="value">The <see cref="HttpPostedFile"/> containing the file that will be uploaded</param>
/// <param name="content"><see cref="IContentBase"/>A content item.</param>
/// <param name="propertyTypeAlias">The property alias.</param>
/// <param name="value">The uploaded <see cref="HttpPostedFile"/>.</param>
public static void SetValue(this IContentBase content, string propertyTypeAlias, HttpPostedFile value)
{
SetValue(content, propertyTypeAlias, (HttpPostedFileBase)new HttpPostedFileWrapper(value));
SetValue(content, propertyTypeAlias, (HttpPostedFileBase) new HttpPostedFileWrapper(value));
}
/// <summary>
/// Sets and uploads the file from a HttpPostedFileWrapper object as the property value
/// Stores and sets an uploaded HttpPostedFileWrapper as a property value.
/// </summary>
/// <param name="content"><see cref="IContentBase"/> to add property value to</param>
/// <param name="propertyTypeAlias">Alias of the property to save the value on</param>
/// <param name="value">The <see cref="HttpPostedFileWrapper"/> containing the file that will be uploaded</param>
/// <param name="content"><see cref="IContentBase"/>A content item.</param>
/// <param name="propertyTypeAlias">The property alias.</param>
/// <param name="value">The uploaded <see cref="HttpPostedFileWrapper"/>.</param>
[Obsolete("There is no reason for this overload since HttpPostedFileWrapper inherits from HttpPostedFileBase")]
public static void SetValue(this IContentBase content, string propertyTypeAlias, HttpPostedFileWrapper value)
{
SetValue(content, propertyTypeAlias, (HttpPostedFileBase)value);
SetValue(content, propertyTypeAlias, (HttpPostedFileBase) value);
}
/// <summary>
/// Sets a content item property value with a file coming from a stream.
/// Stores and sets a file as a property value.
/// </summary>
/// <param name="content">The content item.</param>
/// <param name="propertyTypeAlias">The property type alias.</param>
/// <param name="filename">Name of the file</param>
/// <param name="filestream">The stream containing the file data.</param>
/// <param name="content"><see cref="IContentBase"/>A content item.</param>
/// <param name="propertyTypeAlias">The property alias.</param>
/// <param name="filename">The name of the file.</param>
/// <param name="filestream">A stream containing the file data.</param>
/// <remarks>This really is for FileUpload fields only, and should be obsoleted. For anything else,
/// you need to store the file by yourself using <see cref="StoreFile"/> and then figure out
/// you need to store the file by yourself using Store and then figure out
/// how to deal with auto-fill properties (if any) and thumbnails (if any) by yourself.</remarks>
public static void SetValue(this IContentBase content, string propertyTypeAlias, string filename, Stream filestream)
{
@@ -522,12 +522,28 @@ namespace Umbraco.Core.Models
MediaHelper.SetUploadFile(content, propertyTypeAlias, filename, filestream);
}
public static string StoreFile(this IContentBase content, string propertyTypeAlias, string filename, Stream filestream, string oldpath)
/// <summary>
/// Stores a file.
/// </summary>
/// <param name="content"><see cref="IContentBase"/>A content item.</param>
/// <param name="propertyTypeAlias">The property alias.</param>
/// <param name="filename">The name of the file.</param>
/// <param name="filestream">A stream containing the file data.</param>
/// <param name="filepath">The original file path, if any.</param>
/// <returns>The path to the file, relative to the media filesystem.</returns>
/// <remarks>
/// <para>Does NOT set the property value, so one should probably store the file and then do
/// something alike: property.Value = MediaHelper.FileSystem.GetUrl(filepath).</para>
/// <para>The original file path is used, in the old media file path scheme, to try and reuse
/// the "folder number" that was assigned to the previous file referenced by the property,
/// if any.</para>
/// </remarks>
public static string StoreFile(this IContentBase content, string propertyTypeAlias, string filename, Stream filestream, string filepath)
{
var propertyType = content.GetContentType()
.CompositionPropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias));
if (propertyType == null) throw new ArgumentException("Invalid property type alias " + propertyTypeAlias + ".");
return MediaHelper.StoreFile(content, propertyType, filename, filestream, oldpath);
return MediaHelper.StoreFile(content, propertyType, filename, filestream, filepath);
}
#endregion

View File

@@ -25,21 +25,6 @@ namespace Umbraco.Core.Models
private string _content;
internal Func<File, string> GetFileContent { get; set; }
// whether to use whatever already exists on filesystem
internal bool _useExistingContent;
/// <summary>
/// Indicates that the file should use whatever content already
/// exists on the filesystem which manages the file, bypassing content
/// management entirely.
/// </summary>
/// <remarks>Only for the next save. Is resetted when the file is saved.</remarks>
public void UseExistingContent()
{
_useExistingContent = true;
_content = null; // force content to be loaded
}
protected File(string path, Func<File, string> getFileContent = null)
{
_path = SanitizePath(path);

View File

@@ -39,14 +39,6 @@ namespace Umbraco.Core.Models
/// </summary>
string Content { get; set; }
/// <summary>
/// Indicates that the file should use whatever content already
/// exists on the filesystem which manages the file, bypassing content
/// management entirely.
/// </summary>
/// <remarks>Only for the next save. Is resetted when the file is saved.</remarks>
void UseExistingContent();
/// <summary>
/// Gets or sets the file's virtual path (i.e. the file path relative to the root of the website)
/// </summary>

View File

@@ -15,7 +15,7 @@ using Umbraco.Core.Strings;
namespace Umbraco.Core.Models
{
/// <summary>
/// Represents a Template file
/// Represents a Template file.
/// </summary>
[Serializable]
[DataContract(IsReference = true)]

View File

@@ -0,0 +1,52 @@
using System;
using System.Runtime.Serialization;
namespace Umbraco.Core.Models
{
/// <summary>
/// Represents a Template file that can have its content on disk.
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
public class TemplateOnDisk : Template
{
/// <summary>
/// Initializes a new instance of the <see cref="TemplateOnDisk"/> class.
/// </summary>
/// <param name="name">The name of the template.</param>
/// <param name="alias">The alias of the template.</param>
public TemplateOnDisk(string name, string alias)
: base(name, alias)
{
IsOnDisk = true;
}
/// <summary>
/// Gets or sets a value indicating whether the content is on disk already.
/// </summary>
public bool IsOnDisk { get; set; }
/// <summary>
/// Gets or sets the content.
/// </summary>
/// <remarks>
/// <para>Getting the content while the template is "on disk" throws,
/// the template must be saved before its content can be retrieved.</para>
/// <para>Setting the content means it is not "on disk" anymore, and the
/// template becomes (and behaves like) a normal template.</para>
/// </remarks>
public override string Content
{
get
{
if (IsOnDisk) throw new InvalidOperationException("On-disk template do not have content until saved.");
return base.Content;
}
set
{
base.Content = value;
IsOnDisk = false;
}
}
}
}