Core.Attempt - replace calls to obsolete members

This commit is contained in:
Stephan
2013-09-12 12:54:34 +02:00
parent d1af20424e
commit ff76e58e1c
5 changed files with 70 additions and 90 deletions

View File

@@ -50,14 +50,14 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
try
{
var converted = (T)input;
return new Attempt<T>(true, converted);
return Attempt.Succeed(converted);
}
catch (Exception e)
{
return new Attempt<T>(e);
return Attempt<T>.Fail(e);
}
}
return !result.Success ? Attempt<T>.False : new Attempt<T>(true, (T)result.Result);
return !result.Success ? Attempt<T>.Fail() : Attempt.Succeed((T)result.Result);
}
/// <summary>
@@ -69,22 +69,22 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
/// <returns></returns>
public static Attempt<object> TryConvertTo(this object input, Type destinationType)
{
if (input == null) return Attempt<object>.False;
if (input == null) return Attempt<object>.Fail();
if (destinationType == typeof(object)) return new Attempt<object>(true, input);
if (destinationType == typeof(object)) return Attempt.Succeed(input);
if (input.GetType() == destinationType) return new Attempt<object>(true, input);
if (input.GetType() == destinationType) return Attempt.Succeed(input);
if (input is string && destinationType.IsEnum)
{
try
{
var output = Enum.Parse(destinationType, (string)input, true);
return new Attempt<object>(true, output);
return Attempt.Succeed(output);
}
catch (Exception e)
{
return new Attempt<object>(e);
{
return Attempt<object>.Succeed(e);
}
}
@@ -99,11 +99,11 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
try
{
var casted = Convert.ChangeType(input, destinationType);
return new Attempt<object>(true, casted);
return Attempt<object>.Succeed(casted);
}
catch (Exception e)
{
return new Attempt<object>(e);
return Attempt<object>.Fail(e);
}
}
}
@@ -114,11 +114,11 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
try
{
var converted = inputConverter.ConvertTo(input, destinationType);
return new Attempt<object>(true, converted);
return Attempt<object>.Succeed(converted);
}
catch (Exception e)
{
return new Attempt<object>(e);
return Attempt<object>.Fail(e);
}
}
@@ -130,11 +130,11 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
try
{
var converted = boolConverter.ConvertFrom(input);
return new Attempt<object>(true, converted);
return Attempt<object>.Succeed(converted);
}
catch (Exception e)
{
return new Attempt<object>(e);
return Attempt<object>.Fail(e);
}
}
}
@@ -145,11 +145,11 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
try
{
var converted = outputConverter.ConvertFrom(input);
return new Attempt<object>(true, converted);
return Attempt<object>.Succeed(converted);
}
catch (Exception e)
{
return new Attempt<object>(e);
return Attempt<object>.Fail(e);
}
}
@@ -159,15 +159,15 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
try
{
var casted = Convert.ChangeType(input, destinationType);
return new Attempt<object>(true, casted);
return Attempt<object>.Succeed(casted);
}
catch (Exception e)
{
return new Attempt<object>(e);
return Attempt<object>.Fail(e);
}
}
return Attempt<object>.False;
return Attempt<object>.Fail();
}
public static void CheckThrowObjectDisposed(this IDisposable disposable, bool isDisposed, string objectname)

View File

