Dalibor Votruba 2 лет назад
Родитель
Сommit
4b5095a0d1

+ 2 - 5
Workbench/Processor/Dependencies/Object/Extensions/ObjectExt.cs

@@ -1,16 +1,13 @@
 using System.Collections;
 using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
 using Quadarax.Foundation.Core.Reflection.Extensions;
 using Quadarax.Foundation.Core.Reflection.Extensions;
 
 
 namespace Quadarax.Foundation.Core.Object.Extensions
 namespace Quadarax.Foundation.Core.Object.Extensions
 {
 {
     public static class ObjectExt
     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)
             if (obj == null)
                 return props;
                 return props;
 
 

+ 6 - 6
Workbench/Processor/Dependencies/Reflection/AttributeQuery.cs

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

+ 4 - 2
Workbench/Processor/Dependencies/Reflection/Extensions/ActivatorExt.cs

@@ -11,9 +11,11 @@ namespace Quadarax.Foundation.Core.Reflection.Extensions
         #region *** Constructors ***
         #region *** Constructors ***
         #endregion
         #endregion
         #region *** Public operations & overrides ***
         #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);
             var oType = Type.GetType(sClassOrInterfaceQualifiedName, false) ?? TypeUtils.GetRemoteType(sClassOrInterfaceQualifiedName);
+            if (oType == null) return null;
+
             if (oType.IsInterface)
             if (oType.IsInterface)
             {
             {
                 throw new ArgumentException($"Input class name '{sClassOrInterfaceQualifiedName}' cannot be an interface.",nameof(sClassOrInterfaceQualifiedName));
                 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)
         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
         #endregion
         #region *** Private operations & overrides ***
         #region *** Private operations & overrides ***

+ 8 - 2
Workbench/Processor/Dependencies/Reflection/Extensions/AssemblyExt.cs

@@ -15,8 +15,11 @@ namespace Quadarax.Foundation.Core.Reflection.Extensions
         #region *** Constructors ***
         #region *** Constructors ***
         #endregion
         #endregion
         #region *** Public operations & overrides ***
         #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;
             return oAssembly.GetName().Version;
         }
         }
         public static string GetDescription(this Assembly oAssembly)
         public static string GetDescription(this Assembly oAssembly)
@@ -56,7 +59,10 @@ namespace Quadarax.Foundation.Core.Reflection.Extensions
         }
         }
         public static string GetAssemblyPath(this Assembly oAssembly)
         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
         public static IEnumerable<Type> GetTypesWithAttribute<TAttribute>(this Assembly oAssembly, bool bInherit)where TAttribute : System.Attribute
         {
         {

+ 1 - 1
Workbench/Processor/Dependencies/Reflection/Extensions/TypeExt.cs

@@ -15,7 +15,7 @@ namespace Quadarax.Foundation.Core.Reflection.Extensions
         }
         }
 
 
 
 
-        public static IList<PropertyInfo> GetAllProperties(this Type type)
+        public static IList<PropertyInfo> GetAllProperties(this Type? type)
         {
         {
             if (type == null)
             if (type == null)
                 return new List<PropertyInfo>();
                 return new List<PropertyInfo>();

+ 11 - 4
Workbench/Processor/Dependencies/Reflection/QualifiedName.cs

@@ -13,8 +13,8 @@ namespace Quadarax.Foundation.Core.Reflection
         // ReSharper disable MemberCanBePrivate.Global
         // ReSharper disable MemberCanBePrivate.Global
         // ReSharper disable UnusedAutoPropertyAccessor.Global
         // ReSharper disable UnusedAutoPropertyAccessor.Global
         public string Name { get; private set; }
         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 Token { get; private set; }
         public string Version { get; private set; }
         public string Version { get; private set; }
         public string AssemblyFullName { get; private set; }
         public string AssemblyFullName { get; private set; }
@@ -24,6 +24,10 @@ namespace Quadarax.Foundation.Core.Reflection
         #region *** Constructors ***
         #region *** Constructors ***
         public QualifiedName(string sReflectionQualifiedName)
         public QualifiedName(string sReflectionQualifiedName)
         {
         {
+            Name = string.Empty;
+            Token = string.Empty;
+            Version = string.Empty;
+            AssemblyFullName = string.Empty;
             var aParts = sReflectionQualifiedName.Split(CC_SEPARATOR)
             var aParts = sReflectionQualifiedName.Split(CC_SEPARATOR)
                             .Select(x => x.Trim())
                             .Select(x => x.Trim())
                             .ToList();
                             .ToList();
@@ -101,8 +105,11 @@ namespace Quadarax.Foundation.Core.Reflection
         }
         }
         #endregion
         #endregion
         #region *** Private Operations ***
         #region *** Private Operations ***
-        private void SetupProperties(AssemblyName oName)
+        private void SetupProperties(AssemblyName? oName)
         {
         {
+            if (oName == null)
+                throw new ArgumentNullException(nameof(oName));
+
             Assembly = oName.Name;
             Assembly = oName.Name;
             AssemblyFullName = oName.FullName;
             AssemblyFullName = oName.FullName;
             Culture = oName.CultureName;
             Culture = oName.CultureName;
@@ -112,7 +119,7 @@ namespace Quadarax.Foundation.Core.Reflection
         }
         }
         private void ThrowCannotParse(string sReflectionQualifiedName, System.Exception oInnerException)
         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
         #endregion
     }
     }

