Core.Attempt - refactor Succ() into Succeed()
This commit is contained in:
@@ -13,9 +13,9 @@ namespace Umbraco.Core
|
||||
/// <typeparam name="T">The type of the attempted operation result.</typeparam>
|
||||
/// <param name="result">The result of the attempt.</param>
|
||||
/// <returns>The successful attempt.</returns>
|
||||
public static Attempt<T> Succ<T>(T result)
|
||||
public static Attempt<T> Succeed<T>(T result)
|
||||
{
|
||||
return Attempt<T>.Succ(result);
|
||||
return Attempt<T>.Succeed(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -50,7 +50,7 @@ namespace Umbraco.Core
|
||||
/// <returns>The attempt.</returns>
|
||||
public static Attempt<T> If<T>(bool success, T result)
|
||||
{
|
||||
return Attempt<T>.If(success, result);
|
||||
return Attempt<T>.SucceedIf(success, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ namespace Umbraco.Core
|
||||
[Obsolete(".Failed is obsolete, you should use Attempt<T>.Fail() instead.", false)]
|
||||
public static readonly Attempt<T> False = Failed;
|
||||
|
||||
// private - use Succ() or Fail() methods to create attempts
|
||||
// private - use Succeed() or Fail() methods to create attempts
|
||||
private Attempt(bool success, T result, Exception exception)
|
||||
{
|
||||
_success = success;
|
||||
@@ -66,7 +66,7 @@ namespace Umbraco.Core
|
||||
/// <param name="success">A value indicating whether the attempt is successful.</param>
|
||||
/// <param name="result">The result of the attempt.</param>
|
||||
/// <remarks>Keep it for backward compatibility sake.</remarks>
|
||||
[Obsolete("Attempt ctors are obsolete, you should use Attempt<T>.Succ(), Attempt<T>.Fail() or Attempt<T>.If() instead.", false)]
|
||||
[Obsolete("Attempt ctors are obsolete, you should use Attempt<T>.Succeed(), Attempt<T>.Fail() or Attempt<T>.If() instead.", false)]
|
||||
public Attempt(bool success, T result)
|
||||
: this(success, result, null)
|
||||
{ }
|
||||
@@ -76,7 +76,7 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception causing the failure of the attempt.</param>
|
||||
/// <remarks>Keep it for backward compatibility sake.</remarks>
|
||||
[Obsolete("Attempt ctors are obsolete, you should use Attempt<T>.Succ(), Attempt<T>.Fail() or Attempt<T>.If() instead.", false)]
|
||||
[Obsolete("Attempt ctors are obsolete, you should use Attempt<T>.Succeed(), Attempt<T>.Fail() or Attempt<T>.If() instead.", false)]
|
||||
public Attempt(Exception exception)
|
||||
: this(false, default(T), exception)
|
||||
{ }
|
||||
@@ -85,7 +85,7 @@ namespace Umbraco.Core
|
||||
/// Creates a successful attempt.
|
||||
/// </summary>
|
||||
/// <returns>The successful attempt.</returns>
|
||||
public static Attempt<T> Succ()
|
||||
public static Attempt<T> Succeed()
|
||||
{
|
||||
return new Attempt<T>(true, default(T), null);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
/// <param name="result">The result of the attempt.</param>
|
||||
/// <returns>The successful attempt.</returns>
|
||||
public static Attempt<T> Succ(T result)
|
||||
public static Attempt<T> Succeed(T result)
|
||||
{
|
||||
return new Attempt<T>(true, result, null);
|
||||
}
|
||||
@@ -143,22 +143,22 @@ namespace Umbraco.Core
|
||||
/// <summary>
|
||||
/// Creates a successful or a failed attempt.
|
||||
/// </summary>
|
||||
/// <param name="success">A value indicating whether the attempt is successful.</param>
|
||||
/// <param name="condition">A value indicating whether the attempt is successful.</param>
|
||||
/// <returns>The attempt.</returns>
|
||||
public static Attempt<T> If(bool success)
|
||||
public static Attempt<T> SucceedIf(bool condition)
|
||||
{
|
||||
return success ? new Attempt<T>(true, default(T), null) : Failed;
|
||||
return condition ? new Attempt<T>(true, default(T), null) : Failed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a successful or a failed attempt, with a result.
|
||||
/// </summary>
|
||||
/// <param name="success">A value indicating whether the attempt is successful.</param>
|
||||
/// <param name="condition">A value indicating whether the attempt is successful.</param>
|
||||
/// <param name="result">The result of the attempt.</param>
|
||||
/// <returns>The attempt.</returns>
|
||||
public static Attempt<T> If(bool success, T result)
|
||||
public static Attempt<T> SucceedIf(bool condition, T result)
|
||||
{
|
||||
return new Attempt<T>(success, result, null);
|
||||
return new Attempt<T>(condition, result, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ namespace Umbraco.Core.Dynamics
|
||||
null,
|
||||
thisObject,
|
||||
args);
|
||||
return Attempt.Succ(new TryInvokeMemberResult(result, TryInvokeMemberSuccessReason.FoundProperty));
|
||||
return Attempt.Succeed(new TryInvokeMemberResult(result, TryInvokeMemberSuccessReason.FoundProperty));
|
||||
}
|
||||
catch (MissingMethodException)
|
||||
{
|
||||
@@ -97,7 +97,7 @@ namespace Umbraco.Core.Dynamics
|
||||
null,
|
||||
thisObject,
|
||||
args);
|
||||
return Attempt.Succ(new TryInvokeMemberResult(result, TryInvokeMemberSuccessReason.FoundMethod));
|
||||
return Attempt.Succeed(new TryInvokeMemberResult(result, TryInvokeMemberSuccessReason.FoundMethod));
|
||||
}
|
||||
catch (MissingMethodException)
|
||||
{
|
||||
@@ -106,7 +106,7 @@ namespace Umbraco.Core.Dynamics
|
||||
try
|
||||
{
|
||||
result = FindAndExecuteExtensionMethod(thisObject, args, binder.Name, findExtensionMethodsOnTypes);
|
||||
return Attempt.Succ(new TryInvokeMemberResult(result, TryInvokeMemberSuccessReason.FoundExtensionMethod));
|
||||
return Attempt.Succeed(new TryInvokeMemberResult(result, TryInvokeMemberSuccessReason.FoundExtensionMethod));
|
||||
}
|
||||
catch (TargetInvocationException ext)
|
||||
{
|
||||
|
||||
@@ -261,7 +261,7 @@ namespace Umbraco.Core.Dynamics
|
||||
var attributes = xmlElement.Attributes(name).Select(attr => attr.Value).ToArray();
|
||||
if (attributes.Any())
|
||||
{
|
||||
return Attempt<IEnumerable<string>>.Succ(attributes);
|
||||
return Attempt<IEnumerable<string>>.Succeed(attributes);
|
||||
}
|
||||
|
||||
if (!attributes.Any() && xmlElement.Name == "root" && xmlElement.Elements().Count() == 1)
|
||||
@@ -271,7 +271,7 @@ namespace Umbraco.Core.Dynamics
|
||||
if (childElements.Any())
|
||||
{
|
||||
//we've found a match by the first child of an element called 'root' (strange, but sure)
|
||||
return Attempt<IEnumerable<string>>.Succ(childElements);
|
||||
return Attempt<IEnumerable<string>>.Succeed(childElements);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ namespace Umbraco.Core.Dynamics
|
||||
//Check if we've got any matches, if so then return true
|
||||
if (elements.Any())
|
||||
{
|
||||
return Attempt<IEnumerable<XElement>>.Succ(elements);
|
||||
return Attempt<IEnumerable<XElement>>.Succeed(elements);
|
||||
}
|
||||
|
||||
if (!elements.Any() && xmlElement.Name == "root" && xmlElement.Elements().Count() == 1)
|
||||
@@ -303,7 +303,7 @@ namespace Umbraco.Core.Dynamics
|
||||
if (childElements.Any())
|
||||
{
|
||||
//we've found a match by the first child of an element called 'root' (strange, but sure)
|
||||
return Attempt<IEnumerable<XElement>>.Succ(childElements);
|
||||
return Attempt<IEnumerable<XElement>>.Succeed(childElements);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,14 +58,14 @@ namespace Umbraco.Core
|
||||
try
|
||||
{
|
||||
var converted = (T) input;
|
||||
return Attempt<T>.Succ(converted);
|
||||
return Attempt<T>.Succeed(converted);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return Attempt<T>.Fail(e);
|
||||
}
|
||||
}
|
||||
return !result.Success ? Attempt<T>.Fail() : Attempt<T>.Succ((T)result.Result);
|
||||
return !result.Success ? Attempt<T>.Fail() : Attempt<T>.Succeed((T)result.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -79,9 +79,9 @@ namespace Umbraco.Core
|
||||
{
|
||||
if (input == null) return Attempt<object>.Fail();
|
||||
|
||||
if (destinationType == typeof(object)) return Attempt.Succ(input);
|
||||
if (destinationType == typeof(object)) return Attempt.Succeed(input);
|
||||
|
||||
if (input.GetType() == destinationType) return Attempt.Succ(input);
|
||||
if (input.GetType() == destinationType) return Attempt.Succeed(input);
|
||||
|
||||
if (!destinationType.IsGenericType || destinationType.GetGenericTypeDefinition() != typeof(Nullable<>))
|
||||
{
|
||||
@@ -94,7 +94,7 @@ namespace Umbraco.Core
|
||||
try
|
||||
{
|
||||
var casted = Convert.ChangeType(input, destinationType);
|
||||
return Attempt.Succ(casted);
|
||||
return Attempt.Succeed(casted);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -109,7 +109,7 @@ namespace Umbraco.Core
|
||||
try
|
||||
{
|
||||
var converted = inputConverter.ConvertTo(input, destinationType);
|
||||
return Attempt.Succ(converted);
|
||||
return Attempt.Succeed(converted);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -125,7 +125,7 @@ namespace Umbraco.Core
|
||||
try
|
||||
{
|
||||
var converted = boolConverter.ConvertFrom(input);
|
||||
return Attempt.Succ(converted);
|
||||
return Attempt.Succeed(converted);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -140,7 +140,7 @@ namespace Umbraco.Core
|
||||
try
|
||||
{
|
||||
var converted = outputConverter.ConvertFrom(input);
|
||||
return Attempt.Succ(converted);
|
||||
return Attempt.Succeed(converted);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -154,7 +154,7 @@ namespace Umbraco.Core
|
||||
try
|
||||
{
|
||||
var casted = Convert.ChangeType(input, destinationType);
|
||||
return Attempt.Succ(casted);
|
||||
return Attempt.Succeed(casted);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -351,7 +351,7 @@ namespace Umbraco.Core
|
||||
try
|
||||
{
|
||||
var output = value.ToXmlString(type);
|
||||
return Attempt.Succ(output);
|
||||
return Attempt.Succeed(output);
|
||||
}
|
||||
catch (NotSupportedException ex)
|
||||
{
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Umbraco.Core.Persistence.Mappers
|
||||
{
|
||||
var instance = Activator.CreateInstance(mapper) as BaseMapper;
|
||||
return instance != null
|
||||
? Attempt<BaseMapper>.Succ(instance)
|
||||
? Attempt<BaseMapper>.Succeed(instance)
|
||||
: Attempt<BaseMapper>.Fail();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
var rEntity = _cache.GetById(typeof(TEntity), key);
|
||||
if (rEntity != null)
|
||||
{
|
||||
return Attempt.Succ((TEntity) rEntity);
|
||||
return Attempt.Succeed((TEntity) rEntity);
|
||||
}
|
||||
return Attempt<TEntity>.Fail();
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ namespace Umbraco.Core
|
||||
return Attempt<IEnumerable<string>>.Fail(new CachedPluginNotFoundInFile());
|
||||
|
||||
//return success
|
||||
return Attempt.Succ(typeElement.Elements("add")
|
||||
return Attempt.Succeed(typeElement.Elements("add")
|
||||
.Select(x => (string)x.Attribute("type")));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace Umbraco.Core.Profiling
|
||||
try
|
||||
{
|
||||
var req = app.Request;
|
||||
return Attempt<HttpRequestBase>.Succ(new HttpRequestWrapper(req));
|
||||
return Attempt<HttpRequestBase>.Succeed(new HttpRequestWrapper(req));
|
||||
}
|
||||
catch (HttpException ex)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Umbraco.Core.PropertyEditors
|
||||
/// <returns></returns>
|
||||
public virtual Attempt<object> ConvertPropertyValue(object value)
|
||||
{
|
||||
return Attempt<object>.Succ(new HtmlString(value.ToString()));
|
||||
return Attempt<object>.Succeed(new HtmlString(value.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ namespace Umbraco.Core
|
||||
.Select(p => p.ConvertPropertyValue(currentValue))
|
||||
.Where(converted => converted.Success))
|
||||
{
|
||||
return Attempt.Succ(converted.Result);
|
||||
return Attempt.Succeed(converted.Result);
|
||||
}
|
||||
|
||||
//if none of the converters worked, then we'll process this from what we know
|
||||
@@ -118,17 +118,17 @@ namespace Umbraco.Core
|
||||
decimal dResult;
|
||||
if (decimal.TryParse(sResult, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.CurrentCulture, out dResult))
|
||||
{
|
||||
return Attempt<object>.Succ(dResult);
|
||||
return Attempt<object>.Succeed(dResult);
|
||||
}
|
||||
}
|
||||
//process string booleans as booleans
|
||||
if (sResult.InvariantEquals("true"))
|
||||
{
|
||||
return Attempt<object>.Succ(true);
|
||||
return Attempt<object>.Succeed(true);
|
||||
}
|
||||
if (sResult.InvariantEquals("false"))
|
||||
{
|
||||
return Attempt<object>.Succ(false);
|
||||
return Attempt<object>.Succeed(false);
|
||||
}
|
||||
|
||||
//a really rough check to see if this may be valid xml
|
||||
@@ -147,7 +147,7 @@ namespace Umbraco.Core
|
||||
if (!UmbracoSettings.NotDynamicXmlDocumentElements.Any(
|
||||
tag => string.Equals(tag, documentElement, StringComparison.CurrentCultureIgnoreCase)))
|
||||
{
|
||||
return Attempt<object>.Succ(new DynamicXml(e));
|
||||
return Attempt<object>.Succeed(new DynamicXml(e));
|
||||
}
|
||||
return Attempt<object>.Fail();
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Umbraco.Core.Publishing
|
||||
string.Format("Content '{0}' with Id '{1}' has been published.",
|
||||
content.Name, content.Id));
|
||||
|
||||
return Attempt.Succ(new PublishStatus(content));
|
||||
return Attempt.Succeed(new PublishStatus(content));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -125,7 +125,7 @@ namespace Umbraco.Core.Publishing
|
||||
//We're going to populate the statuses with all content that is already published because below we are only going to iterate over
|
||||
// content that is not published. We'll set the status to "AlreadyPublished"
|
||||
statuses.AddRange(fetchedContent.Where(x => x.Published)
|
||||
.Select(x => Attempt.Succ(new PublishStatus(x, PublishStatusType.SuccessAlreadyPublished))));
|
||||
.Select(x => Attempt.Succeed(new PublishStatus(x, PublishStatusType.SuccessAlreadyPublished))));
|
||||
|
||||
int? firstLevel = null;
|
||||
|
||||
@@ -239,7 +239,7 @@ namespace Umbraco.Core.Publishing
|
||||
string.Format("Content '{0}' with Id '{1}' has been published.",
|
||||
item.Name, item.Id));
|
||||
|
||||
statuses.Add(Attempt.Succ(new PublishStatus(item)));
|
||||
statuses.Add(Attempt.Succeed(new PublishStatus(item)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -370,7 +370,7 @@ namespace Umbraco.Core.Publishing
|
||||
string.Format("Content '{0}' with Id '{1}' has been unpublished.",
|
||||
item.Name, item.Id));
|
||||
|
||||
result.Add(Attempt.Succ(new PublishStatus(item)));
|
||||
result.Add(Attempt.Succeed(new PublishStatus(item)));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace Umbraco.Core
|
||||
}
|
||||
if (types.Length == 1)
|
||||
{
|
||||
return Attempt.Succ(types[0]);
|
||||
return Attempt.Succeed(types[0]);
|
||||
}
|
||||
|
||||
foreach (var curr in types)
|
||||
@@ -112,7 +112,7 @@ namespace Umbraco.Core
|
||||
//if this type is the base for all others
|
||||
if (isBase)
|
||||
{
|
||||
return Attempt.Succ(curr);
|
||||
return Attempt.Succeed(curr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace Umbraco.Web.Models
|
||||
{
|
||||
if (binder.Name.InvariantEquals("ChildrenAsList") || binder.Name.InvariantEquals("Children"))
|
||||
{
|
||||
return Attempt<object>.Succ(Children);
|
||||
return Attempt<object>.Succeed(Children);
|
||||
}
|
||||
|
||||
if (binder.Name.InvariantEquals("parentId"))
|
||||
@@ -160,7 +160,7 @@ namespace Umbraco.Web.Models
|
||||
{
|
||||
throw new InvalidOperationException(string.Format("The node {0} does not have a parent", Id));
|
||||
}
|
||||
return Attempt<object>.Succ(parent.Id);
|
||||
return Attempt<object>.Succeed(parent.Id);
|
||||
}
|
||||
return Attempt<object>.Fail();
|
||||
}
|
||||
@@ -182,7 +182,7 @@ namespace Umbraco.Web.Models
|
||||
.ToArray();
|
||||
if (filteredTypeChildren.Any())
|
||||
{
|
||||
return Attempt<object>.Succ(
|
||||
return Attempt<object>.Succeed(
|
||||
new DynamicPublishedContentList(filteredTypeChildren.Select(x => new DynamicPublishedContent(x))));
|
||||
}
|
||||
return Attempt<object>.Fail();
|
||||
@@ -247,7 +247,7 @@ namespace Umbraco.Web.Models
|
||||
result = converted.Result;
|
||||
}
|
||||
|
||||
return Attempt<object>.Succ(result);
|
||||
return Attempt<object>.Succeed(result);
|
||||
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ namespace Umbraco.Web.Models
|
||||
{
|
||||
try
|
||||
{
|
||||
return Attempt<object>.Succ(
|
||||
return Attempt<object>.Succeed(
|
||||
content.GetType().InvokeMember(memberAlias,
|
||||
System.Reflection.BindingFlags.GetProperty |
|
||||
System.Reflection.BindingFlags.Instance |
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace Umbraco.Web.Mvc
|
||||
var currentRouteData = currentContext.RouteData;
|
||||
if (currentRouteData.DataTokens.ContainsKey("umbraco-route-def"))
|
||||
{
|
||||
return Attempt.Succ((RouteDefinition) currentRouteData.DataTokens["umbraco-route-def"]);
|
||||
return Attempt.Succeed((RouteDefinition) currentRouteData.DataTokens["umbraco-route-def"]);
|
||||
}
|
||||
if (currentContext.IsChildAction)
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
//needs to be explicitly casted to Dictionary<string, object>
|
||||
macroAttributes.ConvertTo(x => (string)x, x => (object)x)).ToString()));
|
||||
|
||||
return Attempt<object>.Succ(new HtmlString(sb.ToString()));
|
||||
return Attempt<object>.Succeed(new HtmlString(sb.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,12 +35,12 @@ namespace Umbraco.Web.WebApi
|
||||
var httpContext = context as HttpContextBase;
|
||||
if (httpContext != null)
|
||||
{
|
||||
return Attempt.Succ(httpContext);
|
||||
return Attempt.Succeed(httpContext);
|
||||
}
|
||||
}
|
||||
if (HttpContext.Current != null)
|
||||
{
|
||||
return Attempt<HttpContextBase>.Succ(new HttpContextWrapper(HttpContext.Current));
|
||||
return Attempt<HttpContextBase>.Succeed(new HttpContextWrapper(HttpContext.Current));
|
||||
}
|
||||
|
||||
return Attempt<HttpContextBase>.Fail();
|
||||
|
||||
@@ -649,7 +649,7 @@ namespace umbraco.MacroEngines
|
||||
{
|
||||
try
|
||||
{
|
||||
return Attempt<object>.Succ(
|
||||
return Attempt<object>.Succeed(
|
||||
n.GetType().InvokeMember(memberAlias,
|
||||
System.Reflection.BindingFlags.GetProperty |
|
||||
System.Reflection.BindingFlags.Instance |
|
||||
|
||||
Reference in New Issue
Block a user