Przeglądaj źródła

sync changes fnd

Dalibor Votruba 2 lat temu
rodzic
commit
273c9d49db
32 zmienionych plików z 633 dodań i 119 usunięć
  1. 45 0
      Common/qdr.fnd.core/Data/Error.cs
  2. 33 0
      Common/qdr.fnd.core/Data/Extensions/PagingExt.cs
  3. 34 0
      Common/qdr.fnd.core/Data/IError.cs
  4. 9 0
      Common/qdr.fnd.core/Data/IPaging.cs
  5. 23 0
      Common/qdr.fnd.core/Data/IResult.cs
  6. 12 0
      Common/qdr.fnd.core/Data/ITypedArgument.cs
  7. 32 0
      Common/qdr.fnd.core/Data/Paging.cs
  8. 58 0
      Common/qdr.fnd.core/Data/Result.cs
  9. 38 0
      Common/qdr.fnd.core/Data/TypedArgument.cs
  10. 20 0
      Common/qdr.fnd.core/Exceptions/ExceptionExc.cs
  11. 2 2
      Common/qdr.fnd.core/Exceptions/TryCatchExt.cs
  12. 1 3
      Common/qdr.fnd.core/Json/ListConverter.cs
  13. 64 0
      Common/qdr.fnd.core/Logging/ConsoleLog.cs
  14. 16 0
      Common/qdr.fnd.core/Logging/ConsoleLogger.cs
  15. 2 2
      Common/qdr.fnd.core/Logging/ILog.cs
  16. 1 1
      Common/qdr.fnd.core/Logging/ILogHandler.cs
  17. 2 5
      Common/qdr.fnd.core/Object/Extensions/ObjectExt.cs
  18. 2 2
      Common/qdr.fnd.core/Object/Singleton.cs
  19. 1 1
      Common/qdr.fnd.core/Object/WeakReference.cs
  20. 7 9
      Common/qdr.fnd.core/Reflection/AttributeQuery.cs
  21. 4 2
      Common/qdr.fnd.core/Reflection/Extensions/ActivatorExt.cs
  22. 8 2
      Common/qdr.fnd.core/Reflection/Extensions/AssemblyExt.cs
  23. 7 6
      Common/qdr.fnd.core/Reflection/Extensions/TypeExt.cs
  24. 14 7
      Common/qdr.fnd.core/Reflection/QualifiedName.cs
  25. 54 51
      Common/qdr.fnd.core/Reflection/TypeUtils.cs
  26. 15 0
      Common/qdr.fnd.core/Value/Extensions/EnumExt.cs
  27. 50 5
      Common/qdr.fnd.core/Value/Extensions/EnumerableExt.cs
  28. 28 0
      Common/qdr.fnd.core/Value/Extensions/ListExt.cs
  29. 1 7
      Common/qdr.fnd.core/Value/Extensions/TimeSpanExt.cs
  30. 6 8
      Common/qdr.fnd.core/Value/Formatters/HmsFormatter.cs
  31. 7 6
      Common/qdr.fnd.core/Value/Formatters/PluralFormatter.cs
  32. 37 0
      Common/qdr.fnd.core/Value/ValueConverter.cs

+ 45 - 0
Common/qdr.fnd.core/Data/Error.cs

@@ -0,0 +1,45 @@
+using System.Text;
+using Quadarax.Foundation.Core.Exceptions;
+
+namespace Quadarax.Foundation.Core.Data
+{
+    public class Error : IError
+    {
+        #region *** Properties ***
+        public string Message { get; }
+        public int Code { get; }
+        public ErrorLevelEnum Level { get; }
+
+        #endregion
+
+        #region *** Constructors ***
+        public Error(string message, int code, ErrorLevelEnum level)
+        {
+            Message = message;
+            Code = code;
+            Level = level;
+        }
+        public Error(Exception exception)
+        {
+            if (exception==null)
+                throw new ArgumentNullException(nameof(exception));
+
+            Message = exception.Message;
+            Code = exception.GetCode();
+        }
+        #endregion
+
+        #region *** Operations ***
+        public override string ToString()
+        {
+            var sb = new StringBuilder();
+            sb.Append("Error");
+            if (Code != 0)
+                sb.Append("[").Append(Code).Append("]");
+            sb.Append(":").Append(Message);
+            return sb.ToString();
+        }
+
+        #endregion
+    }
+}

+ 33 - 0
Common/qdr.fnd.core/Data/Extensions/PagingExt.cs

