update headers

This commit is contained in:
Frede Hundewadt 2023-03-21 07:19:55 +01:00
parent d8f5895dbb
commit 477a3a2e2b
13 changed files with 2151 additions and 2096 deletions

View file

@ -1,25 +1,25 @@
// *********************************************************************** // ***********************************************************************
// Assembly : FCS.Lib.Utility // Assembly : FCS.Lib.Utility
// Author : FH // Author : fhdk
// Created : 27-08-2016 // Created : 2022 12 17 13:33
// //
// Last Modified By : Frede H. // Last Modified By: fhdk
// Last Modified On : 02-24-2022 // Last Modified On : 2023 03 14 09:16
// *********************************************************************** // ***********************************************************************
// <copyright file="ExtensionsEx.cs" company="FCS-TECH"> // <copyright file="ExtensionsEx.cs" company="FCS">
// Copyright (C) 2022 FCS Frede's Computer Services. // Copyright (C) 2022-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the Affero GNU General Public License as // it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the // published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version. // License, or (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Affero GNU General Public License for more details. // GNU Affero General Public License for more details.
// //
// You should have received a copy of the Affero GNU General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright> // </copyright>
// <summary></summary> // <summary></summary>
// *********************************************************************** // ***********************************************************************
@ -27,13 +27,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace FCS.Lib.Utility namespace FCS.Lib.Utility;
/// <summary>
/// Class ExtensionsEx.
/// </summary>
public static class ExtensionsEx
{ {
/// <summary>
/// Class ExtensionsEx.
/// </summary>
public static class ExtensionsEx
{
/// <summary> /// <summary>
/// ForEach loop /// ForEach loop
/// </summary> /// </summary>
@ -45,5 +45,4 @@ namespace FCS.Lib.Utility
foreach (var item in items) foreach (var item in items)
action(item); action(item);
} }
}
} }

View file

