This commit is contained in:
FH 2021-11-06 11:16:18 +01:00
parent 1f8d75a096
commit f5dbaa237b
No known key found for this signature in database
GPG key ID: 3629B5D280E47F0A
14 changed files with 299 additions and 267 deletions

View file

@ -4,7 +4,7 @@
// Created : 27-08-2016
//
// Last Modified By : Frede H.
// Last Modified On : 2020-08-30
// Last Modified On : 2021-02-24
// ***********************************************************************
// <copyright file="ExtensionsEx.cs" company="FCS">
// Copyright © FCS 2015-2020

View file

@ -2,7 +2,7 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -33,6 +33,12 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>FCS.Lib.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -47,7 +53,7 @@
<Compile Include="ExtensionsEx.cs" />
<Compile Include="Generators.cs" />
<Compile Include="IRepository.cs" />
<Compile Include="IRepositoryAsync.cs" />
<Compile Include="IAsyncReadonlyRepo.cs" />
<Compile Include="IRepositoryEx.cs" />
<Compile Include="Mogrifiers.cs" />
<Compile Include="StringOptions.cs" />
@ -58,7 +64,9 @@
</Compile>
<Compile Include="Squid.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="FCS.Lib.pfx" />
</ItemGroup>
<ItemGroup>
<Content Include=".gitignore" />
<Content Include="Properties\AssemblyInfo.tt">

View file

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp90</s:String></wpf:ResourceDictionary>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>

BIN
FCS.Lib.pfx Normal file

Binary file not shown.

View file