@@ -0,0 +1,33 @@
+namespace Quadarax.Foundation.Core.Data.Extensions
+{
+    public static class PagingExt
+    {
+        public static IQueryable<TEntity> Page<TEntity>(this IQueryable<TEntity> queryable, IPaging paging, int overlap = 0)
+        {
+            return queryable.Page(paging.IsDisabled ? null : paging.Page, paging.IsDisabled ? null :paging.PageSize, overlap);
+        }
+        public static IQueryable<TEntity> Page<TEntity>(this IQueryable<TEntity> queryable, int? page, int? pageSize, int overlap = 0)
+        {
+            if (!(page.HasValue && pageSize.HasValue))
+                return queryable;
+
+            pageSize = pageSize.GetValueOrDefault(int.MaxValue);
+
+            return queryable.Skip(page.Value * pageSize.Value).Take(pageSize.Value + overlap);
+        }
+
+        public static IEnumerable<TEntity> Page<TEntity>(this IEnumerable<TEntity> queryable, IPaging paging, int overlap = 0)
+        {
+            return queryable.Page(paging.IsDisabled ? null : paging.Page, paging.IsDisabled ? null :paging.PageSize, overlap);
+        }
+
+        public static IEnumerable<TEntity> Page<TEntity>(this IEnumerable<TEntity> queryable, int? page, int? pageSize, int overlap = 0)
+        {
+            if (!(page.HasValue && pageSize.HasValue))
+                return queryable;
+            pageSize = pageSize.GetValueOrDefault(int.MaxValue);
+
+            return queryable.Skip(page.Value * pageSize.Value).Take(pageSize.Value + overlap);
+        }
+    }
+}

+ 34 - 0
Common/qdr.fnd.core/Data/IError.cs

@@ -0,0 +1,34 @@
+namespace Quadarax.Foundation.Core.Data
+{
+
+    /// <summary>
+    /// Defines error message structure
+    /// </summary>
+    public interface IError
+    {
+        /// <summary>
+        /// Full error message
+        /// </summary>
+        public string Message { get; }
+        /// <summary>
+        /// Error message short numeric code
+        /// </summary>
+        public int Code { get; }
+        /// <summary>
+        /// Defines error level
+        /// </summary>
+        public ErrorLevelEnum Level { get; }
+    }
+
+    /// <summary>
+    /// Error levels enumeration
+    /// </summary>
+    public enum ErrorLevelEnum
+    {
+        Note,
+        Warning,
+        Error,
+        Critical,
+        Fatal
+    }
+}

+ 9 - 0
Common/qdr.fnd.core/Data/IPaging.cs

@@ -0,0 +1,9 @@
+namespace Quadarax.Foundation.Core.Data
+{
+    public interface IPaging
+    {
+        int Page { get; }
+        int PageSize { get; }
+        bool IsDisabled { get; }
+    }
+}

+ 23 - 0
Common/qdr.fnd.core/Data/IResult.cs

@@ -0,0 +1,23 @@
+namespace Quadarax.Foundation.Core.Data
+{
+    /// <summary>
+    /// Represents structure of result state
+    /// </summary>
+    public interface IResult
+    {
+        /// <summary>
+        /// Gets if result is logically success
+        /// </summary>
+        bool IsSuccess { get; }
+        /// <summary>
+        /// Collection of error items
+        /// </summary>
+        public IEnumerable<IError> Errors { get; }
+
+        /// <summary>
+        /// Returns result value
+        /// </summary>
+        /// <returns>Value</returns>
+        public object? GetValue();
+    }
+}

+ 12 - 0
Common/qdr.fnd.core/Data/ITypedArgument.cs

@@ -0,0 +1,12 @@
+namespace Quadarax.Foundation.Core.Data;
+
+public interface ITypedArgument
+{
+    string Name {get;}
+    string? Value { get; }
+    public Type ValueType { get; }
+    bool IsOutput { get; }
+
+    TValue? GetTypedValue<TValue>();
+
+}

+ 32 - 0
Common/qdr.fnd.core/Data/Paging.cs

@@ -0,0 +1,32 @@
+using System.Text;
+
+namespace Quadarax.Foundation.Core.Data
+{
+    public class Paging : IPaging
+    {
+        #region *** Properties ***
+        public int Page { get; protected set; }
+        public int PageSize { get; protected set; }
+        public bool IsDisabled { get; protected set; }
+        public static IPaging NoPaging => new Paging(0, 0);
+        #endregion
+
+        #region *** Constructors ***
+        public Paging(int page, int pageSize)
+        {
+            Page = page;
+            PageSize = pageSize;
+            IsDisabled = (PageSize == 0);
+        }
+        #endregion
+
+        #region *** Operations ***
+        public override string ToString()
+        {
+            var sb = new StringBuilder();
+            sb.Append("Paging:").Append(IsDisabled ? "Disabled" : "Enabled").Append(";Page=").Append(Page).Append(";PageSize=").Append(PageSize);
+            return sb.ToString();
+        }
+        #endregion
+    }
+}

+ 58 - 0
Common/qdr.fnd.core/Data/Result.cs

@@ -0,0 +1,58 @@
+using Quadarax.Foundation.Core.Value.Extensions;
+
+namespace Quadarax.Foundation.Core.Data
+{
+    public class Result : IResult
+    {
+        #region *** Properties ***
+        public bool IsSuccess { get; protected set; }
+        public IEnumerable<IError> Errors => _errors;
+        public static IResult Ok => new Result();
+        public static IResult Fail => new Result(false, new List<IError> { new Error("Operation failed", 0, ErrorLevelEnum.Error) });
+        #endregion
+
+        #region *** Private Fields ***
+        private readonly IList<IError> _errors = new List<IError>();
+        #endregion
+
+        #region *** Constructors ***
+
+        public Result() : this(true, null)
+        {
+        }
+        public Result(IEnumerable<IError> errors) : this(false, errors)
+        {
+        }
+        public Result(bool isSuccess, IEnumerable<IError>? errors)
+        {
+            errors ??= new List<IError>();
+            IsSuccess = isSuccess;
+            _errors.AddRange(errors);
+        }
+        #endregion
+
+        #region *** Operations ***
+        public void SetSuccess(bool isSuccess)
+        {
+            IsSuccess = isSuccess;
+        }
+        public void AddError(IError error)
+        {
+            if (error == null)
+                throw new ArgumentNullException(nameof(error));
+
+            _errors.Add(error);
+        }
+
+        public void ClearErrors()
+        {
+            _errors.Clear();
+        }
+
+        public object? GetValue()
+        {
+            return null;
+        }
+        #endregion
+    }
+}