@ -1,25 +1,25 @@
// *********************************************************************** // ***********************************************************************
// Assembly : FCS.Lib.Utility // Assembly : FCS.Lib.Utility
// Author : FH // Author : fhdk
// Created : 2020-07-01 // Created : 2023 02 02 06:59
// //
// Last Modified By : FH // Last Modified By: fhdk
// Last Modified On : 02-24-2022 // Last Modified On : 2023 03 14 09:16
// *********************************************************************** // ***********************************************************************
// <copyright file="Generators.cs" company="FCS-TECH"> // <copyright file="Generators.cs" company="FCS">
// Copyright (C) 2022 FCS Frede's Computer Services. // Copyright (C) 2023-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the Affero GNU General Public License as // it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the // published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version. // License, or (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Affero GNU General Public License for more details. // GNU Affero General Public License for more details.
// //
// You should have received a copy of the Affero GNU General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright> // </copyright>
// <summary></summary> // <summary></summary>
// *********************************************************************** // ***********************************************************************
@ -29,13 +29,13 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
namespace FCS.Lib.Utility namespace FCS.Lib.Utility;
/// <summary>
/// Generators
/// </summary>
public static class Generators
{ {
/// <summary>
/// Generators
/// </summary>
public static class Generators
{
/// <summary> /// <summary>
/// Generate 6 character shortUrl /// Generate 6 character shortUrl
/// </summary> /// </summary>
@ -81,7 +81,7 @@ namespace FCS.Lib.Utility
for (var i = 0; i < leftGroupsOrder.Length; i++) for (var i = 0; i < leftGroupsOrder.Length; i++)
leftGroupsOrder[i] = i; leftGroupsOrder[i] = i;
// Using our private randomizer // Using our private random number generator
var random = RandomSeed(); var random = RandomSeed();
// This array will hold short-url characters. // This array will hold short-url characters.
@ -133,9 +133,8 @@ namespace FCS.Lib.Utility
// so that we don't pick it until we process all characters in // so that we don't pick it until we process all characters in
// this group. // this group.
if (lastCharIdx != nextCharIdx) if (lastCharIdx != nextCharIdx)
{ (charGroups[nextGroupIdx][lastCharIdx], charGroups[nextGroupIdx][nextCharIdx]) = (
(charGroups[nextGroupIdx][lastCharIdx], charGroups[nextGroupIdx][nextCharIdx]) = (charGroups[nextGroupIdx][nextCharIdx], charGroups[nextGroupIdx][lastCharIdx]); charGroups[nextGroupIdx][nextCharIdx], charGroups[nextGroupIdx][lastCharIdx]);
}
// Decrement the number of unprocessed characters in // Decrement the number of unprocessed characters in
// this group. // this group.
@ -153,9 +152,8 @@ namespace FCS.Lib.Utility
// Swap processed group with the last unprocessed group // Swap processed group with the last unprocessed group
// so that we don't pick it until we process all groups. // so that we don't pick it until we process all groups.
if (lastLeftGroupsOrderIdx != nextLeftGroupsOrderIdx) if (lastLeftGroupsOrderIdx != nextLeftGroupsOrderIdx)
{ (leftGroupsOrder[lastLeftGroupsOrderIdx], leftGroupsOrder[nextLeftGroupsOrderIdx]) = (
(leftGroupsOrder[lastLeftGroupsOrderIdx], leftGroupsOrder[nextLeftGroupsOrderIdx]) = (leftGroupsOrder[nextLeftGroupsOrderIdx], leftGroupsOrder[lastLeftGroupsOrderIdx]); leftGroupsOrder[nextLeftGroupsOrderIdx], leftGroupsOrder[lastLeftGroupsOrderIdx]);
}
// Decrement the number of unprocessed groups. // Decrement the number of unprocessed groups.
lastLeftGroupsOrderIdx--; lastLeftGroupsOrderIdx--;
@ -176,7 +174,7 @@ namespace FCS.Lib.Utility
{ {
options ??= new StringOptions options ??= new StringOptions
{ {
RequiredLength = 10, RequiredLength = 16,
RequireDigit = true, RequireDigit = true,
RequireLowercase = true, RequireLowercase = true,
RequireUppercase = true, RequireUppercase = true,
@ -197,13 +195,13 @@ namespace FCS.Lib.Utility
{ {
options ??= new StringOptions options ??= new StringOptions
{ {
RequiredLength = 10, RequiredLength = 16,
RequireDigit = true, RequireDigit = true,
RequireLowercase = true, RequireLowercase = true,
RequireUppercase = true, RequireUppercase = true,
RequiredUniqueChars = 4, RequiredUniqueChars = 8,
RequireNonLetterOrDigit = true, RequireNonLetterOrDigit = false,
RequireNonAlphanumeric = true RequireNonAlphanumeric = false
}; };
return GenerateRandomString(options); return GenerateRandomString(options);
} }
@ -240,7 +238,7 @@ namespace FCS.Lib.Utility
{ {
options ??= new StringOptions options ??= new StringOptions
{ {
RequiredLength = 10, RequiredLength = 16,
RequireDigit = true, RequireDigit = true,
RequireLowercase = true, RequireLowercase = true,
RequireUppercase = true, RequireUppercase = true,
@ -257,7 +255,7 @@ namespace FCS.Lib.Utility
"!@$?_-" // non-alphanumeric "!@$?_-" // non-alphanumeric
}; };
// Using our private randomizer // Using our private random number generator
var rand = RandomSeed(); var rand = RandomSeed();
var chars = new List<char>(); var chars = new List<char>();
@ -319,5 +317,4 @@ namespace FCS.Lib.Utility
// Return a truly randomized random generator // Return a truly randomized random generator
return new Random(seed); return new Random(seed);
} }
}
} }

View file

@ -1,15 +1,40 @@
using System; // ***********************************************************************
// Assembly : FCS.Lib.Utility
// Author : fhdk
// Created : 2022 12 17 13:33
//
// Last Modified By: fhdk
// Last Modified On : 2023 03 14 09:16
// ***********************************************************************
// <copyright file="GuidGenerator.cs" company="FCS">
// Copyright (C) 2022-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Text; using System.Text;
namespace FCS.Lib.Utility namespace FCS.Lib.Utility;
{
/// <summary>
/// Used for generating UUID based on RFC 4122.
/// </summary>
/// <seealso href="http://www.ietf.org/rfc/rfc4122.txt">RFC 4122 - A Universally Unique IDentifier (UUID) URN Namespace</seealso>
public static class GuidGenerator
{
/// <summary>
/// Used for generating UUID based on RFC 4122.
/// </summary>
/// <seealso href="http://www.ietf.org/rfc/rfc4122.txt">RFC 4122 - A Universally Unique IDentifier (UUID) URN Namespace</seealso>
public static class GuidGenerator
{
/// <summary> /// <summary>
/// number of bytes in guid /// number of bytes in guid
/// </summary> /// </summary>
@ -53,16 +78,6 @@ namespace FCS.Lib.Utility
// offset to move from 1/1/0001, which is 0-time for .NET, to gregorian 0-time of 10/15/1582 // offset to move from 1/1/0001, which is 0-time for .NET, to gregorian 0-time of 10/15/1582
private static readonly DateTimeOffset GregorianCalendarStart = new(1582, 10, 15, 0, 0, 0, TimeSpan.Zero); private static readonly DateTimeOffset GregorianCalendarStart = new(1582, 10, 15, 0, 0, 0, TimeSpan.Zero);
/// <summary>
/// Default clock sequence
/// </summary>
public static byte[] DefaultClockSequence { get; set; }
/// <summary>
/// Default node
/// </summary>
public static byte[] DefaultNode { get; set; }
static GuidGenerator() static GuidGenerator()
{ {
DefaultClockSequence = new byte[2]; DefaultClockSequence = new byte[2];
@ -73,6 +88,17 @@ namespace FCS.Lib.Utility
random.NextBytes(DefaultNode); random.NextBytes(DefaultNode);
} }
/// <summary>
/// Default clock sequence
/// </summary>
public static byte[] DefaultClockSequence { get; set; }
/// <summary>
/// Default node
/// </summary>
public static byte[] DefaultNode { get; set; }
/// <summary> /// <summary>
/// Set default node /// Set default node
/// </summary> /// </summary>
@ -247,5 +273,4 @@ namespace FCS.Lib.Utility
return new Guid(guid); return new Guid(guid);
} }
}
} }

View file

@ -1,25 +1,53 @@
namespace FCS.Lib.Utility // ***********************************************************************
// Assembly : FCS.Lib.Utility
// Author : fhdk
// Created : 2022 12 17 13:33
//
// Last Modified By: fhdk
// Last Modified On : 2023 03 14 09:16
// ***********************************************************************
// <copyright file="GuidVersion.cs" company="FCS">
// Copyright (C) 2022-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright>
// <summary></summary>
// ***********************************************************************
namespace FCS.Lib.Utility;
/// <summary>
/// Guid Version Enum
/// </summary>
public enum GuidVersion
{ {
/// <summary>
/// Guid Version Enum
/// </summary>
public enum GuidVersion
{
/// <summary> /// <summary>
/// Time /// Time
/// </summary> /// </summary>
TimeBased = 0x01, TimeBased = 0x01,
/// <summary> /// <summary>
/// Reserved /// Reserved
/// </summary> /// </summary>
Reserved = 0x02, Reserved = 0x02,
/// <summary> /// <summary>
/// Name /// Name
/// </summary> /// </summary>
NameBased = 0x03, NameBased = 0x03,
/// <summary> /// <summary>
/// Random /// Random
/// </summary> /// </summary>
Random = 0x04 Random = 0x04
}
} }

View file

@ -1,25 +1,25 @@
// *********************************************************************** // ***********************************************************************
// Assembly : FCS.Lib.Utility // Assembly : FCS.Lib.Utility
// Author : FH // Author : fhdk
// Created : 03-10-2015 // Created : 2023 01 23 07:31
// //
// Last Modified By : FH // Last Modified By: fhdk
// Last Modified On : 02-24-2022 // Last Modified On : 2023 03 14 09:16
// *********************************************************************** // ***********************************************************************
// <copyright file="IAsyncReadonlyRepo.cs" company="FCS-TECH"> // <copyright file="IAsyncReadonlyRepo.cs" company="FCS">
// Copyright (C) 2022 FCS Frede's Computer Services. // Copyright (C) 2023-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the Affero GNU General Public License as // it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the // published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version. // License, or (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Affero GNU General Public License for more details. // GNU Affero General Public License for more details.
// //
// You should have received a copy of the Affero GNU General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright> // </copyright>
// <summary></summary> // <summary></summary>
// *********************************************************************** // ***********************************************************************
@ -30,14 +30,14 @@ using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FCS.Lib.Utility namespace FCS.Lib.Utility;
/// <summary>
/// Interface IRepositoryAsync
/// </summary>
/// <typeparam name="TEntity">The type of the t entity.</typeparam>
public interface IAsyncReadonlyRepo<TEntity> where TEntity : class
{ {
/// <summary>
/// Interface IRepositoryAsync
/// </summary>
/// <typeparam name="TEntity">The type of the t entity.</typeparam>
public interface IAsyncReadonlyRepo<TEntity> where TEntity : class
{
/// <summary> /// <summary>
/// Queryable /// Queryable
/// </summary> /// </summary>
@ -92,5 +92,4 @@ namespace FCS.Lib.Utility
/// <param name="id">The identifier.</param> /// <param name="id">The identifier.</param>
/// <returns>TEntity.</returns> /// <returns>TEntity.</returns>
TEntity GetById(string id); TEntity GetById(string id);
}
} }

View file

@ -1,38 +1,38 @@
// *********************************************************************** // ***********************************************************************
// Assembly : FCS.Lib.Utility // Assembly : FCS.Lib.Utility
// Author : FH // Author : fhdk
// Created : 05-13-2020 // Created : 2022 12 17 13:33
// //
// Last Modified By : FH // Last Modified By: fhdk
// Last Modified On : 02-24-2022 // Last Modified On : 2023 03 14 09:16
// *********************************************************************** // ***********************************************************************
// <copyright file="IRepository.cs" company="FCS-TECH"> // <copyright file="IRepository.cs" company="FCS">
// Copyright (C) 2022 FCS Frede's Computer Services. // Copyright (C) 2022-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the Affero GNU General Public License as // it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the // published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version. // License, or (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Affero GNU General Public License for more details. // GNU Affero General Public License for more details.
// //
// You should have received a copy of the Affero GNU General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright> // </copyright>
// <summary></summary> // <summary></summary>
// *********************************************************************** // ***********************************************************************
namespace FCS.Lib.Utility namespace FCS.Lib.Utility;
/// <summary>
/// Interface IRepository
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TKey">The type of the TKey.</typeparam>
public interface IRepository<T, in TKey> where T : class
{ {
/// <summary>
/// Interface IRepository
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TKey">The type of the TKey.</typeparam>
public interface IRepository<T, in TKey> where T : class
{
/// <summary> /// <summary>
/// Gets the specified identifier. /// Gets the specified identifier.
/// </summary> /// </summary>
@ -57,5 +57,4 @@ namespace FCS.Lib.Utility
/// </summary> /// </summary>
/// <param name="id">The identifier.</param> /// <param name="id">The identifier.</param>
void Delete(TKey id); void Delete(TKey id);
}
} }

View file

@ -1,25 +1,25 @@
// *********************************************************************** // ***********************************************************************
// Assembly : FCS.Lib.Utility // Assembly : FCS.Lib.Utility
// Author : FH // Author : fhdk
// Created : 03-10-2015 // Created : 2022 12 17 13:33
// //
// Last Modified By : FH // Last Modified By: fhdk
// Last Modified On : 02-24-2022 // Last Modified On : 2023 03 14 09:16
// *********************************************************************** // ***********************************************************************
// <copyright file="IRepositoryEx.cs" company="FCS-TECH"> // <copyright file="IRepositoryEx.cs" company="FCS">
// Copyright (C) 2022 FCS Frede's Computer Services. // Copyright (C) 2022-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the Affero GNU General Public License as // it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the // published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version. // License, or (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Affero GNU General Public License for more details. // GNU Affero General Public License for more details.
// //
// You should have received a copy of the Affero GNU General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright> // </copyright>
// <summary></summary> // <summary></summary>
// *********************************************************************** // ***********************************************************************
@ -29,14 +29,14 @@ using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace FCS.Lib.Utility namespace FCS.Lib.Utility;
/// <summary>
/// Interface IRepositoryEx
/// </summary>
/// <typeparam name="TEntity">The type of the t entity</typeparam>
public interface IRepositoryEx<TEntity> where TEntity : class
{ {
/// <summary>
/// Interface IRepositoryEx
/// </summary>
/// <typeparam name="TEntity">The type of the t entity</typeparam>
public interface IRepositoryEx<TEntity> where TEntity : class
{
/// <summary> /// <summary>
/// Get all entities synchronous /// Get all entities synchronous
/// </summary> /// </summary>
@ -123,5 +123,4 @@ namespace FCS.Lib.Utility
/// </summary> /// </summary>
/// <returns>IQueryable&lt;TEntity&gt;</returns> /// <returns>IQueryable&lt;TEntity&gt;</returns>
IQueryable<TEntity> All(); IQueryable<TEntity> All();
}
} }

View file

@ -1,25 +1,25 @@
// *********************************************************************** // ***********************************************************************
// Assembly : FCS.Lib.Utility // Assembly : FCS.Lib.Utility
// Author : FH // Author : fhdk
// Created : 27-08-2016 // Created : 2023 03 02 09:52
// //
// Last Modified By : Frede H. // Last Modified By: fhdk
// Last Modified On : 02-24-2022 // Last Modified On : 2023 03 14 09:16
// *********************************************************************** // ***********************************************************************
// <copyright file="Mogrify.cs" company="FCS-TECH"> // <copyright file="Mogrify.cs" company="FCS">
// Copyright (C) 2022 FCS Frede's Computer Services. // Copyright (C) 2023-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the Affero GNU General Public License as // it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the // published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version. // License, or (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Affero GNU General Public License for more details. // GNU Affero General Public License for more details.
// //
// You should have received a copy of the Affero GNU General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright> // </copyright>
// <summary></summary> // <summary></summary>
// *********************************************************************** // ***********************************************************************
@ -33,13 +33,27 @@ using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace FCS.Lib.Utility namespace FCS.Lib.Utility;
/// <summary>
/// Mogrify between units
/// </summary>
public static class Mogrify
{ {
/// <summary> /// <summary>
/// Mogrify between units /// Remove everything but digits and country code
/// </summary> /// </summary>
public static class Mogrify /// <param name="phone"></param>
/// <returns></returns>
public static string SanitizePhone(string phone)
{ {
if (string.IsNullOrWhiteSpace(phone))
return "";
phone = phone.Replace("+45", "").Replace("+46", "").Replace("+47", "");
var regexObj = new Regex(@"[^\d]");
return regexObj.Replace(phone, "");
}
/// <summary> /// <summary>
/// Get month from timestamp /// Get month from timestamp
/// </summary> /// </summary>
@ -70,6 +84,7 @@ namespace FCS.Lib.Utility
{ {
return DateTimeIso8601(TimeStampToDateTime(timestamp)); return DateTimeIso8601(TimeStampToDateTime(timestamp));
} }
/// <summary> /// <summary>
/// return date as ISO /// return date as ISO
/// </summary> /// </summary>
@ -77,7 +92,7 @@ namespace FCS.Lib.Utility
/// <returns></returns> /// <returns></returns>
public static string DateTimeIso8601(DateTime date) public static string DateTimeIso8601(DateTime date)
{ {
return date.ToString("o",CultureInfo.InvariantCulture); return date.ToString("o", CultureInfo.InvariantCulture);
} }
/// <summary> /// <summary>
@ -85,11 +100,12 @@ namespace FCS.Lib.Utility
/// </summary> /// </summary>
/// <param name="dateTime"></param> /// <param name="dateTime"></param>
/// <returns>dictionary</returns> /// <returns>dictionary</returns>
public static Dictionary<string,long> DateToTimestampRange(DateTime dateTime) public static Dictionary<string, long> DateToTimestampRange(DateTime dateTime)
{ {
var dt1 = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,0,0,0); var dt1 = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0);
var dt2 = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 23, 59, 59); var dt2 = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 23, 59, 59);
return new Dictionary<string, long>{ return new Dictionary<string, long>
{
{ "lower", DateTimeToTimeStamp(dt1) }, { "lower", DateTimeToTimeStamp(dt1) },
{ "upper", DateTimeToTimeStamp(dt2) } { "upper", DateTimeToTimeStamp(dt2) }
}; };
@ -264,7 +280,7 @@ namespace FCS.Lib.Utility
/// <returns></returns> /// <returns></returns>
public static T IntToEnum<T>(int value) public static T IntToEnum<T>(int value)
{ {
return (T) Enum.ToObject(typeof(T), value); return (T)Enum.ToObject(typeof(T), value);
} }
/// <summary> /// <summary>
@ -289,7 +305,7 @@ namespace FCS.Lib.Utility
{ {
var empty = string.Empty; var empty = string.Empty;
if (list == null) return empty; if (list == null) return empty;
var enumerator = (IEnumerator) list.GetType().GetMethod("GetEnumerator")?.Invoke(list, null); var enumerator = (IEnumerator)list.GetType().GetMethod("GetEnumerator")?.Invoke(list, null);
while (enumerator != null && enumerator.MoveNext()) while (enumerator != null && enumerator.MoveNext())
if (enumerator.Current != null) if (enumerator.Current != null)
empty = string.Concat(empty, enumerator.Current.ToString(), delimiter); empty = string.Concat(empty, enumerator.Current.ToString(), delimiter);
@ -334,6 +350,7 @@ namespace FCS.Lib.Utility
return flag; return flag;
} }
/// <summary> /// <summary>
/// get decimal from string /// get decimal from string
/// </summary> /// </summary>
@ -345,8 +362,8 @@ namespace FCS.Lib.Utility
return return
!decimal.TryParse(inString.Replace(",", "").Replace(".", ""), NumberStyles.Number, !decimal.TryParse(inString.Replace(",", "").Replace(".", ""), NumberStyles.Number,
CultureInfo.InvariantCulture, out var num) CultureInfo.InvariantCulture, out var num)
? (decimal?) null ? null
: decimal.Divide(num, new decimal((long) 100)); : decimal.Divide(num, new decimal((long)100));
} }
/// <summary> /// <summary>
@ -393,16 +410,16 @@ namespace FCS.Lib.Utility
var upperInvariant = o.ToUpperInvariant(); var upperInvariant = o.ToUpperInvariant();
if (string.CompareOrdinal(upperInvariant, "system.string") == 0) if (string.CompareOrdinal(upperInvariant, "system.string") == 0)
{ {
ts.Add((T) Convert.ChangeType(str, typeof(T), CultureInfo.InvariantCulture)); ts.Add((T)Convert.ChangeType(str, typeof(T), CultureInfo.InvariantCulture));
} }
else if (string.CompareOrdinal(upperInvariant, "system.int32") == 0) else if (string.CompareOrdinal(upperInvariant, "system.int32") == 0)
{ {
ts.Add((T) Convert.ChangeType(str, typeof(T), CultureInfo.InvariantCulture)); ts.Add((T)Convert.ChangeType(str, typeof(T), CultureInfo.InvariantCulture));
} }
else if (string.CompareOrdinal(upperInvariant, "system.guid") == 0) else if (string.CompareOrdinal(upperInvariant, "system.guid") == 0)
{ {
var guid = new Guid(str); var guid = new Guid(str);
ts.Add((T) Convert.ChangeType(guid, typeof(T), CultureInfo.InvariantCulture)); ts.Add((T)Convert.ChangeType(guid, typeof(T), CultureInfo.InvariantCulture));
} }
} }
@ -474,5 +491,4 @@ namespace FCS.Lib.Utility
// } // }
// return empty; // return empty;
//} //}
}
} }

