Get rid of Mandate

This commit is contained in:
Stephan
2017-05-31 09:18:09 +02:00
parent 1e62ea8b16
commit d3133abcab
36 changed files with 188 additions and 330 deletions
@@ -2,6 +2,7 @@
using System.Linq;
using System.Web;
using Umbraco.Core.Composing;
using Umbraco.Core.Exceptions;
using Umbraco.Web;
// ReSharper disable once CheckNamespace
@@ -38,8 +39,8 @@ namespace Umbraco.Core.Logging
[Obsolete("Warnings with http trace should not be used. This method will be removed in future versions")]
public static void Warn(Type callingType, string message, bool showHttpTrace, params Func<object>[] formatItems)
{
Mandate.ParameterNotNull(callingType, "callingType");
Mandate.ParameterNotNullOrEmpty(message, "message");
if (callingType == null) throw new ArgumentNullException(nameof(callingType));
if (string.IsNullOrEmpty(message)) throw new ArgumentNullOrEmptyException(nameof(message));
if (showHttpTrace && HttpContext.Current != null)
{
@@ -59,9 +60,9 @@ namespace Umbraco.Core.Logging
[Obsolete("Warnings with http trace should not be used. This method will be removed in future versions")]
public static void WarnWithException(Type callingType, string message, bool showHttpTrace, Exception e, params Func<object>[] formatItems)
{
Mandate.ParameterNotNull(e, "e");
Mandate.ParameterNotNull(callingType, "callingType");
Mandate.ParameterNotNullOrEmpty(message, "message");
if (e == null) throw new ArgumentNullException(nameof(e));
if (callingType == null) throw new ArgumentNullException(nameof(callingType));
if (string.IsNullOrEmpty(message)) throw new ArgumentNullOrEmptyException(nameof(message));
if (showHttpTrace && HttpContext.Current != null)
{
-108
View File
@@ -1,108 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Umbraco.Core
{
/// <summary>
/// Helper class for mandating values, for example on method parameters.
/// </summary>
[Obsolete]
public static class Mandate
{
/// <summary>
/// Mandates that the specified parameter is not null.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="paramName">Name of the param.</param>
/// <exception cref="ArgumentNullException">If <paramref name="value"/> is null.</exception>
public static void ParameterNotNull<T>(T value, string paramName) where T : class
{
That(value != null, () => new ArgumentNullException(paramName));
}
/// <summary>
/// Mandates that the specified parameter is not null.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="paramName">Name of the param.</param>
/// <exception cref="ArgumentNullException">If <paramref name="value"/> is null or whitespace.</exception>
public static void ParameterNotNullOrEmpty(string value, string paramName)
{
That(!string.IsNullOrWhiteSpace(value), () => new ArgumentNullException(paramName));
}
/// <summary>
/// Mandates that the specified sequence is not null and has at least one element.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="sequence">The sequence.</param>
/// <param name="paramName">Name of the param.</param>
public static void ParameterNotNullOrEmpty<T>(IEnumerable<T> sequence, string paramName)
{
ParameterNotNull(sequence, paramName);
ParameterCondition(sequence.Any(), paramName);
}
/// <summary>
/// Mandates that the specified parameter matches the condition.
/// </summary>
/// <param name="condition">The condition to check.</param>
/// <param name="paramName">Name of the param.</param>
/// <exception cref="ArgumentException">If the condition is false.</exception>
public static void ParameterCondition(bool condition, string paramName)
{
ParameterCondition(condition, paramName, (string)null);
}
/// <summary>
/// Mandates that the specified parameter matches the condition.
/// </summary>
/// <param name="condition">The condition to check.</param>
/// <param name="paramName">Name of the param.</param>
/// <param name="message">The message.</param>
/// <exception cref="ArgumentException">If the condition is false.</exception>
public static void ParameterCondition(bool condition, string paramName, string message)
{
// Warning: don't make this method have an optional message parameter (removing the other ParameterCondition overload) as it will
// make binaries compiled against previous Framework libs incompatible unneccesarily
message = message ?? "A parameter passed into a method was not a valid value";
That(condition, () => new ArgumentException(message, paramName));
}
/// <summary>
/// Mandates that the specified condition is true, otherwise throws an exception specified in <typeparamref name="TException"/>.
/// </summary>
/// <typeparam name="TException">The type of the exception.</typeparam>
/// <param name="condition">if set to <c>true</c>, throws exception <typeparamref name="TException"/>.</param>
/// <exception cref="Exception">An exception of type <typeparamref name="TException"/> is raised if the condition is false.</exception>
public static void That<TException>(bool condition) where TException : Exception, new()
{
if (!condition)
throw ActivatorHelper.CreateInstance<TException>();
}
/// <summary>
/// Mandates that the specified condition is true, otherwise throws an exception specified in <typeparamref name="TException"/>.
/// </summary>
/// <typeparam name="TException">The type of the exception.</typeparam>
/// <param name="condition">if set to <c>true</c>, throws exception <typeparamref name="TException"/>.</param>
/// <param name="defer">Deffered expression to call if the exception should be raised.</param>
/// <exception cref="Exception">An exception of type <typeparamref name="TException"/> is raised if the condition is false.</exception>
public static void That<TException>(bool condition, Func<TException> defer) where TException : Exception, new()
{
if (!condition)
{
throw defer.Invoke();
}
// Here is an example of how this method is actually called
//object myParam = null;
//Mandate.That(myParam != null,
// textManager => new ArgumentNullException(textManager.Get("blah", new {User = "blah"})));
}
}
}
+2 -6
View File
@@ -43,9 +43,7 @@ namespace Umbraco.Core.Models
public Content(string name, IContent parent, IContentType contentType, PropertyCollection properties)
: base(name, parent, contentType, properties)
{
Mandate.ParameterNotNull(contentType, "contentType");
_contentType = contentType;
_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
PublishedState = PublishedState.Unpublished;
}
@@ -69,9 +67,7 @@ namespace Umbraco.Core.Models
public Content(string name, int parentId, IContentType contentType, PropertyCollection properties)
: base(name, parentId, contentType, properties)
{
Mandate.ParameterNotNull(contentType, "contentType");
_contentType = contentType;
_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
PublishedState = PublishedState.Unpublished;
}
+6 -10
View File
@@ -43,17 +43,15 @@ namespace Umbraco.Core.Models
/// <param name="properties"></param>
protected ContentBase(string name, int parentId, IContentTypeComposition contentType, PropertyCollection properties)
{
Mandate.ParameterCondition(parentId != 0, "parentId");
Mandate.ParameterNotNull(contentType, "contentType");
Mandate.ParameterNotNull(properties, "properties");
if (parentId == 0) throw new ArgumentOutOfRangeException(nameof(parentId));
ContentTypeBase = contentType;
ContentTypeBase = contentType ?? throw new ArgumentNullException(nameof(contentType));
Version = Guid.NewGuid();
_parentId = new Lazy<int>(() => parentId);
_name = name;
_contentTypeId = contentType.Id;
_properties = properties;
_properties = properties ?? throw new ArgumentNullException(nameof(properties));
_properties.EnsurePropertyTypes(PropertyTypes);
_additionalData = new Dictionary<string, object>();
}
@@ -67,17 +65,15 @@ namespace Umbraco.Core.Models
/// <param name="properties"></param>
protected ContentBase(string name, IContentBase parent, IContentTypeComposition contentType, PropertyCollection properties)
{
Mandate.ParameterNotNull(parent, "parent");
Mandate.ParameterNotNull(contentType, "contentType");
Mandate.ParameterNotNull(properties, "properties");
if (parent == null) throw new ArgumentNullException(nameof(parent));
ContentTypeBase = contentType;
ContentTypeBase = contentType ?? throw new ArgumentNullException(nameof(contentType));
Version = Guid.NewGuid();
_parentId = new Lazy<int>(() => parent.Id);
_name = name;
_contentTypeId = contentType.Id;
_properties = properties;
_properties = properties ?? throw new ArgumentNullException(nameof(properties));
_properties.EnsurePropertyTypes(PropertyTypes);
_additionalData = new Dictionary<string, object>();
}
+2 -2
View File
@@ -40,7 +40,7 @@ namespace Umbraco.Core.Models
protected ContentTypeBase(int parentId)
{
Mandate.ParameterCondition(parentId != 0, "parentId");
if (parentId == 0) throw new ArgumentOutOfRangeException(nameof(parentId));
_parentId = new Lazy<int>(() => parentId);
_allowedContentTypes = new List<ContentTypeSort>();
@@ -56,7 +56,7 @@ namespace Umbraco.Core.Models
protected ContentTypeBase(IContentTypeBase parent, string alias)
{
Mandate.ParameterNotNull(parent, "parent");
if (parent == null) throw new ArgumentNullException(nameof(parent));
_alias = alias;
_parentId = new Lazy<int>(() => parent.Id);
+3 -8
View File
@@ -34,8 +34,7 @@ namespace Umbraco.Core.Models
public Media(string name, IMedia parent, IMediaType contentType, PropertyCollection properties)
: base(name, parent, contentType, properties)
{
Mandate.ParameterNotNull(contentType, "contentType");
_contentType = contentType;
_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
}
/// <summary>
@@ -59,18 +58,14 @@ namespace Umbraco.Core.Models
public Media(string name, int parentId, IMediaType contentType, PropertyCollection properties)
: base(name, parentId, contentType, properties)
{
Mandate.ParameterNotNull(contentType, "contentType");
_contentType = contentType;
_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
}
/// <summary>
/// Gets the ContentType used by this Media object
/// </summary>
[IgnoreDataMember]
public IMediaType ContentType
{
get { return _contentType; }
}
public IMediaType ContentType => _contentType;
/// <summary>
/// Changes the <see cref="IMediaType"/> for the current Media object
+17 -21
View File
@@ -4,6 +4,7 @@ using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using Umbraco.Core.Composing;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
namespace Umbraco.Core.Models
@@ -29,10 +30,8 @@ namespace Umbraco.Core.Models
public Member(IMemberType contentType)
: base("", -1, contentType, new PropertyCollection())
{
Mandate.ParameterNotNull(contentType, "contentType");
_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
_contentTypeAlias = contentType.Alias;
_contentType = contentType;
IsApproved = true;
//this cannot be null but can be empty
@@ -47,13 +46,12 @@ namespace Umbraco.Core.Models
/// <param name="name">Name of the content</param>
/// <param name="contentType">ContentType for the current Content object</param>
public Member(string name, IMemberType contentType)
: this(contentType)
: base(name, -1, contentType, new PropertyCollection())
{
Mandate.ParameterNotNull(contentType, "contentType");
Mandate.ParameterNotNullOrEmpty(name, "name");
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
_contentTypeAlias = contentType.Alias;
_contentType = contentType;
IsApproved = true;
//this cannot be null but can be empty
@@ -72,13 +70,12 @@ namespace Umbraco.Core.Models
public Member(string name, string email, string username, IMemberType contentType)
: base(name, -1, contentType, new PropertyCollection())
{
Mandate.ParameterNotNull(contentType, "contentType");
Mandate.ParameterNotNullOrEmpty(name, "name");
Mandate.ParameterNotNullOrEmpty(email, "email");
Mandate.ParameterNotNullOrEmpty(username, "username");
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));
_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
_contentTypeAlias = contentType.Alias;
_contentType = contentType;
_email = email;
_username = username;
IsApproved = true;
@@ -100,10 +97,9 @@ namespace Umbraco.Core.Models
public Member(string name, string email, string username, string rawPasswordValue, IMemberType contentType)
: base(name, -1, contentType, new PropertyCollection())
{
Mandate.ParameterNotNull(contentType, "contentType");
_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
_contentTypeAlias = contentType.Alias;
_contentType = contentType;
_email = email;
_username = username;
_rawPasswordValue = rawPasswordValue;
@@ -195,7 +191,7 @@ namespace Umbraco.Core.Models
/// <remarks>
/// For security reasons this value should be encrypted, the encryption process is handled by the memberhip provider
/// Alias: umbracoMemberPasswordRetrievalAnswer
///
///
/// Part of the standard properties collection.
/// </remarks>
[IgnoreDataMember]
@@ -261,7 +257,7 @@ namespace Umbraco.Core.Models
{
get
{
var a = WarnIfPropertyTypeNotFoundOnGet(Constants.Conventions.Member.IsApproved, "IsApproved",
var a = WarnIfPropertyTypeNotFoundOnGet(Constants.Conventions.Member.IsApproved, "IsApproved",
//This is the default value if the prop is not found
true);
if (a.Success == false) return a.Result;
@@ -463,7 +459,7 @@ namespace Umbraco.Core.Models
/// User key from the Provider.
/// </summary>
/// <remarks>
/// When using standard umbraco provider this key will
/// When using standard umbraco provider this key will
/// correspond to the guid UniqueId/Key.
/// Otherwise it will the one available from the asp.net
/// membership provider.
@@ -478,7 +474,7 @@ namespace Umbraco.Core.Models
set { SetPropertyValueAndDetectChanges(value, ref _providerUserKey, Ps.Value.ProviderUserKeySelector); }
}
/// <summary>
/// Method to call when Entity is being saved
/// </summary>
@@ -500,7 +496,7 @@ namespace Umbraco.Core.Models
get { return _contentType; }
}
/* Internal experiment - only used for mapping queries.
/* Internal experiment - only used for mapping queries.
* Adding these to have first level properties instead of the Properties collection.
*/
[IgnoreDataMember]
@@ -529,7 +525,7 @@ namespace Umbraco.Core.Models
+ propertyAlias
+ " configured on your member type in order to use the '"
+ propertyName
+ "' property on the model correctly.");
+ "' property on the model correctly.");
//if the property doesn't exist, then do the logging and return a failure
if (Properties.Contains(propertyAlias) == false)
+6 -5
View File
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.Serialization;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Persistence.Mappers;
@@ -19,19 +20,19 @@ namespace Umbraco.Core.Models
private Guid _parentObjectType;
private Guid _childObjectType;
public RelationType(Guid childObjectType, Guid parentObjectType, string @alias)
public RelationType(Guid childObjectType, Guid parentObjectType, string alias)
{
Mandate.ParameterNotNullOrEmpty(@alias, "alias");
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias));
_childObjectType = childObjectType;
_parentObjectType = parentObjectType;
_alias = alias;
Name = _alias;
}
public RelationType(Guid childObjectType, Guid parentObjectType, string @alias, string name)
:this(childObjectType, parentObjectType, @alias)
public RelationType(Guid childObjectType, Guid parentObjectType, string alias, string name)
: this(childObjectType, parentObjectType, alias)
{
Mandate.ParameterNotNullOrEmpty(name, "name");
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
Name = name;
}
+2 -1
View File
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.Linq;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Services;
@@ -75,7 +76,7 @@ namespace Umbraco.Core.Models
internal static bool HasPathAccess(string path, int startNodeId, int recycleBinId)
{
Mandate.ParameterNotNullOrEmpty(path, "path");
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentNullOrEmptyException(nameof(path));
var formattedPath = "," + path + ",";
var formattedStartNodeId = "," + startNodeId.ToInvariantString() + ",";
@@ -9,6 +9,7 @@ using NPoco;
using Semver;
using Umbraco.Core.Configuration;
using Umbraco.Core.Events;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.Migrations.Syntax.IfDatabase;
using Umbraco.Core.Persistence.SqlSyntax;
@@ -32,18 +33,13 @@ namespace Umbraco.Core.Persistence.Migrations
public MigrationRunner(IMigrationCollectionBuilder builder, IMigrationEntryService migrationEntryService, ILogger logger, SemVersion currentVersion, SemVersion targetVersion, string productName, params IMigration[] migrations)
{
if (builder == null) throw new ArgumentNullException("builder");
if (migrationEntryService == null) throw new ArgumentNullException("migrationEntryService");
if (logger == null) throw new ArgumentNullException("logger");
if (currentVersion == null) throw new ArgumentNullException("currentVersion");
if (targetVersion == null) throw new ArgumentNullException("targetVersion");
Mandate.ParameterNotNullOrEmpty(productName, "productName");
if (string.IsNullOrWhiteSpace(productName)) throw new ArgumentNullOrEmptyException(nameof(productName));
_builder = builder;
_migrationEntryService = migrationEntryService;
_logger = logger;
_currentVersion = currentVersion;
_targetVersion = targetVersion;
_builder = builder ?? throw new ArgumentNullException(nameof(builder));
_migrationEntryService = migrationEntryService ?? throw new ArgumentNullException(nameof(migrationEntryService));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_currentVersion = currentVersion ?? throw new ArgumentNullException(nameof(currentVersion));
_targetVersion = targetVersion ?? throw new ArgumentNullException(nameof(targetVersion));
_productName = productName;
//ensure this is null if there aren't any
_migrations = migrations == null || migrations.Length == 0 ? null : migrations;
@@ -214,18 +214,13 @@ namespace Umbraco.Core.Persistence.Repositories
protected override void PersistNewItem(IContentType entity)
{
Mandate.That<Exception>(string.IsNullOrEmpty(entity.Alias) == false,
() =>
{
var message =
string.Format(
"ContentType '{0}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.",
entity.Name);
var exception = new Exception(message);
Logger.Error<ContentTypeRepository>(message, exception);
throw exception;
});
if (string.IsNullOrWhiteSpace(entity.Alias))
{
var m = $"ContentType '{entity.Name}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.";
var e = new Exception(m);
Logger.Error<ContentTypeRepository>(m, e);
throw e;
}
((ContentType)entity).AddingEntity();
@@ -520,36 +520,24 @@ AND umbracoNode.id <> @id",
protected void ValidateAlias(PropertyType pt)
{
Mandate.That<InvalidOperationException>(string.IsNullOrEmpty(pt.Alias) == false,
() =>
{
var message =
string.Format(
"{0} '{1}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.",
"Property Type",
pt.Name);
var exception = new InvalidOperationException(message);
Logger.Error<ContentTypeRepositoryBase<TEntity>>(message, exception);
throw exception;
});
if (string.IsNullOrWhiteSpace(pt.Alias))
{
var m = $"Property Type '{pt.Name}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.";
var e = new InvalidOperationException(m);
Logger.Error<ContentTypeRepositoryBase<TEntity>>(m, e);
throw e;
}
}
protected void ValidateAlias(TEntity entity)
{
Mandate.That<InvalidOperationException>(string.IsNullOrEmpty(entity.Alias) == false,
() =>
{
var message =
string.Format(
"{0} '{1}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.",
typeof(TEntity).Name,
entity.Name);
var exception = new InvalidOperationException(message);
Logger.Error<ContentTypeRepositoryBase<TEntity>>(message, exception);
throw exception;
});
if (string.IsNullOrWhiteSpace(entity.Alias))
{
var m = $"{typeof(TEntity).Name} '{entity.Name}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.";
var e = new InvalidOperationException(m);
Logger.Error<ContentTypeRepositoryBase<TEntity>>(m, e);
throw e;
}
}
/// <summary>
@@ -759,7 +747,7 @@ AND umbracoNode.id <> @id",
internal static IEnumerable<IMediaType> MapMediaTypes(IDatabase db, ISqlSyntaxProvider sqlSyntax,
out IDictionary<int, List<int>> parentMediaTypeIds)
{
Mandate.ParameterNotNull(db, "db");
if (db == null) throw new ArgumentNullException(nameof(db));
var sql = @"SELECT cmsContentType.pk as ctPk, cmsContentType.alias as ctAlias, cmsContentType.allowAtRoot as ctAllowAtRoot, cmsContentType.description as ctDesc,
cmsContentType.icon as ctIcon, cmsContentType.isContainer as ctIsContainer, cmsContentType.nodeId as ctId, cmsContentType.thumbnail as ctThumb,
@@ -898,7 +886,7 @@ AND umbracoNode.id <> @id",
out IDictionary<int, List<AssociatedTemplate>> associatedTemplates,
out IDictionary<int, List<int>> parentContentTypeIds)
{
Mandate.ParameterNotNull(db, "db");
if (db == null) throw new ArgumentNullException(nameof(db));
var sql = @"SELECT cmsDocumentType.IsDefault as dtIsDefault, cmsDocumentType.templateNodeId as dtTemplateId,
cmsContentType.pk as ctPk, cmsContentType.alias as ctAlias, cmsContentType.allowAtRoot as ctAllowAtRoot, cmsContentType.description as ctDesc,
@@ -3,6 +3,7 @@ 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.Models.Rdbms;
@@ -165,8 +166,8 @@ namespace Umbraco.Core.Persistence.Repositories
{
EnsureContainerType(entity);
if (string.IsNullOrWhiteSpace(entity.Name)) throw new ArgumentNullOrEmptyException("entity.Name");
entity.Name = entity.Name.Trim();
Mandate.ParameterNotNullOrEmpty(entity.Name, "entity.Name");
// guard against duplicates
var nodeDto = Database.FirstOrDefault<NodeDto>(Sql().SelectAll()
@@ -227,7 +228,7 @@ namespace Umbraco.Core.Persistence.Repositories
EnsureContainerType(entity);
entity.Name = entity.Name.Trim();
Mandate.ParameterNotNullOrEmpty(entity.Name, "entity.Name");
if (string.IsNullOrWhiteSpace(entity.Name)) throw new ArgumentNullOrEmptyException("entity.Name");
// find container to update
var nodeDto = Database.FirstOrDefault<NodeDto>(Sql().SelectAll()
@@ -1,4 +1,5 @@
using System;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.PropertyEditors
{
@@ -11,9 +12,9 @@ namespace Umbraco.Core.PropertyEditors
{
public ParameterEditorAttribute(string alias, string name, string editorView)
{
Mandate.ParameterNotNullOrEmpty(alias, "alias");
Mandate.ParameterNotNullOrEmpty(name, "name");
Mandate.ParameterNotNullOrEmpty(editorView, "editorView");
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (string.IsNullOrWhiteSpace(editorView)) throw new ArgumentNullOrEmptyException(nameof(editorView));
Alias = alias;
Name = name;
@@ -22,16 +23,15 @@ namespace Umbraco.Core.PropertyEditors
public ParameterEditorAttribute(string alias, string name)
{
Mandate.ParameterNotNullOrEmpty(alias, "id");
Mandate.ParameterNotNullOrEmpty(name, "name");
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
Alias = alias;
Name = name;
}
public string Alias { get; private set; }
public string Name { get; private set; }
public string EditorView { get; private set; }
public string Alias { get; }
public string Name { get; }
public string EditorView { get; }
}
}
@@ -1,4 +1,5 @@
using System;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.PropertyEditors
{
@@ -10,9 +11,9 @@ namespace Umbraco.Core.PropertyEditors
{
public PropertyEditorAttribute(string alias, string name, string editorView)
{
Mandate.ParameterNotNullOrEmpty(alias, "alias");
Mandate.ParameterNotNullOrEmpty(name, "name");
Mandate.ParameterNotNullOrEmpty(editorView, "editorView");
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (string.IsNullOrWhiteSpace(editorView)) throw new ArgumentNullOrEmptyException(nameof(editorView));
Alias = alias;
Name = name;
@@ -26,8 +27,8 @@ namespace Umbraco.Core.PropertyEditors
public PropertyEditorAttribute(string alias, string name)
{
Mandate.ParameterNotNullOrEmpty(alias, "id");
Mandate.ParameterNotNullOrEmpty(name, "name");
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
Alias = alias;
Name = name;
@@ -40,10 +41,10 @@ namespace Umbraco.Core.PropertyEditors
public PropertyEditorAttribute(string alias, string name, string valueType, string editorView)
{
Mandate.ParameterNotNullOrEmpty(alias, "alias");
Mandate.ParameterNotNullOrEmpty(name, "name");
Mandate.ParameterNotNullOrEmpty(valueType, "valueType");
Mandate.ParameterNotNullOrEmpty(editorView, "editorView");
if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias));
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
if (string.IsNullOrWhiteSpace(valueType)) throw new ArgumentNullOrEmptyException(nameof(valueType));
if (string.IsNullOrWhiteSpace(editorView)) throw new ArgumentNullOrEmptyException(nameof(editorView));
Alias = alias;
Name = name;
@@ -50,16 +50,14 @@ namespace Umbraco.Core.Services
/// <param name="source"></param>
/// <param name="logger"></param>
public LocalizedTextService(IDictionary<CultureInfo, IDictionary<string, IDictionary<string, string>>> source, ILogger logger)
{
if (source == null) throw new ArgumentNullException("source");
if (logger == null) throw new ArgumentNullException("logger");
_dictionarySource = source;
_logger = logger;
{
_dictionarySource = source ?? throw new ArgumentNullException(nameof(source));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public string Localize(string key, CultureInfo culture, IDictionary<string, string> tokens = null)
{
Mandate.ParameterNotNull(culture, "culture");
if (culture == null) throw new ArgumentNullException(nameof(culture));
//TODO: Hack, see notes on ConvertToSupportedCultureWithRegionCode
culture = ConvertToSupportedCultureWithRegionCode(culture);
-1
View File
@@ -438,7 +438,6 @@
<Compile Include="Macros\XsltExtensionCollection.cs" />
<Compile Include="Macros\XsltExtensionCollectionBuilder.cs" />
<Compile Include="MainDom.cs" />
<Compile Include="Mandate.cs" />
<Compile Include="Manifest\GridEditorConverter.cs" />
<Compile Include="Manifest\ManifestBuilder.cs" />
<Compile Include="Manifest\ManifestParser.cs" />
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Exceptions;
namespace Umbraco.Core.Xml
{
@@ -36,9 +37,9 @@ namespace Umbraco.Core.Xml
// allowed 'inline', not just at the beginning... whether or not we want to support that is up
// for discussion.
Mandate.ParameterNotNullOrEmpty(xpathExpression, "xpathExpression");
Mandate.ParameterNotNull(getPath, "getPath");
Mandate.ParameterNotNull(publishedContentExists, "publishedContentExists");
if (string.IsNullOrWhiteSpace(xpathExpression)) throw new ArgumentNullOrEmptyException(nameof(xpathExpression));
if (getPath == null) throw new ArgumentNullException(nameof(getPath));
if (publishedContentExists == null) throw new ArgumentNullException(nameof(publishedContentExists));
//no need to parse it
if (xpathExpression.StartsWith("$") == false)
+7 -6
View File
@@ -10,6 +10,7 @@ using System.Web.Mvc;
using Umbraco.Web.Templates;
using System.IO;
using System.Web.Routing;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Mvc;
@@ -34,14 +35,14 @@ namespace Umbraco.Web
public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedContent contentItem, string propertyAlias)
{
Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias");
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias));
return html.GetGridHtml(contentItem, propertyAlias, "bootstrap3");
}
public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedContent contentItem, string propertyAlias, string framework)
{
Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias");
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias));
var view = "Grid/" + framework;
var prop = contentItem.GetProperty(propertyAlias);
@@ -68,13 +69,13 @@ namespace Umbraco.Web
}
public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, HtmlHelper html, string propertyAlias)
{
Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias");
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias));
return GetGridHtml(contentItem, html, propertyAlias, "bootstrap3");
}
public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, HtmlHelper html, string propertyAlias, string framework)
{
Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias");
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias));
var view = "Grid/" + framework;
var prop = contentItem.GetProperty(propertyAlias);
@@ -107,7 +108,7 @@ namespace Umbraco.Web
[Obsolete("This should not be used, GetGridHtml methods accepting HtmlHelper as a parameter or GetGridHtml extensions on HtmlHelper should be used instead")]
public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, string propertyAlias)
{
Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias");
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias));
return GetGridHtml(contentItem, propertyAlias, "bootstrap3");
}
@@ -115,7 +116,7 @@ namespace Umbraco.Web
[Obsolete("This should not be used, GetGridHtml methods accepting HtmlHelper as a parameter or GetGridHtml extensions on HtmlHelper should be used instead")]
public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, string propertyAlias, string framework)
{
Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias");
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias));
var prop = contentItem.GetProperty(propertyAlias);
if (prop == null) throw new NullReferenceException("No property type found with alias " + propertyAlias);
+12 -11
View File
@@ -9,6 +9,7 @@ using System.Web.Mvc.Html;
using System.Web.Routing;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Exceptions;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
@@ -172,8 +173,8 @@ namespace Umbraco.Web
/// <returns></returns>
public static IHtmlString Action(this HtmlHelper htmlHelper, string actionName, Type surfaceType)
{
Mandate.ParameterNotNull(surfaceType, "surfaceType");
Mandate.ParameterNotNullOrEmpty(actionName, "actionName");
if (surfaceType == null) throw new ArgumentNullException(nameof(surfaceType));
if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName));
var routeVals = new RouteValueDictionary(new {area = ""});
@@ -412,8 +413,8 @@ namespace Umbraco.Web
IDictionary<string, object> htmlAttributes,
FormMethod method)
{
Mandate.ParameterNotNullOrEmpty(action, "action");
Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName");
if (string.IsNullOrWhiteSpace(action)) throw new ArgumentNullOrEmptyException(nameof(action));
if (string.IsNullOrWhiteSpace(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
return html.BeginUmbracoForm(action, controllerName, "", additionalRouteVals, htmlAttributes, method);
}
@@ -431,10 +432,10 @@ namespace Umbraco.Web
object additionalRouteVals,
IDictionary<string, object> htmlAttributes)
{
Mandate.ParameterNotNullOrEmpty(action, "action");
Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName");
if (string.IsNullOrWhiteSpace(action)) throw new ArgumentNullOrEmptyException(nameof(action));
if (string.IsNullOrWhiteSpace(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
return html.BeginUmbracoForm(action, controllerName, "", additionalRouteVals, htmlAttributes);
return html.BeginUmbracoForm(action, controllerName, "", additionalRouteVals, htmlAttributes);
}
/// <summary>
@@ -632,8 +633,8 @@ namespace Umbraco.Web
IDictionary<string, object> htmlAttributes,
FormMethod method)
{
Mandate.ParameterNotNullOrEmpty(action, "action");
Mandate.ParameterNotNull(surfaceType, "surfaceType");
if (string.IsNullOrWhiteSpace(action)) throw new ArgumentNullOrEmptyException(nameof(action));
if (surfaceType == null) throw new ArgumentNullException(nameof(surfaceType));
var area = "";
@@ -744,8 +745,8 @@ namespace Umbraco.Web
IDictionary<string, object> htmlAttributes,
FormMethod method)
{
Mandate.ParameterNotNullOrEmpty(action, "action");
Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName");
if (string.IsNullOrEmpty(action)) throw new ArgumentNullOrEmptyException(nameof(action));
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
var formAction = UmbracoContext.Current.OriginalRequestUrl.PathAndQuery;
return html.RenderForm(formAction, method, htmlAttributes, controllerName, action, area, additionalRouteVals);
+5 -4
View File
@@ -3,6 +3,7 @@ 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;
@@ -52,8 +53,8 @@ namespace Umbraco.Web
/// <returns></returns>
public static string GetUmbracoApiService(this UrlHelper url, string actionName, Type apiControllerType, object id = null)
{
Mandate.ParameterNotNullOrEmpty(actionName, "actionName");
Mandate.ParameterNotNull(apiControllerType, "apiControllerType");
if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName));
if (apiControllerType == null) throw new ArgumentNullException(nameof(apiControllerType));
var area = "";
@@ -94,8 +95,8 @@ namespace Umbraco.Web
/// <returns></returns>
public static string GetUmbracoApiService(this UrlHelper url, string actionName, string controllerName, string area, object id = null)
{
Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName");
Mandate.ParameterNotNullOrEmpty(actionName, "actionName");
if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName));
if (string.IsNullOrWhiteSpace(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
string routeName;
if (area.IsNullOrWhiteSpace())
@@ -1,5 +1,5 @@
using System;
using Umbraco.Core;
using Umbraco.Core.Exceptions;
namespace Umbraco.Web.Models.Trees
{
@@ -16,8 +16,8 @@ namespace Umbraco.Web.Models.Trees
/// <param name="methodName"></param>
public ActionMenuItemAttribute(string serviceName, string methodName)
{
Mandate.ParameterNotNullOrEmpty(serviceName, "serviceName");
Mandate.ParameterNotNullOrEmpty(methodName, "methodName");
if (string.IsNullOrWhiteSpace(serviceName)) throw new ArgumentNullOrEmptyException(nameof(serviceName));
if (string.IsNullOrWhiteSpace(methodName)) throw new ArgumentNullOrEmptyException(nameof(methodName));
MethodName = methodName;
ServiceName = serviceName;
}
@@ -28,12 +28,12 @@ namespace Umbraco.Web.Models.Trees
/// <param name="serviceName"></param>
public ActionMenuItemAttribute(string serviceName)
{
Mandate.ParameterNotNullOrEmpty(serviceName, "serviceName");
if (string.IsNullOrWhiteSpace(serviceName)) throw new ArgumentNullOrEmptyException(nameof(serviceName));
MethodName = "";
ServiceName = serviceName;
}
public string MethodName { get; private set; }
public string ServiceName { get; private set; }
public string MethodName { get; }
public string ServiceName { get; }
}
}
+3 -2
View File
@@ -3,6 +3,7 @@ using Umbraco.Core.IO;
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Exceptions;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.Models.Trees
@@ -25,8 +26,8 @@ namespace Umbraco.Web.Models.Trees
/// <param name="menuUrl"></param>
internal TreeNode(string nodeId, string parentId, string getChildNodesUrl, string menuUrl)
{
Mandate.ParameterNotNullOrEmpty(nodeId, "nodeId");
if (string.IsNullOrWhiteSpace(nodeId)) throw new ArgumentNullOrEmptyException(nameof(nodeId));
Id = nodeId;
ParentId = parentId;
ChildNodesUrl = getChildNodesUrl;
@@ -6,6 +6,7 @@ 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
@@ -44,12 +45,12 @@ namespace Umbraco.Web.Mvc
bool isMvc = true,
string areaPathPrefix = "")
{
Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName");
Mandate.ParameterNotNull(controllerSuffixName, "controllerSuffixName");
Mandate.ParameterNotNull(controllerType, "controllerType");
Mandate.ParameterNotNull(routes, "routes");
Mandate.ParameterNotNull(defaultId, "defaultId");
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
if (controllerSuffixName == null) throw new ArgumentNullException(nameof(controllerSuffixName));
if (controllerType == null) throw new ArgumentNullException(nameof(controllerType));
if (routes == null) throw new ArgumentNullException(nameof(routes));
if (defaultId == null) throw new ArgumentNullException(nameof(defaultId));
var umbracoArea = GlobalSettings.UmbracoMvcArea;
@@ -4,6 +4,7 @@ using Microsoft.Owin.Security;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Composing;
using Umbraco.Core.Exceptions;
namespace Umbraco.Web.Security.Identity
{
@@ -75,7 +76,7 @@ namespace Umbraco.Web.Security.Identity
/// </param>
public static void ForUmbracoBackOffice(this AuthenticationOptions options, string style, string icon, string callbackPath = null)
{
Mandate.ParameterNotNullOrEmpty(options.AuthenticationType, "options.AuthenticationType");
if (string.IsNullOrEmpty(options.AuthenticationType)) throw new ArgumentNullOrEmptyException("options.AuthenticationType");
//Ensure the prefix is set
if (options.AuthenticationType.StartsWith(Constants.Security.BackOfficeExternalAuthenticationTypePrefix) == false)
@@ -3,6 +3,7 @@ using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models.Identity;
namespace Umbraco.Web.Security.Identity
@@ -18,7 +19,7 @@ namespace Umbraco.Web.Security.Identity
string[] defaultAllowedSections = null,
string defaultCulture = null)
{
Mandate.ParameterNotNullOrEmpty(defaultUserType, "defaultUserType");
if (string.IsNullOrEmpty(defaultUserType)) throw new ArgumentNullOrEmptyException(nameof(defaultUserType));
_defaultUserType = defaultUserType;
_defaultAllowedSections = defaultAllowedSections ?? new[] { "content", "media" };
+3 -2
View File
@@ -10,6 +10,7 @@ using Umbraco.Web.Templates;
using umbraco;
using System.Collections.Generic;
using umbraco.presentation.templateControls;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Composing;
using Umbraco.Web.Macros;
@@ -217,8 +218,8 @@ namespace Umbraco.Web
//TODO: commented out until as it is not implemented by umbraco:item yet
//,string formatString = "")
{
Mandate.ParameterNotNull(currentPage, "currentPage");
Mandate.ParameterNotNullOrEmpty(fieldAlias, "fieldAlias");
if (currentPage == null) throw new ArgumentNullException(nameof(currentPage));
if (string.IsNullOrEmpty(fieldAlias)) throw new ArgumentNullOrEmptyException(nameof(fieldAlias));
//TODO: This is real nasty and we should re-write the 'item' and 'ItemRenderer' class but si fine for now
+4 -3
View File
@@ -15,6 +15,7 @@ using System.IO;
using System.Linq;
using System.Web.Mvc;
using Umbraco.Core.Cache;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Composing;
@@ -1030,9 +1031,9 @@ namespace Umbraco.Web
/// <returns></returns>
internal static string CreateEncryptedRouteString(string controllerName, string controllerAction, string area, object additionalRouteVals = null)
{
Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName");
Mandate.ParameterNotNullOrEmpty(controllerAction, "controllerAction");
Mandate.ParameterNotNull(area, "area");
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
if (string.IsNullOrEmpty(controllerAction)) throw new ArgumentNullOrEmptyException(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
var surfaceRouteParams = $"c={HttpUtility.UrlEncode(controllerName)}&a={HttpUtility.UrlEncode(controllerAction)}&ar={area}";
+5 -4
View File
@@ -8,6 +8,7 @@ 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.Mvc;
using Umbraco.Web.WebApi;
@@ -92,8 +93,8 @@ namespace Umbraco.Web
/// <returns></returns>
public static string GetUmbracoApiService(this UrlHelper url, string actionName, Type apiControllerType, RouteValueDictionary routeVals = null)
{
Mandate.ParameterNotNullOrEmpty(actionName, "actionName");
Mandate.ParameterNotNull(apiControllerType, "apiControllerType");
if (string.IsNullOrEmpty(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName));
if (apiControllerType == null) throw new ArgumentNullException(nameof(apiControllerType));
var area = "";
@@ -134,8 +135,8 @@ namespace Umbraco.Web
/// <returns></returns>
public static string GetUmbracoApiService(this UrlHelper url, string actionName, string controllerName, string area, RouteValueDictionary routeVals = null)
{
Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName");
Mandate.ParameterNotNullOrEmpty(actionName, "actionName");
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
if (string.IsNullOrEmpty(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName));
if (routeVals == null)
{
+5 -4
View File
@@ -3,6 +3,7 @@ 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.Web.Composing;
@@ -266,8 +267,8 @@ namespace Umbraco.Web
/// <returns></returns>
public static string SurfaceAction(this UrlHelper url, string action, string controllerName, string area, object additionalRouteVals)
{
Mandate.ParameterNotNullOrEmpty(action, "action");
Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName");
if (string.IsNullOrEmpty(action)) throw new ArgumentNullOrEmptyException(nameof(action));
if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName));
var encryptedRoute = UmbracoHelper.CreateEncryptedRouteString(controllerName, action, area, additionalRouteVals);
@@ -297,8 +298,8 @@ namespace Umbraco.Web
/// <returns></returns>
public static string SurfaceAction(this UrlHelper url, string action, Type surfaceType, object additionalRouteVals)
{
Mandate.ParameterNotNullOrEmpty(action, "action");
Mandate.ParameterNotNull(surfaceType, "surfaceType");
if (string.IsNullOrEmpty(action)) throw new ArgumentNullOrEmptyException(nameof(action));
if (surfaceType == null) throw new ArgumentNullException(nameof(surfaceType));
var area = "";
@@ -2,6 +2,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Umbraco.Core;
using Umbraco.Core.Exceptions;
namespace Umbraco.Web.WebApi
{
@@ -14,7 +15,7 @@ namespace Umbraco.Web.WebApi
public CustomDateTimeConvertor(string dateTimeFormat)
{
Mandate.ParameterNotNullOrEmpty(dateTimeFormat, "dateTimeFormat");
if (string.IsNullOrEmpty(dateTimeFormat)) throw new ArgumentNullOrEmptyException(nameof(dateTimeFormat));
_dateTimeFormat = dateTimeFormat;
}
@@ -1,18 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Services;
using Umbraco.Core.Exceptions;
using Umbraco.Web.Composing;
using Umbraco.Web.Editors;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web._Legacy.Actions;
namespace Umbraco.Web.WebApi.Filters
@@ -43,7 +35,7 @@ namespace Umbraco.Web.WebApi.Filters
public EnsureUserPermissionForContentAttribute(string paramName)
{
Mandate.ParameterNotNullOrEmpty(paramName, "paramName");
if (string.IsNullOrEmpty(paramName)) throw new ArgumentNullOrEmptyException(nameof(paramName));
_paramName = paramName;
_permissionToCheck = ActionBrowse.Instance.Letter;
}
@@ -53,10 +45,7 @@ namespace Umbraco.Web.WebApi.Filters
_permissionToCheck = permissionToCheck;
}
public override bool AllowMultiple
{
get { return true; }
}
public override bool AllowMultiple => true;
public override void OnActionExecuting(HttpActionContext actionContext)
{
@@ -69,7 +58,7 @@ namespace Umbraco.Web.WebApi.Filters
int nodeId;
if (_nodeId.HasValue == false)
{
var parts = _paramName.Split(new char[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
var parts = _paramName.Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
if (actionContext.ActionArguments[parts[0]] == null)
{
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
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.Core.Models.Membership;
using Umbraco.Core.Services;
using Umbraco.Web.Composing;
using Umbraco.Web.Editors;
@@ -40,21 +38,18 @@ namespace Umbraco.Web.WebApi.Filters
public EnsureUserPermissionForMediaAttribute(string paramName)
{
Mandate.ParameterNotNullOrEmpty(paramName, "paramName");
if (string.IsNullOrEmpty(paramName)) throw new ArgumentNullOrEmptyException(nameof(paramName));
_paramName = paramName;
}
// fixme v8 guess this is not used anymore, source is ignored?!
public EnsureUserPermissionForMediaAttribute(string paramName, DictionarySource source)
{
Mandate.ParameterNotNullOrEmpty(paramName, "paramName");
if (string.IsNullOrEmpty(paramName)) throw new ArgumentNullOrEmptyException(nameof(paramName));
_paramName = paramName;
}
public override bool AllowMultiple
{
get { return true; }
}
public override bool AllowMultiple => true;
private int GetNodeIdFromParameter(object parameterValue)
{
@@ -3,6 +3,7 @@ using System.Linq;
using System.Net.Http.Formatting;
using System.Web.Http.Controllers;
using Umbraco.Core;
using Umbraco.Core.Exceptions;
namespace Umbraco.Web.WebApi.Filters
{
@@ -19,7 +20,7 @@ namespace Umbraco.Web.WebApi.Filters
/// <param name="format"></param>
public OutgoingDateTimeFormatAttribute(string format)
{
Mandate.ParameterNotNullOrEmpty(format, "format");
if (string.IsNullOrEmpty(format)) throw new ArgumentNullOrEmptyException(nameof(format));
_format = format;
}
@@ -1,5 +1,6 @@
using System;
using Umbraco.Core;
using Umbraco.Core.Exceptions;
namespace Umbraco.Web._Legacy.Actions
{
@@ -20,8 +21,9 @@ namespace Umbraco.Web._Legacy.Actions
/// <param name="methodName"></param>
public LegacyActionMenuItemAttribute(string serviceName, string methodName)
{
Mandate.ParameterNotNullOrEmpty(serviceName, "serviceName");
Mandate.ParameterNotNullOrEmpty(methodName, "methodName");
if (string.IsNullOrEmpty(serviceName)) throw new ArgumentNullOrEmptyException(nameof(serviceName));
if (string.IsNullOrEmpty(methodName)) throw new ArgumentNullOrEmptyException(nameof(methodName));
MethodName = methodName;
ServiceName = serviceName;
}
@@ -32,12 +34,13 @@ namespace Umbraco.Web._Legacy.Actions
/// <param name="serviceName"></param>
public LegacyActionMenuItemAttribute(string serviceName)
{
Mandate.ParameterNotNullOrEmpty(serviceName, "serviceName");
if (string.IsNullOrEmpty(serviceName)) throw new ArgumentNullOrEmptyException(nameof(serviceName));
MethodName = "";
ServiceName = serviceName;
}
public string MethodName { get; private set; }
public string ServiceName { get; private set; }
public string MethodName { get; }
public string ServiceName { get; }
}
}
@@ -17,6 +17,7 @@ using System.Text;
using System.Security.Cryptography;
using System.Linq;
using Umbraco.Core.Composing;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Security;
using Umbraco.Core.Xml;
@@ -255,7 +256,7 @@ namespace umbraco.cms.businesslogic.member
/// <returns>The member with the specified loginname - null if no Member with the login exists</returns>
public static Member GetMemberFromLoginName(string loginName)
{
Mandate.ParameterNotNullOrEmpty(loginName, "loginName");
if (string.IsNullOrEmpty(loginName)) throw new ArgumentNullOrEmptyException(nameof(loginName));
var found = Current.Services.MemberService.GetByUsername(loginName);
if (found == null) return null;
@@ -374,7 +375,7 @@ namespace umbraco.cms.businesslogic.member
/// <returns>True if the member exists</returns>
public static bool IsMember(string loginName)
{
Mandate.ParameterNotNullOrEmpty(loginName, "loginName");
if (string.IsNullOrWhiteSpace(loginName)) throw new ArgumentNullOrEmptyException(nameof(loginName));
return Current.Services.MemberService.Exists(loginName);
}