+ 38 - 0
Common/qdr.fnd.core/Data/TypedArgument.cs

@@ -0,0 +1,38 @@
+using System;
+using System.Net.Http.Headers;
+using Quadarax.Foundation.Core.Value;
+
+namespace Quadarax.Foundation.Core.Data;
+
+public class TypedArgument : ITypedArgument
+{
+    public string Name {get; private set;}
+    public string? Value {get; private set;}  //TODO: must be nullable
+    public Type ValueType {get; private set;}
+       
+    public bool IsOutput {get; private set;}
+       
+    public TypedArgument(string name, string? valueAsString, Type? valueType, bool isOutput = false)
+    {
+        Name = name ?? throw new ArgumentNullException(nameof(name));
+        ValueType = valueType ?? throw new ArgumentNullException(nameof(valueType));
+        Value = valueAsString;
+        IsOutput = isOutput;
+    }
+    public TypedArgument(string name, Type valueType, bool isOutput = false) : this(name, string.Empty, valueType, isOutput)
+    {
+         
+    }
+    public TypedArgument(string name, object valueTyped, bool isOutput = false) : this(name, valueTyped?.ToString(), valueTyped?.GetType(), isOutput)
+    {
+         
+    }
+
+    public TValue? GetTypedValue<TValue>()
+    {
+        if (Value == null) return default(TValue);
+        return ValueConverter.ConvertTo<TValue>(Value);
+    }
+
+}
+   

+ 20 - 0
Common/qdr.fnd.core/Exceptions/ExceptionExc.cs

@@ -16,5 +16,25 @@ namespace Quadarax.Foundation.Core.Exceptions
         {
             e.Data.Add("Code", code);
         }
+
+        public static string Dump(this Exception e)
+        {
+            var level = 0;
+            var sb = new System.Text.StringBuilder();
+            sb.Append("[#").Append(level).Append("]:").AppendLine(e.Message);
+            var inner = e.InnerException;
+            while (inner != null)
+            {
+                sb.Append("[#").Append(level).Append("]:").AppendLine(inner.Message);
+                inner = inner.InnerException;
+            }
+
+            if (e.StackTrace != null)
+            {
+                sb.AppendLine("[#0] Stack list:");
+                sb.AppendLine(e.StackTrace);
+            }
+            return sb.ToString();
+        }
     }
 }

+ 2 - 2
Common/qdr.fnd.core/Exceptions/TryCatchExt.cs

