Remotely/Shared/Result.cs
Jared Goodwin 3f8d63c2c0
Azure Pipelines, Docker, and embedded server data. (#543)
* Add Azure Pipelines yml.

* Remove Server Installer.

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml for Azure Pipelines

* Update signtool.exe

* Update Release Build.yml

* Update Publish.ps1

* Update pipeline and Dockerfile.

* Move docker files.

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* Move files.

* Update Dockerfile

* Update Dockerfile

* Create RewritableStream.

* Finish implementation of rewritable stream and embedded data searcher.

* Remove RelayCode.

* Get branding from default org if orgId is missing.

* Update README.md

* Remove AppConstants.ServerUrl.  Fix main module file path.

* Update submodule.

* Extract embedded data in Program.cs.

* Add logging.  Update submodule.

* Remove size block.  BinaryWriter prefixes size.

* Remove unused async

* Update Immense.RemoteControl

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml for Azure Pipelines

* Use UpgradeService for determining out of date clients.
2022-12-31 19:10:40 -08:00

94 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Remotely.Shared
{
public class Result
{
public static Result<T> Empty<T>()
{
return new Result<T>(true, default);
}
public static Result Fail(string error)
{
return new Result(false, error);
}
public static Result Fail(Exception ex)
{
return new Result(false, null, ex);
}
public static Result<T> Fail<T>(string error)
{
return new Result<T>(false, default, error);
}
public static Result<T> Fail<T>(Exception ex)
{
return new Result<T>(false, default, exception: ex);
}
public static Result Ok()
{
return new Result(true);
}
public static Result<T> Ok<T>(T value)
{
return new Result<T>(true, value, null);
}
public Result(bool isSuccess, string error = null, Exception exception = null)
{
IsSuccess = isSuccess;
Error = error;
Exception = exception;
if (string.IsNullOrWhiteSpace(Error) && !string.IsNullOrWhiteSpace(Exception?.Message))
{
Error = Exception.Message;
}
Exception ??= new Exception(Error ?? string.Empty);
}
public bool IsSuccess { get; init; }
public string Error { get; init; } = string.Empty;
public Exception Exception { get; init; }
}
public class Result<T>
{
public Result(bool isSuccess, T value, string error = null, Exception exception = null)
{
IsSuccess = isSuccess;
Value = value;
Error = error;
Exception = exception;
if (string.IsNullOrWhiteSpace(Error) && !string.IsNullOrWhiteSpace(Exception?.Message))
{
Error = Exception.Message;
}
Exception ??= new Exception(Error ?? string.Empty);
}
public bool IsSuccess { get; init; }
public string Error { get; init; } = string.Empty;
public Exception Exception { get; init; }
public T Value { get; init; }
}
}