From 32e3048717065d2f0e94b600a597bcf1aac5b9a4 Mon Sep 17 00:00:00 2001 From: Stephan Date: Wed, 11 Sep 2013 08:22:28 +0200 Subject: [PATCH] Core.Attempt - refactor Succ() into Succeed() --- src/Umbraco.Core/Attempt.cs | 6 ++--- src/Umbraco.Core/Attempt{T}.cs | 22 +++++++++---------- .../Dynamics/DynamicInstanceHelper.cs | 6 ++--- src/Umbraco.Core/Dynamics/DynamicXml.cs | 8 +++---- src/Umbraco.Core/ObjectExtensions.cs | 20 ++++++++--------- .../Persistence/Mappers/MappingResolver.cs | 2 +- .../Repositories/RepositoryBase.cs | 2 +- src/Umbraco.Core/PluginManager.cs | 2 +- src/Umbraco.Core/Profiling/WebProfiler.cs | 2 +- .../TinyMcePropertyEditorValueConverter.cs | 2 +- src/Umbraco.Core/PublishedContentHelper.cs | 10 ++++----- .../Publishing/PublishingStrategy.cs | 8 +++---- src/Umbraco.Core/TypeHelper.cs | 4 ++-- .../Models/DynamicPublishedContent.cs | 10 ++++----- src/Umbraco.Web/Mvc/SurfaceController.cs | 2 +- ...roRenderingPropertyEditorValueConverter.cs | 2 +- .../WebApi/UmbracoApiController.cs | 4 ++-- .../RazorDynamicNode/DynamicNode.cs | 2 +- 18 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/Umbraco.Core/Attempt.cs b/src/Umbraco.Core/Attempt.cs index ed7c978b52..f87c46c6a3 100644 --- a/src/Umbraco.Core/Attempt.cs +++ b/src/Umbraco.Core/Attempt.cs @@ -13,9 +13,9 @@ namespace Umbraco.Core /// The type of the attempted operation result. /// The result of the attempt. /// The successful attempt. - public static Attempt Succ(T result) + public static Attempt Succeed(T result) { - return Attempt.Succ(result); + return Attempt.Succeed(result); } /// @@ -50,7 +50,7 @@ namespace Umbraco.Core /// The attempt. public static Attempt If(bool success, T result) { - return Attempt.If(success, result); + return Attempt.SucceedIf(success, result); } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Attempt{T}.cs b/src/Umbraco.Core/Attempt{T}.cs index c1f88cab20..4a348247d4 100644 --- a/src/Umbraco.Core/Attempt{T}.cs +++ b/src/Umbraco.Core/Attempt{T}.cs @@ -52,7 +52,7 @@ namespace Umbraco.Core [Obsolete(".Failed is obsolete, you should use Attempt.Fail() instead.", false)] public static readonly Attempt 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 /// A value indicating whether the attempt is successful. /// The result of the attempt. /// Keep it for backward compatibility sake. - [Obsolete("Attempt ctors are obsolete, you should use Attempt.Succ(), Attempt.Fail() or Attempt.If() instead.", false)] + [Obsolete("Attempt ctors are obsolete, you should use Attempt.Succeed(), Attempt.Fail() or Attempt.If() instead.", false)] public Attempt(bool success, T result) : this(success, result, null) { } @@ -76,7 +76,7 @@ namespace Umbraco.Core /// /// The exception causing the failure of the attempt. /// Keep it for backward compatibility sake. - [Obsolete("Attempt ctors are obsolete, you should use Attempt.Succ(), Attempt.Fail() or Attempt.If() instead.", false)] + [Obsolete("Attempt ctors are obsolete, you should use Attempt.Succeed(), Attempt.Fail() or Attempt.If() instead.", false)] public Attempt(Exception exception) : this(false, default(T), exception) { } @@ -85,7 +85,7 @@ namespace Umbraco.Core /// Creates a successful attempt. /// /// The successful attempt. - public static Attempt Succ() + public static Attempt Succeed() { return new Attempt(true, default(T), null); } @@ -95,7 +95,7 @@ namespace Umbraco.Core /// /// The result of the attempt. /// The successful attempt. - public static Attempt Succ(T result) + public static Attempt Succeed(T result) { return new Attempt(true, result, null); } @@ -143,22 +143,22 @@ namespace Umbraco.Core /// /// Creates a successful or a failed attempt. /// - /// A value indicating whether the attempt is successful. + /// A value indicating whether the attempt is successful. /// The attempt. - public static Attempt If(bool success) + public static Attempt SucceedIf(bool condition) { - return success ? new Attempt(true, default(T), null) : Failed; + return condition ? new Attempt(true, default(T), null) : Failed; } /// /// Creates a successful or a failed attempt, with a result. /// - /// A value indicating whether the attempt is successful. + /// A value indicating whether the attempt is successful. /// The result of the attempt. /// The attempt. - public static Attempt If(bool success, T result) + public static Attempt SucceedIf(bool condition, T result) { - return new Attempt(success, result, null); + return new Attempt(condition, result, null); } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Dynamics/DynamicInstanceHelper.cs b/src/Umbraco.Core/Dynamics/DynamicInstanceHelper.cs index b0e5981bff..1338ee03e2 100644 --- a/src/Umbraco.Core/Dynamics/DynamicInstanceHelper.cs +++ b/src/Umbraco.Core/Dynamics/DynamicInstanceHelper.cs @@ -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) { diff --git a/src/Umbraco.Core/Dynamics/DynamicXml.cs b/src/Umbraco.Core/Dynamics/DynamicXml.cs index 0e02e44db9..a84389d2e5 100644 --- a/src/Umbraco.Core/Dynamics/DynamicXml.cs +++ b/src/Umbraco.Core/Dynamics/DynamicXml.cs @@ -261,7 +261,7 @@ namespace Umbraco.Core.Dynamics var attributes = xmlElement.Attributes(name).Select(attr => attr.Value).ToArray(); if (attributes.Any()) { - return Attempt>.Succ(attributes); + return Attempt>.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>.Succ(childElements); + return Attempt>.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>.Succ(elements); + return Attempt>.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>.Succ(childElements); + return Attempt>.Succeed(childElements); } } diff --git a/src/Umbraco.Core/ObjectExtensions.cs b/src/Umbraco.Core/ObjectExtensions.cs index 7726af50ff..40708d0fc4 100644 --- a/src/Umbraco.Core/ObjectExtensions.cs +++ b/src/Umbraco.Core/ObjectExtensions.cs @@ -58,14 +58,14 @@ namespace Umbraco.Core try { var converted = (T) input; - return Attempt.Succ(converted); + return Attempt.Succeed(converted); } catch (Exception e) { return Attempt.Fail(e); } } - return !result.Success ? Attempt.Fail() : Attempt.Succ((T)result.Result); + return !result.Success ? Attempt.Fail() : Attempt.Succeed((T)result.Result); } /// @@ -79,9 +79,9 @@ namespace Umbraco.Core { if (input == null) return Attempt.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) { diff --git a/src/Umbraco.Core/Persistence/Mappers/MappingResolver.cs b/src/Umbraco.Core/Persistence/Mappers/MappingResolver.cs index 8c576f1e63..4b6b513bf2 100644 --- a/src/Umbraco.Core/Persistence/Mappers/MappingResolver.cs +++ b/src/Umbraco.Core/Persistence/Mappers/MappingResolver.cs @@ -73,7 +73,7 @@ namespace Umbraco.Core.Persistence.Mappers { var instance = Activator.CreateInstance(mapper) as BaseMapper; return instance != null - ? Attempt.Succ(instance) + ? Attempt.Succeed(instance) : Attempt.Fail(); } catch (Exception ex) diff --git a/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs index b9f20cd706..26e97beff7 100644 --- a/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs @@ -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.Fail(); } diff --git a/src/Umbraco.Core/PluginManager.cs b/src/Umbraco.Core/PluginManager.cs index 1db052396a..485602f23f 100644 --- a/src/Umbraco.Core/PluginManager.cs +++ b/src/Umbraco.Core/PluginManager.cs @@ -275,7 +275,7 @@ namespace Umbraco.Core return Attempt>.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) diff --git a/src/Umbraco.Core/Profiling/WebProfiler.cs b/src/Umbraco.Core/Profiling/WebProfiler.cs index 6dae4cde0c..d3fd0daae0 100644 --- a/src/Umbraco.Core/Profiling/WebProfiler.cs +++ b/src/Umbraco.Core/Profiling/WebProfiler.cs @@ -148,7 +148,7 @@ namespace Umbraco.Core.Profiling try { var req = app.Request; - return Attempt.Succ(new HttpRequestWrapper(req)); + return Attempt.Succeed(new HttpRequestWrapper(req)); } catch (HttpException ex) { diff --git a/src/Umbraco.Core/PropertyEditors/TinyMcePropertyEditorValueConverter.cs b/src/Umbraco.Core/PropertyEditors/TinyMcePropertyEditorValueConverter.cs index e6acbf36e0..8480d91260 100644 --- a/src/Umbraco.Core/PropertyEditors/TinyMcePropertyEditorValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/TinyMcePropertyEditorValueConverter.cs @@ -20,7 +20,7 @@ namespace Umbraco.Core.PropertyEditors /// public virtual Attempt ConvertPropertyValue(object value) { - return Attempt.Succ(new HtmlString(value.ToString())); + return Attempt.Succeed(new HtmlString(value.ToString())); } } } \ No newline at end of file diff --git a/src/Umbraco.Core/PublishedContentHelper.cs b/src/Umbraco.Core/PublishedContentHelper.cs index db8d2dbbe4..6dffef290d 100644 --- a/src/Umbraco.Core/PublishedContentHelper.cs +++ b/src/Umbraco.Core/PublishedContentHelper.cs @@ -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.Succ(dResult); + return Attempt.Succeed(dResult); } } //process string booleans as booleans if (sResult.InvariantEquals("true")) { - return Attempt.Succ(true); + return Attempt.Succeed(true); } if (sResult.InvariantEquals("false")) { - return Attempt.Succ(false); + return Attempt.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.Succ(new DynamicXml(e)); + return Attempt.Succeed(new DynamicXml(e)); } return Attempt.Fail(); } diff --git a/src/Umbraco.Core/Publishing/PublishingStrategy.cs b/src/Umbraco.Core/Publishing/PublishingStrategy.cs index d115bb1a10..899567bf8d 100644 --- a/src/Umbraco.Core/Publishing/PublishingStrategy.cs +++ b/src/Umbraco.Core/Publishing/PublishingStrategy.cs @@ -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)); } /// @@ -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; diff --git a/src/Umbraco.Core/TypeHelper.cs b/src/Umbraco.Core/TypeHelper.cs index 71e558e55c..e77f03ee78 100644 --- a/src/Umbraco.Core/TypeHelper.cs +++ b/src/Umbraco.Core/TypeHelper.cs @@ -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); } } diff --git a/src/Umbraco.Web/Models/DynamicPublishedContent.cs b/src/Umbraco.Web/Models/DynamicPublishedContent.cs index 57f5981385..2d17ee11c0 100644 --- a/src/Umbraco.Web/Models/DynamicPublishedContent.cs +++ b/src/Umbraco.Web/Models/DynamicPublishedContent.cs @@ -150,7 +150,7 @@ namespace Umbraco.Web.Models { if (binder.Name.InvariantEquals("ChildrenAsList") || binder.Name.InvariantEquals("Children")) { - return Attempt.Succ(Children); + return Attempt.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.Succ(parent.Id); + return Attempt.Succeed(parent.Id); } return Attempt.Fail(); } @@ -182,7 +182,7 @@ namespace Umbraco.Web.Models .ToArray(); if (filteredTypeChildren.Any()) { - return Attempt.Succ( + return Attempt.Succeed( new DynamicPublishedContentList(filteredTypeChildren.Select(x => new DynamicPublishedContent(x)))); } return Attempt.Fail(); @@ -247,7 +247,7 @@ namespace Umbraco.Web.Models result = converted.Result; } - return Attempt.Succ(result); + return Attempt.Succeed(result); } @@ -382,7 +382,7 @@ namespace Umbraco.Web.Models { try { - return Attempt.Succ( + return Attempt.Succeed( content.GetType().InvokeMember(memberAlias, System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance | diff --git a/src/Umbraco.Web/Mvc/SurfaceController.cs b/src/Umbraco.Web/Mvc/SurfaceController.cs index 0011718b3c..4aa2052519 100644 --- a/src/Umbraco.Web/Mvc/SurfaceController.cs +++ b/src/Umbraco.Web/Mvc/SurfaceController.cs @@ -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) { diff --git a/src/Umbraco.Web/PropertyEditors/RteMacroRenderingPropertyEditorValueConverter.cs b/src/Umbraco.Web/PropertyEditors/RteMacroRenderingPropertyEditorValueConverter.cs index 2448ce0578..ee59ea6e94 100644 --- a/src/Umbraco.Web/PropertyEditors/RteMacroRenderingPropertyEditorValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/RteMacroRenderingPropertyEditorValueConverter.cs @@ -35,7 +35,7 @@ namespace Umbraco.Web.PropertyEditors //needs to be explicitly casted to Dictionary macroAttributes.ConvertTo(x => (string)x, x => (object)x)).ToString())); - return Attempt.Succ(new HtmlString(sb.ToString())); + return Attempt.Succeed(new HtmlString(sb.ToString())); } } } \ No newline at end of file diff --git a/src/Umbraco.Web/WebApi/UmbracoApiController.cs b/src/Umbraco.Web/WebApi/UmbracoApiController.cs index ca334d6371..bf25dc0e7c 100644 --- a/src/Umbraco.Web/WebApi/UmbracoApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoApiController.cs @@ -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.Succ(new HttpContextWrapper(HttpContext.Current)); + return Attempt.Succeed(new HttpContextWrapper(HttpContext.Current)); } return Attempt.Fail(); diff --git a/src/umbraco.MacroEngines/RazorDynamicNode/DynamicNode.cs b/src/umbraco.MacroEngines/RazorDynamicNode/DynamicNode.cs index 5ffacf8bfb..a2ac541247 100644 --- a/src/umbraco.MacroEngines/RazorDynamicNode/DynamicNode.cs +++ b/src/umbraco.MacroEngines/RazorDynamicNode/DynamicNode.cs @@ -649,7 +649,7 @@ namespace umbraco.MacroEngines { try { - return Attempt.Succ( + return Attempt.Succeed( n.GetType().InvokeMember(memberAlias, System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance |