ca956afd7e
- update EgwConf (valutare se da postare iin MapoSDK finito il lavoro ora è direttamente in IOB-WIN)
94 lines
2.4 KiB
C#
94 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EgwProxy.Shelly
|
|
{
|
|
public class ShellyResult<T>
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Indicates the client request has failed
|
|
/// </summary>
|
|
public bool IsFailure => !IsSuccess;
|
|
|
|
/// <summary>
|
|
/// Indicates the client request has completed successfully
|
|
/// </summary>
|
|
public bool IsSuccess
|
|
{
|
|
get
|
|
{
|
|
_successChecked = true;
|
|
return _success;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indicates if the reason for failure is transient
|
|
/// </summary>
|
|
public bool IsTransient { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Any message that accompanies this result
|
|
/// </summary>
|
|
public string Message { get; }
|
|
|
|
public T Value
|
|
{
|
|
get
|
|
{
|
|
if (!_successChecked)
|
|
{
|
|
throw new InvalidOperationException("Cannot access value of result without checking success first");
|
|
}
|
|
|
|
return _value;
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public static ShellyResult<T> Failure(string message = null)
|
|
{
|
|
return new ShellyResult<T>(default, success: false, isTransient: false, message);
|
|
}
|
|
|
|
public static ShellyResult<T> Success(T value, string rawResp, string message = null)
|
|
{
|
|
return new ShellyResult<T>(value, true, false, message);
|
|
}
|
|
|
|
public static ShellyResult<T> TransientFailure(string message = null)
|
|
{
|
|
return new ShellyResult<T>(default, success: false, isTransient: true, message);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private bool _success = false;
|
|
private bool _successChecked = false;
|
|
private T _value;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Constructors
|
|
|
|
private ShellyResult(T value, bool success, bool isTransient, string message = null)
|
|
{
|
|
_value = value;
|
|
_success = success;
|
|
IsTransient = isTransient;
|
|
Message = message;
|
|
}
|
|
|
|
#endregion Private Constructors
|
|
}
|
|
} |