64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
|
|
namespace Sarand.Net.Standard.Base.Core
|
|
{
|
|
//=======================================================================
|
|
/// <summary>State Item interface.</summary>
|
|
public interface ISacsStateItem
|
|
{
|
|
bool HasErrorState();
|
|
SacsErrorState ErrorState { get; }
|
|
String ErrorStateMessage { get; }
|
|
bool SetErrorState(String message);
|
|
void ClearErrorState();
|
|
}
|
|
|
|
//=======================================================================
|
|
/// <summary>
|
|
/// State Item - allows business component to record and report error message.
|
|
/// </summary>
|
|
public class SacsStateItem : ISacsStateItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data items.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Protected construction - use derived classes.
|
|
protected SacsStateItem() { }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Poperties.
|
|
|
|
/// <summary>OK - No error state message.</summary>
|
|
public bool OK { get { return !HasErrorState(); } }
|
|
|
|
// Error state.
|
|
public SacsErrorState ErrorState { get; private set; }
|
|
public bool HasErrorState()
|
|
{
|
|
return ErrorState != null;
|
|
}
|
|
public String ErrorStateMessage
|
|
{
|
|
get { return (ErrorState != null ? ErrorState.Message : String.Empty); }
|
|
}
|
|
// Update properties.
|
|
public virtual bool SetErrorState(String message)
|
|
{
|
|
if (StringUtil.IsEmpty(StringUtil.EmptyOnNull(message).Trim()))
|
|
throw new NotSupportedException($"{SysUtil.Fn} Blank error message.");
|
|
this.ErrorState = new SacsErrorState(message);
|
|
return false;
|
|
}
|
|
public void ClearErrorState()
|
|
{
|
|
ErrorState = null;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|