+ 51 - 51
Workbench/Processor/Dependencies/Reflection/TypeUtils.cs

@@ -1,54 +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.TryGetValue(sReflectionQualifiedName, out var type))
+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)
                 lock (@lock)
                 {
                 {
                     return type;
                     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               
-    }
-}
+                }
+
+            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               
+    }
+}

+ 4 - 3
Workbench/Processor/Task/AffinityToken.cs

@@ -16,12 +16,13 @@ public class AffinityToken : IAffinityToken
 	#region *** Constructor ***
 	#region *** Constructor ***
 	public AffinityToken()
 	public AffinityToken()
 	{
 	{
+        QueueIdentifier = string.Empty;
 	}
 	}
-	public AffinityToken(string queueIdentifier, int workerOrdinal)
+	public AffinityToken(string queueIdentifier, int workerOrdinal) : this()
 	{
 	{
-		Set(QueueIdentifier, workerOrdinal);
+		Set(queueIdentifier, workerOrdinal);
 	}
 	}
-	public AffinityToken(string affinityTokenComplex)
+	public AffinityToken(string affinityTokenComplex) : this()
 	{
 	{
 		FromComplex(affinityTokenComplex);	
 		FromComplex(affinityTokenComplex);	
 	}
 	}

+ 1 - 1
Workbench/Processor/Task/ITaskItemData.cs

@@ -9,7 +9,7 @@ namespace Quadarax.Foundation.Core.Business.Processor.Task
         /// <summary>
         /// <summary>
         /// Contains the affinity token which is used to identify owning/locking queue.
         /// Contains the affinity token which is used to identify owning/locking queue.
         /// </summary>
         /// </summary>
-        IAffinityToken AffinityToken { get; }
+        IAffinityToken? AffinityToken { get; }
         /// <summary>
         /// <summary>
         /// External reference of the task.
         /// External reference of the task.
         /// </summary>
         /// </summary>

+ 3 - 2
Workbench/Processor/Task/TaskItem.cs

@@ -29,7 +29,7 @@ namespace Quadarax.Foundation.Core.Business.Processor.Task
         /// <summary>
         /// <summary>
         /// <inheritdoc cref="ITaskItem.AffinityToken"/>
         /// <inheritdoc cref="ITaskItem.AffinityToken"/>
         /// </summary>
         /// </summary>
-        public IAffinityToken AffinityToken { get; private set;}
+        public IAffinityToken? AffinityToken { get; private set;}
         /// <summary>
         /// <summary>
         /// <inheritdoc cref="ITaskItem.Reference"/>
         /// <inheritdoc cref="ITaskItem.Reference"/>
         /// </summary>
         /// </summary>
@@ -97,7 +97,8 @@ namespace Quadarax.Foundation.Core.Business.Processor.Task
             Status = initialStatus;
             Status = initialStatus;
         }
         }
         public TaskItem(ProcessQueue parent, string reference, string providerClass, TypedArgument[] initialArguments, byte priority, int attepts, TimeSpan? attemptTimeout, DateTime validFrom, DateTime? validTo, ITaskStatusLogItem[]? initialStatusLog)
         public TaskItem(ProcessQueue parent, string reference, string providerClass, TypedArgument[] initialArguments, byte priority, int attepts, TimeSpan? attemptTimeout, DateTime validFrom, DateTime? validTo, ITaskStatusLogItem[]? initialStatusLog)
-        {	   
+        {	
+            AffinityToken = null;
             _parent = parent ?? throw new ArgumentNullException(nameof(parent)); 
             _parent = parent ?? throw new ArgumentNullException(nameof(parent)); 
             _log = new ConsoleLogger().GetLogger(GetType());      
             _log = new ConsoleLogger().GetLogger(GetType());      
             Priority = priority;
             Priority = priority;