Removed usage of obsoleted ArgumentNullOrEmptyException

This commit is contained in:
Ronald Barendse
2019-10-07 22:10:21 +02:00
parent 8920e10a94
commit ed90e71f76
43 changed files with 394 additions and 307 deletions

View File

@@ -1,15 +1,10 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
using Umbraco.Core.Media;
using Umbraco.Core.Models;
namespace Umbraco.Core.IO
@@ -92,7 +87,8 @@ namespace Umbraco.Core.IO
{
if (content == null) throw new ArgumentNullException(nameof(content));
if (propertyType == null) throw new ArgumentNullException(nameof(propertyType));
if (string.IsNullOrWhiteSpace(filename)) throw new ArgumentNullOrEmptyException(nameof(filename));
if (filename == null) throw new ArgumentNullException(nameof(filename));
if (string.IsNullOrWhiteSpace(filename)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(filename));
if (filestream == null) throw new ArgumentNullException(nameof(filestream));
// clear the old file, if any
@@ -111,7 +107,8 @@ namespace Umbraco.Core.IO
{
if (content == null) throw new ArgumentNullException(nameof(content));
if (propertyType == null) throw new ArgumentNullException(nameof(propertyType));
if (string.IsNullOrWhiteSpace(sourcepath)) throw new ArgumentNullOrEmptyException(nameof(sourcepath));
if (sourcepath == null) throw new ArgumentNullException(nameof(sourcepath));
if (string.IsNullOrWhiteSpace(sourcepath)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(sourcepath));
// ensure we have a file to copy
if (FileExists(sourcepath) == false) return null;

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using Umbraco.Core.Composing;
using Umbraco.Core.Exceptions;
using System.Threading;
using Umbraco.Core.Logging;
@@ -39,9 +38,11 @@ namespace Umbraco.Core.IO
public PhysicalFileSystem(string rootPath, string rootUrl)
{
if (string.IsNullOrEmpty(rootPath)) throw new ArgumentNullOrEmptyException(nameof(rootPath));
if (string.IsNullOrEmpty(rootUrl)) throw new ArgumentNullOrEmptyException(nameof(rootUrl));
if (rootPath.StartsWith("~/")) throw new ArgumentException("The rootPath argument cannot be a virtual path and cannot start with '~/'");
if (rootPath == null) throw new ArgumentNullException(nameof(rootPath));
if (string.IsNullOrEmpty(rootPath)) throw new ArgumentException("Value can't be empty.", nameof(rootPath));
if (rootUrl == null) throw new ArgumentNullException(nameof(rootUrl));
if (string.IsNullOrEmpty(rootUrl)) throw new ArgumentException("Value can't be empty.", nameof(rootUrl));
if (rootPath.StartsWith("~/")) throw new ArgumentException("Value can't be a virtual path and start with '~/'.", nameof(rootPath));
// rootPath should be... rooted, as in, it's a root path!
if (Path.IsPathRooted(rootPath) == false)

View File

@@ -5,7 +5,6 @@ using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Umbraco.Core.Cache;
using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.PropertyEditors;
@@ -42,7 +41,8 @@ namespace Umbraco.Core.Manifest
_cache = appCaches.RuntimeCache;
_validators = validators ?? throw new ArgumentNullException(nameof(validators));
_filters = filters ?? throw new ArgumentNullException(nameof(filters));
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentNullOrEmptyException(nameof(path));
if (path == null) throw new ArgumentNullException(nameof(path));
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(path));
Path = path;
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
@@ -155,8 +155,8 @@ namespace Umbraco.Core.Manifest
/// </summary>
internal PackageManifest ParseManifest(string text)
{
if (string.IsNullOrWhiteSpace(text))
throw new ArgumentNullOrEmptyException(nameof(text));
if (text == null) throw new ArgumentNullException(nameof(text));
if (string.IsNullOrWhiteSpace(text)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(text));
var manifest = JsonConvert.DeserializeObject<PackageManifest>(text,
new DataEditorConverter(_logger),

View File

@@ -1,4 +1,4 @@
using Umbraco.Core.Exceptions;
using System;
using Umbraco.Core.Migrations.Expressions.Common;
using Umbraco.Core.Migrations.Expressions.Delete.Column;
using Umbraco.Core.Migrations.Expressions.Delete.Constraint;
@@ -39,8 +39,9 @@ namespace Umbraco.Core.Migrations.Expressions.Delete
/// <inheritdoc />
public IExecutableBuilder KeysAndIndexes(string tableName, bool local = true, bool foreign = true)
{
if (tableName.IsNullOrWhiteSpace())
throw new ArgumentNullOrEmptyException(nameof(tableName));
if (tableName == null) throw new ArgumentNullException(nameof(tableName));
if (string.IsNullOrWhiteSpace(tableName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(tableName));
return new DeleteKeysAndIndexesBuilder(_context) { TableName = tableName, DeleteLocal = local, DeleteForeign = foreign };
}

View File

@@ -5,7 +5,6 @@ using System.IO;
using System.Linq;
using System.Xml.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Migrations.Upgrade;
@@ -278,8 +277,10 @@ namespace Umbraco.Core.Migrations.Install
/// <param name="logger">A logger.</param>
private static void SaveConnectionString(string connectionString, string providerName, ILogger logger)
{
if (string.IsNullOrWhiteSpace(connectionString)) throw new ArgumentNullOrEmptyException(nameof(connectionString));
if (string.IsNullOrWhiteSpace(providerName)) throw new ArgumentNullOrEmptyException(nameof(providerName));
if (connectionString == null) throw new ArgumentNullException(nameof(connectionString));
if (string.IsNullOrWhiteSpace(connectionString)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(connectionString));
if (providerName == null) throw new ArgumentNullException(nameof(providerName));
if (string.IsNullOrWhiteSpace(providerName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(providerName));
var fileSource = "web.config";
var fileName = IOHelper.MapPath(SystemDirectories.Root +"/" + fileSource);

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
using Umbraco.Core.Scoping;
using Type = System.Type;
@@ -25,7 +24,9 @@ namespace Umbraco.Core.Migrations
/// <param name="name">The name of the plan.</param>
public MigrationPlan(string name)
{
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
Name = name;
}
@@ -43,7 +44,8 @@ namespace Umbraco.Core.Migrations
private MigrationPlan Add(string sourceState, string targetState, Type migration)
{
if (sourceState == null) throw new ArgumentNullException(nameof(sourceState));
if (string.IsNullOrWhiteSpace(targetState)) throw new ArgumentNullOrEmptyException(nameof(targetState));
if (targetState == null) throw new ArgumentNullException(nameof(targetState));
if (string.IsNullOrWhiteSpace(targetState)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(targetState));
if (sourceState == targetState) throw new ArgumentException("Source and target state cannot be identical.");
if (migration == null) throw new ArgumentNullException(nameof(migration));
if (!migration.Implements<IMigration>()) throw new ArgumentException($"Type {migration.Name} does not implement IMigration.", nameof(migration));
@@ -135,10 +137,12 @@ namespace Umbraco.Core.Migrations
/// </summary>
public MigrationPlan ToWithClone(string startState, string endState, string targetState)
{
if (string.IsNullOrWhiteSpace(startState)) throw new ArgumentNullOrEmptyException(nameof(startState));
if (string.IsNullOrWhiteSpace(endState)) throw new ArgumentNullOrEmptyException(nameof(endState));
if (string.IsNullOrWhiteSpace(targetState)) throw new ArgumentNullOrEmptyException(nameof(targetState));
if (startState == null) throw new ArgumentNullException(nameof(startState));
if (string.IsNullOrWhiteSpace(startState)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(startState));
if (endState == null) throw new ArgumentNullException(nameof(endState));
if (string.IsNullOrWhiteSpace(endState)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(endState));
if (targetState == null) throw new ArgumentNullException(nameof(targetState));
if (string.IsNullOrWhiteSpace(targetState)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(targetState));
if (startState == endState) throw new ArgumentException("Start and end states cannot be identical.");
startState = startState.Trim();
@@ -317,7 +321,7 @@ namespace Umbraco.Core.Migrations
// throw a raw exception here: this should never happen as the plan has
// been validated - this is just a paranoid safety test
if (!_transitions.TryGetValue(origState, out transition))
throw new Exception($"Unknown state \"{origState}\".");
throw new InvalidOperationException($"Unknown state \"{origState}\".");
}
// prepare and de-duplicate post-migrations, only keeping the 1st occurence
@@ -339,7 +343,7 @@ namespace Umbraco.Core.Migrations
// safety check - again, this should never happen as the plan has been validated,
// and this is just a paranoid safety test
if (origState != _finalState)
throw new Exception($"Internal error, reached state {origState} which is not final state {_finalState}");
throw new InvalidOperationException($"Internal error, reached state {origState} which is not final state {_finalState}");
return origState;
}
@@ -358,7 +362,7 @@ namespace Umbraco.Core.Migrations
var states = new List<string> { origState };
if (!_transitions.TryGetValue(origState, out var transition))
throw new Exception($"Unknown state \"{origState}\".");
throw new InvalidOperationException($"Unknown state \"{origState}\".");
while (transition != null)
{
@@ -373,12 +377,12 @@ namespace Umbraco.Core.Migrations
}
if (!_transitions.TryGetValue(origState, out transition))
throw new Exception($"Unknown state \"{origState}\".");
throw new InvalidOperationException($"Unknown state \"{origState}\".");
}
// safety check
if (origState != (toState ?? _finalState))
throw new Exception($"Internal error, reached state {origState} which is not state {toState ?? _finalState}");
throw new InvalidOperationException($"Internal error, reached state {origState} which is not state {toState ?? _finalState}");
return states;
}
@@ -417,7 +421,7 @@ namespace Umbraco.Core.Migrations
public override string ToString()
{
return MigrationType == typeof(NoopMigration)
? $"{(SourceState == "" ? "<empty>" : SourceState)} --> {TargetState}"
? $"{(SourceState == string.Empty ? "<empty>" : SourceState)} --> {TargetState}"
: $"{SourceState} -- ({MigrationType.FullName}) --> {TargetState}";
}
}

View File

@@ -4,8 +4,6 @@ using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using Umbraco.Core.Composing;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models.Entities;
namespace Umbraco.Core.Models
@@ -229,8 +227,8 @@ namespace Umbraco.Core.Models
private void ClearCultureInfo(string culture)
{
if (culture.IsNullOrWhiteSpace())
throw new ArgumentNullOrEmptyException(nameof(culture));
if (culture == null) throw new ArgumentNullException(nameof(culture));
if (string.IsNullOrWhiteSpace(culture)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(culture));
if (_cultureInfos == null) return;
_cultureInfos.Remove(culture);

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models.Entities;
namespace Umbraco.Core.Models
@@ -18,7 +17,9 @@ namespace Umbraco.Core.Models
/// </summary>
public ContentCultureInfos(string culture)
{
if (culture.IsNullOrWhiteSpace()) throw new ArgumentNullOrEmptyException(nameof(culture));
if (culture == null) throw new ArgumentNullException(nameof(culture));
if (string.IsNullOrWhiteSpace(culture)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(culture));
Culture = culture;
}

View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using Umbraco.Core.Collections;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.Models
{
@@ -23,7 +21,9 @@ namespace Umbraco.Core.Models
/// </summary>
public void AddOrUpdate(string culture, string name, DateTime date)
{
if (culture.IsNullOrWhiteSpace()) throw new ArgumentNullOrEmptyException(nameof(culture));
if (culture == null) throw new ArgumentNullException(nameof(culture));
if (string.IsNullOrWhiteSpace(culture)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(culture));
culture = culture.ToLowerInvariant();
if (TryGetValue(culture, out var item))

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.Models
{
@@ -103,11 +102,11 @@ namespace Umbraco.Core.Models
public static void SetPublishInfo(this IContent content, string culture, string name, DateTime date)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullOrEmptyException(nameof(name));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
if (culture.IsNullOrWhiteSpace())
throw new ArgumentNullOrEmptyException(nameof(culture));
if (culture == null) throw new ArgumentNullException(nameof(culture));
if (string.IsNullOrWhiteSpace(culture)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(culture));
content.PublishCultureInfos.AddOrUpdate(culture, name, date);
}
@@ -153,11 +152,11 @@ namespace Umbraco.Core.Models
public static void SetCultureInfo(this IContentBase content, string culture, string name, DateTime date)
{
if (name.IsNullOrWhiteSpace())
throw new ArgumentNullOrEmptyException(nameof(name));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
if (culture.IsNullOrWhiteSpace())
throw new ArgumentNullOrEmptyException(nameof(culture));
if (culture == null) throw new ArgumentNullException(nameof(culture));
if (string.IsNullOrWhiteSpace(culture)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(culture));
content.CultureInfos.AddOrUpdate(culture, name, date);
}
@@ -249,8 +248,8 @@ namespace Umbraco.Core.Models
public static void ClearPublishInfo(this IContent content, string culture)
{
if (culture.IsNullOrWhiteSpace())
throw new ArgumentNullOrEmptyException(nameof(culture));
if (culture == null) throw new ArgumentNullException(nameof(culture));
if (string.IsNullOrWhiteSpace(culture)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(culture));
content.PublishCultureInfos.Remove(culture);

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Umbraco.Core.Composing;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
namespace Umbraco.Core.Models
@@ -43,7 +42,8 @@ namespace Umbraco.Core.Models
public Member(string name, IMemberType contentType)
: base(name, -1, contentType, new PropertyCollection())
{
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
IsApproved = true;
@@ -63,9 +63,12 @@ namespace Umbraco.Core.Models
public Member(string name, string email, string username, IMemberType contentType, bool isApproved = true)
: base(name, -1, contentType, new PropertyCollection())
{
if (string.IsNullOrWhiteSpace(email)) throw new ArgumentNullOrEmptyException(nameof(email));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (string.IsNullOrWhiteSpace(username)) throw new ArgumentNullOrEmptyException(nameof(username));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
if (email == null) throw new ArgumentNullException(nameof(email));
if (string.IsNullOrWhiteSpace(email)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(email));
if (username == null) throw new ArgumentNullException(nameof(username));
if (string.IsNullOrWhiteSpace(username)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(username));
_email = email;
_username = username;

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.Models.PublishedContent
{
@@ -20,7 +19,9 @@ namespace Umbraco.Core.Models.PublishedContent
{
private ModelType(string contentTypeAlias)
{
if (string.IsNullOrWhiteSpace(contentTypeAlias)) throw new ArgumentNullOrEmptyException(nameof(contentTypeAlias));
if (contentTypeAlias == null) throw new ArgumentNullException(nameof(contentTypeAlias));
if (string.IsNullOrWhiteSpace(contentTypeAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(contentTypeAlias));
ContentTypeAlias = contentTypeAlias;
Name = "{" + ContentTypeAlias + "}";
}

View File

@@ -1,5 +1,4 @@
using System;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.Models.PublishedContent
{
@@ -13,7 +12,8 @@ namespace Umbraco.Core.Models.PublishedContent
/// </summary>
public PublishedCultureInfo(string culture, string name, string urlSegment, DateTime date)
{
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
Culture = culture ?? throw new ArgumentNullException(nameof(culture));
Name = name;

View File

@@ -1,5 +1,4 @@
using System;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.Models.PublishedContent
{
@@ -19,7 +18,9 @@ namespace Umbraco.Core.Models.PublishedContent
/// <param name="contentTypeAlias">The content type alias.</param>
public PublishedModelAttribute(string contentTypeAlias)
{
if (string.IsNullOrWhiteSpace(contentTypeAlias)) throw new ArgumentNullOrEmptyException(nameof(contentTypeAlias));
if (contentTypeAlias == null) throw new ArgumentNullException(nameof(contentTypeAlias));
if (string.IsNullOrWhiteSpace(contentTypeAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(contentTypeAlias));
ContentTypeAlias = contentTypeAlias;
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Runtime.Serialization;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models.Entities;
namespace Umbraco.Core.Models
@@ -20,7 +19,9 @@ namespace Umbraco.Core.Models
public RelationType(Guid childObjectType, Guid parentObjectType, string alias)
{
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias));
if (alias == null) throw new ArgumentNullException(nameof(alias));
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(alias));
_childObjectType = childObjectType;
_parentObjectType = parentObjectType;
_alias = alias;
@@ -30,7 +31,9 @@ namespace Umbraco.Core.Models
public RelationType(Guid childObjectType, Guid parentObjectType, string alias, string name)
: this(childObjectType, parentObjectType, alias)
{
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
Name = name;
}

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using NPoco;
using Umbraco.Core.Cache;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Dtos;
@@ -129,6 +128,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
protected override void PersistDeletedItem(EntityContainer entity)
{
if (entity == null) throw new ArgumentNullException(nameof(entity));
EnsureContainerType(entity);
var nodeDto = Database.FirstOrDefault<NodeDto>(Sql().SelectAll()
@@ -162,9 +162,12 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
protected override void PersistNewItem(EntityContainer entity)
{
// TODO Ensure correct exceptions are thrown (entity.Name is not an argument and NullReferenceException shouldn't be thrown by user code)
if (entity == null) throw new ArgumentNullException(nameof(entity));
EnsureContainerType(entity);
if (string.IsNullOrWhiteSpace(entity.Name)) throw new ArgumentNullOrEmptyException("entity.Name");
if (entity.Name == null) throw new ArgumentNullException(nameof(entity.Name));
if (string.IsNullOrWhiteSpace(entity.Name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(entity.Name));
entity.Name = entity.Name.Trim();
// guard against duplicates
@@ -223,10 +226,13 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
//
protected override void PersistUpdatedItem(EntityContainer entity)
{
// TODO Ensure correct exceptions are thrown (entity.Name is not an argument and NullReferenceException shouldn't be thrown by user code)
if (entity == null) throw new ArgumentNullException(nameof(entity));
EnsureContainerType(entity);
if (entity.Name == null) throw new ArgumentNullException(nameof(entity.Name));
if (string.IsNullOrWhiteSpace(entity.Name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(entity.Name));
entity.Name = entity.Name.Trim();
if (string.IsNullOrWhiteSpace(entity.Name)) throw new ArgumentNullOrEmptyException("entity.Name");
// find container to update
var nodeDto = Database.FirstOrDefault<NodeDto>(Sql().SelectAll()

View File

@@ -4,7 +4,6 @@ using System.Data.Common;
using System.Threading;
using NPoco;
using NPoco.FluentMappings;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.FaultHandling;
using Umbraco.Core.Persistence.Mappers;
@@ -61,8 +60,8 @@ namespace Umbraco.Core.Persistence
/// <remarks>Used by the other ctor and in tests.</remarks>
public UmbracoDatabaseFactory(string connectionStringName, ILogger logger, Lazy<IMapperCollection> mappers)
{
if (string.IsNullOrWhiteSpace(connectionStringName))
throw new ArgumentNullOrEmptyException(nameof(connectionStringName));
if (connectionStringName == null) throw new ArgumentNullException(nameof(connectionStringName));
if (string.IsNullOrWhiteSpace(connectionStringName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(connectionStringName));
_mappers = mappers ?? throw new ArgumentNullException(nameof(mappers));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));

View File

@@ -1,5 +1,4 @@
using System;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.PropertyEditors
{
@@ -28,13 +27,15 @@ namespace Umbraco.Core.PropertyEditors
/// <param name="view">The view to use to render the field editor.</param>
public ConfigurationFieldAttribute(string key, string name, string view)
{
if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullOrEmptyException(nameof(key));
if (key == null) throw new ArgumentNullException(nameof(key));
if (string.IsNullOrWhiteSpace(key)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(key));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
if (view == null) throw new ArgumentNullException(nameof(view));
if (string.IsNullOrWhiteSpace(view)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(view));
Key = key;
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
Name = name;
if (string.IsNullOrWhiteSpace(view)) throw new ArgumentNullOrEmptyException(nameof(view));
View = view;
}
@@ -47,10 +48,12 @@ namespace Umbraco.Core.PropertyEditors
/// from the name of the property marked with this attribute.</remarks>
public ConfigurationFieldAttribute(string name, string view)
{
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
Name = name;
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
if (view == null) throw new ArgumentNullException(nameof(view));
if (string.IsNullOrWhiteSpace(view)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(view));
if (string.IsNullOrWhiteSpace(view)) throw new ArgumentNullOrEmptyException(nameof(view));
Name = name;
View = view;
}

View File

@@ -1,5 +1,4 @@
using System;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.PropertyEditors
{
@@ -53,17 +52,17 @@ namespace Umbraco.Core.PropertyEditors
/// </remarks>
public DataEditorAttribute(string alias, EditorType type, string name, string view)
{
if ((type & ~(EditorType.PropertyValue | EditorType.MacroParameter)) > 0)
throw new ArgumentOutOfRangeException(nameof(type), $"Not a valid {typeof(EditorType)} value.");
if (alias == null) throw new ArgumentNullException(nameof(alias));
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(alias));
if ((type & ~(EditorType.PropertyValue | EditorType.MacroParameter)) > 0) throw new ArgumentOutOfRangeException(nameof(type), type, $"Not a valid {typeof(EditorType)} value.");
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
if (view == null) throw new ArgumentNullException(nameof(view));
if (string.IsNullOrWhiteSpace(view)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(view));
Type = type;
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias));
Alias = alias;
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
Name = name;
if (string.IsNullOrWhiteSpace(view)) throw new ArgumentNullOrEmptyException(nameof(view));
View = view == NullView ? null : view;
}
@@ -100,8 +99,10 @@ namespace Umbraco.Core.PropertyEditors
get => _valueType;
set
{
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentNullOrEmptyException(nameof(value));
if (!ValueTypes.IsValue(value)) throw new ArgumentOutOfRangeException(nameof(value), $"Not a valid {typeof(ValueTypes)} value.");
if (value == null) throw new ArgumentNullException(nameof(value));
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(value));
if (!ValueTypes.IsValue(value)) throw new ArgumentOutOfRangeException(nameof(value), value, $"Not a valid {typeof(ValueTypes)} value.");
_valueType = value;
}
}

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using Umbraco.Core.Composing;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Services;
namespace Umbraco.Core.PropertyEditors.Validators
@@ -48,8 +47,9 @@ namespace Umbraco.Core.PropertyEditors.Validators
get => _regex;
set
{
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentNullOrEmptyException(nameof(value));
if (value == null) throw new ArgumentNullException(nameof(value));
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(value));
_regex = value;
}
}
@@ -66,7 +66,9 @@ namespace Umbraco.Core.PropertyEditors.Validators
/// <inheritdoc cref="IValueFormatValidator.ValidateFormat"/>
public IEnumerable<ValidationResult> ValidateFormat(object value, string valueType, string format)
{
if (string.IsNullOrWhiteSpace(format)) throw new ArgumentNullOrEmptyException(nameof(format));
if (format == null) throw new ArgumentNullException(nameof(format));
if (string.IsNullOrWhiteSpace(format)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(format));
if (value == null || !new Regex(format).IsMatch(value.ToString()))
yield return new ValidationResult(_textService.Localize("validation", "invalidPattern"), new[] { "value" });
}

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core
{
@@ -29,10 +28,14 @@ namespace Umbraco.Core
/// <typeparam name="TDeclaring">The declaring type.</typeparam>
/// <typeparam name="TValue">The field type.</typeparam>
/// <param name="fieldName">The name of the field.</param>
/// <returns>A field getter function.</returns>
/// <exception cref="ArgumentNullOrEmptyException">Occurs when <paramref name="fieldName"/> is null or empty.</exception>
/// <exception cref="InvalidOperationException">Occurs when the field does not exist.</exception>
/// <exception cref="ArgumentException">Occurs when <typeparamref name="TValue"/> does not match the type of the field.</exception>
/// <returns>
/// A field getter function.
/// </returns>
/// <exception cref="ArgumentNullException">fieldName</exception>
/// <exception cref="ArgumentException">Value can't be empty or consist only of white-space characters. - <paramref name="fieldName" />
/// or
/// Value type <typeparamref name="TValue" /> does not match field <typeparamref name="TDeclaring" />.<paramref name="fieldName" /> type.</exception>
/// <exception cref="InvalidOperationException">Could not find field <typeparamref name="TDeclaring" />.<paramref name="fieldName" />.</exception>
public static Func<TDeclaring, TValue> EmitFieldGetter<TDeclaring, TValue>(string fieldName)
{
var field = GetField<TDeclaring, TValue>(fieldName);
@@ -45,10 +48,14 @@ namespace Umbraco.Core
/// <typeparam name="TDeclaring">The declaring type.</typeparam>
/// <typeparam name="TValue">The field type.</typeparam>
/// <param name="fieldName">The name of the field.</param>
/// <returns>A field setter action.</returns>
/// <exception cref="ArgumentNullOrEmptyException">Occurs when <paramref name="fieldName"/> is null or empty.</exception>
/// <exception cref="InvalidOperationException">Occurs when the field does not exist.</exception>
/// <exception cref="ArgumentException">Occurs when <typeparamref name="TValue"/> does not match the type of the field.</exception>
/// <returns>
/// A field setter action.
/// </returns>
/// <exception cref="ArgumentNullException">fieldName</exception>
/// <exception cref="ArgumentException">Value can't be empty or consist only of white-space characters. - <paramref name="fieldName" />
/// or
/// Value type <typeparamref name="TValue" /> does not match field <typeparamref name="TDeclaring" />.<paramref name="fieldName" /> type.</exception>
/// <exception cref="InvalidOperationException">Could not find field <typeparamref name="TDeclaring" />.<paramref name="fieldName" />.</exception>
public static Action<TDeclaring, TValue> EmitFieldSetter<TDeclaring, TValue>(string fieldName)
{
var field = GetField<TDeclaring, TValue>(fieldName);
@@ -61,19 +68,36 @@ namespace Umbraco.Core
/// <typeparam name="TDeclaring">The declaring type.</typeparam>
/// <typeparam name="TValue">The field type.</typeparam>
/// <param name="fieldName">The name of the field.</param>
/// <returns>A field getter and setter functions.</returns>
/// <exception cref="ArgumentNullOrEmptyException">Occurs when <paramref name="fieldName"/> is null or empty.</exception>
/// <exception cref="InvalidOperationException">Occurs when the field does not exist.</exception>
/// <exception cref="ArgumentException">Occurs when <typeparamref name="TValue"/> does not match the type of the field.</exception>
/// <returns>
/// A field getter and setter functions.
/// </returns>
/// <exception cref="ArgumentNullException">fieldName</exception>
/// <exception cref="ArgumentException">Value can't be empty or consist only of white-space characters. - <paramref name="fieldName" />
/// or
/// Value type <typeparamref name="TValue" /> does not match field <typeparamref name="TDeclaring" />.<paramref name="fieldName" /> type.</exception>
/// <exception cref="InvalidOperationException">Could not find field <typeparamref name="TDeclaring" />.<paramref name="fieldName" />.</exception>
public static (Func<TDeclaring, TValue>, Action<TDeclaring, TValue>) EmitFieldGetterAndSetter<TDeclaring, TValue>(string fieldName)
{
var field = GetField<TDeclaring, TValue>(fieldName);
return (EmitFieldGetter<TDeclaring, TValue>(field), EmitFieldSetter<TDeclaring, TValue>(field));
}
/// <summary>
/// Gets the field.
/// </summary>
/// <typeparam name="TDeclaring">The type of the declaring.</typeparam>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <param name="fieldName">Name of the field.</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException">fieldName</exception>
/// <exception cref="ArgumentException">Value can't be empty or consist only of white-space characters. - <paramref name="fieldName" />
/// or
/// Value type <typeparamref name="TValue" /> does not match field <typeparamref name="TDeclaring" />.<paramref name="fieldName" /> type.</exception>
/// <exception cref="InvalidOperationException">Could not find field <typeparamref name="TDeclaring" />.<paramref name="fieldName" />.</exception>
private static FieldInfo GetField<TDeclaring, TValue>(string fieldName)
{
if (string.IsNullOrWhiteSpace(fieldName)) throw new ArgumentNullOrEmptyException(nameof(fieldName));
if (fieldName == null) throw new ArgumentNullException(nameof(fieldName));
if (string.IsNullOrWhiteSpace(fieldName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(fieldName));
// get the field
var field = typeof(TDeclaring).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
@@ -120,13 +144,18 @@ namespace Umbraco.Core
/// <typeparam name="TValue">The property type.</typeparam>
/// <param name="propertyName">The name of the property.</param>
/// <param name="mustExist">A value indicating whether the property and its getter must exist.</param>
/// <returns>A property getter function. If <paramref name="mustExist"/> is <c>false</c>, returns null when the property or its getter does not exist.</returns>
/// <exception cref="ArgumentNullOrEmptyException">Occurs when <paramref name="propertyName"/> is null or empty.</exception>
/// <exception cref="InvalidOperationException">Occurs when the property or its getter does not exist.</exception>
/// <exception cref="ArgumentException">Occurs when <typeparamref name="TValue"/> does not match the type of the property.</exception>
/// <returns>
/// A property getter function. If <paramref name="mustExist" /> is <c>false</c>, returns null when the property or its getter does not exist.
/// </returns>
/// <exception cref="ArgumentNullException">propertyName</exception>
/// <exception cref="ArgumentException">Value can't be empty or consist only of white-space characters. - <paramref name="propertyName" />
/// or
/// Value type <typeparamref name="TValue" /> does not match property <typeparamref name="TDeclaring" />.<paramref name="propertyName" /> type.</exception>
/// <exception cref="InvalidOperationException">Could not find property getter for <typeparamref name="TDeclaring" />.<paramref name="propertyName" />.</exception>
public static Func<TDeclaring, TValue> EmitPropertyGetter<TDeclaring, TValue>(string propertyName, bool mustExist = true)
{
if (string.IsNullOrWhiteSpace(propertyName)) throw new ArgumentNullOrEmptyException(nameof(propertyName));
if (propertyName == null) throw new ArgumentNullException(nameof(propertyName));
if (string.IsNullOrWhiteSpace(propertyName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyName));
var property = typeof(TDeclaring).GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
@@ -146,13 +175,18 @@ namespace Umbraco.Core
/// <typeparam name="TValue">The property type.</typeparam>
/// <param name="propertyName">The name of the property.</param>
/// <param name="mustExist">A value indicating whether the property and its setter must exist.</param>
/// <returns>A property setter function. If <paramref name="mustExist"/> is <c>false</c>, returns null when the property or its setter does not exist.</returns>
/// <exception cref="ArgumentNullOrEmptyException">Occurs when <paramref name="propertyName"/> is null or empty.</exception>
/// <exception cref="InvalidOperationException">Occurs when the property or its setter does not exist.</exception>
/// <exception cref="ArgumentException">Occurs when <typeparamref name="TValue"/> does not match the type of the property.</exception>
/// <returns>
/// A property setter function. If <paramref name="mustExist" /> is <c>false</c>, returns null when the property or its setter does not exist.
/// </returns>
/// <exception cref="ArgumentNullException">propertyName</exception>
/// <exception cref="ArgumentException">Value can't be empty or consist only of white-space characters. - <paramref name="propertyName" />
/// or
/// Value type <typeparamref name="TValue" /> does not match property <typeparamref name="TDeclaring" />.<paramref name="propertyName" /> type.</exception>
/// <exception cref="InvalidOperationException">Could not find property setter for <typeparamref name="TDeclaring" />.<paramref name="propertyName" />.</exception>
public static Action<TDeclaring, TValue> EmitPropertySetter<TDeclaring, TValue>(string propertyName, bool mustExist = true)
{
if (string.IsNullOrWhiteSpace(propertyName)) throw new ArgumentNullOrEmptyException(nameof(propertyName));
if (propertyName == null) throw new ArgumentNullException(nameof(propertyName));
if (string.IsNullOrWhiteSpace(propertyName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyName));
var property = typeof(TDeclaring).GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
@@ -172,13 +206,18 @@ namespace Umbraco.Core
/// <typeparam name="TValue">The property type.</typeparam>
/// <param name="propertyName">The name of the property.</param>
/// <param name="mustExist">A value indicating whether the property and its getter and setter must exist.</param>
/// <returns>A property getter and setter functions. If <paramref name="mustExist"/> is <c>false</c>, returns null when the property or its getter or setter does not exist.</returns>
/// <exception cref="ArgumentNullOrEmptyException">Occurs when <paramref name="propertyName"/> is null or empty.</exception>
/// <exception cref="InvalidOperationException">Occurs when the property or its getter or setter does not exist.</exception>
/// <exception cref="ArgumentException">Occurs when <typeparamref name="TValue"/> does not match the type of the property.</exception>
/// <returns>
/// A property getter and setter functions. If <paramref name="mustExist" /> is <c>false</c>, returns null when the property or its getter or setter does not exist.
/// </returns>
/// <exception cref="ArgumentNullException">propertyName</exception>
/// <exception cref="ArgumentException">Value can't be empty or consist only of white-space characters. - <paramref name="propertyName" />
/// or
/// Value type <typeparamref name="TValue" /> does not match property <typeparamref name="TDeclaring" />.<paramref name="propertyName" /> type.</exception>
/// <exception cref="InvalidOperationException">Could not find property getter and setter for <typeparamref name="TDeclaring" />.<paramref name="propertyName" />.</exception>
public static (Func<TDeclaring, TValue>, Action<TDeclaring, TValue>) EmitPropertyGetterAndSetter<TDeclaring, TValue>(string propertyName, bool mustExist = true)
{
if (string.IsNullOrWhiteSpace(propertyName)) throw new ArgumentNullOrEmptyException(nameof(propertyName));
if (propertyName == null) throw new ArgumentNullException(nameof(propertyName));
if (string.IsNullOrWhiteSpace(propertyName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyName));
var property = typeof(TDeclaring).GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
@@ -402,13 +441,17 @@ namespace Umbraco.Core
/// <typeparam name="TLambda">A lambda representing the method.</typeparam>
/// <param name="methodName">The name of the method.</param>
/// <param name="mustExist">A value indicating whether the constructor must exist.</param>
/// <returns>The method. If <paramref name="mustExist"/> is <c>false</c>, returns null when the method does not exist.</returns>
/// <returns>
/// The method. If <paramref name="mustExist" /> is <c>false</c>, returns null when the method does not exist.
/// </returns>
/// <exception cref="ArgumentNullException">methodName</exception>
/// <exception cref="ArgumentException">Value can't be empty or consist only of white-space characters. - <paramref name="methodName" />
/// or
/// Occurs when <typeparamref name="TLambda" /> does not match the method signature..</exception>
/// <exception cref="InvalidOperationException">Occurs when no proper method with name <paramref name="methodName" /> could be found.</exception>
/// <remarks>
/// <para>The method arguments are determined by <typeparamref name="TLambda"/> generic arguments.</para>
/// The method arguments are determined by <typeparamref name="TLambda" /> generic arguments.
/// </remarks>
/// <exception cref="ArgumentNullOrEmptyException">Occurs when <paramref name="methodName"/> is null or empty.</exception>
/// <exception cref="InvalidOperationException">Occurs when no proper method with name <paramref name="methodName"/> could be found.</exception>
/// <exception cref="ArgumentException">Occurs when Occurs when <typeparamref name="TLambda"/> does not match the method signature.</exception>
public static TLambda EmitMethod<TDeclaring, TLambda>(string methodName, bool mustExist = true)
{
return EmitMethod<TLambda>(typeof(TDeclaring), methodName, mustExist);
@@ -421,16 +464,21 @@ namespace Umbraco.Core
/// <param name="declaring">The declaring type.</param>
/// <param name="methodName">The name of the method.</param>
/// <param name="mustExist">A value indicating whether the constructor must exist.</param>
/// <returns>The method. If <paramref name="mustExist"/> is <c>false</c>, returns null when the method does not exist.</returns>
/// <returns>
/// The method. If <paramref name="mustExist" /> is <c>false</c>, returns null when the method does not exist.
/// </returns>
/// <exception cref="ArgumentNullException">methodName</exception>
/// <exception cref="ArgumentException">Value can't be empty or consist only of white-space characters. - <paramref name="methodName" />
/// or
/// Occurs when <typeparamref name="TLambda" /> does not match the method signature..</exception>
/// <exception cref="InvalidOperationException">Occurs when no proper method with name <paramref name="methodName" /> could be found.</exception>
/// <remarks>
/// <para>The method arguments are determined by <typeparamref name="TLambda"/> generic arguments.</para>
/// The method arguments are determined by <typeparamref name="TLambda" /> generic arguments.
/// </remarks>
/// <exception cref="ArgumentNullOrEmptyException">Occurs when <paramref name="methodName"/> is null or empty.</exception>
/// <exception cref="InvalidOperationException">Occurs when no proper method with name <paramref name="methodName"/> could be found.</exception>
/// <exception cref="ArgumentException">Occurs when Occurs when <typeparamref name="TLambda"/> does not match the method signature.</exception>
public static TLambda EmitMethod<TLambda>(Type declaring, string methodName, bool mustExist = true)
{
if (string.IsNullOrWhiteSpace(methodName)) throw new ArgumentNullOrEmptyException(nameof(methodName));
if (methodName == null) throw new ArgumentNullException(nameof(methodName));
if (string.IsNullOrWhiteSpace(methodName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(methodName));
var (lambdaDeclaring, lambdaParameters, lambdaReturned) = AnalyzeLambda<TLambda>(true, out var isFunction);
@@ -510,17 +558,21 @@ namespace Umbraco.Core
/// <typeparam name="TLambda">A lambda representing the method.</typeparam>
/// <param name="methodName">The name of the method.</param>
/// <param name="mustExist">A value indicating whether the constructor must exist.</param>
/// <returns>The method. If <paramref name="mustExist"/> is <c>false</c>, returns null when the method does not exist.</returns>
/// <returns>
/// The method. If <paramref name="mustExist" /> is <c>false</c>, returns null when the method does not exist.
/// </returns>
/// <exception cref="ArgumentNullException">methodName</exception>
/// <exception cref="ArgumentException">Value can't be empty or consist only of white-space characters. - <paramref name="methodName" />
/// or
/// Occurs when <typeparamref name="TLambda" /> does not match the method signature..</exception>
/// <exception cref="InvalidOperationException">Occurs when no proper method with name <paramref name="methodName" /> could be found.</exception>
/// <remarks>
/// <para>The method arguments are determined by <typeparamref name="TLambda"/> generic arguments.</para>
/// The method arguments are determined by <typeparamref name="TLambda" /> generic arguments.
/// </remarks>
/// <exception cref="ArgumentNullOrEmptyException">Occurs when <paramref name="methodName"/> is null or empty.</exception>
/// <exception cref="InvalidOperationException">Occurs when no proper method with name <paramref name="methodName"/> could be found.</exception>
/// <exception cref="ArgumentException">Occurs when Occurs when <typeparamref name="TLambda"/> does not match the method signature.</exception>
public static TLambda EmitMethod<TLambda>(string methodName, bool mustExist = true)
{
if (string.IsNullOrWhiteSpace(methodName))
throw new ArgumentNullOrEmptyException(nameof(methodName));
if (methodName == null) throw new ArgumentNullException(nameof(methodName));
if (string.IsNullOrWhiteSpace(methodName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(methodName));
// validate lambda type
var (lambdaDeclaring, lambdaParameters, lambdaReturned) = AnalyzeLambda<TLambda>(false, out var isFunction);

View File

@@ -6,7 +6,6 @@ using System.Threading.Tasks;
using System.Web.Security;
using Microsoft.AspNet.Identity;
using Umbraco.Core.Configuration;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Identity;
@@ -217,7 +216,8 @@ namespace Umbraco.Core.Security
{
ThrowIfDisposed();
if (user == null) throw new ArgumentNullException(nameof(user));
if (string.IsNullOrEmpty(passwordHash)) throw new ArgumentNullOrEmptyException(nameof(passwordHash));
if (passwordHash == null) throw new ArgumentNullException(nameof(passwordHash));
if (string.IsNullOrEmpty(passwordHash)) throw new ArgumentException("Value can't be empty.", nameof(passwordHash));
user.PasswordHash = passwordHash;
@@ -329,7 +329,7 @@ namespace Umbraco.Core.Security
{
ThrowIfDisposed();
if (user == null) throw new ArgumentNullException(nameof(user));
if (login == null) throw new ArgumentNullException("login");
if (login == null) throw new ArgumentNullException(nameof(login));
var logins = user.Logins;
var instance = new IdentityUserLogin(login.LoginProvider, login.ProviderKey, user.Id);
@@ -348,7 +348,7 @@ namespace Umbraco.Core.Security
{
ThrowIfDisposed();
if (user == null) throw new ArgumentNullException(nameof(user));
if (login == null) throw new ArgumentNullException("login");
if (login == null) throw new ArgumentNullException(nameof(login));
var provider = login.LoginProvider;
var key = login.ProviderKey;
@@ -379,7 +379,7 @@ namespace Umbraco.Core.Security
public Task<BackOfficeIdentityUser> FindAsync(UserLoginInfo login)
{
ThrowIfDisposed();
if (login == null) throw new ArgumentNullException("login");
if (login == null) throw new ArgumentNullException(nameof(login));
//get all logins associated with the login id
var result = _externalLoginService.Find(login).ToArray();
@@ -413,7 +413,8 @@ namespace Umbraco.Core.Security
{
ThrowIfDisposed();
if (user == null) throw new ArgumentNullException(nameof(user));
if (string.IsNullOrWhiteSpace(roleName)) throw new ArgumentException("Value cannot be null or whitespace.", "roleName");
if (roleName == null) throw new ArgumentNullException(nameof(roleName));
if (string.IsNullOrWhiteSpace(roleName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(roleName));
var userRole = user.Roles.SingleOrDefault(r => r.RoleId == roleName);
@@ -434,7 +435,8 @@ namespace Umbraco.Core.Security
{
ThrowIfDisposed();
if (user == null) throw new ArgumentNullException(nameof(user));
if (string.IsNullOrWhiteSpace(roleName)) throw new ArgumentException("Value cannot be null or whitespace.", "roleName");
if (roleName == null) throw new ArgumentNullException(nameof(roleName));
if (string.IsNullOrWhiteSpace(roleName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(roleName));
var userRole = user.Roles.SingleOrDefault(r => r.RoleId == roleName);

View File

@@ -3,9 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using Umbraco.Core.Events;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
@@ -2793,7 +2791,8 @@ namespace Umbraco.Core.Services.Implement
private IContentType GetContentType(IScope scope, string contentTypeAlias)
{
if (string.IsNullOrWhiteSpace(contentTypeAlias)) throw new ArgumentNullOrEmptyException(nameof(contentTypeAlias));
if (contentTypeAlias == null) throw new ArgumentNullException(nameof(contentTypeAlias));
if (string.IsNullOrWhiteSpace(contentTypeAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(contentTypeAlias));
scope.ReadLock(Constants.Locks.ContentTypes);
@@ -2808,7 +2807,8 @@ namespace Umbraco.Core.Services.Implement
private IContentType GetContentType(string contentTypeAlias)
{
if (string.IsNullOrWhiteSpace(contentTypeAlias)) throw new ArgumentNullOrEmptyException(nameof(contentTypeAlias));
if (contentTypeAlias == null) throw new ArgumentNullException(nameof(contentTypeAlias));
if (string.IsNullOrWhiteSpace(contentTypeAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(contentTypeAlias));
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{
@@ -2900,7 +2900,7 @@ namespace Umbraco.Core.Services.Implement
{
foreach (var property in blueprint.Properties)
{
var propertyCulture = property.PropertyType.VariesByCulture() ? culture : null;
var propertyCulture = property.PropertyType.VariesByCulture() ? culture : null;
content.SetValue(property.Alias, property.GetValue(propertyCulture), propertyCulture);
}

View File

@@ -590,10 +590,9 @@ namespace Umbraco.Core.Services.Implement
public TItem Copy(TItem original, string alias, string name, TItem parent)
{
if (original == null) throw new ArgumentNullException(nameof(original));
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias));
if (parent != null && parent.HasIdentity == false)
throw new InvalidOperationException("Parent must have an identity.");
if (alias == null) throw new ArgumentNullException(nameof(alias));
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(alias));
if (parent != null && parent.HasIdentity == false) throw new InvalidOperationException("Parent must have an identity.");
// this is illegal
//var originalb = (ContentTypeCompositionBase)original;

View File

@@ -5,7 +5,6 @@ using System.Globalization;
using System.IO;
using System.Linq;
using Umbraco.Core.Events;
using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
@@ -1323,7 +1322,8 @@ namespace Umbraco.Core.Services.Implement
private IMediaType GetMediaType(string mediaTypeAlias)
{
if (string.IsNullOrWhiteSpace(mediaTypeAlias)) throw new ArgumentNullOrEmptyException(nameof(mediaTypeAlias));
if (mediaTypeAlias == null) throw new ArgumentNullException(nameof(mediaTypeAlias));
if (string.IsNullOrWhiteSpace(mediaTypeAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(mediaTypeAlias));
using (var scope = ScopeProvider.CreateScope())
{
@@ -1333,7 +1333,7 @@ namespace Umbraco.Core.Services.Implement
var mediaType = _mediaTypeRepository.Get(query).FirstOrDefault();
if (mediaType == null)
throw new Exception($"No MediaType matching the passed in Alias: '{mediaTypeAlias}' was found"); // causes rollback // causes rollback
throw new InvalidOperationException($"No media type matched the specified alias '{mediaTypeAlias}'.");
scope.Complete();
return mediaType;

View File

@@ -1344,7 +1344,8 @@ namespace Umbraco.Core.Services.Implement
private IMemberType GetMemberType(IScope scope, string memberTypeAlias)
{
if (string.IsNullOrWhiteSpace(memberTypeAlias)) throw new ArgumentNullOrEmptyException(nameof(memberTypeAlias));
if (memberTypeAlias == null) throw new ArgumentNullException(nameof(memberTypeAlias));
if (string.IsNullOrWhiteSpace(memberTypeAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(memberTypeAlias));
scope.ReadLock(Constants.Locks.MemberTypes);
@@ -1358,7 +1359,8 @@ namespace Umbraco.Core.Services.Implement
private IMemberType GetMemberType(string memberTypeAlias)
{
if (string.IsNullOrWhiteSpace(memberTypeAlias)) throw new ArgumentNullOrEmptyException(nameof(memberTypeAlias));
if (memberTypeAlias == null) throw new ArgumentNullException(nameof(memberTypeAlias));
if (string.IsNullOrWhiteSpace(memberTypeAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(memberTypeAlias));
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data.SqlServerCe;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using Umbraco.Core.Configuration;
using Umbraco.Core.Events;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
@@ -17,7 +13,6 @@ using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.Repositories.Implement;
using Umbraco.Core.Scoping;
using Umbraco.Core.Security;
namespace Umbraco.Core.Services.Implement
{
@@ -107,7 +102,8 @@ namespace Umbraco.Core.Services.Implement
/// <returns><see cref="IUser"/></returns>
private IUser CreateUserWithIdentity(string username, string email, string passwordValue, bool isApproved = true)
{
if (string.IsNullOrWhiteSpace(username)) throw new ArgumentNullOrEmptyException(nameof(username));
if (username == null) throw new ArgumentNullException(nameof(username));
if (string.IsNullOrWhiteSpace(username)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(username));
// TODO: PUT lock here!!

View File

@@ -10,9 +10,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Web.Security;
using Newtonsoft.Json;
using Umbraco.Core.Configuration;
using Umbraco.Core.Composing;
using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
using Umbraco.Core.Strings;
@@ -1102,7 +1100,8 @@ namespace Umbraco.Core
/// <returns>The safe url segment.</returns>
public static string ToUrlSegment(this string text)
{
if (string.IsNullOrWhiteSpace(text)) throw new ArgumentNullOrEmptyException(nameof(text));
if (text == null) throw new ArgumentNullException(nameof(text));
if (string.IsNullOrWhiteSpace(text)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(text));
return Current.ShortStringHelper.CleanStringForUrlSegment(text);
}
@@ -1115,7 +1114,8 @@ namespace Umbraco.Core
/// <returns>The safe url segment.</returns>
public static string ToUrlSegment(this string text, string culture)
{
if (string.IsNullOrWhiteSpace(text)) throw new ArgumentNullOrEmptyException(nameof(text));
if (text == null) throw new ArgumentNullException(nameof(text));
if (string.IsNullOrWhiteSpace(text)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(text));
return Current.ShortStringHelper.CleanStringForUrlSegment(text, culture);
}

View File

@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.Xml
{
@@ -37,7 +34,8 @@ namespace Umbraco.Core.Xml
// allowed 'inline', not just at the beginning... whether or not we want to support that is up
// for discussion.
if (string.IsNullOrWhiteSpace(xpathExpression)) throw new ArgumentNullOrEmptyException(nameof(xpathExpression));
if (xpathExpression == null) throw new ArgumentNullException(nameof(xpathExpression));
if (string.IsNullOrWhiteSpace(xpathExpression)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(xpathExpression));
if (getPath == null) throw new ArgumentNullException(nameof(getPath));
if (publishedContentExists == null) throw new ArgumentNullException(nameof(publishedContentExists));

View File

@@ -4,9 +4,7 @@ using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
namespace Umbraco.Core.Xml
@@ -25,9 +23,10 @@ namespace Umbraco.Core.Xml
/// <param name="value"></param>
public static void SetAttribute(XmlDocument xml, XmlNode n, string name, string value)
{
if (xml == null) throw new ArgumentNullException("xml");
if (n == null) throw new ArgumentNullException("n");
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (xml == null) throw new ArgumentNullException(nameof(xml));
if (n == null) throw new ArgumentNullException(nameof(n));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
if (n.Attributes == null)
{
@@ -229,8 +228,9 @@ namespace Umbraco.Core.Xml
/// <returns>a XmlAttribute</returns>
public static XmlAttribute AddAttribute(XmlDocument xd, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
if (string.IsNullOrEmpty(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (xd == null) throw new ArgumentNullException(nameof(xd));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrEmpty(name)) throw new ArgumentException("Value can't be empty.", nameof(name));
var temp = xd.CreateAttribute(name);
temp.Value = value;
@@ -246,8 +246,9 @@ namespace Umbraco.Core.Xml
/// <returns>a XmlNode</returns>
public static XmlNode AddTextNode(XmlDocument xd, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (xd == null) throw new ArgumentNullException(nameof(xd));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
var temp = xd.CreateNode(XmlNodeType.Element, name, "");
temp.AppendChild(xd.CreateTextNode(value));
@@ -264,9 +265,10 @@ namespace Umbraco.Core.Xml
/// <returns>a XmlNode</returns>
public static XmlNode SetTextNode(XmlDocument xd, XmlNode parent, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
if (parent == null) throw new ArgumentNullException("parent");
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (xd == null) throw new ArgumentNullException(nameof(xd));
if (parent == null) throw new ArgumentNullException(nameof(parent));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
var child = parent.SelectSingleNode(name);
if (child != null)
@@ -289,7 +291,8 @@ namespace Umbraco.Core.Xml
{
if (xd == null) throw new ArgumentNullException(nameof(xd));
if (parent == null) throw new ArgumentNullException(nameof(parent));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", nameof(name));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
var child = parent.SelectSingleNode(name) ?? xd.CreateNode(XmlNodeType.Element, name, "");
child.InnerXml = value;
@@ -305,8 +308,9 @@ namespace Umbraco.Core.Xml
/// <returns>A XmlNode</returns>
public static XmlNode AddCDataNode(XmlDocument xd, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (xd == null) throw new ArgumentNullException(nameof(xd));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
var temp = xd.CreateNode(XmlNodeType.Element, name, "");
temp.AppendChild(xd.CreateCDataSection(value));
@@ -323,9 +327,10 @@ namespace Umbraco.Core.Xml
/// <returns>a XmlNode</returns>
public static XmlNode SetCDataNode(XmlDocument xd, XmlNode parent, string name, string value)
{
if (xd == null) throw new ArgumentNullException("xd");
if (parent == null) throw new ArgumentNullException("parent");
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (xd == null) throw new ArgumentNullException(nameof(xd));
if (parent == null) throw new ArgumentNullException(nameof(parent));
if (name == null) throw new ArgumentNullException(nameof(name));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
var child = parent.SelectSingleNode(name);
if (child != null)

View File

@@ -865,7 +865,7 @@ namespace Umbraco.Tests.Services
var userService = ServiceContext.UserService;
// Act & Assert
Assert.Throws<ArgumentNullOrEmptyException>(() => userService.CreateUserWithIdentity(string.Empty, "john@umbraco.io"));
Assert.Throws<ArgumentException>(() => userService.CreateUserWithIdentity(string.Empty, "john@umbraco.io"));
}
[Test]

View File

@@ -1,13 +1,10 @@
using System;
using System.Web.Mvc.Html;
using System.Web.Mvc;
using System.IO;
using Umbraco.Core.Exceptions;
using System.Web.Mvc.Html;
using Umbraco.Core.Models.PublishedContent;
namespace Umbraco.Web
{
public static class GridTemplateExtensions
{
public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedProperty property, string framework = "bootstrap3")
@@ -26,18 +23,20 @@ namespace Umbraco.Web
public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedContent contentItem, string propertyAlias)
{
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias));
if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias));
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyAlias));
return html.GetGridHtml(contentItem, propertyAlias, "bootstrap3");
}
public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedContent contentItem, string propertyAlias, string framework)
{
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias));
if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias));
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyAlias));
var view = "Grid/" + framework;
var prop = contentItem.GetProperty(propertyAlias);
if (prop == null) throw new NullReferenceException("No property type found with alias " + propertyAlias);
if (prop == null) throw new NullReferenceException("No property type found with alias " + propertyAlias); // TODO NullReferenceException should not be thrown by user code
var model = prop.GetValue();
var asString = model as string;
@@ -60,17 +59,19 @@ namespace Umbraco.Web
}
public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, HtmlHelper html, string propertyAlias)
{
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias));
if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias));
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyAlias));
return GetGridHtml(contentItem, html, propertyAlias, "bootstrap3");
}
public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, HtmlHelper html, string propertyAlias, string framework)
{
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias));
if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias));
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyAlias));
var view = "Grid/" + framework;
var prop = contentItem.GetProperty(propertyAlias);
if (prop == null) throw new NullReferenceException("No property type found with alias " + propertyAlias);
if (prop == null) throw new NullReferenceException("No property type found with alias " + propertyAlias); // TODO NullReferenceException should not be thrown by user code
var model = prop.GetValue();
var asString = model as string;
@@ -78,12 +79,5 @@ namespace Umbraco.Web
return html.Partial(view, model);
}
private class FakeView : IView
{
public void Render(ViewContext viewContext, TextWriter writer)
{
}
}
}
}

View File

@@ -8,11 +8,7 @@ using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
using Umbraco.Web.Security;
using Current = Umbraco.Web.Composing.Current;
@@ -169,8 +165,9 @@ namespace Umbraco.Web
/// <returns></returns>
public static IHtmlString Action(this HtmlHelper htmlHelper, string actionName, Type surfaceType)
{
if (actionName == null) throw new ArgumentNullException(nameof(actionName));
if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(actionName));
if (surfaceType == null) throw new ArgumentNullException(nameof(surfaceType));
if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName));
var routeVals = new RouteValueDictionary(new {area = ""});
@@ -221,7 +218,7 @@ namespace Umbraco.Web
{
_viewContext = viewContext;
_method = method;
_controllerName = controllerName;
_controllerName = controllerName;
_encryptedString = UrlHelperRenderExtensions.CreateEncryptedRouteString(controllerName, controllerAction, area, additionalRouteVals);
}
@@ -230,7 +227,7 @@ namespace Umbraco.Web
private readonly FormMethod _method;
private bool _disposed;
private readonly string _encryptedString;
private readonly string _controllerName;
private readonly string _controllerName;
protected override void Dispose(bool disposing)
{
@@ -243,9 +240,9 @@ namespace Umbraco.Web
|| _controllerName == "UmbProfile"
|| _controllerName == "UmbLoginStatus"
|| _controllerName == "UmbLogin")
{
{
_viewContext.Writer.Write(AntiForgery.GetHtml().ToString());
}
}
//write out the hidden surface form routes
_viewContext.Writer.Write("<input name='ufprt' type='hidden' value='" + _encryptedString + "' />");
@@ -355,8 +352,10 @@ namespace Umbraco.Web
IDictionary<string, object> htmlAttributes,
FormMethod method)
{
if (string.IsNullOrWhiteSpace(action)) throw new ArgumentNullOrEmptyException(nameof(action));
if (string.IsNullOrWhiteSpace(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
if (action == null) throw new ArgumentNullException(nameof(action));
if (string.IsNullOrWhiteSpace(action)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(action));
if (controllerName == null) throw new ArgumentNullException(nameof(controllerName));
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentException("Value can't be empty.", nameof(controllerName));
return html.BeginUmbracoForm(action, controllerName, "", additionalRouteVals, htmlAttributes, method);
}
@@ -374,8 +373,10 @@ namespace Umbraco.Web
object additionalRouteVals,
IDictionary<string, object> htmlAttributes)
{
if (string.IsNullOrWhiteSpace(action)) throw new ArgumentNullOrEmptyException(nameof(action));
if (string.IsNullOrWhiteSpace(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
if (action == null) throw new ArgumentNullException(nameof(action));
if (string.IsNullOrWhiteSpace(action)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(action));
if (controllerName == null) throw new ArgumentNullException(nameof(controllerName));
if (string.IsNullOrWhiteSpace(controllerName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(controllerName));
return html.BeginUmbracoForm(action, controllerName, "", additionalRouteVals, htmlAttributes);
}
@@ -575,7 +576,9 @@ namespace Umbraco.Web
IDictionary<string, object> htmlAttributes,
FormMethod method)
{
if (string.IsNullOrWhiteSpace(action)) throw new ArgumentNullOrEmptyException(nameof(action));
if (action == null) throw new ArgumentNullException(nameof(action));
if (string.IsNullOrWhiteSpace(action)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(action));
if (surfaceType == null) throw new ArgumentNullException(nameof(surfaceType));
var area = "";
@@ -687,8 +690,10 @@ namespace Umbraco.Web
IDictionary<string, object> htmlAttributes,
FormMethod method)
{
if (string.IsNullOrEmpty(action)) throw new ArgumentNullOrEmptyException(nameof(action));
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
if (action == null) throw new ArgumentNullException(nameof(action));
if (string.IsNullOrEmpty(action)) throw new ArgumentException("Value can't be empty.", nameof(action));
if (controllerName == null) throw new ArgumentNullException(nameof(controllerName));
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentException("Value can't be empty.", nameof(controllerName));
var formAction = Current.UmbracoContext.OriginalRequestUrl.PathAndQuery;
return html.RenderForm(formAction, method, htmlAttributes, controllerName, action, area, additionalRouteVals);

View File

@@ -3,7 +3,6 @@ using System.Linq;
using System.Linq.Expressions;
using System.Web.Http.Routing;
using Umbraco.Core;
using Umbraco.Core.Exceptions;
using Umbraco.Web.Composing;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
@@ -53,7 +52,8 @@ namespace Umbraco.Web
/// <returns></returns>
public static string GetUmbracoApiService(this UrlHelper url, string actionName, Type apiControllerType, object id = null)
{
if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName));
if (actionName == null) throw new ArgumentNullException(nameof(actionName));
if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(actionName));
if (apiControllerType == null) throw new ArgumentNullException(nameof(apiControllerType));
var area = "";
@@ -95,8 +95,10 @@ namespace Umbraco.Web
/// <returns></returns>
public static string GetUmbracoApiService(this UrlHelper url, string actionName, string controllerName, string area, object id = null)
{
if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName));
if (string.IsNullOrWhiteSpace(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
if (actionName == null) throw new ArgumentNullException(nameof(actionName));
if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(actionName));
if (controllerName == null) throw new ArgumentNullException(nameof(controllerName));
if (string.IsNullOrWhiteSpace(controllerName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(controllerName));
string routeName;
if (area.IsNullOrWhiteSpace())

View File

@@ -1,10 +1,9 @@
using System.Runtime.Serialization;
using Umbraco.Core.IO;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Trees
@@ -27,7 +26,8 @@ namespace Umbraco.Web.Models.Trees
/// <param name="menuUrl"></param>
internal TreeNode(string nodeId, string parentId, string getChildNodesUrl, string menuUrl)
{
if (string.IsNullOrWhiteSpace(nodeId)) throw new ArgumentNullOrEmptyException(nameof(nodeId));
if (nodeId == null) throw new ArgumentNullException(nameof(nodeId));
if (string.IsNullOrWhiteSpace(nodeId)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(nodeId));
Id = nodeId;
ParentId = parentId;

View File

@@ -6,7 +6,6 @@ using System.Web.Routing;
using System.Web.SessionState;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Exceptions;
using Umbraco.Web.WebApi;
namespace Umbraco.Web.Mvc
@@ -48,7 +47,8 @@ namespace Umbraco.Web.Mvc
bool isMvc = true,
string areaPathPrefix = "")
{
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
if (controllerName == null) throw new ArgumentNullException(nameof(controllerName));
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentException("Value can't be empty.", nameof(controllerName));
if (controllerSuffixName == null) throw new ArgumentNullException(nameof(controllerSuffixName));
if (controllerType == null) throw new ArgumentNullException(nameof(controllerType));

View File

@@ -1,5 +1,4 @@
using System;
using Umbraco.Core.Exceptions;
namespace Umbraco.Web.Search
{
@@ -8,42 +7,47 @@ namespace Umbraco.Web.Search
{
public const int DefaultSortOrder = 1000;
/// <summary>
/// This constructor defines both the angular service and method name to use
/// </summary>
/// <param name="serviceName"></param>
/// <param name="methodName"></param>
public SearchableTreeAttribute(string serviceName, string methodName) : this(serviceName, methodName, DefaultSortOrder) { }
/// <summary>
/// This constructor defines both the angular service and method name to use and explicitly defines a sort order for the results
/// </summary>
/// <param name="serviceName"></param>
/// <param name="methodName"></param>
/// <param name="sortOrder"></param>
public SearchableTreeAttribute(string serviceName, string methodName, int sortOrder)
{
if (string.IsNullOrWhiteSpace(serviceName)) throw new ArgumentNullOrEmptyException(nameof(serviceName));
if (string.IsNullOrWhiteSpace(methodName)) throw new ArgumentNullOrEmptyException(nameof(methodName));
MethodName = methodName;
SortOrder = sortOrder;
ServiceName = serviceName;
}
/// <summary>
/// This constructor will assume that the method name equals `format(searchResult, appAlias, treeAlias)`
/// </summary>
/// <param name="serviceName"></param>
public SearchableTreeAttribute(string serviceName)
{
if (string.IsNullOrWhiteSpace(serviceName)) throw new ArgumentNullOrEmptyException(nameof(serviceName));
MethodName = "";
ServiceName = serviceName;
SortOrder = DefaultSortOrder;
}
public string ServiceName { get; }
public string MethodName { get; }
public string ServiceName { get; }
public int SortOrder { get; }
/// <summary>
/// This constructor will assume that the method name equals `format(searchResult, appAlias, treeAlias)`.
/// </summary>
/// <param name="serviceName">Name of the service.</param>
public SearchableTreeAttribute(string serviceName)
: this(serviceName, string.Empty)
{ }
/// <summary>
/// This constructor defines both the Angular service and method name to use.
/// </summary>
/// <param name="serviceName">Name of the service.</param>
/// <param name="methodName">Name of the method.</param>
public SearchableTreeAttribute(string serviceName, string methodName)
: this(serviceName, methodName, DefaultSortOrder)
{ }
/// <summary>
/// This constructor defines both the Angular service and method name to use and explicitly defines a sort order for the results
/// </summary>
/// <param name="serviceName">Name of the service.</param>
/// <param name="methodName">Name of the method.</param>
/// <param name="sortOrder">The sort order.</param>
/// <exception cref="ArgumentNullException">serviceName
/// or
/// methodName</exception>
/// <exception cref="ArgumentException">Value can't be empty or consist only of white-space characters. - serviceName</exception>
public SearchableTreeAttribute(string serviceName, string methodName, int sortOrder)
{
if (serviceName == null) throw new ArgumentNullException(nameof(serviceName));
if (string.IsNullOrWhiteSpace(serviceName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(serviceName));
ServiceName = serviceName;
MethodName = methodName ?? throw new ArgumentNullException(nameof(methodName));
SortOrder = sortOrder;
}
}
}

View File

@@ -75,7 +75,9 @@ namespace Umbraco.Web.Security
/// </param>
public static void ForUmbracoBackOffice(this AuthenticationOptions options, string style, string icon, string callbackPath = null)
{
if (string.IsNullOrEmpty(options.AuthenticationType)) throw new ArgumentNullOrEmptyException("options.AuthenticationType");
// TODO Change exceptions to InvalidOperationException, as the value isn't an argument
if (options.AuthenticationType == null) throw new ArgumentNullException(nameof(options.AuthenticationType));
if (string.IsNullOrEmpty(options.AuthenticationType)) throw new ArgumentException("Value can't be empty.", nameof(options.AuthenticationType));
//Ensure the prefix is set
if (options.AuthenticationType.StartsWith(Constants.Security.BackOfficeExternalAuthenticationTypePrefix) == false)

View File

@@ -2,15 +2,12 @@
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Management.Instrumentation;
using System.Web.Mvc;
using System.Web.Routing;
using ClientDependency.Core.Config;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Exceptions;
using Umbraco.Web.Composing;
using Umbraco.Web.Editors;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
@@ -70,7 +67,8 @@ namespace Umbraco.Web
/// <returns></returns>
public static string GetUmbracoApiService(this UrlHelper url, string actionName, Type apiControllerType, RouteValueDictionary routeVals = null)
{
if (string.IsNullOrEmpty(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName));
if (actionName == null) throw new ArgumentNullException(nameof(actionName));
if (string.IsNullOrEmpty(actionName)) throw new ArgumentException("Value can't be empty.", nameof(actionName));
if (apiControllerType == null) throw new ArgumentNullException(nameof(apiControllerType));
var area = "";
@@ -99,8 +97,10 @@ namespace Umbraco.Web
/// <returns></returns>
public static string GetUmbracoApiService(this UrlHelper url, string actionName, string controllerName, string area, RouteValueDictionary routeVals = null)
{
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
if (string.IsNullOrEmpty(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName));
if (actionName == null) throw new ArgumentNullException(nameof(actionName));
if (string.IsNullOrEmpty(actionName)) throw new ArgumentException("Value can't be empty.", nameof(actionName));
if (controllerName == null) throw new ArgumentNullException(nameof(controllerName));
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentException("Value can't be empty.", nameof(controllerName));
if (routeVals == null)
{

View File

@@ -4,8 +4,6 @@ using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors.ValueConverters;
using Umbraco.Web.Composing;
@@ -302,8 +300,10 @@ namespace Umbraco.Web
/// <returns></returns>
public static string SurfaceAction(this UrlHelper url, string action, string controllerName, string area, object additionalRouteVals)
{
if (string.IsNullOrEmpty(action)) throw new ArgumentNullOrEmptyException(nameof(action));
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
if (action == null) throw new ArgumentNullException(nameof(action));
if (string.IsNullOrEmpty(action)) throw new ArgumentException("Value can't be empty.", nameof(action));
if (controllerName == null) throw new ArgumentNullException(nameof(controllerName));
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentException("Value can't be empty.", nameof(controllerName));
var encryptedRoute = CreateEncryptedRouteString(controllerName, action, area, additionalRouteVals);
@@ -333,7 +333,8 @@ namespace Umbraco.Web
/// <returns></returns>
public static string SurfaceAction(this UrlHelper url, string action, Type surfaceType, object additionalRouteVals)
{
if (string.IsNullOrEmpty(action)) throw new ArgumentNullOrEmptyException(nameof(action));
if (action == null) throw new ArgumentNullException(nameof(action));
if (string.IsNullOrEmpty(action)) throw new ArgumentException("Value can't be empty.", nameof(action));
if (surfaceType == null) throw new ArgumentNullException(nameof(surfaceType));
var area = "";
@@ -392,8 +393,10 @@ namespace Umbraco.Web
/// <returns></returns>
internal static string CreateEncryptedRouteString(string controllerName, string controllerAction, string area, object additionalRouteVals = null)
{
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
if (string.IsNullOrEmpty(controllerAction)) throw new ArgumentNullOrEmptyException(nameof(controllerAction));
if (controllerName == null) throw new ArgumentNullException(nameof(controllerName));
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentException("Value can't be empty.", nameof(controllerName));
if (controllerAction == null) throw new ArgumentNullException(nameof(controllerAction));
if (string.IsNullOrEmpty(controllerAction)) throw new ArgumentException("Value can't be empty.", nameof(controllerAction));
if (area == null) throw new ArgumentNullException(nameof(area));
//need to create a params string as Base64 to put into our hidden field to use during the routes

View File

@@ -1,16 +1,13 @@
using System;
using System.Net;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
using Umbraco.Core.Exceptions;
using Umbraco.Web.Composing;
using Umbraco.Web.Editors;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web.Actions;
using Umbraco.Core.Security;
using System.Net;
using Umbraco.Web.Actions;
using Umbraco.Web.Composing;
namespace Umbraco.Web.WebApi.Filters
{
@@ -46,7 +43,9 @@ namespace Umbraco.Web.WebApi.Filters
public EnsureUserPermissionForContentAttribute(string paramName)
{
if (string.IsNullOrEmpty(paramName)) throw new ArgumentNullOrEmptyException(nameof(paramName));
if (paramName == null) throw new ArgumentNullException(nameof(paramName));
if (string.IsNullOrEmpty(paramName)) throw new ArgumentException("Value can't be empty.", nameof(paramName));
_paramName = paramName;
_permissionToCheck = ActionBrowse.ActionLetter;
}

View File

@@ -3,7 +3,6 @@ using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
using Umbraco.Core;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models;
using Umbraco.Web.Composing;
using Umbraco.Web.Editors;
@@ -38,14 +37,18 @@ namespace Umbraco.Web.WebApi.Filters
public EnsureUserPermissionForMediaAttribute(string paramName)
{
if (string.IsNullOrEmpty(paramName)) throw new ArgumentNullOrEmptyException(nameof(paramName));
if (paramName == null) throw new ArgumentNullException(nameof(paramName));
if (string.IsNullOrEmpty(paramName)) throw new ArgumentException("Value can't be empty.", nameof(paramName));
_paramName = paramName;
}
// TODO: v8 guess this is not used anymore, source is ignored?!
public EnsureUserPermissionForMediaAttribute(string paramName, DictionarySource source)
{
if (string.IsNullOrEmpty(paramName)) throw new ArgumentNullOrEmptyException(nameof(paramName));
if (paramName == null) throw new ArgumentNullException(nameof(paramName));
if (string.IsNullOrEmpty(paramName)) throw new ArgumentException("Value can't be empty.", nameof(paramName));
_paramName = paramName;
}

View File

@@ -1,10 +1,8 @@
using Newtonsoft.Json.Converters;
using System;
using System;
using System.Linq;
using System.Net.Http.Formatting;
using System.Web.Http.Controllers;
using Umbraco.Core;
using Umbraco.Core.Exceptions;
using Newtonsoft.Json.Converters;
namespace Umbraco.Web.WebApi.Filters
{
@@ -21,7 +19,9 @@ namespace Umbraco.Web.WebApi.Filters
/// <param name="format"></param>
public JsonDateTimeFormatAttributeAttribute(string format)
{
if (string.IsNullOrEmpty(format)) throw new ArgumentNullOrEmptyException(nameof(format));
if (format == null) throw new ArgumentNullException(nameof(format));
if (string.IsNullOrEmpty(format)) throw new ArgumentException("Value can't be empty.", nameof(format));
_format = format;
}