Add project files.
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
namespace MyOffice.Core;
|
||||
|
||||
public enum GeneralExecStatus
|
||||
{
|
||||
success,
|
||||
failure,
|
||||
not_found
|
||||
}
|
||||
|
||||
public class Exec<TResult> : Exec<TResult, GeneralExecStatus>
|
||||
where TResult : class
|
||||
{
|
||||
public Exec(TResult result, GeneralExecStatus status) : base(result, status)
|
||||
{
|
||||
}
|
||||
|
||||
public Exec(GeneralExecStatus status) : base(status)
|
||||
{
|
||||
}
|
||||
|
||||
public Exec() : base(GeneralExecStatus.success)
|
||||
{
|
||||
}
|
||||
|
||||
public new Exec<TResult> Set(GeneralExecStatus status)
|
||||
{
|
||||
Status = status;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public new Exec<TResult> Set(TResult? result)
|
||||
{
|
||||
Result = result;
|
||||
Status = result == null ? GeneralExecStatus.failure : GeneralExecStatus.success;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public class Exec<TResult, TStatus>
|
||||
where TResult : class
|
||||
where TStatus : Enum
|
||||
{
|
||||
public static Exec<TResult, TStatus> Start(TResult result, TStatus status)
|
||||
{
|
||||
return new Exec<TResult, TStatus>(result, status);
|
||||
}
|
||||
|
||||
public static Exec<TResult, TStatus> Start(TStatus status)
|
||||
{
|
||||
return new Exec<TResult, TStatus>(status);
|
||||
}
|
||||
|
||||
public static Exec<TResult, GeneralExecStatus> StartSuccess()
|
||||
{
|
||||
return new Exec<TResult, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
}
|
||||
|
||||
public static Exec<TResult, GeneralExecStatus> StartFailure()
|
||||
{
|
||||
return new Exec<TResult, GeneralExecStatus>(GeneralExecStatus.failure);
|
||||
}
|
||||
|
||||
public static Exec<TResult, GeneralExecStatus> StartNotFound()
|
||||
{
|
||||
return new Exec<TResult, GeneralExecStatus>(GeneralExecStatus.not_found);
|
||||
}
|
||||
|
||||
public Exec(TResult result, TStatus status)
|
||||
{
|
||||
Result = result;
|
||||
Status = status;
|
||||
}
|
||||
|
||||
public Exec(TStatus status)
|
||||
{
|
||||
Status = status;
|
||||
}
|
||||
|
||||
public TResult? Result { get; internal set; }
|
||||
public TStatus Status { get; internal set; }
|
||||
|
||||
public Exec<TResult, TStatus> Set(TResult result, TStatus status)
|
||||
{
|
||||
Result = result;
|
||||
Status = status;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Exec<TResult, TStatus> Set(TStatus status)
|
||||
{
|
||||
Status = status;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Exec<TResult, TStatus> Set(TResult result)
|
||||
{
|
||||
Result = result;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace MyOffice.Core.Extensions;
|
||||
|
||||
public static class BoolExtensions
|
||||
{
|
||||
public static string ToLowerCase(this bool value)
|
||||
{
|
||||
return value.ToString().ToLower();
|
||||
}
|
||||
|
||||
public static string? ToLowerCase(this bool? value)
|
||||
{
|
||||
return value == null ? null : value.ToString()?.ToLower();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace MyOffice.Core.Extensions;
|
||||
|
||||
using System.Security.Claims;
|
||||
|
||||
public static class ClaimsExtensions
|
||||
{
|
||||
public static string? GetValue(this IEnumerable<Claim> claims, string type)
|
||||
{
|
||||
return claims.FirstOrDefault(x => x.Type.Equals(type, StringComparison.OrdinalIgnoreCase))?.Value;
|
||||
}
|
||||
|
||||
public static string? GetValue(this IEnumerable<Claim> claims, string[] types)
|
||||
{
|
||||
return claims.FirstOrDefault(x => types.Any(z => x.Type.Equals(z, StringComparison.OrdinalIgnoreCase)))?.Value;
|
||||
}
|
||||
|
||||
public static string? GetEmail(this IEnumerable<Claim> claims)
|
||||
{
|
||||
return GetValue(claims, new[] { ClaimTypes.Email, "email" });
|
||||
}
|
||||
|
||||
public static string? GetNameIdentifier(this IEnumerable<Claim> claims)
|
||||
{
|
||||
return GetValue(claims, ClaimTypes.NameIdentifier);
|
||||
}
|
||||
|
||||
public static string? GetSID(this IEnumerable<Claim> claims)
|
||||
{
|
||||
return GetValue(claims, "sid");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MyOffice.Core.Extensions;
|
||||
|
||||
public static class GuidExtensions
|
||||
{
|
||||
public static bool EqualsString(this Guid guid, string str)
|
||||
{
|
||||
return guid.ToString().EqualsIgnoreCase(str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace MyOffice.Core.Extensions;
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static bool IsMissing(this string? str)
|
||||
{
|
||||
return str == null || string.IsNullOrEmpty(str) || string.IsNullOrEmpty(str.Trim());
|
||||
}
|
||||
|
||||
public static bool IsPresent(this string? str)
|
||||
{
|
||||
return !IsMissing(str);
|
||||
}
|
||||
|
||||
public static string? NullIfEmpty(this string? str)
|
||||
{
|
||||
return IsMissing(str) ? null : str;
|
||||
}
|
||||
|
||||
public static bool EqualsIgnoreCase(this string? str, string? value)
|
||||
{
|
||||
return str != null && str.Equals(value, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public static bool AsBool(this string? str, bool defaultValue = false)
|
||||
{
|
||||
return true.ToString().Equals(str, StringComparison.OrdinalIgnoreCase) || defaultValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace MyOffice.Core.Identity;
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
public interface IExternalProviderValidator
|
||||
{
|
||||
string Provider { get; }
|
||||
public bool IsConfigured { get; }
|
||||
|
||||
Task<ExternalProviderValidatorResult> ValidateAsync(string token);
|
||||
}
|
||||
|
||||
public class ExternalProviderValidatorResult
|
||||
{
|
||||
public static ExternalProviderValidatorResult Failed()
|
||||
{
|
||||
return new ExternalProviderValidatorResult();
|
||||
}
|
||||
|
||||
public static ExternalProviderValidatorResult Success(string email, bool emailVerified, string externalId,
|
||||
string? fullName)
|
||||
{
|
||||
return new ExternalProviderValidatorResult(email, emailVerified, externalId, fullName);
|
||||
}
|
||||
|
||||
public ExternalProviderValidatorResult()
|
||||
{
|
||||
IsSuccessed = false;
|
||||
}
|
||||
|
||||
public ExternalProviderValidatorResult(string email, bool emailVerified, string externalId, string? fullName) :
|
||||
this()
|
||||
{
|
||||
Email = email;
|
||||
EmailVerified = emailVerified;
|
||||
IsSuccessed = true;
|
||||
ExternalId = externalId;
|
||||
FullName = fullName;
|
||||
}
|
||||
|
||||
public bool IsSuccessed { get; }
|
||||
public string? Email { get; }
|
||||
public bool EmailVerified { get; }
|
||||
public string? ExternalId { get; }
|
||||
public string? FullName { get; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user