@ -4,7 +4,7 @@
// Created : 2020-07-01
//
// Last Modified By : FH
// Last Modified On : 2020-09-11
// Last Modified On : 2021-02-24
// ***********************************************************************
// <copyright file="Generators.cs" company="Frede Hundewadt">
// Copyright © FCS 2015-2020
@ -37,9 +37,9 @@ namespace FCS.Lib
/// <summary>
/// Randoms the string.
/// </summary>
/// <remarks>derived from https://sourceforge.net/projects/shorturl-dotnet/ </remarks>
/// <param name="length">The lengt h.</param>
/// <returns>System.String.</returns>
/// <remarks>derived from https://sourceforge.net/projects/shorturl-dotnet/</remarks>
public static string ShortUrlGenerator(int length)
{
const string charsLower = "cdfghjkmnpqrstvwxyz";
@ -161,6 +161,11 @@ namespace FCS.Lib
return new string(shortUrl);
}
/// <summary>
/// Generates the username.
/// </summary>
/// <param name="options">The options.</param>
/// <returns>System.String.</returns>
public static string GenerateUsername(StringOptions options = null)
{
options ??= new StringOptions
@ -176,6 +181,11 @@ namespace FCS.Lib
return GenerateRandomString(options);
}
/// <summary>
/// Generates the password.
/// </summary>
/// <param name="options">The options.</param>
/// <returns>System.String.</returns>
public static string GeneratePassword(StringOptions options = null)
{
options ??= new StringOptions
@ -191,6 +201,11 @@ namespace FCS.Lib
return GenerateRandomString(options);
}
/// <summary>
/// Generates the random text.
/// </summary>
/// <param name="length">The length.</param>
/// <returns>System.String.</returns>
public static string GenerateRandomText(int length)
{
const string consonants = "bdfghjklmnprstvyBDFGHJKLMNPRSTVY";
@ -270,8 +285,8 @@ namespace FCS.Lib
/// <summary>
/// Randoms the seed.
/// </summary>
/// <remarks>derived from https://sourceforge.net/projects/shorturl-dotnet/ </remarks>
/// <returns>Random.</returns>
/// <remarks>derived from https://sourceforge.net/projects/shorturl-dotnet/</remarks>
public static Random RandomSeed()
{
// As the default randomizer is based on the current time

84
IAsyncReadonlyRepo.cs Normal file
View file

@ -0,0 +1,84 @@
// ***********************************************************************
// Assembly : FCS.Lib
// Author : FH
// Created : 03-10-2015
//
// Last Modified By : FH
// Last Modified On : 2021-03-27
// ***********************************************************************
// <copyright file="IRepositoryAsync.cs" company="FCS">
// Copyright © FCS 2015-2020
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace FCS.Lib
{
/// <summary>
/// Interface IRepositoryAsync
/// </summary>
/// <typeparam name="TEntity">The type of the t entity.</typeparam>
public interface IAsyncReadonlyRepo<TEntity> where TEntity : class
{
/// <summary>
/// Alls this instance.
/// </summary>
/// <returns>IQueryable&lt;TEntity&gt;.</returns>
IQueryable<TEntity> All();
/// <summary>
/// Alls the asynchronous.
/// </summary>
/// <param name="predicate">The predicate.</param>
/// <returns>Task&lt;IList&lt;TEntity&gt;&gt;.</returns>
Task<IList<TEntity>> AllAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Anies the asynchronous.
/// </summary>
/// <param name="predicate">The predicate.</param>
/// <returns>Task&lt;System.Boolean&gt;.</returns>
Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Finds the asynchronous.
/// </summary>
/// <param name="predicate">The predicate.</param>
/// <returns>Task&lt;TEntity&gt;.</returns>
Task<TEntity> FindAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Firsts the asynchronous.
/// </summary>
/// <param name="predicate">The predicate.</param>
/// <returns>Task&lt;TEntity&gt;.</returns>
Task<TEntity> FirstAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Firsts the or default asynchronous.
/// </summary>
/// <param name="predicate">The predicate.</param>
/// <returns>Task&lt;TEntity&gt;.</returns>
Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Anies the specified predicate.
/// </summary>
/// <param name="predicate">The predicate.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
bool Any(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Gets the by identifier.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>TEntity.</returns>
TEntity GetById(string id);
}
}

View file

@ -4,7 +4,7 @@
// Created : 05-13-2020
//
// Last Modified By : FH
// Last Modified On : 2020-08-30
// Last Modified On : 2021-02-24
// ***********************************************************************
// <copyright file="IRepository.cs" company="FCS">
// Copyright © FCS 2015-2020

View file

@ -1,122 +0,0 @@
// ***********************************************************************
// Assembly : FCS.Lib
// Author : FH
// Created : 03-10-2015
//
// Last Modified By : FH
// Last Modified On : 2020-08-30
// ***********************************************************************
// <copyright file="IRepositoryAsync.cs" company="FCS">
// Copyright © FCS 2015-2020
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace FCS.Lib
{
/// <summary>
/// Interface IRepositoryAsyncEx
/// </summary>
/// <typeparam name="TEntity">The type of the t entity</typeparam>
public interface IRepositoryAsync<TEntity> where TEntity : class
{
/// <summary>
/// Get all entities asynchronous
/// </summary>
/// <param name="predicate">Predicate</param>
/// <returns>Task&lt;System.Boolean&gt;</returns>
Task<bool> AllAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Get all entities synchronous
/// </summary>
/// <param name="predicate">Predicate</param>
/// <returns>Task&lt;System.Boolean&gt;</returns>
Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Find matching entity asynchronous
/// </summary>
/// <param name="predicate">Predicate</param>
/// <returns>Task&lt;TEntity&gt;</returns>
Task<TEntity> FindAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Find first matching entity asynchronous
/// </summary>
/// <param name="predicate">Predicate</param>
/// <returns>Task&lt;TEntity&gt;</returns>
Task<TEntity> FirstAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Get first entity matching query or default entity asynchronous
/// </summary>
/// <param name="predicate">Predicate</param>
/// <returns>Task&lt;TEntity&gt;</returns>
Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Add an entity
/// </summary>
/// <param name="entity">The entity.</param>
void Add(TEntity entity);
/// <summary>
/// Attach the entity
/// </summary>
/// <param name="entity">The entity.</param>
void Attach(TEntity entity);
/// <summary>
/// Delete the entity
/// </summary>
/// <param name="entity">The entity.</param>
void Delete(TEntity entity);
/// <summary>
/// Anies the specified predicate.
/// </summary>
/// <param name="predicate">The predicate.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
bool Any(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Get all entities
/// </summary>
/// <returns>IQueryable&lt;TEntity&gt;</returns>
IQueryable<TEntity> All();
/// <summary>
/// Find all matching entities matching query
/// </summary>
/// <param name="predicate">Predicate</param>
/// <returns>IQueryable&lt;TEntity&gt;</returns>
IQueryable<TEntity> Find(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Find first entity matching query
/// </summary>
/// <param name="predicate">Predicate</param>
/// <returns>TEntity</returns>
TEntity First(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Find first matching entity or default entity
/// </summary>
/// <param name="predicate">Predicate</param>
/// <returns>TEntity</returns>
TEntity FirstOrDefault(Expression<Func<TEntity, bool>> predicate);
/// <summary>
/// Get entity by id
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns>TEntity</returns>
TEntity GetById(string id);
}
}

View file

@ -4,7 +4,7 @@
// Created : 03-10-2015
//
// Last Modified By : FH
// Last Modified On : 2020-08-30
// Last Modified On : 2021-02-24
// ***********************************************************************
// <copyright file="IRepositoryEx.cs" company="FCS">
// Copyright © FCS 2015-2020

View file

@ -4,7 +4,7 @@
// Created : 27-08-2016
//
// Last Modified By : Frede H.
// Last Modified On : 2020-08-30
// Last Modified On : 2021-02-24
// ***********************************************************************
// <copyright file="Mogrifiers.cs" company="FCS">
// Copyright © FCS 2015-2020
@ -15,10 +15,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace FCS.Lib
{
@ -79,6 +80,11 @@ namespace FCS.Lib
return value == null ? string.Empty : value.ToString();
}
public static IEnumerable<T> GetEnumList<T>()
{
return (T[])Enum.GetValues(typeof(T));
}
/// <summary>
/// Integer to boolean.
/// </summary>
@ -86,7 +92,7 @@ namespace FCS.Lib
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
public static bool IntToBool(int value)
{
return value == 1;
return value > 0 || value < 0;
}
/// <summary>
@ -157,13 +163,22 @@ namespace FCS.Lib
return empty;
}
/// <summary>
/// Pascals to lower.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>System.String.</returns>
public static string PascalToLower(string value)
{
var result = string.Join("-", Regex.Split(value, @"(?<!^)(?=[A-Z])").ToArray());
return result.ToLower(CultureInfo.InvariantCulture);
}
/// <summary>
/// String to bool.
/// </summary>
/// <param name="value">The value.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
[SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "<Pending>")]
public static bool StringToBool(string value)
{
if (string.IsNullOrEmpty(value))
@ -230,10 +245,13 @@ namespace FCS.Lib
/// <param name="value">The value.</param>
/// <param name="delimiter">The delimiter.</param>
/// <returns>List&lt;T&gt;.</returns>
/// <exception cref="System.ArgumentNullException">value</exception>
/// <exception cref="System.ArgumentNullException">delimiter</exception>
/// <exception cref="ArgumentNullException">value</exception>
/// <exception cref="ArgumentNullException">delimiter</exception>
/// <exception cref="ArgumentNullException">value</exception>
/// <exception cref="ArgumentNullException">delimiter</exception>
/// <exception cref="ArgumentNullException">value</exception>
/// <exception cref="ArgumentNullException">delimiter</exception>
/// <exception cref="ArgumentNullException">value</exception>
public static List<T> StringToList<T>(string value, string delimiter)
{
if (string.IsNullOrEmpty(value)) throw new ArgumentNullException(nameof(value));
@ -295,6 +313,24 @@ namespace FCS.Lib
return Convert.ToUInt32(DateTimeToTimeStamp(DateTime.Now));
}
/// <summary>
/// Currents the date time to alpha.
/// </summary>
/// <returns>System.String.</returns>
public static string CurrentDateTimeToAlpha()
{
var dt = DateTime.UtcNow.ToString("yy MM dd HH MM ss");
var sb = new StringBuilder();
var dts = dt.Split(' ');
sb.Append((char) int.Parse(dts[0]) + 65);
sb.Append((char) int.Parse(dts[1]) + 65);
sb.Append((char) int.Parse(dts[2]) + 97);
sb.Append((char) int.Parse(dts[3]) + 65);
sb.Append((char) int.Parse(dts[4]) + 97);
sb.Append((char) int.Parse(dts[5]) + 97);
return sb.ToString();
}
/// <summary>
/// Convert a DateTime object to timestamp
/// </summary>
@ -306,10 +342,10 @@ namespace FCS.Lib
var nixDate = new DateTime(1970, 1, 1, 0, 0, 0, 0);
if (dateTime >= bigDate)
return Convert.ToUInt32((bigDate - nixDate).TotalSeconds) +
Convert.ToUInt32((dateTime - bigDate).TotalSeconds);
return Convert.ToInt64((bigDate - nixDate).TotalSeconds) +
Convert.ToInt64((dateTime - bigDate).TotalSeconds);
return Convert.ToUInt32((dateTime - nixDate).TotalSeconds);
return Convert.ToInt64((dateTime - nixDate).TotalSeconds);
}
/// <summary>

View file

@ -16,5 +16,5 @@ using System.Runtime.InteropServices;
[assembly: ComVisible(false)]
[assembly: Guid("aaf08873-14e5-411d-8ec8-629782ac8f03")]
[assembly: AssemblyVersion("2.1.20289.1156")]
[assembly: AssemblyFileVersion("2.1.20289.1156")]
[assembly: AssemblyVersion("2.1.21308.1057")]
[assembly: AssemblyFileVersion("2.1.21308.1057")]

View file

@ -4,7 +4,7 @@
// Created : 2020-07-01
//
// Last Modified By : FH
// Last Modified On : 2020-08-30
// Last Modified On : 2021-02-24
// ***********************************************************************
// <copyright file="Squid.cs" company="Frede Hundewadt">
// Copyright © FCS 2015-2020
@ -20,8 +20,10 @@ namespace FCS.Lib
/// <summary>
/// A wrapper for handling URL-safe Base64 encoded globally unique identifiers (GUID).
/// </summary>
/// <remarks>Special characters are replaced (/, +) or removed (==).
/// Derived from https:github.com/csharpvitamins/CSharpVitamins.ShortGuid</remarks>
/// <remarks>
/// Special characters are replaced (/, +) or removed (==).
/// Derived from https:github.com/csharpvitamins/CSharpVitamins.ShortGuid
/// </remarks>
[DebuggerDisplay("{" + nameof(Value) + "}")]
public readonly struct Squid : IEquatable<Squid>
{
@ -30,7 +32,7 @@ namespace FCS.Lib
/// Value is guaranteed to be all zeroes.
/// Equivalent to <see cref="Guid.Empty" />.
/// </summary>
public static readonly Squid Empty = new Squid(Guid.Empty);
public static readonly Squid Empty = new(Guid.Empty);
/// <summary>
/// Creates a new Squid from a Squid encoded string.
@ -39,7 +41,7 @@ namespace FCS.Lib
public Squid(string value)
{
Value = value;
Guid = Decode(value);
Guid = DecodeSquid(value);
}
/// <summary>
@ -48,7 +50,7 @@ namespace FCS.Lib
/// <param name="obj">A valid System.Guid object.</param>
public Squid(Guid obj)
{
Value = Encode(obj);
Value = EncodeGuid(obj);
Guid = obj;
}
@ -115,7 +117,7 @@ namespace FCS.Lib
/// <returns>New Squid object</returns>
public static Squid NewGuid()
{
return new Squid(Guid.NewGuid());
return new(Guid.NewGuid());
}
/// <summary>
@ -125,10 +127,10 @@ namespace FCS.Lib
/// </summary>
/// <param name="value">A valid <see cref="System.Guid" />.Tostring().</param>
/// <returns>A 22 character URL-safe Base64 string.</returns>
public static string Encode(string value)
public static string EncodeString(string value)
{
var guid = new Guid(value);
return Encode(guid);
return EncodeGuid(guid);
}
/// <summary>
@ -138,7 +140,7 @@ namespace FCS.Lib
/// </summary>
/// <param name="obj">A valid <see cref="System.Guid" /> object.</param>
/// <returns>A 22 character URL-safe Base64 string.</returns>
public static string Encode(Guid obj)
public static string EncodeGuid(Guid obj)
{
var encoded = Convert.ToBase64String(obj.ToByteArray());
encoded = encoded
@ -154,7 +156,7 @@ namespace FCS.Lib
/// </summary>
/// <param name="value">A valid Squid encoded string.</param>
/// <returns>A new <see cref="System.Guid" /> object from the parsed string.</returns>
public static Guid Decode(string value)
public static Guid DecodeSquid(string value)
{
if (value == null) return Empty;
value = value
@ -198,7 +200,7 @@ namespace FCS.Lib
try
{
// Decode as Squid
obj = Decode(value);
obj = DecodeSquid(value);
return true;
}
#pragma warning disable CA1031 // Do not catch general exception types

View file

@ -4,13 +4,14 @@
// Created : 2020-09-09
//
// Last Modified By : FH
// Last Modified On : 2020-08-30
// Last Modified On : 2021-02-24
// ***********************************************************************
// <copyright file="StringOptions.cs" company="Frede Hundewadt">
// Copyright © FCS 2015-2020
// </copyright>
// <summary></summary>
// ***********************************************************************
namespace FCS.Lib
{
/// <summary>
@ -23,31 +24,37 @@ namespace FCS.Lib
/// </summary>
/// <value>The length of the required.</value>
public int RequiredLength { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [require non letter or digit].
/// </summary>
/// <value><c>true</c> if [require non letter or digit]; otherwise, <c>false</c>.</value>
public bool RequireNonLetterOrDigit { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [require digit].
/// </summary>
/// <value><c>true</c> if [require digit]; otherwise, <c>false</c>.</value>
public bool RequireDigit { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [require lowercase].
/// </summary>
/// <value><c>true</c> if [require lowercase]; otherwise, <c>false</c>.</value>
public bool RequireLowercase { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [require uppercase].
/// </summary>
/// <value><c>true</c> if [require uppercase]; otherwise, <c>false</c>.</value>
public bool RequireUppercase { get; set; }
/// <summary>
/// Gets or sets the required unique chars.
/// </summary>
/// <value>The required unique chars.</value>
public int RequiredUniqueChars { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [require non alphanumeric].
/// </summary>