View file

@ -17,5 +17,5 @@ using System.Runtime.InteropServices;
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: Guid("8D850197-78DB-4D16-A91F-E5BB6E8880A7")] [assembly: Guid("8D850197-78DB-4D16-A91F-E5BB6E8880A7")]
[assembly: AssemblyVersion("1.0.23023.0820")] [assembly: AssemblyVersion("1.0.23077.1334")]
[assembly: AssemblyFileVersion("1.0.23023.0820")] [assembly: AssemblyFileVersion("1.0.23077.1334")]

View file

@ -1,25 +1,25 @@
// *********************************************************************** // ***********************************************************************
// Assembly : FCS.Lib.Utility // Assembly : FCS.Lib.Utility
// Author : FH // Author : fhdk
// Created : 01-01-2022 // Created : 2022 12 17 13:33
// //
// Last Modified By : FH // Last Modified By: fhdk
// Last Modified On : 02-24-2022 // Last Modified On : 2023 03 14 09:16
// *********************************************************************** // ***********************************************************************
// <copyright file="QueryHelper.cs" company="Frede Hundewadt"> // <copyright file="QueryHelper.cs" company="FCS">
// Copyright (C) 2022 FCS Frede's Computer Services. // Copyright (C) 2022-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the Affero GNU General Public License as // it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the // published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version. // License, or (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Affero GNU General Public License for more details. // GNU Affero General Public License for more details.
// //
// You should have received a copy of the Affero GNU General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright> // </copyright>
// <summary></summary> // <summary></summary>
// *********************************************************************** // ***********************************************************************
@ -29,13 +29,13 @@ using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
namespace FCS.Lib.Utility namespace FCS.Lib.Utility;
/// <summary>
/// Class QueryHelper.
/// </summary>
public static class QueryHelper
{ {
/// <summary>
/// Class QueryHelper.
/// </summary>
public static class QueryHelper
{
// https://stackoverflow.com/a/45761590 // https://stackoverflow.com/a/45761590
/// <summary> /// <summary>
@ -46,7 +46,7 @@ namespace FCS.Lib.Utility
/// <param name="desc"></param> /// <param name="desc"></param>
/// <typeparam name="TModel"></typeparam> /// <typeparam name="TModel"></typeparam>
/// <returns></returns> /// <returns></returns>
public static IQueryable<TModel> OrderBy<TModel> (this IQueryable<TModel> q, string name, bool desc) public static IQueryable<TModel> OrderBy<TModel>(this IQueryable<TModel> q, string name, bool desc)
{ {
var entityType = typeof(TModel); var entityType = typeof(TModel);
var p = entityType.GetProperty(name); var p = entityType.GetProperty(name);
@ -54,7 +54,7 @@ namespace FCS.Lib.Utility
.GetMethod("OrderByProperty") .GetMethod("OrderByProperty")
?.MakeGenericMethod(entityType, p.PropertyType); ?.MakeGenericMethod(entityType, p.PropertyType);
return(IQueryable<TModel>) m.Invoke(null, new object[] { q, p , desc }); return (IQueryable<TModel>)m.Invoke(null, new object[] { q, p, desc });
} }
/// <summary> /// <summary>
@ -65,7 +65,7 @@ namespace FCS.Lib.Utility
/// <param name="desc"></param> /// <param name="desc"></param>
/// <typeparam name="TModel"></typeparam> /// <typeparam name="TModel"></typeparam>
/// <returns></returns> /// <returns></returns>
public static IQueryable<TModel> ThenBy<TModel> (this IQueryable<TModel> q, string name, bool desc) public static IQueryable<TModel> ThenBy<TModel>(this IQueryable<TModel> q, string name, bool desc)
{ {
var entityType = typeof(TModel); var entityType = typeof(TModel);
var p = entityType.GetProperty(name); var p = entityType.GetProperty(name);
@ -73,7 +73,7 @@ namespace FCS.Lib.Utility
.GetMethod("OrderByProperty") .GetMethod("OrderByProperty")
?.MakeGenericMethod(entityType, p.PropertyType); ?.MakeGenericMethod(entityType, p.PropertyType);
return(IQueryable<TModel>) m.Invoke(null, new object[] { q, p , desc }); return (IQueryable<TModel>)m.Invoke(null, new object[] { q, p, desc });
} }
@ -94,5 +94,4 @@ namespace FCS.Lib.Utility
return desc ? q.OrderByDescending(exp) : q.OrderBy(exp); return desc ? q.OrderByDescending(exp) : q.OrderBy(exp);
} }
}
}}