@@ -235,7 +235,7 @@ namespace Umbraco.Web.Editors
}
//initialize this to successful
var publishStatus = new Attempt<PublishStatus>(true, null);
var publishStatus = Attempt<PublishStatus>.Succeed();
if (contentItem.Action == ContentSaveAction.Save || contentItem.Action == ContentSaveAction.SaveNew)
{

View File

@@ -33,9 +33,9 @@ namespace Umbraco.Web.Trees
var foundControllerTree = controllerTrees.FirstOrDefault(x => x == appTree.GetRuntimeType());
if (foundControllerTree == null)
{
return new Attempt<Type>(new InstanceNotFoundException("Could not find tree of type " + appTree.Type + " in any loaded DLLs"));
return Attempt<Type>.Fail(new InstanceNotFoundException("Could not find tree of type " + appTree.Type + " in any loaded DLLs"));
}
return new Attempt<Type>(true, foundControllerTree);
return Attempt.Succeed(foundControllerTree);
}
internal static Attempt<TreeNode> TryGetRootNodeFromControllerTree(this ApplicationTree appTree, FormDataCollection formCollection, HttpControllerContext controllerContext)
@@ -43,7 +43,7 @@ namespace Umbraco.Web.Trees
var foundControllerTreeAttempt = appTree.TryGetControllerTree();
if (foundControllerTreeAttempt.Success == false)
{
return new Attempt<TreeNode>(foundControllerTreeAttempt.Error);
return Attempt<TreeNode>.Fail(foundControllerTreeAttempt.Exception);
}
var foundControllerTree = foundControllerTreeAttempt.Result;
//instantiate it, since we are proxying, we need to setup the instance with our current context
@@ -53,8 +53,8 @@ namespace Umbraco.Web.Trees
//return the root
var node = instance.GetRootNode(formCollection);
return node == null
? new Attempt<TreeNode>(new InvalidOperationException("Could not return a root node for tree " + appTree.Type))
: new Attempt<TreeNode>(true, node);
? Attempt<TreeNode>.Fail(new InvalidOperationException("Could not return a root node for tree " + appTree.Type))
: Attempt<TreeNode>.Succeed(node);
}
internal static Attempt<TreeNodeCollection> TryLoadFromControllerTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, HttpControllerContext controllerContext)
@@ -62,7 +62,7 @@ namespace Umbraco.Web.Trees
var foundControllerTreeAttempt = appTree.TryGetControllerTree();
if (foundControllerTreeAttempt.Success == false)
{
return new Attempt<TreeNodeCollection>(foundControllerTreeAttempt.Error);
return Attempt<TreeNodeCollection>.Fail(foundControllerTreeAttempt.Exception);
}
var foundControllerTree = foundControllerTreeAttempt.Result;
@@ -71,7 +71,7 @@ namespace Umbraco.Web.Trees
instance.ControllerContext = controllerContext;
instance.Request = controllerContext.Request;
//return it's data
return new Attempt<TreeNodeCollection>(true, instance.GetNodes(id, formCollection));
return Attempt.Succeed(instance.GetNodes(id, formCollection));
}
internal static Attempt<TreeNode> TryGetRootNodeFromLegacyTree(this ApplicationTree appTree, FormDataCollection formCollection, UrlHelper urlHelper, string currentSection)
@@ -79,9 +79,9 @@ namespace Umbraco.Web.Trees
var xmlTreeNodeAttempt = TryGetRootXmlNodeFromLegacyTree(appTree, formCollection, urlHelper);
if (xmlTreeNodeAttempt.Success == false)
{
return new Attempt<TreeNode>(xmlTreeNodeAttempt.Error);
return Attempt<TreeNode>.Fail(xmlTreeNodeAttempt.Exception);
}
return new Attempt<TreeNode>(true,
return Attempt.Succeed(
LegacyTreeDataConverter.ConvertFromLegacy(xmlTreeNodeAttempt.Result.NodeID, xmlTreeNodeAttempt.Result, urlHelper, currentSection, isRoot: true));
}
@@ -90,13 +90,13 @@ namespace Umbraco.Web.Trees
var treeDefAttempt = appTree.TryGetLegacyTreeDef();
if (treeDefAttempt.Success == false)
{
return new Attempt<XmlTreeNode>(treeDefAttempt.Error);
return Attempt<XmlTreeNode>.Fail(treeDefAttempt.Exception);
}
var treeDef = treeDefAttempt.Result;
var bTree = treeDef.CreateInstance();
var treeParams = new LegacyTreeParams(formCollection);
bTree.SetTreeParameters(treeParams);
return new Attempt<XmlTreeNode>(true, bTree.RootNode);
return Attempt.Succeed(bTree.RootNode);
}
internal static Attempt<TreeDefinition> TryGetLegacyTreeDef(this ApplicationTree appTree)
@@ -104,8 +104,8 @@ namespace Umbraco.Web.Trees
//This is how the legacy trees worked....
var treeDef = TreeDefinitionCollection.Instance.FindTree(appTree.Alias);
return treeDef == null
? new Attempt<TreeDefinition>(new InstanceNotFoundException("Could not find tree of type " + appTree.Alias))
: new Attempt<TreeDefinition>(true, treeDef);
? Attempt<TreeDefinition>.Fail(new InstanceNotFoundException("Could not find tree of type " + appTree.Alias))
: Attempt<TreeDefinition>.Succeed(treeDef);
}
internal static Attempt<TreeNodeCollection> TryLoadFromLegacyTree(this ApplicationTree appTree, string id, FormDataCollection formCollection, UrlHelper urlHelper, string currentSection)
@@ -113,9 +113,9 @@ namespace Umbraco.Web.Trees
var xTreeAttempt = appTree.TryGetXmlTree(id, formCollection);
if (xTreeAttempt.Success == false)
{
return new Attempt<TreeNodeCollection>(xTreeAttempt.Error);
return Attempt<TreeNodeCollection>.Fail(xTreeAttempt.Exception);
}
return new Attempt<TreeNodeCollection>(true, LegacyTreeDataConverter.ConvertFromLegacy(id, xTreeAttempt.Result, urlHelper, currentSection));
return Attempt.Succeed(LegacyTreeDataConverter.ConvertFromLegacy(id, xTreeAttempt.Result, urlHelper, currentSection));
}
internal static Attempt<MenuItemCollection> TryGetMenuFromLegacyTreeRootNode(this ApplicationTree appTree, FormDataCollection formCollection, UrlHelper urlHelper)
@@ -123,13 +123,13 @@ namespace Umbraco.Web.Trees
var rootAttempt = appTree.TryGetRootXmlNodeFromLegacyTree(formCollection, urlHelper);
if (rootAttempt.Success == false)
{
return new Attempt<MenuItemCollection>(rootAttempt.Error);
return Attempt<MenuItemCollection>.Fail(rootAttempt.Exception);
}
var currentSection = formCollection.GetRequiredString("section");
var result = LegacyTreeDataConverter.ConvertFromLegacyMenu(rootAttempt.Result, currentSection);
return new Attempt<MenuItemCollection>(true, result);
return Attempt.Succeed(result);
}
internal static Attempt<MenuItemCollection> TryGetMenuFromLegacyTreeNode(this ApplicationTree appTree, string parentId, string nodeId, FormDataCollection formCollection, UrlHelper urlHelper)
@@ -137,7 +137,7 @@ namespace Umbraco.Web.Trees
var xTreeAttempt = appTree.TryGetXmlTree(parentId, formCollection);
if (xTreeAttempt.Success == false)
{
return new Attempt<MenuItemCollection>(xTreeAttempt.Error);
return Attempt<MenuItemCollection>.Fail(xTreeAttempt.Exception);
}
var currentSection = formCollection.GetRequiredString("section");
@@ -145,9 +145,9 @@ namespace Umbraco.Web.Trees
var result = LegacyTreeDataConverter.ConvertFromLegacyMenu(nodeId, xTreeAttempt.Result, currentSection);
if (result == null)
{
return new Attempt<MenuItemCollection>(new ApplicationException("Could not find the node with id " + nodeId + " in the collection of nodes contained with parent id " + parentId));
return Attempt<MenuItemCollection>.Fail(new ApplicationException("Could not find the node with id " + nodeId + " in the collection of nodes contained with parent id " + parentId));
}
return new Attempt<MenuItemCollection>(true, result);
return Attempt.Succeed(result);
}
private static Attempt<XmlTree> TryGetXmlTree(this ApplicationTree appTree, string id, FormDataCollection formCollection)
@@ -155,7 +155,7 @@ namespace Umbraco.Web.Trees
var treeDefAttempt = appTree.TryGetLegacyTreeDef();
if (treeDefAttempt.Success == false)
{
return new Attempt<XmlTree>(treeDefAttempt.Error);
return Attempt<XmlTree>.Fail(treeDefAttempt.Exception);
}
var treeDef = treeDefAttempt.Result;
//This is how the legacy trees worked....
@@ -176,7 +176,7 @@ namespace Umbraco.Web.Trees
var xTree = new XmlTree();
bTree.SetTreeParameters(treeParams);
bTree.Render(ref xTree);
return new Attempt<XmlTree>(true, xTree);
return Attempt.Succeed(xTree);
}
}

