diff --git a/VERSION b/VERSION index 47b322c97..4d9d11cf5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.4.1 +3.4.2 diff --git a/src/Moryx.Runtime.Kernel/Modules/Components/ModuleStarter.cs b/src/Moryx.Runtime.Kernel/Modules/Components/ModuleStarter.cs index aa3f7d29f..bf9365730 100644 --- a/src/Moryx.Runtime.Kernel/Modules/Components/ModuleStarter.cs +++ b/src/Moryx.Runtime.Kernel/Modules/Components/ModuleStarter.cs @@ -65,22 +65,21 @@ public void StartAll() private void StartModule(IServerModule module) { + // Check for any failed dependencies + var hasfailedDependecies = _dependencyManager.GetDependencyBranch(module).Dependencies + .Any(item => item.RepresentedModule.State == ServerModuleState.Failure); + // Don't try to start modules which initialization has been failed or for which dependency initializations have failed + if (module.State == ServerModuleState.Failure || hasfailedDependecies) + return; + // Now we check for any not running dependencies and start them var awaitingDependecies = _dependencyManager.GetDependencyBranch(module).Dependencies .Where(item => !item.RepresentedModule.State.HasFlag(ServerModuleState.Running)) .Select(item => item.RepresentedModule).ToArray(); if (awaitingDependecies.Any()) - { EnqueServiceAndStartDependencies(awaitingDependecies, module); - } else - { - // Don't try to start modules which initialization has been failed - if (module.State != ServerModuleState.Failure) - { - ThreadPool.QueueUserWorkItem(ExecuteModuleStart, module); - } - } + ThreadPool.QueueUserWorkItem(ExecuteModuleStart, module); } private void ExecuteModuleStart(object moduleObj) diff --git a/src/Moryx.Runtime.Kestrel/EndpointCollector.cs b/src/Moryx.Runtime.Kestrel/EndpointCollector.cs index 176204dbf..ba4625c95 100644 --- a/src/Moryx.Runtime.Kestrel/EndpointCollector.cs +++ b/src/Moryx.Runtime.Kestrel/EndpointCollector.cs @@ -9,7 +9,7 @@ namespace Moryx.Runtime.Kestrel { internal class EndpointCollector { - private readonly Dictionary _endpoints = new Dictionary(); + private readonly ICollection _endpoints = new List(); public Endpoint[] AllEndpoints { @@ -17,24 +17,16 @@ public Endpoint[] AllEndpoints { lock (_endpoints) { - return _endpoints.Values.ToArray(); + return _endpoints.ToArray(); } } } - public void AddEndpoint(string address, Endpoint endpoint) + public void AddEndpoint(Endpoint endpoint) { lock (_endpoints) { - _endpoints[address] = endpoint; - } - } - - public void RemoveEndpoint(string address) - { - lock (_endpoints) - { - _endpoints.Remove(address); + _endpoints.Add(endpoint); } } } diff --git a/src/Moryx.Runtime.Kestrel/KestrelEndpointHosting.cs b/src/Moryx.Runtime.Kestrel/KestrelEndpointHosting.cs index d7b35d5fe..3bd5c3264 100644 --- a/src/Moryx.Runtime.Kestrel/KestrelEndpointHosting.cs +++ b/src/Moryx.Runtime.Kestrel/KestrelEndpointHosting.cs @@ -98,7 +98,9 @@ internal void LinkController(Type controller, IContainer moduleContainer) var authorizeAttr = controller.GetCustomAttribute(); var endpointAtt = controller.GetCustomAttribute(); - _hostingContainer.Resolve().AddEndpoint(address, new Endpoint + + var endpointCollector = _hostingContainer.Resolve(); + endpointCollector.AddEndpoint(new Endpoint { Address = address, Path = route, diff --git a/src/Moryx.Runtime.Kestrel/VersionController.cs b/src/Moryx.Runtime.Kestrel/VersionController.cs index 5fb7be4da..6c39c00ad 100644 --- a/src/Moryx.Runtime.Kestrel/VersionController.cs +++ b/src/Moryx.Runtime.Kestrel/VersionController.cs @@ -1,6 +1,7 @@ // Copyright (c) 2021, Phoenix Contact GmbH & Co. KG // Licensed under the Apache License, Version 2.0 +using System; using System.Linq; using Microsoft.AspNetCore.Mvc; using Moryx.Communication.Endpoints; @@ -25,6 +26,7 @@ public Endpoint[] FilteredEndpoints(string service) return Collector.AllEndpoints.Where(e => e.Service == service).ToArray(); } + [Obsolete("Will be removed or returns array in the next major")] [HttpGet("endpoint/{endpoint}")] public Endpoint GetEndpointConfig(string endpoint) { diff --git a/src/Moryx/Configuration/ValueProvider/Filters/DefaultCanWriteValueProviderFilter.cs b/src/Moryx/Configuration/ValueProvider/Filters/DefaultCanWriteValueProviderFilter.cs index ac862e1bb..9ae77c2ae 100644 --- a/src/Moryx/Configuration/ValueProvider/Filters/DefaultCanWriteValueProviderFilter.cs +++ b/src/Moryx/Configuration/ValueProvider/Filters/DefaultCanWriteValueProviderFilter.cs @@ -13,7 +13,7 @@ public sealed class DefaultCanWriteValueProviderFilter : IValueProviderFilter /// public bool CheckProperty(PropertyInfo propertyInfo) { - return propertyInfo.CanWrite; + return propertyInfo.GetSetMethod() != null; } } } diff --git a/src/Tests/Moryx.Tests/Configuration/ValueProvider/DefaultCanWriteValueProviderFilterTests.cs b/src/Tests/Moryx.Tests/Configuration/ValueProvider/DefaultCanWriteValueProviderFilterTests.cs new file mode 100644 index 000000000..acabac96d --- /dev/null +++ b/src/Tests/Moryx.Tests/Configuration/ValueProvider/DefaultCanWriteValueProviderFilterTests.cs @@ -0,0 +1,37 @@ +// Copyright (c) 2022, Phoenix Contact GmbH & Co. KG +// Licensed under the Apache License, Version 2.0 + +using Moryx.Configuration; +using NUnit.Framework; + +namespace Moryx.Tests.Configuration.ValueProvider +{ + [TestFixture] + public class DefaultCanWriteValueProviderFilterTests + { + [Test(Description = "Test detects private setter right")] + public void DetectPrivateSetter() + { + // Arrange + var filter = new DefaultCanWriteValueProviderFilter(); + var classType = typeof(PrivateSetterClass); + var privateSetterProperty = classType.GetProperty(nameof(PrivateSetterClass.PrivateSetterBool)); + var noSetterProperty = classType.GetProperty(nameof(PrivateSetterClass.NoSetterBool)); + + // Act + var canWritePrivateSetter = filter.CheckProperty(privateSetterProperty); + var canWriteNoSetter = filter.CheckProperty(noSetterProperty); + + // Assert + Assert.IsFalse(canWritePrivateSetter, "Private setter should be treated as not writable"); + Assert.IsFalse(canWriteNoSetter, "No setter should be treated as not writable"); + } + + public class PrivateSetterClass + { + public bool PrivateSetterBool { get; private set; } + + public bool NoSetterBool => false; + } + } +} diff --git a/src/Tests/Moryx.Tests/Configuration/ValueProvider/ValueProviderTests.cs b/src/Tests/Moryx.Tests/Configuration/ValueProvider/ValueProviderTests.cs index db0dc563b..e288ad762 100644 --- a/src/Tests/Moryx.Tests/Configuration/ValueProvider/ValueProviderTests.cs +++ b/src/Tests/Moryx.Tests/Configuration/ValueProvider/ValueProviderTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0 using System.Collections.Generic; -using System.Linq; using Moryx.Configuration; using NUnit.Framework; @@ -18,7 +17,6 @@ public void SetDefaultsOnlyOnWritableProperties() var config = new TestConfig1(); // Act - ValueProviderExecutor.Execute(config, new ValueProviderExecutorSettings().AddDefaultValueProvider()); // Assert diff --git a/src/Tests/Moryx.Tools.Wcf.SystemTests/VersionServiceTests.cs b/src/Tests/Moryx.Tools.Wcf.SystemTests/VersionServiceTests.cs index 87a75c944..8e43fd7f4 100644 --- a/src/Tests/Moryx.Tools.Wcf.SystemTests/VersionServiceTests.cs +++ b/src/Tests/Moryx.Tools.Wcf.SystemTests/VersionServiceTests.cs @@ -143,7 +143,7 @@ public void TestActiveEndpointsLifeCycle() _hogController.StartService(ModuleController.ModuleName); result = _hogController.WaitForService(DependentTestModule.ModuleController.ModuleName, ServerModuleState.Running, 5); - Assert.IsTrue(result, "Service '{0}' did not reach state 'Running' ", ModuleController.ModuleName); + Assert.IsTrue(result, "Service '{0}' did not reach state 'Running' ", DependentTestModule.ModuleController.ModuleName); endpoints = _versionService.ActiveEndpoints();