Browse Source

qdr.fnd.core.business

- Change AbstractService base depends on qdr.fnd.core.logging.ILogger instead of ILoggerFactory
- fix obsolete implementation in PasswordHelper
Dalibor Votruba 1 year ago
parent
commit
2a46bae95a

+ 5 - 5
qdr.fnd.core.business/AbstractMultiRepositoryService.cs

@@ -1,6 +1,6 @@
 using System;
 using System.Security.Principal;
-using Microsoft.Extensions.Logging;
+using Quadarax.Foundation.Core.Logging;
 using Quadarax.Foundation.Core.Data.Interface.Repository;
 
 namespace Quadarax.Foundation.Core.Business
@@ -12,7 +12,7 @@ namespace Quadarax.Foundation.Core.Business
         protected TRepository1 Repository1 { get; }
         protected TRepository2 Repository2 { get; }
 
-        protected AbstractMultiRepositoryService(TRepository1 repository1, TRepository2 repository2,IPrincipal currentPrincipal,  ILoggerFactory logger) : base(currentPrincipal, logger)
+        protected AbstractMultiRepositoryService(TRepository1 repository1, TRepository2 repository2,IPrincipal currentPrincipal,  ILogger logger) : base(currentPrincipal, logger)
         {
             Repository1 = repository1 ?? throw new ArgumentNullException(nameof(repository1));
             Repository2 = repository2 ?? throw new ArgumentNullException(nameof(repository2));
@@ -29,7 +29,7 @@ namespace Quadarax.Foundation.Core.Business
         protected TRepository2 Repository2 { get; }
         protected TRepository3 Repository3 { get; }
 
-        protected AbstractMultiRepositoryService(TRepository1 repository1, TRepository2 repository2, TRepository3 repository3,IPrincipal currentPrincipal, ILoggerFactory logger) : base(currentPrincipal, logger)
+        protected AbstractMultiRepositoryService(TRepository1 repository1, TRepository2 repository2, TRepository3 repository3,IPrincipal currentPrincipal, ILogger logger) : base(currentPrincipal, logger)
         {
             Repository1 = repository1 ?? throw new ArgumentNullException(nameof(repository1));
             Repository2 = repository2 ?? throw new ArgumentNullException(nameof(repository2));
@@ -48,7 +48,7 @@ namespace Quadarax.Foundation.Core.Business
         protected TRepository3 Repository3 { get; }
         protected TRepository4 Repository4 { get; }
 
-        protected AbstractMultiRepositoryService(TRepository1 repository1, TRepository2 repository2, TRepository3 repository3,TRepository4 repository4, IPrincipal currentPrincipal, ILoggerFactory logger) : base(currentPrincipal, logger)
+        protected AbstractMultiRepositoryService(TRepository1 repository1, TRepository2 repository2, TRepository3 repository3,TRepository4 repository4, IPrincipal currentPrincipal, ILogger logger) : base(currentPrincipal, logger)
         {
             Repository1 = repository1 ?? throw new ArgumentNullException(nameof(repository1));
             Repository2 = repository2 ?? throw new ArgumentNullException(nameof(repository2));
@@ -71,7 +71,7 @@ namespace Quadarax.Foundation.Core.Business
         protected TRepository4 Repository4 { get; }
         protected TRepository5 Repository5 { get; }
 
-        protected AbstractMultiRepositoryService(TRepository1 repository1, TRepository2 repository2, TRepository3 repository3,TRepository4 repository4,TRepository5 repository5,IPrincipal currentPrincipal, ILoggerFactory logger) : base(currentPrincipal, logger)
+        protected AbstractMultiRepositoryService(TRepository1 repository1, TRepository2 repository2, TRepository3 repository3,TRepository4 repository4,TRepository5 repository5,IPrincipal currentPrincipal, ILogger logger) : base(currentPrincipal, logger)
         {
             Repository1 = repository1 ?? throw new ArgumentNullException(nameof(repository1));
             Repository2 = repository2 ?? throw new ArgumentNullException(nameof(repository2));

+ 2 - 3
qdr.fnd.core.business/AbstractRepositoryService.cs

@@ -1,7 +1,6 @@
 using System;
 using System.Security.Principal;
-using Microsoft.Extensions.Logging;
-using NLog;
+using Quadarax.Foundation.Core.Logging;
 using Quadarax.Foundation.Core.Data.Interface.Repository;
 
 namespace Quadarax.Foundation.Core.Business
@@ -10,7 +9,7 @@ namespace Quadarax.Foundation.Core.Business
     {
         protected TRepository Repository { get; }
 
-        protected AbstractRepositoryService(TRepository repository,IPrincipal currentPrincipal, ILoggerFactory logger) : base(currentPrincipal, logger)
+        protected AbstractRepositoryService(TRepository repository,IPrincipal currentPrincipal, ILogger logger) : base(currentPrincipal, logger)
         {
             Repository = repository ?? throw new ArgumentNullException(nameof(repository));
         }

+ 10 - 8
qdr.fnd.core.business/AbstractService.cs

@@ -1,23 +1,23 @@
-using System;
-using System.Security.Principal;
-using Microsoft.Extensions.Logging;
+using System.Security.Principal;
 using Quadarax.Foundation.Core.Business.Interface;
 using Quadarax.Foundation.Core.Data.Interface.Entity;
 using Quadarax.Foundation.Core.Data.Interface.Entity.Dto;
+using Quadarax.Foundation.Core.Logging;
 
 namespace Quadarax.Foundation.Core.Business
 {
-    public abstract class AbstractService : IService
+
+     public abstract class AbstractService : IService
     {
         #region *** Properties ***
-        protected ILogger<AbstractService> Log { get; }
+        protected ILog Log { get; }
         protected IPrincipal CurrentPrincipal { get; }
         #endregion
 
         #region *** Constructors ***
-        protected AbstractService(IPrincipal currentPrincipal, ILoggerFactory logger)
+        protected AbstractService(IPrincipal currentPrincipal, ILogger logger)
         {
-            Log = logger.CreateLogger<AbstractService>();
+            Log = logger.GetLogger(typeof(AbstractService));
 
             if (currentPrincipal == null)
             {
@@ -25,7 +25,7 @@ namespace Quadarax.Foundation.Core.Business
                 currentPrincipal = new GenericPrincipal(genericIdentity, new string[] {});
             }
             CurrentPrincipal = currentPrincipal;
-            Log.LogTrace($"Service '{GetType().Name}' [Hash:{GetHashCode()}] initialized.");
+            Log.Log(LogSeverityEnum.Trace, $"Service '{GetType().Name}' [Hash:{GetHashCode()}] initialized.");
         }
         #endregion
 
@@ -37,4 +37,6 @@ namespace Quadarax.Foundation.Core.Business
 
         #endregion
     }
+
+ 
 }

+ 3 - 3
qdr.fnd.core.business/Security/PasswordHelper.cs

@@ -13,7 +13,7 @@ namespace Quadarax.Foundation.Core.Business.Security
             {
                 throw new ArgumentNullException("password");
             }
-            using (Rfc2898DeriveBytes bytes = new Rfc2898DeriveBytes(password, 0x10, 0x3e8))
+            using (var bytes = new Rfc2898DeriveBytes(password, 0x10, 0x3e8, HashAlgorithmName.SHA256))
             {
                 salt = bytes.Salt;
                 buffer2 = bytes.GetBytes(0x20);
@@ -44,7 +44,7 @@ namespace Quadarax.Foundation.Core.Business.Security
             Buffer.BlockCopy(src, 1, dst, 0, 0x10);
             byte[] buffer3 = new byte[0x20];
             Buffer.BlockCopy(src, 0x11, buffer3, 0, 0x20);
-            using (Rfc2898DeriveBytes bytes = new Rfc2898DeriveBytes(password, dst, 0x3e8))
+            using (var bytes = new Rfc2898DeriveBytes(password, dst, 0x3e8, HashAlgorithmName.SHA256))
             {
                 buffer4 = bytes.GetBytes(0x20);
             }
@@ -56,7 +56,7 @@ namespace Quadarax.Foundation.Core.Business.Security
             if (b1 == b2) return true;
             if (b1 == null || b2 == null) return false;
             if (b1.Length != b2.Length) return false;
-            for (int i=0; i < b1.Length; i++)
+            for (int i = 0; i < b1.Length; i++)
             {
                 if (b1[i] != b2[i]) return false;
             }

+ 5 - 5
qdr.fnd.core.business/qdr.fnd.core.business.csproj

@@ -15,15 +15,15 @@
     <Copyright>Copyright © 2023, 2024, 2025 Quadarax</Copyright>
     <PackageIcon>quadarax_dll.png</PackageIcon>
     <PackageTags>QDR;FND;CORE;BUSSINES</PackageTags>
-    <AssemblyVersion>0.0.4.0</AssemblyVersion>
-    <FileVersion>0.0.4.0</FileVersion>
-    <Version>0.0.4.0-alpha</Version>
+    <AssemblyVersion>0.0.5.0</AssemblyVersion>
+    <FileVersion>0.0.5.0</FileVersion>
+    <Version>0.0.5.0-alpha</Version>
     <Nullable>enable</Nullable>
     <PackageReadmeFile>releasenotes.md</PackageReadmeFile>
     <PackageReleaseNotes>
       Date:7.1.2025
-		- update dependency to qdr.fnd.core v.0.0.6.0
-		- update to .NET 9.0
+		- Change AbstractService base depends on qdr.fnd.core.logging.ILogger instead of ILoggerFactory
+		- fix obsolete implementation in PasswordHelper
     </PackageReleaseNotes>
   </PropertyGroup>
 

+ 6 - 0
qdr.fnd.core.business/releasenotes.md

@@ -1,5 +1,11 @@
 # Quadarax.Foundation.Core * Release notes
 Ordered by version descending
+
+## 0.0.5.0
+Date:__9.1.2025__
+- Change AbstractService base depends on qdr.fnd.core.logging.ILogger instead of ILoggerFactory
+- fix obsolete implementation in PasswordHelper
+---
 ## 0.0.4.0
 Date:__7.1.2025__
 - update dependency to qdr.fnd.core v.0.0.6.0

+ 132 - 132
qdr.fnd.core.data/Extensions/SqlConnectionExt.cs

@@ -1,133 +1,133 @@
-using System;
-using System.Data;
-using System.Data.SqlClient;
-
-namespace Quadarax.Foundation.Core.Data.Extensions
-{
-    public static class SqlConnectionExt
-    {
+using System;
+using System.Data;
+using System.Data.SqlClient;
+
+namespace Quadarax.Foundation.Core.Data.Extensions
+{
+    public static class SqlConnectionExt
+    {
        
-        public static SqlDataReader Query(this SqlConnection owner, string query, params SqlParameter[] parameters)
-        {
-            if (owner == null)
-                throw new ArgumentNullException(nameof(owner));
-            if (string.IsNullOrEmpty(query))
-                throw new ArgumentNullException(nameof(query));
-
-            var command = owner.CreateCommand();
-            command.CommandText = query;
-            command.CommandType = CommandType.Text;
-
-            if (parameters!=null)
-                foreach (var par in parameters)
-                    command.Parameters.Add(par);
-
-            return command.ExecuteReader(CommandBehavior.Default);
-        }
-
-        public static int Execute(this SqlConnection owner, string query, params SqlParameter[] parameters)
-        {
-            return Execute(owner, CommandType.Text, query, parameters);
-        }
-
-        public static int BatchExecute(this SqlConnection owner, string query, params SqlParameter[] parameters)
-        {
-            var result = 0;
-            var sqlBatch = string.Empty;
-
-            query += "\nGO"; // make sure last batch is executed.
-            foreach (var line in query.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries))
-            {
-                if (line.ToUpperInvariant().Trim() == "GO")
-                {
-                    if (string.IsNullOrEmpty(sqlBatch)) continue;
-                    result = Execute(owner, sqlBatch, parameters);
-                    sqlBatch = string.Empty;
-                }
-                else
-                {
-                    sqlBatch += line + "\n";
-                }
-            }
-
-            return result;
-        }
-
-        public static int ExecuteSp(this SqlConnection owner, string query, params SqlParameter[] parameters)
-        {
-            return Execute(owner, CommandType.StoredProcedure, query, parameters);
-        }
-
-        public static TResult ExecuteScalar<TResult>(this SqlConnection owner,CommandType type, string query, params SqlParameter[] parameters)
-        {
-            if (owner == null)
-                throw new ArgumentNullException(nameof(owner));
-            if (string.IsNullOrEmpty(query))
-                throw new ArgumentNullException(nameof(query));
-
-            var command = owner.CreateCommand();
-            command.CommandText = query;
-            command.CommandType = type;
-
-            if (parameters!=null)
-                foreach (var par in parameters)
-                    command.Parameters.Add(par);
-
-            return (TResult)command.ExecuteScalar();
-        }
-
-        public static int Execute(this SqlConnection owner, CommandType type, string query,
-            params SqlParameter[] parameters)
-        {
-            if (owner == null)
-                throw new ArgumentNullException(nameof(owner));
-            if (string.IsNullOrEmpty(query))
-                throw new ArgumentNullException(nameof(query));
-
-            var command = new SqlCommand(query, owner);
-            command.CommandType = type;
-
-            if (parameters != null)
-                foreach (var par in parameters)
-                    command.Parameters.Add(par);
-
-            var result = command.ExecuteNonQuery();
-            return result;
-        }
-
-        public static bool DatabasePropertyExists(this SqlConnection owner, string databaseProperty)
-        {
-            return ExecuteScalar<int>(owner, CommandType.Text, $"select count(*) FROM SYS.EXTENDED_PROPERTIES where name='{databaseProperty}' and class_desc = 'DATABASE'") > 0;
-        }
-
-        public static string DatabasePropertyGet(this SqlConnection owner, string databaseProperty)
-        {
-            if (DatabasePropertyExists(owner, databaseProperty))
-                return ExecuteScalar<string>(owner, CommandType.Text, $"select [value] FROM SYS.EXTENDED_PROPERTIES where name='{databaseProperty}' and class_desc = 'DATABASE'");
-            else
-                return string.Empty;
-        }
-
-        public static bool DatabasePropertyAddOrUpdate(this SqlConnection owner, string databaseProperty, string value)
-        {
-            bool result;
-            var spParams = new SqlParameter[]
-            {
-                new SqlParameter("@name", SqlDbType.VarChar) { Value = databaseProperty },
-                new SqlParameter("@value", SqlDbType.VarChar) { Value = value },
-            };
-
-            if (DatabasePropertyExists(owner, databaseProperty))
-            {
-                result = ExecuteSp(owner, "sys.sp_updateextendedproperty", spParams) > 0;
-            }
-            else
-            {
-                result = ExecuteSp(owner, "sys.sp_addextendedproperty", spParams) > 0;
-            }
-
-            return result;
-        }
-
-    }
-}
+        public static SqlDataReader Query(this SqlConnection owner, string query, params SqlParameter[] parameters)
+        {
+            if (owner == null)
+                throw new ArgumentNullException(nameof(owner));
+            if (string.IsNullOrEmpty(query))
+                throw new ArgumentNullException(nameof(query));
+
+            var command = owner.CreateCommand();
+            command.CommandText = query;
+            command.CommandType = CommandType.Text;
+
+            if (parameters!=null)
+                foreach (var par in parameters)
+                    command.Parameters.Add(par);
+
+            return command.ExecuteReader(CommandBehavior.Default);
+        }
+
+        public static int Execute(this SqlConnection owner, string query, params SqlParameter[] parameters)
+        {
+            return Execute(owner, CommandType.Text, query, parameters);
+        }
+
+        public static int BatchExecute(this SqlConnection owner, string query, params SqlParameter[] parameters)
+        {
+            var result = 0;
+            var sqlBatch = string.Empty;
+
+            query += "\nGO"; // make sure last batch is executed.
+            foreach (var line in query.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries))
+            {
+                if (line.ToUpperInvariant().Trim() == "GO")
+                {
+                    if (string.IsNullOrEmpty(sqlBatch)) continue;
+                    result = Execute(owner, sqlBatch, parameters);
+                    sqlBatch = string.Empty;
+                }
+                else
+                {
+                    sqlBatch += line + "\n";
+                }
+            }
+
+            return result;
+        }
+
+        public static int ExecuteSp(this SqlConnection owner, string query, params SqlParameter[] parameters)
+        {
+            return Execute(owner, CommandType.StoredProcedure, query, parameters);
+        }
+
+        public static TResult ExecuteScalar<TResult>(this SqlConnection owner,CommandType type, string query, params SqlParameter[] parameters)
+        {
+            if (owner == null)
+                throw new ArgumentNullException(nameof(owner));
+            if (string.IsNullOrEmpty(query))
+                throw new ArgumentNullException(nameof(query));
+
+            var command = owner.CreateCommand();
+            command.CommandText = query;
+            command.CommandType = type;
+
+            if (parameters!=null)
+                foreach (var par in parameters)
+                    command.Parameters.Add(par);
+
+            return (TResult)command.ExecuteScalar();
+        }
+
+        public static int Execute(this SqlConnection owner, CommandType type, string query,
+            params SqlParameter[] parameters)
+        {
+            if (owner == null)
+                throw new ArgumentNullException(nameof(owner));
+            if (string.IsNullOrEmpty(query))
+                throw new ArgumentNullException(nameof(query));
+
+            var command = new SqlCommand(query, owner);
+            command.CommandType = type;
+
+            if (parameters != null)
+                foreach (var par in parameters)
+                    command.Parameters.Add(par);
+
+            var result = command.ExecuteNonQuery();
+            return result;
+        }
+
+        public static bool DatabasePropertyExists(this SqlConnection owner, string databaseProperty)
+        {
+            return ExecuteScalar<int>(owner, CommandType.Text, $"select count(*) FROM SYS.EXTENDED_PROPERTIES where name='{databaseProperty}' and class_desc = 'DATABASE'") > 0;
+        }
+
+        public static string DatabasePropertyGet(this SqlConnection owner, string databaseProperty)
+        {
+            if (DatabasePropertyExists(owner, databaseProperty))
+                return ExecuteScalar<string>(owner, CommandType.Text, $"select [value] FROM SYS.EXTENDED_PROPERTIES where name='{databaseProperty}' and class_desc = 'DATABASE'");
+            else
+                return string.Empty;
+        }
+
+        public static bool DatabasePropertyAddOrUpdate(this SqlConnection owner, string databaseProperty, string value)
+        {
+            bool result;
+            var spParams = new SqlParameter[]
+            {
+                new SqlParameter("@name", SqlDbType.VarChar) { Value = databaseProperty },
+                new SqlParameter("@value", SqlDbType.VarChar) { Value = value },
+            };
+
+            if (DatabasePropertyExists(owner, databaseProperty))
+            {
+                result = ExecuteSp(owner, "sys.sp_updateextendedproperty", spParams) > 0;
+            }
+            else
+            {
+                result = ExecuteSp(owner, "sys.sp_addextendedproperty", spParams) > 0;
+            }
+
+            return result;
+        }
+
+    }
+}