View File

@@ -33,7 +33,7 @@ namespace Umbraco.Web.Trees
if (attempt.Success == false)
{
var msg = "Could not render tree " + queryStrings.GetRequiredString("treeType") + " for node id " + id;
LogHelper.Error<LegacyTreeController>(msg, attempt.Error);
LogHelper.Error<LegacyTreeController>(msg, attempt.Exception);
throw new ApplicationException(msg);
}
@@ -71,7 +71,7 @@ namespace Umbraco.Web.Trees
if (attempt.Success == false)
{
var msg = "Could not render menu for root node for treeType " + queryStrings.GetRequiredString("treeType");
LogHelper.Error<LegacyTreeController>(msg, attempt.Error);
LogHelper.Error<LegacyTreeController>(msg, attempt.Exception);
throw new ApplicationException(msg);
}
return attempt.Result;
@@ -82,7 +82,7 @@ namespace Umbraco.Web.Trees
if (attempt.Success == false)
{
var msg = "Could not render menu for treeType " + queryStrings.GetRequiredString("treeType") + " for node id " + parentId;
LogHelper.Error<LegacyTreeController>(msg, attempt.Error);
LogHelper.Error<LegacyTreeController>(msg, attempt.Exception);
throw new ApplicationException(msg);
}
return attempt.Result;

