Adds a null check to set the label values, if the content item wasn't loaded then no properties were filled and thsu

no need to update the labels. Cleans up a tiny bit more code.
This commit is contained in:
Shannon Deminick
2013-01-08 00:58:22 +03:00
parent 147867a7a8
commit e49bb2dd51
3 changed files with 29 additions and 17 deletions

View File

@@ -27,5 +27,11 @@ namespace Umbraco.Core.IO
{
return Path.GetExtension(fs.GetFullPath(path));
}
[UmbracoExperimentalFeature("http://issues.umbraco.org/issue/U4-1156", "Will be declared public after 4.10")]
internal static string GetFileName(this IFileSystem fs, string path)
{
return Path.GetFileName(fs.GetFullPath(path));
}
}
}

View File

@@ -13,13 +13,13 @@ namespace umbraco.cms.businesslogic.Files
{
public class UmbracoFile : IFile
{
private string _path;
private readonly string _path;
private string _fileName;
private string _extension;
private string _url;
private long _length;
private MediaFileSystem _fs;
private readonly MediaFileSystem _fs;
#region Constructors
@@ -34,7 +34,7 @@ namespace umbraco.cms.businesslogic.Files
_path = path;
initialize();
Initialize();
}
#endregion
@@ -81,12 +81,12 @@ namespace umbraco.cms.businesslogic.Files
#endregion
private void initialize()
private void Initialize()
{
_fileName = System.IO.Path.GetFileName(_path);
_fileName = _fs.GetFileName(_path);
_length = _fs.GetSize(_path);
_extension = System.IO.Path.GetExtension(_path) != null
? System.IO.Path.GetExtension(_path).Substring(1).ToLowerInvariant()
_extension = _fs.GetExtension(_path) != null
? _fs.GetExtension(_path).Substring(1).ToLowerInvariant()
: "";
_url = _fs.GetUrl(_path);
}

View File

@@ -110,14 +110,20 @@ namespace umbraco.editorControls
// we update additional properties post image upload
if (_data.Value != DBNull.Value && !string.IsNullOrEmpty(_data.Value.ToString()))
{
var content = _data.LoadedContentItem;
// update extension in UI
UpdateLabelValue("umbracoExtension", "prop_umbracoExtension", Page, content);
// update file size in UI
UpdateLabelValue("umbracoBytes", "prop_umbracoBytes", Page, content);
UpdateLabelValue("umbracoWidth", "prop_umbracoWidth", Page, content);
UpdateLabelValue("umbracoHeight", "prop_umbracoHeight", Page, content);
//check the FileHandlerData to see if it already loaded in the content item and set it's properties.
//if not, then the properties haven't changed so skip.
if (_data.LoadedContentItem != null)
{
var content = _data.LoadedContentItem;
// update extension in UI
UpdateLabelValue("umbracoExtension", "prop_umbracoExtension", Page, content);
// update file size in UI
UpdateLabelValue("umbracoBytes", "prop_umbracoBytes", Page, content);
UpdateLabelValue("umbracoWidth", "prop_umbracoWidth", Page, content);
UpdateLabelValue("umbracoHeight", "prop_umbracoHeight", Page, content);
}
}
Text = _data.Value.ToString();
}
@@ -249,8 +255,8 @@ namespace umbraco.editorControls
{
var relativeFilePath = _fs.GetRelativePath(_text);
var ext = relativeFilePath.Substring(relativeFilePath.LastIndexOf(".") + 1, relativeFilePath.Length - relativeFilePath.LastIndexOf(".") - 1);
var relativeThumbFilePath = relativeFilePath.Replace("." + ext, "_thumb.jpg");
var hasThumb = false;
var relativeThumbFilePath = relativeFilePath.Replace("." + ext, "_thumb.jpg");
var hasThumb = false;
try
{
hasThumb = _fs.FileExists(relativeThumbFilePath);