mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.6 KiB
71 lines
1.6 KiB
// ==========================================================================
|
|
// CommandContext.cs
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex Group
|
|
// All rights reserved.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
|
|
namespace Squidex.Infrastructure.CQRS.Commands
|
|
{
|
|
public sealed class CommandContext
|
|
{
|
|
private readonly ICommand command;
|
|
private Exception exception;
|
|
private Tuple<object> result;
|
|
|
|
public ICommand Command
|
|
{
|
|
get { return command; }
|
|
}
|
|
|
|
public bool IsHandled
|
|
{
|
|
get { return result != null || exception != null; }
|
|
}
|
|
|
|
public bool IsSucceeded
|
|
{
|
|
get { return result != null; }
|
|
}
|
|
|
|
public Exception Exception
|
|
{
|
|
get { return exception; }
|
|
}
|
|
|
|
public CommandContext(ICommand command)
|
|
{
|
|
Guard.NotNull(command, nameof(command));
|
|
|
|
this.command = command;
|
|
}
|
|
|
|
public void Succeed(object resultValue = null)
|
|
{
|
|
if (IsHandled)
|
|
{
|
|
return;
|
|
}
|
|
|
|
result = Tuple.Create(resultValue);
|
|
}
|
|
|
|
public void Fail(Exception handlerException)
|
|
{
|
|
if (IsHandled)
|
|
{
|
|
return;
|
|
}
|
|
|
|
exception = handlerException;
|
|
}
|
|
|
|
public T Result<T>()
|
|
{
|
|
return result != null ? (T)result.Item1 : default(T);
|
|
}
|
|
}
|
|
}
|