View File

@@ -188,18 +188,17 @@ namespace Umbraco.Web.Trees
{
if (action.JsFunctionName.IsNullOrWhiteSpace())
{
return Attempt<string>.False;
return Attempt<string>.Fail();
}
switch (action.JsFunctionName)
{
case "UmbClientMgr.appActions().actionDelete()":
return new Attempt<string>(
true,
return Attempt.Succeed(
Core.Configuration.GlobalSettings.Path.EnsureEndsWith('/') + "views/common/dialogs/legacydelete.html");
}
return Attempt<string>.False;
return Attempt<string>.Fail();
}
/// <summary>
@@ -214,128 +213,109 @@ namespace Umbraco.Web.Trees
{
if (action.JsFunctionName.IsNullOrWhiteSpace())
{
return Attempt<LegacyUrlAction>.False;
return Attempt<LegacyUrlAction>.Fail();
}
switch (action.JsFunctionName)
{
case "UmbClientMgr.appActions().actionNew()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"create.aspx?nodeId=" + nodeId + "&nodeType=" + nodeType + "&nodeName=" + nodeName + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "create")));
case "UmbClientMgr.appActions().actionNewFolder()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"createFolder.aspx?nodeId=" + nodeId + "&nodeType=" + nodeType + "&nodeName=" + nodeName + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "create")));
case "UmbClientMgr.appActions().actionSort()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/sort.aspx?id=" + nodeId + "&nodeType=" + nodeType + "&app=" + currentSection + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "sort")));
case "UmbClientMgr.appActions().actionRights()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/cruds.aspx?id=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "rights")));
case "UmbClientMgr.appActions().actionProtect()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/protectPage.aspx?mode=cut&nodeId=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "protect")));
case "UmbClientMgr.appActions().actionRollback()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/rollback.aspx?nodeId=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "rollback")));
case "UmbClientMgr.appActions().actionNotify()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/notifications.aspx?id=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "notify")));
case "UmbClientMgr.appActions().actionPublish()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/publish.aspx?id=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "publish")));
case "UmbClientMgr.appActions().actionToPublish()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/SendPublish.aspx?id=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "sendtopublish")));
case "UmbClientMgr.appActions().actionRePublish()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/republish.aspx?rnd=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
"Republishing entire site"));
case "UmbClientMgr.appActions().actionAssignDomain()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/assignDomain2.aspx?id=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "assignDomain")));
case "UmbClientMgr.appActions().actionLiveEdit()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"canvas.aspx?redir=/" + nodeId + ".aspx",
"",
ActionUrlMethod.BlankWindow));
case "UmbClientMgr.appActions().actionSendToTranslate()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/sendToTranslation.aspx?id=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "sendToTranslate")));
case "UmbClientMgr.appActions().actionEmptyTranscan()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/emptyTrashcan.aspx?type=" + currentSection,
ui.GetText("actions", "emptyTrashcan")));
case "UmbClientMgr.appActions().actionImport()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/importDocumentType.aspx",
ui.GetText("actions", "importDocumentType")));
case "UmbClientMgr.appActions().actionExport()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/exportDocumentType.aspx?nodeId=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
""));
case "UmbClientMgr.appActions().actionAudit()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/viewAuditTrail.aspx?nodeId=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "auditTrail")));
case "UmbClientMgr.appActions().actionMove()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/moveOrCopy.aspx?app=" + currentSection + "&mode=cut&id=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "move")));
case "UmbClientMgr.appActions().actionCopy()":
return new Attempt<LegacyUrlAction>(
true,
return Attempt.Succeed(
new LegacyUrlAction(
"dialogs/moveOrCopy.aspx?app=" + currentSection + "&mode=copy&id=" + nodeId + "&rnd=" + DateTime.UtcNow.Ticks,
ui.GetText("actions", "copy")));
}
return Attempt<LegacyUrlAction>.False;
return Attempt<LegacyUrlAction>.Fail();
}
internal static TreeNode ConvertFromLegacy(string parentId, XmlTreeNode xmlTreeNode, UrlHelper urlHelper, string currentSection, bool isRoot = false)