Separates some classes

This commit is contained in:
Shannon
2013-10-28 15:36:08 +11:00
parent 2b7a9389b4
commit 025e7eba1d
4 changed files with 51 additions and 40 deletions

View File

@@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Xml;
using Newtonsoft.Json.Linq;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
@@ -14,7 +11,6 @@ using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using umbraco;
namespace Umbraco.Web.PropertyEditors
{
@@ -177,39 +173,4 @@ namespace Umbraco.Web.PropertyEditors
}
}
internal class UploadFileTypeValidator : IPropertyValidator
{
public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor)
{
//now check the file type
var asJson = value as JObject;
if (asJson == null) yield break;
if (asJson["selectedFiles"] == null) yield break;
var fileNames = asJson["selectedFiles"].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var fileName in fileNames)
{
if (ValidateFileExtension(fileName) == false)
{
yield return new ValidationResult(ui.Text("errors", "dissallowedMediaType"),
new[]
{
//we only store a single value for this editor so the 'member' or 'field'
// we'll associate this error with will simply be called 'value'
"value"
});
}
}
}
internal static bool ValidateFileExtension(string fileName)
{
if (fileName.IndexOf('.') <= 0) return false;
var extension = Path.GetExtension(fileName).TrimStart(".");
return UmbracoConfig.For.UmbracoSettings().Content.DisallowedUploadFiles.Any(x => x.InvariantEquals(extension)) == false;
}
}
}

View File

@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using Newtonsoft.Json.Linq;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using umbraco;
namespace Umbraco.Web.PropertyEditors
{
internal class UploadFileTypeValidator : IPropertyValidator
{
public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor)
{
//now check the file type
var asJson = value as JObject;
if (asJson == null) yield break;
if (asJson["selectedFiles"] == null) yield break;
var fileNames = asJson["selectedFiles"].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var fileName in fileNames)
{
if (ValidateFileExtension(fileName) == false)
{
yield return new ValidationResult(ui.Text("errors", "dissallowedMediaType"),
new[]
{
//we only store a single value for this editor so the 'member' or 'field'
// we'll associate this error with will simply be called 'value'
"value"
});
}
}
}
internal static bool ValidateFileExtension(string fileName)
{
if (fileName.IndexOf('.') <= 0) return false;
var extension = Path.GetExtension(fileName).TrimStart(".");
return UmbracoConfig.For.UmbracoSettings().Content.DisallowedUploadFiles.Any(x => StringExtensions.InvariantEquals(x, extension)) == false;
}
}
}

View File

@@ -344,7 +344,7 @@
<Compile Include="PropertyEditors\EmailAddressPropertyEditor.cs" />
<Compile Include="PropertyEditors\ListViewPropertyEditor.cs" />
<Compile Include="PropertyEditors\MemberPickerPropertyEditor.cs" />
<Compile Include="PropertyEditors\MultiNodePreValueEditor.cs" />
<Compile Include="PropertyEditors\MultiNodePickerPreValueEditor.cs" />
<Compile Include="PropertyEditors\MultiNodeTreePickerPropertyEditor.cs" />
<Compile Include="PropertyEditors\ParameterEditors\TextAreaParameterEditor.cs" />
<Compile Include="PropertyEditors\ParameterEditors\TextParameterEditor.cs" />
@@ -385,6 +385,7 @@
<Compile Include="PropertyEditors\RichTextPreValueEditor.cs" />
<Compile Include="PropertyEditors\UltraSimplePropertyEditor.cs" />
<Compile Include="PropertyEditors\TagsPropertyEditor.cs" />
<Compile Include="PropertyEditors\UploadFileTypeValidator.cs" />
<Compile Include="PropertyEditors\UserPickerPropertyEditor.cs" />
<Compile Include="PropertyEditors\ValueListPreValueEditor.cs" />
<Compile Include="PropertyEditors\DropDownPropertyEditor.cs" />