@@ -4,7 +4,7 @@ namespace Quadarax.Foundation.Core.Exceptions
 {
     public static class TryCatchExt
     {
-        public static Exception TryCatch<TResult>(this object owner, Func<TResult> fnc)
+        public static Exception? TryCatch<TResult>(this object owner, Func<TResult>? fnc)
         {
             if (owner == null)
                 throw new ArgumentNullException(nameof(owner));
@@ -21,7 +21,7 @@ namespace Quadarax.Foundation.Core.Exceptions
 
             return null;
         }
-        public static Exception TryCatch(this object owner, Action fnc)
+        public static Exception? TryCatch(this object owner, Action? fnc)
         {
             if (owner == null)
                 throw new ArgumentNullException(nameof(owner));

+ 1 - 3
Common/qdr.fnd.core/Json/ListConverter.cs

@@ -1,6 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Text.Json;
+using System.Text.Json;
 using System.Text.Json.Serialization;
 
 namespace Quadarax.Foundation.Core.Json

+ 64 - 0
Common/qdr.fnd.core/Logging/ConsoleLog.cs

@@ -0,0 +1,64 @@
+using Quadarax.Foundation.Core.Console;
+
+namespace Quadarax.Foundation.Core.Logging
+{
+    public class ConsoleLog : ILog
+    {
+        private string _typeName;
+
+		private ConsoleWriter _infoWriter = new ConsoleWriter(ConsoleColor.White);
+        private ConsoleWriter _debugWriter = new ConsoleWriter(ConsoleColor.Green);
+        private ConsoleWriter _warnWriter = new ConsoleWriter(ConsoleColor.Yellow);
+        private ConsoleWriter _errorWriter = new ConsoleWriter(ConsoleColor.Red);
+        private ConsoleWriter _traceWriter = new ConsoleWriter(ConsoleColor.DarkGray);
+        public ConsoleLog(Type owningType)
+        {
+            _typeName = owningType.Name;
+        }
+
+        public ConsoleLog(string owningTypeName)
+        {
+            _typeName = owningTypeName;
+        }
+
+        public void Log(LogSeverityEnum severity, int code, string message)
+        {
+			Log(severity, $"Code:{code}, {message}");            
+        }
+
+        public void Log(LogSeverityEnum severity, string message)
+        {
+            var now = DateTime.Now;
+            var thNum = Thread.CurrentThread.ManagedThreadId;
+
+            var final = $"[{severity}:{now.ToLongTimeString()}:{thNum}]#{_typeName}: {message}";
+
+            switch (severity)
+            {
+                case LogSeverityEnum.Info:
+                    _infoWriter.WriteLine(final);
+                    break;
+                case LogSeverityEnum.Debug:
+                    _debugWriter.WriteLine(final);
+                    break;
+                case LogSeverityEnum.Warn:
+                    _warnWriter.WriteLine(final);
+                    break;
+                case LogSeverityEnum.Fatal:
+                case LogSeverityEnum.Error:
+                    _errorWriter.WriteLine(final);
+                    break;
+            }
+        }
+
+        public void Log(LogSeverityEnum severity, string message, Exception? exception)
+        {
+            Log(severity, $"{message}\n{exception}");
+        }
+
+        public void Log(LogSeverityEnum severity, int code, string message, Exception? exception)
+        {
+            Log(severity, string.Format("{2} - {0}\n{1}", message,exception, code));
+        }
+    }
+}

+ 16 - 0
Common/qdr.fnd.core/Logging/ConsoleLogger.cs

@@ -0,0 +1,16 @@
+
+namespace Quadarax.Foundation.Core.Logging
+{
+    public class ConsoleLogger : ILogger
+    {
+        public ILog GetLogger(string loggerName)
+        {
+            return new ConsoleLog(loggerName);
+        }
+
+        public ILog GetLogger(Type loggerForType)
+        {
+            return new ConsoleLog(loggerForType);
+        }
+    }
+}

+ 2 - 2
Common/qdr.fnd.core/Logging/ILog.cs

@@ -6,7 +6,7 @@ namespace Quadarax.Foundation.Core.Logging
     {
         void Log(LogSeverityEnum severity, int code, string message);
         void Log(LogSeverityEnum severity, string message);
-        void Log(LogSeverityEnum severity, string message, Exception exception);
-        void Log(LogSeverityEnum severity, int code, string message, Exception exception);
+        void Log(LogSeverityEnum severity, string message, Exception? exception);
+        void Log(LogSeverityEnum severity, int code, string message, Exception? exception);
     }
 }

+ 1 - 1
Common/qdr.fnd.core/Logging/ILogHandler.cs

@@ -4,6 +4,6 @@ namespace Quadarax.Foundation.Core.Logging
 {
     public interface ILogHandler
     {
-        void Log(LogSeverityEnum type, string message, Exception e = null);
+        void Log(LogSeverityEnum type, string message, Exception? e = null);
     }
 }

+ 2 - 5
Common/qdr.fnd.core/Object/Extensions/ObjectExt.cs

@@ -1,16 +1,13 @@
 using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
 using Quadarax.Foundation.Core.Reflection.Extensions;
 
 namespace Quadarax.Foundation.Core.Object.Extensions
 {
     public static class ObjectExt
     {
-        public static IDictionary<string, object> GetAllPropertyValues(this object obj,string indentPrefix = null)
+        public static IDictionary<string, object?> GetAllPropertyValues(this object? obj,string? indentPrefix = null)
         {
-            var props = new Dictionary<string, object>();
+            var props = new Dictionary<string, object?>();
             if (obj == null)
                 return props;
 

+ 2 - 2
Common/qdr.fnd.core/Object/Singleton.cs

@@ -11,7 +11,7 @@
         /// <typeparam name="TInstance"></typeparam>
         public class Singleton<TInstance> where TInstance : new()
         {
-            private static TInstance _instance;
+            private static TInstance? _instance;
             private static readonly object _syncRoot = new object();
 
             /// <summary>
@@ -48,7 +48,7 @@
             where TInstance : TInterface, new()
             where TInterface : class
         {
-            private static volatile TInterface _instance;
+            private static volatile TInterface? _instance;
             private static readonly object _syncRoot = new object();
 
             public static TInterface Instance

+ 1 - 1
Common/qdr.fnd.core/Object/WeakReference.cs

@@ -22,7 +22,7 @@ namespace Quadarax.Foundation.Core.Object
         /// <summary>
         /// Strongly typed version of <see cref="WeakReference.Target"/>.
         /// </summary>
-        public new TReference Target
+        public new TReference? Target
         {
             get { return base.Target as TReference; }
             set { base.Target = value; }

+ 7 - 9
Common/qdr.fnd.core/Reflection/AttributeQuery.cs

@@ -1,6 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
+using System.Reflection;
 
 namespace Quadarax.Foundation.Core.Reflection
 {
@@ -15,7 +13,7 @@ namespace Quadarax.Foundation.Core.Reflection
         public static TAttributeType Get<TAttributeProvider>(TAttributeProvider oProvider, bool bInherit)
             where TAttributeProvider : ICustomAttributeProvider
         {
-            TAttributeType attribute = Find(oProvider, bInherit);
+            var attribute = Find(oProvider, bInherit);
             if (attribute == null)
             {
                 throw new Exception($"Cannot find attribute '{typeof(TAttributeType).Name}' inside class '{oProvider.GetType().AssemblyQualifiedName}'");
@@ -23,23 +21,23 @@ namespace Quadarax.Foundation.Core.Reflection
             return attribute;
         }
 
-        public static TAttributeType Find<TAttributeProvider>(TAttributeProvider oProvider, bool bInherit)
+        public static TAttributeType? Find<TAttributeProvider>(TAttributeProvider oProvider, bool bInherit)
             where TAttributeProvider : ICustomAttributeProvider
         {
-            TAttributeType[] attributes = FindAll(oProvider, bInherit);
+            var attributes = FindAll(oProvider, bInherit);
             return attributes.Length > 0 ? attributes[0] : null;
         }
 
-        public static TAttributeType[] FindAll<TAttributeProvider>(TAttributeProvider oProvider)
+        public static TAttributeType?[] FindAll<TAttributeProvider>(TAttributeProvider oProvider)
             where TAttributeProvider : ICustomAttributeProvider
         {
             return FindAll(oProvider, true);
         }
 
-        public static TAttributeType[] FindAll<TAttributeProvider>(TAttributeProvider oProvider, bool bInherit)
+        public static TAttributeType?[] FindAll<TAttributeProvider>(TAttributeProvider oProvider, bool bInherit)
             where TAttributeProvider : ICustomAttributeProvider
         {
-            return (TAttributeType[])oProvider.GetCustomAttributes(typeof(TAttributeType), bInherit);
+            return (TAttributeType?[])oProvider.GetCustomAttributes(typeof(TAttributeType), bInherit);
         }
 
         public static MemberInfo[] GetMembers(Type oSource, BindingFlags eFlags)

+ 4 - 2
Common/qdr.fnd.core/Reflection/Extensions/ActivatorExt.cs

@@ -11,9 +11,11 @@ namespace Quadarax.Foundation.Core.Reflection.Extensions
         #region *** Constructors ***
         #endregion
         #region *** Public operations & overrides ***
-        public static object CreateInstance(string sClassOrInterfaceQualifiedName, bool bLoadAssemblyIfNeeded, params object[] aConstructorParams)
+        public static object? CreateInstance(string sClassOrInterfaceQualifiedName, bool bLoadAssemblyIfNeeded, params object[] aConstructorParams)
         {
             var oType = Type.GetType(sClassOrInterfaceQualifiedName, false) ?? TypeUtils.GetRemoteType(sClassOrInterfaceQualifiedName);
+            if (oType == null) return null;
+
             if (oType.IsInterface)
             {
                 throw new ArgumentException($"Input class name '{sClassOrInterfaceQualifiedName}' cannot be an interface.",nameof(sClassOrInterfaceQualifiedName));
@@ -22,7 +24,7 @@ namespace Quadarax.Foundation.Core.Reflection.Extensions
         }
         public static T CreateInstance<T>(string sClassOrInterfaceQualifiedName, bool bLoadAssemblyIfNeeded, params object[] aConstructorParams)
         {
-            return (T) CreateInstance(sClassOrInterfaceQualifiedName, bLoadAssemblyIfNeeded, aConstructorParams);
+            return (T) CreateInstance(sClassOrInterfaceQualifiedName, bLoadAssemblyIfNeeded, aConstructorParams)!;
         }
         #endregion
         #region *** Private operations & overrides ***

+ 8 - 2
Common/qdr.fnd.core/Reflection/Extensions/AssemblyExt.cs

@@ -15,8 +15,11 @@ namespace Quadarax.Foundation.Core.Reflection.Extensions
         #region *** Constructors ***
         #endregion
         #region *** Public operations & overrides ***
-        public static Version GetVersion(this Assembly oAssembly)
+        public static Version? GetVersion(this Assembly oAssembly)
         {
+            if (oAssembly == null)
+                throw new ArgumentNullException(nameof(oAssembly));
+
             return oAssembly.GetName().Version;
         }
         public static string GetDescription(this Assembly oAssembly)
@@ -56,7 +59,10 @@ namespace Quadarax.Foundation.Core.Reflection.Extensions
         }
         public static string GetAssemblyPath(this Assembly oAssembly)
         {
-            return Path.GetDirectoryName(new Uri(oAssembly.CodeBase).LocalPath) + Path.DirectorySeparatorChar;
+            if (oAssembly == null)
+                throw new ArgumentNullException(nameof(oAssembly));
+
+            return Path.GetDirectoryName(new Uri(oAssembly.Location)?.LocalPath) + Path.DirectorySeparatorChar;
         }
         public static IEnumerable<Type> GetTypesWithAttribute<TAttribute>(this Assembly oAssembly, bool bInherit)where TAttribute : System.Attribute
         {

+ 7 - 6
Common/qdr.fnd.core/Reflection/Extensions/TypeExt.cs

@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Security.Cryptography.X509Certificates;
+using System.Reflection;
 
 namespace Quadarax.Foundation.Core.Reflection.Extensions
 {
@@ -14,8 +10,13 @@ namespace Quadarax.Foundation.Core.Reflection.Extensions
             return methods.Where(x => x.IsDefined(typeof(TAttribute), bInherit)).ToArray();
         }
 
+        public static IEnumerable<PropertyInfo> GetPropertiesWithAttribute<TAttribute>(this Type type, bool bInherit)where TAttribute : System.Attribute
+        {
+            var properties = type.GetProperties();
+            return properties.Where(x => x.IsDefined(typeof(TAttribute), bInherit)).ToArray();
+        }
 
-        public static IList<PropertyInfo> GetAllProperties(this Type type)
+        public static IList<PropertyInfo> GetAllProperties(this Type? type)
         {
             if (type == null)
                 return new List<PropertyInfo>();

+ 14 - 7
Common/qdr.fnd.core/Reflection/QualifiedName.cs

@@ -1,6 +1,4 @@
-using System;
-using System.Linq;
-using System.Reflection;
+using System.Reflection;
 using Quadarax.Foundation.Core.Reflection.Extensions;
 
 namespace Quadarax.Foundation.Core.Reflection
@@ -15,8 +13,8 @@ namespace Quadarax.Foundation.Core.Reflection
         // ReSharper disable MemberCanBePrivate.Global
         // ReSharper disable UnusedAutoPropertyAccessor.Global
         public string Name { get; private set; }
-        public string Assembly { get; private set; }
-        public string Culture { get; private set; }
+        public string? Assembly { get; private set; }
+        public string? Culture { get; private set; }
         public string Token { get; private set; }
         public string Version { get; private set; }
         public string AssemblyFullName { get; private set; }
@@ -26,6 +24,10 @@ namespace Quadarax.Foundation.Core.Reflection
         #region *** Constructors ***
         public QualifiedName(string sReflectionQualifiedName)
         {
+            Name = string.Empty;
+            Token = string.Empty;
+            Version = string.Empty;
+            AssemblyFullName = string.Empty;
             var aParts = sReflectionQualifiedName.Split(CC_SEPARATOR)
                             .Select(x => x.Trim())
                             .ToList();
@@ -39,6 +41,8 @@ namespace Quadarax.Foundation.Core.Reflection
                 try
                 {
                     var oType = Type.GetType(aParts[0].Trim(), true);
+                    if (oType == null)
+                        throw new Exception("Type is null");
                     SetupProperties(oType.Assembly.GetName());
                     bCodebase = true;
                 }
@@ -101,8 +105,11 @@ namespace Quadarax.Foundation.Core.Reflection
         }
         #endregion
         #region *** Private Operations ***
-        private void SetupProperties(AssemblyName oName)
+        private void SetupProperties(AssemblyName? oName)
         {
+            if (oName == null)
+                throw new ArgumentNullException(nameof(oName));
+
             Assembly = oName.Name;
             AssemblyFullName = oName.FullName;
             Culture = oName.CultureName;
@@ -112,7 +119,7 @@ namespace Quadarax.Foundation.Core.Reflection
         }
         private void ThrowCannotParse(string sReflectionQualifiedName, System.Exception oInnerException)
         {
-            throw new ArgumentException(string.Format("Cannot parse QualifiedName '{0}'!", sReflectionQualifiedName), oInnerException);
+            throw new ArgumentException($"Cannot parse QualifiedName '{sReflectionQualifiedName}'!", oInnerException);
         }
         #endregion
     }

+ 54 - 51
Common/qdr.fnd.core/Reflection/TypeUtils.cs

@@ -1,51 +1,54 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-namespace Quadarax.Foundation.Core.Reflection
-{
-    public static class TypeUtils
-    {
-
-        #region *** Private Fields ***
-        private static readonly IDictionary<string, Type> m_oRemTypeCache = new Dictionary<string, Type>();
-        // ReSharper disable InconsistentNaming
-        private static readonly object @lock;
-        // ReSharper restore InconsistentNaming
-        #endregion
-        #region *** Public Properties ***
-        #endregion
-        #region *** Constructors ***
-        static TypeUtils()
-        {
-            @lock = new object();
-        }
-        #endregion
-        #region *** Public operations & overrides ***
-        public static Type GetRemoteType(string sReflectionQualifiedName)
-        {
-            if (m_oRemTypeCache.ContainsKey(sReflectionQualifiedName))
-                return m_oRemTypeCache[sReflectionQualifiedName];
-
-            var oName = new QualifiedName(sReflectionQualifiedName);
-            Type oType;
-            if (oName.Assembly == null)
-            {
-                oType = Type.GetType(oName.Name, true);
-            }
-            else
-            {
-                var oAssembly = Assembly.Load(oName.Assembly);
-                oType = oAssembly.GetType(oName.Name, true);
-            }
-            lock (@lock)
-            {
-                m_oRemTypeCache.Add(sReflectionQualifiedName, oType);
-            }
-            return oType;
-        }
-        #endregion
-        #region *** Private operations & overrides ***
-        #endregion               
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace Quadarax.Foundation.Core.Reflection
+{
+    public static class TypeUtils
+    {
+
+        #region *** Private Fields ***
+        private static readonly IDictionary<string, Type?> m_oRemTypeCache = new Dictionary<string, Type?>();
+        // ReSharper disable InconsistentNaming
+        private static readonly object @lock;
+        // ReSharper restore InconsistentNaming
+        #endregion
+        #region *** Public Properties ***
+        #endregion
+        #region *** Constructors ***
+        static TypeUtils()
+        {
+            @lock = new object();
+        }
+        #endregion
+        #region *** Public operations & overrides ***
+        public static Type? GetRemoteType(string sReflectionQualifiedName)
+        {
+            if (m_oRemTypeCache.TryGetValue(sReflectionQualifiedName, out var type))
+                lock (@lock)
+                {
+                    return type;
+                }
+
+            var oName = new QualifiedName(sReflectionQualifiedName);
+            Type? oType;
+            if (oName.Assembly == null)
+            {
+                oType = Type.GetType(oName.Name, true);
+            }
+            else
+            {
+                var oAssembly = Assembly.Load(oName.Assembly);
+                oType = oAssembly.GetType(oName.Name, true);
+            }
+            lock (@lock)
+            {
+                m_oRemTypeCache.Add(sReflectionQualifiedName, oType);
+            }
+            return oType;
+        }
+        #endregion
+        #region *** Private operations & overrides ***
+        #endregion               
+    }
+}

+ 15 - 0
Common/qdr.fnd.core/Value/Extensions/EnumExt.cs

@@ -0,0 +1,15 @@
+namespace Quadarax.Foundation.Core.Business.Processor.Dependencies.Value.Extensions
+{
+    public static class EnumExt
+    {
+        public static IEnumerable<TEnum> All<TEnum>(this TEnum owner) where TEnum : Enum
+        {
+            return Enum.GetValues(typeof(TEnum)).Cast<TEnum>();
+        }
+
+        public static bool In<TEnum>(this TEnum owner, params TEnum[] values) where TEnum : Enum
+        {
+            return values.Contains(owner);
+        }
+    }
+}

+ 50 - 5
Common/qdr.fnd.core/Value/Extensions/EnumerableExt.cs

@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Quadarax.Foundation.Core.Value.Extensions
+namespace Quadarax.Foundation.Core.Value.Extensions
 {
     public static class EnumerableExt
     {
@@ -45,5 +41,54 @@ namespace Quadarax.Foundation.Core.Value.Extensions
 
 
         }
+
+
+        public static IEnumerable<TElement> CompareDiff<TElement>(this IEnumerable<TElement> owner,
+            IEnumerable<TElement> other)
+        {
+            if (owner== null)
+                throw new ArgumentNullException(nameof(owner));
+            if (other == null)
+                throw new ArgumentNullException(nameof(other));
+
+            var ownerArr = (owner as TElement[] ?? owner.ToArray()).ToArray();
+            var otherArr = (other as TElement[] ?? other.ToArray()).ToArray();
+            
+            var result = new List<TElement>();
+
+            foreach (var elem in ownerArr)
+            {
+                if (!otherArr.Contains(elem)) result.Add(elem);
+            }
+            foreach (var elem in otherArr)
+            {
+                if (!ownerArr.Contains(elem)) result.Add(elem);
+            }
+            return result.Distinct();
+        }
+        
+        public static IEnumerable<TElement> CompareCommon<TElement>(this IEnumerable<TElement> owner,
+            IEnumerable<TElement> other)
+        {
+            if (owner== null)
+                throw new ArgumentNullException(nameof(owner));
+            if (other == null)
+                throw new ArgumentNullException(nameof(other));
+
+            var ownerArr = (owner as TElement[] ?? owner.ToArray()).ToArray();
+            var otherArr = (other as TElement[] ?? other.ToArray()).ToArray();
+            
+            var result = new List<TElement>();
+
+            foreach (var elem in ownerArr)
+            {
+                if (otherArr.Contains(elem)) result.Add(elem);
+            }
+            foreach (var elem in otherArr)
+            {
+                if (ownerArr.Contains(elem)) result.Add(elem);
+            }
+            return result.Distinct();
+        }
     }
 }

+ 28 - 0
Common/qdr.fnd.core/Value/Extensions/ListExt.cs

@@ -0,0 +1,28 @@
+namespace Quadarax.Foundation.Core.Value.Extensions
+{
+    public static class ListExt
+    {
+        public static void Setup<TItem>(this IList<TItem> owner, IEnumerable<TItem> newItems)
+        {
+            if (owner == null)
+                throw new ArgumentNullException(nameof(owner));
+            if (newItems == null)
+                throw new ArgumentNullException(nameof(newItems));
+
+            owner.Clear();
+            owner.AddRange(newItems);
+
+        }
+
+        public static void AddRange<TItem>(this IList<TItem> owner, IEnumerable<TItem> items)
+        {
+            if (owner == null)
+                throw new ArgumentNullException(nameof(owner));
+            if (items == null)
+                throw new ArgumentNullException(nameof(items));
+
+            foreach (var item in items)
+                owner.Add(item);
+        }
+    }
+}

+ 1 - 7
Common/qdr.fnd.core/Value/Extensions/TimeSpanExt.cs

@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Quadarax.Foundation.Core.Value.Formatters;
+using Quadarax.Foundation.Core.Value.Formatters;
 
 namespace Quadarax.Foundation.Core.Value.Extensions
 {
@@ -9,9 +6,6 @@ namespace Quadarax.Foundation.Core.Value.Extensions
     {
         public static string ToReadableString(this TimeSpan owner)
         {
-            if (owner == null)
-                throw new ArgumentNullException(nameof(owner));
-
             // formats and its cutoffs based on TotalSeconds
             var cutoff = new SortedList<long, string> { 
                 {59, "{3:S}" }, 

+ 6 - 8
Common/qdr.fnd.core/Value/Formatters/HmsFormatter.cs

@@ -1,26 +1,24 @@
-using System;
-using System.Collections.Generic;
-
-namespace Quadarax.Foundation.Core.Value.Formatters
+namespace Quadarax.Foundation.Core.Value.Formatters
 {
     /// <summary>
     /// Formatter for forms of seconds/hours/day
     /// </summary>
     public class HmsFormatter : ICustomFormatter, IFormatProvider 
     {
-        static Dictionary<string, string> _timeformats = new Dictionary<string, string> {
+        static Dictionary<string, string> _timeformats = new()
+        {
             {"S", "{0:P:Seconds:Second}"},
             {"M", "{0:P:Minutes:Minute}"},
             {"H","{0:P:Hours:Hour}"},
             {"D", "{0:P:Days:Day}"}
         };
 
-        public string Format(string format, object arg, IFormatProvider formatProvider)
+        public string Format(string? format, object? arg, IFormatProvider? formatProvider)
         {
-            return string.Format(new PluralFormatter(),_timeformats[format], arg);
+            return string.Format(new PluralFormatter(),format == null ? string.Empty : _timeformats[format], arg);
         }
 
-        public object GetFormat(Type formatType)
+        public object? GetFormat(Type? formatType)
         {
             return formatType == typeof(ICustomFormatter)?this:null;
         }

+ 7 - 6
Common/qdr.fnd.core/Value/Formatters/PluralFormatter.cs

@@ -1,4 +1,5 @@
 using System;
+using static System.String;
 
 namespace Quadarax.Foundation.Core.Value.Formatters
 {
@@ -8,24 +9,24 @@ namespace Quadarax.Foundation.Core.Value.Formatters
     public class PluralFormatter : ICustomFormatter, IFormatProvider
     {
 
-        public string Format(string format, object arg, IFormatProvider formatProvider)
+        public string Format(string? format, object? arg, IFormatProvider? formatProvider)
         {
             if (arg !=null)
             {
-                var parts = format.Split(':'); // ["P", "Plural", "Singular"]
+                var parts = format == null ? Array.Empty<string>() : format.Split(':'); // ["P", "Plural", "Singular"]
 
                 if (parts[0] == "P") // correct format?
                 {
-                    // which index postion to use
+                    // which index position to use
                     int partIndex = (arg.ToString() == "1")?2:1;
                     // pick string (safe guard for array bounds) and format
-                    return String.Format("{0} {1}", arg, (parts.Length>partIndex?parts[partIndex]:""));               
+                    return $"{arg} {(parts.Length > partIndex ? parts[partIndex] : "")}";               
                 }
             }
-            return String.Format(format, arg);
+            return String.Format(format ?? string.Empty, arg);
         }
 
-        public object GetFormat(Type formatType)
+        public object? GetFormat(Type? formatType)
         {
             return formatType == typeof(ICustomFormatter)?this:null;
         }   

+ 37 - 0
Common/qdr.fnd.core/Value/ValueConverter.cs

@@ -0,0 +1,37 @@
+namespace Quadarax.Foundation.Core.Value
+{
+    public static class ValueConverter
+    {
+
+        public static object ConvertTo(Type toType, string value)
+        {
+            if (string.IsNullOrEmpty(value)) return null;
+
+
+            if (toType == typeof(string)) return (object)value;
+            if (toType == typeof(int)) return (object)int.Parse(value);
+            if (toType == typeof(long)) return (object)long.Parse(value);
+            if (toType == typeof(bool)) return (object)bool.Parse(value);
+            if (toType == typeof(double)) return (object)double.Parse(value);
+            if (toType == typeof(float)) return (object)float.Parse(value);
+            if (toType == typeof(decimal)) return (object)decimal.Parse(value);
+            if (toType == typeof(byte)) return (object)byte.Parse(value);
+            if (toType == typeof(sbyte)) return (object)sbyte.Parse(value);
+            if (toType == typeof(short)) return (object)short.Parse(value);
+            if (toType == typeof(ushort)) return (object)ushort.Parse(value);
+            if (toType == typeof(uint)) return (object)uint.Parse(value);
+            if (toType == typeof(ulong)) return (object)ulong.Parse(value);
+            if (toType == typeof(char)) return (object)char.Parse(value);
+            if (toType == typeof(Guid)) return (object)Guid.Parse(value);
+            if (toType == typeof(TimeSpan)) return (object)TimeSpan.Parse(value);
+            if (toType.IsEnum) return (object)Enum.Parse(toType, value, true);
+            
+            throw new NotSupportedException($"Cannot convert value to type '{toType}'. Not supported!");
+        }
+
+        public static TValue? ConvertTo<TValue>(string value)
+        {
+            return (TValue)ConvertTo(typeof(TValue), value);
+        }
+    }
+}