View file

@ -1,42 +1,42 @@
// *********************************************************************** // ***********************************************************************
// Assembly : FCS.Lib.Utility // Assembly : FCS.Lib.Utility
// Author : FH // Author : fhdk
// Created : 2020-07-01 // Created : 2022 12 17 13:33
// //
// Last Modified By : FH // Last Modified By: fhdk
// Last Modified On : 02-24-2022 // Last Modified On : 2023 03 14 09:16
// *********************************************************************** // ***********************************************************************
// <copyright file="Squid.cs" company="FCS-TECH"> // <copyright file="Squid.cs" company="FCS">
// Copyright (C) 2022 FCS Frede's Computer Services. // Copyright (C) 2022-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the Affero GNU General Public License as // it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the // published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version. // License, or (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// Affero GNU General Public License for more details. // GNU Affero General Public License for more details.
// //
// You should have received a copy of the Affero GNU General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // along with this program. If not, see [https://www.gnu.org/licenses]
// </copyright> // </copyright>
// <summary>Derived from https:github.com/csharpvitamins/CSharpVitamins.ShortGuid</summary> // <summary></summary>
// *********************************************************************** // ***********************************************************************
using System; using System;
using System.Diagnostics; using System.Diagnostics;
namespace FCS.Lib.Utility namespace FCS.Lib.Utility;
/// <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>
[DebuggerDisplay("{" + nameof(Value) + "}")]
public readonly struct Squid : IEquatable<Squid>
{ {
/// <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>
[DebuggerDisplay("{" + nameof(Value) + "}")]
public readonly struct Squid : IEquatable<Squid>
{
/// <summary> /// <summary>
/// A read-only object of the Squid struct. /// A read-only object of the Squid struct.
/// Value is guaranteed to be all zeroes. /// Value is guaranteed to be all zeroes.
@ -127,7 +127,7 @@ namespace FCS.Lib.Utility
/// <returns>New Squid object</returns> /// <returns>New Squid object</returns>
public static Squid NewGuid() public static Squid NewGuid()
{ {
return new(Guid.NewGuid()); return new Squid(Guid.NewGuid());
} }
/// <summary> /// <summary>
@ -391,5 +391,4 @@ namespace FCS.Lib.Utility
} }
#endregion #endregion
}
} }

View file

@ -1,13 +1,13 @@
// *********************************************************************** // ***********************************************************************
// Assembly : FCS.Lib.Utility // Assembly : FCS.Lib.Utility
// Author : FH // Author : fhdk
// Created : 2020-09-09 // Created : 2022 12 17 13:33
// //
// Last Modified By : FH // Last Modified By: fhdk
// Last Modified On : 03-14-2022 // Last Modified On : 2023 03 14 09:16
// *********************************************************************** // ***********************************************************************
// <copyright file="StringOptions.cs" company="FCS-TECH"> // <copyright file="StringOptions.cs" company="FCS">
// Copyright (C) 2022 FCS Frede's Computer Services. // Copyright (C) 2022-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as // it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the // published by the Free Software Foundation, either version 3 of the
@ -24,13 +24,13 @@
// <summary></summary> // <summary></summary>
// *********************************************************************** // ***********************************************************************
namespace FCS.Lib.Utility namespace FCS.Lib.Utility;
/// <summary>
/// Class StringOptions.
/// </summary>
public class StringOptions
{ {
/// <summary>
/// Class StringOptions.
/// </summary>
public class StringOptions
{
/// <summary> /// <summary>
/// Gets or sets the required length of a string /// Gets or sets the required length of a string
/// </summary> /// </summary>
@ -72,5 +72,4 @@ namespace FCS.Lib.Utility
/// </summary> /// </summary>
/// <value><c>true</c> if [require non alphanumeric]; otherwise, <c>false</c>.</value> /// <value><c>true</c> if [require non alphanumeric]; otherwise, <c>false</c>.</value>
public bool RequireNonAlphanumeric { get; set; } public bool RequireNonAlphanumeric { get; set; }
}
} }

View file

@ -1,13 +1,13 @@
// *********************************************************************** // ***********************************************************************
// Assembly : FCS.Lib.Utility // Assembly : FCS.Lib.Utility
// Author : FH // Author : fhdk
// Created : 03-30-2022 // Created : 2023 03 09 17:42
// //
// Last Modified By : FH // Last Modified By: fhdk
// Last Modified On : 04-19-2022 // Last Modified On : 2023 03 14 09:16
// *********************************************************************** // ***********************************************************************
// <copyright file="VatFormatValidator.cs" company="FCS-TECH"> // <copyright file="VatFormatValidator.cs" company="FCS">
// Copyright (C) 2022 FCS Frede's Computer Services. // Copyright (C) 2023-2023 FCS Frede's Computer Services.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as // it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the // published by the Free Software Foundation, either version 3 of the
@ -24,17 +24,16 @@
// <summary></summary> // <summary></summary>
// *********************************************************************** // ***********************************************************************
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace FCS.Lib.Utility namespace FCS.Lib.Utility;
/// <summary>
/// Vat format validator
/// </summary>
public static class VatFormatValidator
{ {
/// <summary>
/// Vat format validator
/// </summary>
public static class VatFormatValidator
{
// https://ec.europa.eu/taxation_customs/vies/faqvies.do#item_11 // https://ec.europa.eu/taxation_customs/vies/faqvies.do#item_11
// https://ec.europa.eu/taxation_customs/vies/ // https://ec.europa.eu/taxation_customs/vies/
@ -85,7 +84,7 @@ namespace FCS.Lib.Utility
// C8 check-digit MOD11 // C8 check-digit MOD11
// C1 > 0 // C1 > 0
// R = (2*C1 + 7*C2 + 6*C3 + 5*C4 + 4*C5 + 3*C6 + 2*C7 + C8) // R = (2*C1 + 7*C2 + 6*C3 + 5*C4 + 4*C5 + 3*C6 + 2*C7 + C8)
if(vatNumber.Length == 8 && long.TryParse(vatNumber, out _)) if (vatNumber.Length == 8 && long.TryParse(vatNumber, out _))
return ValidateMod11(vatNumber); return ValidateMod11(vatNumber);
return false; return false;
} }
@ -123,7 +122,7 @@ namespace FCS.Lib.Utility
// C10 is check digit // C10 is check digit
var orgToCheck = orgNumber; var orgToCheck = orgNumber;
if (long.Parse(orgToCheck) == 0) if (!long.TryParse(orgToCheck, out _))
return false; return false;
switch (orgToCheck.Length) switch (orgToCheck.Length)
@ -167,13 +166,13 @@ namespace FCS.Lib.Utility
if (ssn.Length is not 6 or 10 || int.Parse(ssn) == 0) if (ssn.Length is not 6 or 10 || int.Parse(ssn) == 0)
return false; return false;
var y = int.Parse(ssn.Substring(0,2)); var y = int.Parse(ssn.Substring(0, 2));
var m = int.Parse(ssn.Substring(2,2)); var m = int.Parse(ssn.Substring(2, 2));
var d = int.Parse(ssn.Substring(4,2)); var d = int.Parse(ssn.Substring(4, 2));
// this calculation is only valid within 21st century // this calculation is only valid within 21st century
var leap = y % 4 == 0; // 2000 was a leap year; var leap = y % 4 == 0; // 2000 was a leap year;
// day // day
if(d is < 1 or > 31) if (d is < 1 or > 31)
return false; return false;
// month // month
switch (m) switch (m)
@ -217,7 +216,6 @@ namespace FCS.Lib.Utility
{ {
return false; return false;
} }
} }
@ -357,6 +355,4 @@ namespace FCS.Lib.Utility
// return nSum % 10 == 0; // return nSum % 10 == 0;
//} //}
}
} }