From 7b5d9870bf8dab99571269534655813e66d194f5 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Thu, 19 Oct 2023 21:24:10 -0400 Subject: [PATCH 01/11] Use development locations for transports --- src/ServiceControl.Audit/Program.cs | 3 +- .../ServiceControl.Audit.csproj | 3 +- src/ServiceControl.Monitoring/Program.cs | 5 +- .../ServiceControl.Monitoring.csproj | 4 -- .../DevelopmentTransportLocations.cs | 53 +++++++++++++++++++ .../TransportManifest.cs | 45 ++++++++++++---- src/ServiceControl/Program.cs | 3 +- src/ServiceControl/ServiceControl.csproj | 1 - 8 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 src/ServiceControl.Transports/DevelopmentTransportLocations.cs diff --git a/src/ServiceControl.Audit/Program.cs b/src/ServiceControl.Audit/Program.cs index a77a9c3ccd..004165742b 100644 --- a/src/ServiceControl.Audit/Program.cs +++ b/src/ServiceControl.Audit/Program.cs @@ -55,8 +55,7 @@ static Assembly ResolveAssembly(string name) var transportFolder = TransportManifestLibrary.GetTransportFolder(settings.TransportType); if (transportFolder != null) { - var subFolderPath = Path.Combine(appDirectory, "Transports", transportFolder); - assembly = TryLoadTypeFromSubdirectory(subFolderPath, requestingName); + assembly = TryLoadTypeFromSubdirectory(transportFolder, requestingName); } var persistenceFolder = PersistenceManifestLibrary.GetPersistenceFolder(settings.PersistenceType); diff --git a/src/ServiceControl.Audit/ServiceControl.Audit.csproj b/src/ServiceControl.Audit/ServiceControl.Audit.csproj index 239aae652c..c6ce534a2c 100644 --- a/src/ServiceControl.Audit/ServiceControl.Audit.csproj +++ b/src/ServiceControl.Audit/ServiceControl.Audit.csproj @@ -11,9 +11,8 @@ - - + diff --git a/src/ServiceControl.Monitoring/Program.cs b/src/ServiceControl.Monitoring/Program.cs index 675dc3134b..c8b6ade501 100644 --- a/src/ServiceControl.Monitoring/Program.cs +++ b/src/ServiceControl.Monitoring/Program.cs @@ -49,13 +49,10 @@ static Assembly ResolveAssembly(string name) var assembly = !File.Exists(combine) ? null : Assembly.LoadFrom(combine); if (assembly == null && settings != null) { - //look into transport directory var transportFolder = TransportManifestLibrary.GetTransportFolder(settings.TransportType); if (transportFolder != null) { - var transportsPath = Path.Combine(appDirectory, "Transports", transportFolder); - - assembly = TryLoadTypeFromSubdirectory(transportsPath, requestingName); + assembly = TryLoadTypeFromSubdirectory(transportFolder, requestingName); } } diff --git a/src/ServiceControl.Monitoring/ServiceControl.Monitoring.csproj b/src/ServiceControl.Monitoring/ServiceControl.Monitoring.csproj index 30c7a291a4..3b56feeedd 100644 --- a/src/ServiceControl.Monitoring/ServiceControl.Monitoring.csproj +++ b/src/ServiceControl.Monitoring/ServiceControl.Monitoring.csproj @@ -8,10 +8,6 @@ - - - - diff --git a/src/ServiceControl.Transports/DevelopmentTransportLocations.cs b/src/ServiceControl.Transports/DevelopmentTransportLocations.cs new file mode 100644 index 0000000000..c9bca56537 --- /dev/null +++ b/src/ServiceControl.Transports/DevelopmentTransportLocations.cs @@ -0,0 +1,53 @@ +namespace ServiceControl.Transports +{ + using System; + using System.Collections.Generic; + using System.IO; + + static class DevelopmentTransportLocations + { +#if DEBUG + const string configuration = "Debug"; +#else + const string configuration = "Release"; +#endif + +#if NET472 + const string framework = "net472"; +#endif + + public static bool TryGetTransportFolder(string transportName, out string transportFolder) + { + transportFolder = null; + + if (transportName.Contains(".")) + { + transportName = transportName.Split('.')[0]; + } + + var found = projects.TryGetValue(transportName, out var projectFolder); + + if (found) + { + var assemblyPath = typeof(DevelopmentTransportLocations).Assembly.Location; + var assemblyFolder = Path.GetDirectoryName(assemblyPath); + var srcFolder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyFolder)))))); + transportFolder = Path.Combine(srcFolder, projectFolder, "bin", configuration, framework); + } + + return found; + } + + static readonly Dictionary projects = new Dictionary(StringComparer.OrdinalIgnoreCase) + { + {"AmazonSQS", "ServiceControl.Transports.SQS" }, + {"AzureServiceBus", "ServiceControl.Transports.ASB" }, + {"AzureStorageQueue", "ServiceControl.Transports.ASQ" }, + {"LearningTransport", "ServiceControl.Transports.Learning" }, + {"MSMQ", "ServiceControl.Transports.Msmq" }, + {"NetStandardAzureServiceBus", "ServiceControl.Transports.ASBS" }, + {"RabbitMQ", "ServiceControl.Transports.RabbitMQ" }, + {"SQLServer", "ServiceControl.Transports.SqlServer" } + }; + } +} diff --git a/src/ServiceControl.Transports/TransportManifest.cs b/src/ServiceControl.Transports/TransportManifest.cs index ef8d8be4b4..434394d6be 100644 --- a/src/ServiceControl.Transports/TransportManifest.cs +++ b/src/ServiceControl.Transports/TransportManifest.cs @@ -10,14 +10,18 @@ public class TransportManifest { public string Version { get; set; } + public TransportManifestDefinition[] Definitions { get; set; } } public class TransportManifestDefinition { public string Name { get; set; } + public string DisplayName { get; set; } + public string TypeName { get; set; } + public string[] Aliases { get; set; } internal bool IsMatch(string transportType) => @@ -41,7 +45,10 @@ public static class TransportManifestLibrary public static List TransportManifests { get; set; } static bool initialized; - static void Initialize() + + static bool usingDevelopmentLocation; + + static void Initialize(string transportType) { if (TransportManifests == null) { @@ -51,19 +58,28 @@ static void Initialize() if (!initialized) { initialized = true; - var assemblyLocation = GetAssemblyDirectory(); + var transportFolder = GetAssemblyDirectory(); + try { TransportManifests.AddRange( - Directory.EnumerateFiles(assemblyLocation, "transport.manifest", SearchOption.AllDirectories) + Directory.EnumerateFiles(transportFolder, "transport.manifest", SearchOption.AllDirectories) .Select(manifest => JsonSerializer.Deserialize(File.ReadAllText(manifest))) ); + if (TransportManifests.Count == 0 && DevelopmentTransportLocations.TryGetTransportFolder(transportType, out transportFolder)) + { + var manifest = Path.Combine(transportFolder, "transport.manifest"); + TransportManifests.Add(JsonSerializer.Deserialize(File.ReadAllText(manifest))); + + usingDevelopmentLocation = true; + } + TransportManifests.SelectMany(t => t.Definitions).ToList().ForEach(m => logger.Info($"Found transport manifest for {m.DisplayName}")); } catch (Exception ex) { - logger.Warn($"Failed to load transport manifests from {assemblyLocation}", ex); + logger.Warn($"Failed to load transport manifests from {transportFolder}", ex); } } } @@ -81,7 +97,7 @@ public static string Find(string transportType) throw new Exception("No transport has been configured. Either provide a Type or Name in the TransportType setting."); } - Initialize(); + Initialize(transportType); var transportManifestDefinition = TransportManifests .SelectMany(t => t.Definitions) @@ -102,21 +118,32 @@ public static string GetTransportFolder(string transportType) throw new Exception("No transport has been configured. Either provide a Type or Name in the TransportType setting."); } - Initialize(); + Initialize(transportType); var transportManifestDefinition = TransportManifests .SelectMany(t => t.Definitions) .FirstOrDefault(w => w.IsMatch(transportType)); + string transportFolder = null; + if (transportManifestDefinition != null) { - return transportManifestDefinition.Name.Split('.').FirstOrDefault(); + if (usingDevelopmentLocation) + { + _ = DevelopmentTransportLocations.TryGetTransportFolder(transportManifestDefinition.Name, out transportFolder); + } + else + { + var appDirectory = GetAssemblyDirectory(); + var transportName = transportManifestDefinition.Name.Split('.').FirstOrDefault(); + transportFolder = Path.Combine(appDirectory, "Transports", transportName); + } } - return null; + return transportFolder; } - static ILog logger = LogManager.GetLogger(typeof(TransportManifestLibrary)); + static readonly ILog logger = LogManager.GetLogger(typeof(TransportManifestLibrary)); } } diff --git a/src/ServiceControl/Program.cs b/src/ServiceControl/Program.cs index 842f26ae66..bd2331cb66 100644 --- a/src/ServiceControl/Program.cs +++ b/src/ServiceControl/Program.cs @@ -54,8 +54,7 @@ static Assembly ResolveAssembly(string name) if (transportFolder != null) { - var subFolderPath = Path.Combine(appDirectory, "Transports", transportFolder); - assembly = TryLoadTypeFromSubdirectory(subFolderPath, requestingName); + assembly = TryLoadTypeFromSubdirectory(transportFolder, requestingName); } var persistenceFolder = PersistenceManifestLibrary.GetPersistenceFolder(settings.PersistenceType); diff --git a/src/ServiceControl/ServiceControl.csproj b/src/ServiceControl/ServiceControl.csproj index 20b548d915..dfbbfcd3d6 100644 --- a/src/ServiceControl/ServiceControl.csproj +++ b/src/ServiceControl/ServiceControl.csproj @@ -17,7 +17,6 @@ - From 9e394ed125c36917a01a2c07e0f44c4519ff64d7 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Fri, 20 Oct 2023 16:27:42 -0400 Subject: [PATCH 02/11] Use development locations for primary instance persistence --- .../EmbeddedDatabase.cs | 31 +++++------- .../DevelopmentPersistenceLocations.cs | 46 ++++++++++++++++++ .../PersistenceManifestLibrary.cs | 48 +++++++++++++++---- src/ServiceControl/App.config | 4 +- src/ServiceControl/Program.cs | 27 +++++------ src/ServiceControl/ServiceControl.csproj | 4 -- 6 files changed, 111 insertions(+), 49 deletions(-) create mode 100644 src/ServiceControl.Persistence/DevelopmentPersistenceLocations.cs diff --git a/src/ServiceControl.Persistence.RavenDb5/EmbeddedDatabase.cs b/src/ServiceControl.Persistence.RavenDb5/EmbeddedDatabase.cs index 7cb42cb5d6..48c0f30335 100644 --- a/src/ServiceControl.Persistence.RavenDb5/EmbeddedDatabase.cs +++ b/src/ServiceControl.Persistence.RavenDb5/EmbeddedDatabase.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Globalization; using System.IO; + using System.Reflection; using System.Threading; using System.Threading.Tasks; using ByteSizeLib; @@ -25,30 +26,22 @@ public class EmbeddedDatabase : IDisposable static (string LicenseFileName, string ServerDirectory) GetRavenLicenseFileNameAndServerDirectory() { + var assembly = Assembly.GetExecutingAssembly(); + var assemblyDirectory = Path.GetDirectoryName(assembly.Location); + var licenseFileName = "RavenLicense.json"; - var localRavenLicense = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, licenseFileName); - if (File.Exists(localRavenLicense)) + var ravenLicense = Path.Combine(assemblyDirectory, licenseFileName); + var serverDirectory = Path.Combine(assemblyDirectory, "RavenDBServer"); + + if (File.Exists(ravenLicense)) { - return (localRavenLicense, null); + return (ravenLicense, serverDirectory); } - - const string Persisters = "Persisters"; - const string RavenDB5 = "RavenDB5"; - - var persisterDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Persisters, RavenDB5); - - localRavenLicense = Path.Combine(persisterDirectory, licenseFileName); - if (!File.Exists(localRavenLicense)) + else { - throw new Exception($"RavenDB license not found. Make sure the RavenDB license file, '{licenseFileName}', " + - $"is stored in the '{AppDomain.CurrentDomain.BaseDirectory}' folder or in the '{Persisters}/{RavenDB5}' subfolder."); + var assemblyName = Path.GetFileName(assembly.Location); + throw new Exception($"RavenDB license not found. Make sure the RavenDB license file '{licenseFileName}' is stored in the same directory as {assemblyName}."); } - - // By default RavenDB 5 searches its binaries in the RavenDBServer right below the BaseDirectory. - // If we're loading from Persisters/RavenDB5 we also have to signal RavenDB where are binaries - var serverDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Persisters", "RavenDB5", "RavenDBServer"); - - return (localRavenLicense, serverDirectory); } internal static EmbeddedDatabase Start(RavenDBPersisterSettings settings) diff --git a/src/ServiceControl.Persistence/DevelopmentPersistenceLocations.cs b/src/ServiceControl.Persistence/DevelopmentPersistenceLocations.cs new file mode 100644 index 0000000000..17fb865f04 --- /dev/null +++ b/src/ServiceControl.Persistence/DevelopmentPersistenceLocations.cs @@ -0,0 +1,46 @@ +namespace ServiceControl.Persistence +{ + using System; + using System.Collections.Generic; + using System.IO; + + static class DevelopmentPersistenceLocations + { +#if DEBUG + const string configuration = "Debug"; +#else + const string configuration = "Release"; +#endif + +#if NET472 + const string framework = "net472"; +#endif + + public static bool TryGetPersistenceFolder(string transportName, out string persistenceFolder) + { + persistenceFolder = null; + + if (transportName.Contains(".")) + { + transportName = transportName.Split('.')[0]; + } + + var found = projects.TryGetValue(transportName, out var projectFolder); + + if (found) + { + var assemblyPath = typeof(DevelopmentPersistenceLocations).Assembly.Location; + var assemblyFolder = Path.GetDirectoryName(assemblyPath); + var srcFolder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyFolder)))))); + persistenceFolder = Path.Combine(srcFolder, projectFolder, "bin", configuration, framework); + } + + return found; + } + + static readonly Dictionary projects = new Dictionary(StringComparer.OrdinalIgnoreCase) + { + {"RavenDB5", "ServiceControl.Persistence.RavenDb5" } + }; + } +} diff --git a/src/ServiceControl.Persistence/PersistenceManifestLibrary.cs b/src/ServiceControl.Persistence/PersistenceManifestLibrary.cs index 9d1ebaa4c6..24e91b5706 100644 --- a/src/ServiceControl.Persistence/PersistenceManifestLibrary.cs +++ b/src/ServiceControl.Persistence/PersistenceManifestLibrary.cs @@ -10,10 +10,15 @@ public class PersistenceManifest { public string Version { get; set; } + public string Name { get; set; } + public string DisplayName { get; set; } + public string Description { get; set; } + public string TypeName { get; set; } + public bool IsSupported { get; set; } = true; internal bool IsMatch(string persistenceType) => @@ -26,7 +31,10 @@ public static class PersistenceManifestLibrary public static List PersistenceManifests { get; set; } static bool initialized; - static void Initialize() + + static bool usingDevelopmentLocation; + + static void Initialize(string persistenceType) { if (PersistenceManifests == null) { @@ -36,19 +44,28 @@ static void Initialize() if (!initialized) { initialized = true; - var assemblyLocation = GetAssemblyDirectory(); + var persistenceFolder = GetAssemblyDirectory(); + try { PersistenceManifests.AddRange( - Directory.EnumerateFiles(assemblyLocation, "persistence.manifest", SearchOption.AllDirectories) + Directory.EnumerateFiles(persistenceFolder, "persistence.manifest", SearchOption.AllDirectories) .Select(manifest => JsonSerializer.Deserialize(File.ReadAllText(manifest))) - ); + ); + + if (PersistenceManifests.Count == 0 && DevelopmentPersistenceLocations.TryGetPersistenceFolder(persistenceType, out persistenceFolder)) + { + var manifest = Path.Combine(persistenceFolder, "persistence.manifest"); + PersistenceManifests.Add(JsonSerializer.Deserialize(File.ReadAllText(manifest))); + + usingDevelopmentLocation = true; + } PersistenceManifests.ForEach(m => logger.Info($"Found persistence manifest for {m.DisplayName}")); } catch (Exception ex) { - logger.Warn($"Failed to load persistence manifests from {assemblyLocation}", ex); + logger.Warn($"Failed to load persistence manifests from {persistenceFolder}", ex); } } } @@ -66,7 +83,7 @@ public static string Find(string persistenceType) throw new Exception("No persistenceType has been configured. Either provide a Type or Name in the PersistenceType setting."); } - Initialize(); + Initialize(persistenceType); var persistenceManifestDefinition = PersistenceManifests.FirstOrDefault(w => w.IsMatch(persistenceType)); @@ -85,19 +102,30 @@ public static string GetPersistenceFolder(string persistenceType) throw new Exception("No persistenceType has been configured. Either provide a Type or Name in the PersistenceType setting."); } - Initialize(); + Initialize(persistenceType); var persistenceManifestDefinition = PersistenceManifests.FirstOrDefault(w => w.IsMatch(persistenceType)); + string persistenceFolder = null; + if (persistenceManifestDefinition != null) { - return persistenceManifestDefinition.Name.Split('.').FirstOrDefault(); + if (usingDevelopmentLocation) + { + _ = DevelopmentPersistenceLocations.TryGetPersistenceFolder(persistenceManifestDefinition.Name, out persistenceFolder); + } + else + { + var appDirectory = GetAssemblyDirectory(); + var persistenceName = persistenceManifestDefinition.Name.Split('.').FirstOrDefault(); + persistenceFolder = Path.Combine(appDirectory, "Persisters", persistenceName); + } } - return null; + return persistenceFolder; } - static ILog logger = LogManager.GetLogger(typeof(PersistenceManifestLibrary)); + static readonly ILog logger = LogManager.GetLogger(typeof(PersistenceManifestLibrary)); } } diff --git a/src/ServiceControl/App.config b/src/ServiceControl/App.config index 9cd12c53e7..7f10914c78 100644 --- a/src/ServiceControl/App.config +++ b/src/ServiceControl/App.config @@ -23,7 +23,7 @@ These settings are only here so that we can debug ServiceControl while developin --> - + @@ -34,7 +34,7 @@ These settings are only here so that we can debug ServiceControl while developin - + --> diff --git a/src/ServiceControl/Program.cs b/src/ServiceControl/Program.cs index bd2331cb66..260792f784 100644 --- a/src/ServiceControl/Program.cs +++ b/src/ServiceControl/Program.cs @@ -48,21 +48,17 @@ static Assembly ResolveAssembly(string name) var combine = Path.Combine(appDirectory, requestingName + ".dll"); var assembly = !File.Exists(combine) ? null : Assembly.LoadFrom(combine); + if (assembly == null && settings != null) { var transportFolder = TransportManifestLibrary.GetTransportFolder(settings.TransportType); + assembly = TryLoadTypeFromSubdirectory(transportFolder, requestingName); + } - if (transportFolder != null) - { - assembly = TryLoadTypeFromSubdirectory(transportFolder, requestingName); - } - + if (assembly == null && settings != null) + { var persistenceFolder = PersistenceManifestLibrary.GetPersistenceFolder(settings.PersistenceType); - if (assembly == null && persistenceFolder != null) - { - var subFolderPath = Path.Combine(appDirectory, "Persisters", persistenceFolder); - assembly = TryLoadTypeFromSubdirectory(subFolderPath, requestingName); - } + assembly = TryLoadTypeFromSubdirectory(persistenceFolder, requestingName); } return assembly; @@ -70,11 +66,14 @@ static Assembly ResolveAssembly(string name) static Assembly TryLoadTypeFromSubdirectory(string subFolderPath, string requestingName) { - var path = Path.Combine(subFolderPath, $"{requestingName}.dll"); - - if (File.Exists(path)) + if (subFolderPath != null) { - return Assembly.LoadFrom(path); + var path = Path.Combine(subFolderPath, $"{requestingName}.dll"); + + if (File.Exists(path)) + { + return Assembly.LoadFrom(path); + } } return null; diff --git a/src/ServiceControl/ServiceControl.csproj b/src/ServiceControl/ServiceControl.csproj index dfbbfcd3d6..2dddfbfa34 100644 --- a/src/ServiceControl/ServiceControl.csproj +++ b/src/ServiceControl/ServiceControl.csproj @@ -15,10 +15,6 @@ - - - - From 43defc70b51e89fffce1347c463339757ea2c660 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Fri, 20 Oct 2023 16:41:22 -0400 Subject: [PATCH 03/11] Use development locations for audit instance persistence --- .../EmbeddedDatabase.cs | 31 +++++------- .../DevelopmentPersistenceLocations.cs | 47 +++++++++++++++++++ .../PersistenceManifest.cs | 47 +++++++++++++++---- src/ServiceControl.Audit/App.config | 2 +- src/ServiceControl.Audit/Program.cs | 28 +++++------ .../ServiceControl.Audit.csproj | 4 -- 6 files changed, 112 insertions(+), 47 deletions(-) create mode 100644 src/ServiceControl.Audit.Persistence/DevelopmentPersistenceLocations.cs diff --git a/src/ServiceControl.Audit.Persistence.RavenDb5/EmbeddedDatabase.cs b/src/ServiceControl.Audit.Persistence.RavenDb5/EmbeddedDatabase.cs index a39c7746af..a2cebf9eea 100644 --- a/src/ServiceControl.Audit.Persistence.RavenDb5/EmbeddedDatabase.cs +++ b/src/ServiceControl.Audit.Persistence.RavenDb5/EmbeddedDatabase.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Globalization; using System.IO; + using System.Reflection; using System.Threading; using System.Threading.Tasks; using ByteSizeLib; @@ -25,30 +26,22 @@ public EmbeddedDatabase(DatabaseConfiguration configuration) static (string LicenseFileName, string ServerDirectory) GetRavenLicenseFileNameAndServerDirectory() { + var assembly = Assembly.GetExecutingAssembly(); + var assemblyDirectory = Path.GetDirectoryName(assembly.Location); + var licenseFileName = "RavenLicense.json"; - var localRavenLicense = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, licenseFileName); - if (File.Exists(localRavenLicense)) + var ravenLicense = Path.Combine(assemblyDirectory, licenseFileName); + var serverDirectory = Path.Combine(assemblyDirectory, "RavenDBServer"); + + if (File.Exists(ravenLicense)) { - return (localRavenLicense, null); + return (ravenLicense, serverDirectory); } - - const string Persisters = "Persisters"; - const string RavenDB5 = "RavenDB5"; - - var persisterDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Persisters, RavenDB5); - - localRavenLicense = Path.Combine(persisterDirectory, licenseFileName); - if (!File.Exists(localRavenLicense)) + else { - throw new Exception($"RavenDB license not found. Make sure the RavenDB license file, '{licenseFileName}', " + - $"is stored in the '{AppDomain.CurrentDomain.BaseDirectory}' folder or in the '{Persisters}/{RavenDB5}' subfolder."); + var assemblyName = Path.GetFileName(assembly.Location); + throw new Exception($"RavenDB license not found. Make sure the RavenDB license file '{licenseFileName}' is stored in the same directory as {assemblyName}."); } - - // By default RavenDB 5 searches its binaries in the RavenDBServer right below the BaseDirectory. - // If we're loading from Persisters/RavenDB5 we also have to signal RavenDB where are binaries - var serverDirectory = Path.Combine(persisterDirectory, "RavenDBServer"); - - return (localRavenLicense, serverDirectory); } public static EmbeddedDatabase Start(DatabaseConfiguration databaseConfiguration) diff --git a/src/ServiceControl.Audit.Persistence/DevelopmentPersistenceLocations.cs b/src/ServiceControl.Audit.Persistence/DevelopmentPersistenceLocations.cs new file mode 100644 index 0000000000..685daa8ef4 --- /dev/null +++ b/src/ServiceControl.Audit.Persistence/DevelopmentPersistenceLocations.cs @@ -0,0 +1,47 @@ +namespace ServiceControl.Persistence +{ + using System; + using System.Collections.Generic; + using System.IO; + + static class DevelopmentPersistenceLocations + { +#if DEBUG + const string configuration = "Debug"; +#else + const string configuration = "Release"; +#endif + +#if NET472 + const string framework = "net472"; +#endif + + public static bool TryGetPersistenceFolder(string transportName, out string persistenceFolder) + { + persistenceFolder = null; + + if (transportName.Contains(".")) + { + transportName = transportName.Split('.')[0]; + } + + var found = projects.TryGetValue(transportName, out var projectFolder); + + if (found) + { + var assemblyPath = typeof(DevelopmentPersistenceLocations).Assembly.Location; + var assemblyFolder = Path.GetDirectoryName(assemblyPath); + var srcFolder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyFolder)))))); + persistenceFolder = Path.Combine(srcFolder, projectFolder, "bin", configuration, framework); + } + + return found; + } + + static readonly Dictionary projects = new Dictionary(StringComparer.OrdinalIgnoreCase) + { + {"InMemory", "ServiceControl.Audit.Persistence.InMemory" }, + {"RavenDB5", "ServiceControl.Audit.Persistence.RavenDb5" } + }; + } +} diff --git a/src/ServiceControl.Audit.Persistence/PersistenceManifest.cs b/src/ServiceControl.Audit.Persistence/PersistenceManifest.cs index 0936dcd0df..35a10158a8 100644 --- a/src/ServiceControl.Audit.Persistence/PersistenceManifest.cs +++ b/src/ServiceControl.Audit.Persistence/PersistenceManifest.cs @@ -6,14 +6,20 @@ using System.Linq; using System.Text.Json; using NServiceBus.Logging; + using ServiceControl.Persistence; public class PersistenceManifest { public string Version { get; set; } + public string Name { get; set; } + public string DisplayName { get; set; } + public string Description { get; set; } + public string TypeName { get; set; } + public bool IsSupported { get; set; } = true; internal bool IsMatch(string persistenceType) => @@ -26,7 +32,10 @@ public static class PersistenceManifestLibrary public static List PersistenceManifests { get; set; } static bool initialized; - static void Initialize() + + static bool usingDevelopmentLocation; + + static void Initialize(string persistenceType) { if (PersistenceManifests == null) { @@ -36,19 +45,28 @@ static void Initialize() if (!initialized) { initialized = true; - var assemblyLocation = GetAssemblyDirectory(); + var persistenceFolder = GetAssemblyDirectory(); + try { PersistenceManifests.AddRange( - Directory.EnumerateFiles(assemblyLocation, "persistence.manifest", SearchOption.AllDirectories) + Directory.EnumerateFiles(persistenceFolder, "persistence.manifest", SearchOption.AllDirectories) .Select(manifest => JsonSerializer.Deserialize(File.ReadAllText(manifest))) ); + if (PersistenceManifests.Count == 0 && DevelopmentPersistenceLocations.TryGetPersistenceFolder(persistenceType, out persistenceFolder)) + { + var manifest = Path.Combine(persistenceFolder, "persistence.manifest"); + PersistenceManifests.Add(JsonSerializer.Deserialize(File.ReadAllText(manifest))); + + usingDevelopmentLocation = true; + } + PersistenceManifests.ForEach(m => logger.Info($"Found persistence manifest for {m.DisplayName}")); } catch (Exception ex) { - logger.Warn($"Failed to load persistence manifests from {assemblyLocation}", ex); + logger.Warn($"Failed to load persistence manifests from {persistenceFolder}", ex); } } } @@ -66,7 +84,7 @@ public static string Find(string persistenceType) throw new Exception("No persistenceType has been configured. Either provide a Type or Name in the PersistenceType setting."); } - Initialize(); + Initialize(persistenceType); var persistenceManifestDefinition = PersistenceManifests.FirstOrDefault(w => w.IsMatch(persistenceType)); @@ -85,19 +103,30 @@ public static string GetPersistenceFolder(string persistenceType) throw new Exception("No persistenceType has been configured. Either provide a Type or Name in the PersistenceType setting."); } - Initialize(); + Initialize(persistenceType); var persistenceManifestDefinition = PersistenceManifests.FirstOrDefault(w => w.IsMatch(persistenceType)); + string persistenceFolder = null; + if (persistenceManifestDefinition != null) { - return persistenceManifestDefinition.Name.Split('.').FirstOrDefault(); + if (usingDevelopmentLocation) + { + _ = DevelopmentPersistenceLocations.TryGetPersistenceFolder(persistenceManifestDefinition.Name, out persistenceFolder); + } + else + { + var appDirectory = GetAssemblyDirectory(); + var persistenceName = persistenceManifestDefinition.Name.Split('.').FirstOrDefault(); + persistenceFolder = Path.Combine(appDirectory, "Persisters", persistenceName); + } } - return null; + return persistenceFolder; } - static ILog logger = LogManager.GetLogger(typeof(PersistenceManifestLibrary)); + static readonly ILog logger = LogManager.GetLogger(typeof(PersistenceManifestLibrary)); } } diff --git a/src/ServiceControl.Audit/App.config b/src/ServiceControl.Audit/App.config index 435f41a343..cf43fbd84f 100644 --- a/src/ServiceControl.Audit/App.config +++ b/src/ServiceControl.Audit/App.config @@ -27,7 +27,7 @@ These settings are only here so that we can debug ServiceControl while developin - + --> diff --git a/src/ServiceControl.Audit/Program.cs b/src/ServiceControl.Audit/Program.cs index 004165742b..453b2e5714 100644 --- a/src/ServiceControl.Audit/Program.cs +++ b/src/ServiceControl.Audit/Program.cs @@ -50,20 +50,17 @@ static Assembly ResolveAssembly(string name) var combine = Path.Combine(appDirectory, requestingName + ".dll"); var assembly = !File.Exists(combine) ? null : Assembly.LoadFrom(combine); + if (assembly == null && settings != null) { var transportFolder = TransportManifestLibrary.GetTransportFolder(settings.TransportType); - if (transportFolder != null) - { - assembly = TryLoadTypeFromSubdirectory(transportFolder, requestingName); - } + assembly = TryLoadTypeFromSubdirectory(transportFolder, requestingName); + } + if (assembly == null && settings != null) + { var persistenceFolder = PersistenceManifestLibrary.GetPersistenceFolder(settings.PersistenceType); - if (assembly == null && persistenceFolder != null) - { - var subFolderPath = Path.Combine(appDirectory, "Persisters", persistenceFolder); - assembly = TryLoadTypeFromSubdirectory(subFolderPath, requestingName); - } + assembly = TryLoadTypeFromSubdirectory(persistenceFolder, requestingName); } return assembly; @@ -71,11 +68,14 @@ static Assembly ResolveAssembly(string name) static Assembly TryLoadTypeFromSubdirectory(string subFolderPath, string requestingName) { - var path = Path.Combine(subFolderPath, $"{requestingName}.dll"); - - if (File.Exists(path)) + if (subFolderPath != null) { - return Assembly.LoadFrom(path); + var path = Path.Combine(subFolderPath, $"{requestingName}.dll"); + + if (File.Exists(path)) + { + return Assembly.LoadFrom(path); + } } return null; @@ -83,4 +83,4 @@ static Assembly TryLoadTypeFromSubdirectory(string subFolderPath, string request static readonly ILog Logger = LogManager.GetLogger(typeof(Program)); } -} \ No newline at end of file +} diff --git a/src/ServiceControl.Audit/ServiceControl.Audit.csproj b/src/ServiceControl.Audit/ServiceControl.Audit.csproj index c6ce534a2c..5ab74fcccf 100644 --- a/src/ServiceControl.Audit/ServiceControl.Audit.csproj +++ b/src/ServiceControl.Audit/ServiceControl.Audit.csproj @@ -9,10 +9,6 @@ - - - - From dd8ab34ff8c1384e323460cb395c1692fc4f77fc Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Fri, 20 Oct 2023 17:02:54 -0400 Subject: [PATCH 04/11] Update Monitoring to match changes made in other instances --- src/ServiceControl.Monitoring/Program.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ServiceControl.Monitoring/Program.cs b/src/ServiceControl.Monitoring/Program.cs index c8b6ade501..fa224cf75c 100644 --- a/src/ServiceControl.Monitoring/Program.cs +++ b/src/ServiceControl.Monitoring/Program.cs @@ -47,13 +47,11 @@ static Assembly ResolveAssembly(string name) var combine = Path.Combine(appDirectory, requestingName + ".dll"); var assembly = !File.Exists(combine) ? null : Assembly.LoadFrom(combine); + if (assembly == null && settings != null) { var transportFolder = TransportManifestLibrary.GetTransportFolder(settings.TransportType); - if (transportFolder != null) - { - assembly = TryLoadTypeFromSubdirectory(transportFolder, requestingName); - } + assembly = TryLoadTypeFromSubdirectory(transportFolder, requestingName); } return assembly; @@ -61,11 +59,14 @@ static Assembly ResolveAssembly(string name) static Assembly TryLoadTypeFromSubdirectory(string subFolderPath, string requestingName) { - var path = Path.Combine(subFolderPath, $"{requestingName}.dll"); - - if (File.Exists(path)) + if (subFolderPath != null) { - return Assembly.LoadFrom(path); + var path = Path.Combine(subFolderPath, $"{requestingName}.dll"); + + if (File.Exists(path)) + { + return Assembly.LoadFrom(path); + } } return null; From da8230ebacbdae9f9281f02687b886b74349a638 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Fri, 20 Oct 2023 17:41:17 -0400 Subject: [PATCH 05/11] Clean up project files --- src/LegacyArtifacts/LegacyArtifacts.csproj | 1 + ...icular.PlatformSample.ServiceControl.props | 6 ++--- src/Persisters.Audit.Includes.props | 2 ++ src/Persisters.Primary.Includes.props | 2 ++ ...iceControl.AcceptanceTests.RavenDB5.csproj | 6 ++--- .../ServiceControl.runsettings | 8 +++---- ...trol.Audit.AcceptanceTests.RavenDB5.csproj | 2 +- .../ServiceControl.runsettings | 8 +++---- ...erviceControl.Audit.AcceptanceTests.csproj | 4 ++-- .../ServiceControl.runsettings | 8 +++---- ...ol.Audit.Persistence.Tests.RavenDb5.csproj | 2 +- ...viceControl.Audit.Persistence.Tests.csproj | 2 +- .../ServiceControl.Audit.UnitTests.csproj | 4 ++-- .../ServiceControl.runsettings | 8 +++---- .../ServiceControl.Infrastructure.csproj | 2 +- ...iceControl.LoadTests.AuditGenerator.csproj | 2 +- ...eControl.Monitoring.AcceptanceTests.csproj | 1 - .../ServiceControl.runsettings | 8 +++---- ...ServiceControl.Persistence.RavenDb5.csproj | 4 ++-- ...eControl.Persistence.Tests.RavenDb5.csproj | 9 +++----- .../ServiceControl.runsettings | 8 +++---- .../ServiceControl.Persistence.csproj | 11 +++++----- .../ServiceControl.Transports.ASB.csproj | 4 ++-- ...ransports.ASBEndpointTopology.Tests.csproj | 16 ++++++-------- ...nsports.ASBForwardingTopology.Tests.csproj | 16 ++++++-------- ...erviceControl.Transports.ASBS.Tests.csproj | 17 +++++++------- .../ServiceControl.Transports.ASBS.csproj | 4 ++-- ...ServiceControl.Transports.ASQ.Tests.csproj | 16 ++++++-------- .../ServiceControl.Transports.ASQ.csproj | 4 ++-- .../ServiceControl.Transports.Learning.csproj | 4 ++-- ...erviceControl.Transports.Msmq.Tests.csproj | 17 +++++++------- .../ServiceControl.Transports.Msmq.csproj | 4 ++-- .../ServiceControl.Transports.RabbitMQ.csproj | 4 ++-- ...itMQClassicConventionalRoutingTests.csproj | 16 ++++++-------- ....RabbitMQClassicDirectRouting.Tests.csproj | 16 ++++++-------- ...itMQQuorumConventionalRouting.Tests.csproj | 16 ++++++-------- ...s.RabbitMQQuorumDirectRouting.Tests.csproj | 16 ++++++-------- ...ServiceControl.Transports.SQS.Tests.csproj | 16 ++++++-------- .../ServiceControl.Transports.SQS.csproj | 4 ++-- ...eControl.Transports.SqlServer.Tests.csproj | 16 ++++++-------- ...ServiceControl.Transports.SqlServer.csproj | 4 ++-- .../ServiceControl.runsettings | 8 +++---- src/ServiceControl.runsettings | 6 ++--- src/ServiceControl/ServiceControl.csproj | 5 ----- src/Transports.Includes.props | 22 ++++++++++--------- 45 files changed, 170 insertions(+), 189 deletions(-) diff --git a/src/LegacyArtifacts/LegacyArtifacts.csproj b/src/LegacyArtifacts/LegacyArtifacts.csproj index c43b9ad2c1..7632abb5cd 100644 --- a/src/LegacyArtifacts/LegacyArtifacts.csproj +++ b/src/LegacyArtifacts/LegacyArtifacts.csproj @@ -11,4 +11,5 @@ --> + diff --git a/src/Particular.PlatformSample.ServiceControl/buildProps/build/Particular.PlatformSample.ServiceControl.props b/src/Particular.PlatformSample.ServiceControl/buildProps/build/Particular.PlatformSample.ServiceControl.props index ce70b7e6b5..7dcd072371 100644 --- a/src/Particular.PlatformSample.ServiceControl/buildProps/build/Particular.PlatformSample.ServiceControl.props +++ b/src/Particular.PlatformSample.ServiceControl/buildProps/build/Particular.PlatformSample.ServiceControl.props @@ -5,15 +5,15 @@ - + - + - + diff --git a/src/Persisters.Audit.Includes.props b/src/Persisters.Audit.Includes.props index 37dcec6c3f..cb409ec769 100644 --- a/src/Persisters.Audit.Includes.props +++ b/src/Persisters.Audit.Includes.props @@ -1,6 +1,8 @@ + + \ No newline at end of file diff --git a/src/Persisters.Primary.Includes.props b/src/Persisters.Primary.Includes.props index 1cdabb3928..b1eb798370 100644 --- a/src/Persisters.Primary.Includes.props +++ b/src/Persisters.Primary.Includes.props @@ -1,5 +1,7 @@ + + \ No newline at end of file diff --git a/src/ServiceControl.AcceptanceTests.RavenDB5/ServiceControl.AcceptanceTests.RavenDB5.csproj b/src/ServiceControl.AcceptanceTests.RavenDB5/ServiceControl.AcceptanceTests.RavenDB5.csproj index 56ca657cf8..08a3855215 100644 --- a/src/ServiceControl.AcceptanceTests.RavenDB5/ServiceControl.AcceptanceTests.RavenDB5.csproj +++ b/src/ServiceControl.AcceptanceTests.RavenDB5/ServiceControl.AcceptanceTests.RavenDB5.csproj @@ -3,7 +3,7 @@ net472 ServiceControl.runsettings - 8 + 8.0 @@ -25,7 +25,7 @@ - + - + diff --git a/src/ServiceControl.AcceptanceTests.RavenDB5/ServiceControl.runsettings b/src/ServiceControl.AcceptanceTests.RavenDB5/ServiceControl.runsettings index ea2e767f89..624cd65002 100644 --- a/src/ServiceControl.AcceptanceTests.RavenDB5/ServiceControl.runsettings +++ b/src/ServiceControl.AcceptanceTests.RavenDB5/ServiceControl.runsettings @@ -1,7 +1,7 @@  - - - x64 - + + + x64 + diff --git a/src/ServiceControl.Audit.AcceptanceTests.RavenDB5/ServiceControl.Audit.AcceptanceTests.RavenDB5.csproj b/src/ServiceControl.Audit.AcceptanceTests.RavenDB5/ServiceControl.Audit.AcceptanceTests.RavenDB5.csproj index e865288fd6..8d6fafce95 100644 --- a/src/ServiceControl.Audit.AcceptanceTests.RavenDB5/ServiceControl.Audit.AcceptanceTests.RavenDB5.csproj +++ b/src/ServiceControl.Audit.AcceptanceTests.RavenDB5/ServiceControl.Audit.AcceptanceTests.RavenDB5.csproj @@ -3,7 +3,7 @@ net472 ServiceControl.runsettings - 8 + 8.0 diff --git a/src/ServiceControl.Audit.AcceptanceTests.RavenDB5/ServiceControl.runsettings b/src/ServiceControl.Audit.AcceptanceTests.RavenDB5/ServiceControl.runsettings index ea2e767f89..624cd65002 100644 --- a/src/ServiceControl.Audit.AcceptanceTests.RavenDB5/ServiceControl.runsettings +++ b/src/ServiceControl.Audit.AcceptanceTests.RavenDB5/ServiceControl.runsettings @@ -1,7 +1,7 @@  - - - x64 - + + + x64 + diff --git a/src/ServiceControl.Audit.AcceptanceTests/ServiceControl.Audit.AcceptanceTests.csproj b/src/ServiceControl.Audit.AcceptanceTests/ServiceControl.Audit.AcceptanceTests.csproj index 1d668f3f6c..61a8c6b82f 100644 --- a/src/ServiceControl.Audit.AcceptanceTests/ServiceControl.Audit.AcceptanceTests.csproj +++ b/src/ServiceControl.Audit.AcceptanceTests/ServiceControl.Audit.AcceptanceTests.csproj @@ -3,13 +3,13 @@ net472 ServiceControl.runsettings - 8 + 8.0 - + diff --git a/src/ServiceControl.Audit.AcceptanceTests/ServiceControl.runsettings b/src/ServiceControl.Audit.AcceptanceTests/ServiceControl.runsettings index ea2e767f89..624cd65002 100644 --- a/src/ServiceControl.Audit.AcceptanceTests/ServiceControl.runsettings +++ b/src/ServiceControl.Audit.AcceptanceTests/ServiceControl.runsettings @@ -1,7 +1,7 @@  - - - x64 - + + + x64 + diff --git a/src/ServiceControl.Audit.Persistence.Tests.RavenDb5/ServiceControl.Audit.Persistence.Tests.RavenDb5.csproj b/src/ServiceControl.Audit.Persistence.Tests.RavenDb5/ServiceControl.Audit.Persistence.Tests.RavenDb5.csproj index bf93387da9..ad26e94b62 100644 --- a/src/ServiceControl.Audit.Persistence.Tests.RavenDb5/ServiceControl.Audit.Persistence.Tests.RavenDb5.csproj +++ b/src/ServiceControl.Audit.Persistence.Tests.RavenDb5/ServiceControl.Audit.Persistence.Tests.RavenDb5.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/ServiceControl.Audit.Persistence.Tests/ServiceControl.Audit.Persistence.Tests.csproj b/src/ServiceControl.Audit.Persistence.Tests/ServiceControl.Audit.Persistence.Tests.csproj index f564d7aa23..1b785ba1f1 100644 --- a/src/ServiceControl.Audit.Persistence.Tests/ServiceControl.Audit.Persistence.Tests.csproj +++ b/src/ServiceControl.Audit.Persistence.Tests/ServiceControl.Audit.Persistence.Tests.csproj @@ -3,7 +3,7 @@ net472 - + diff --git a/src/ServiceControl.Audit.UnitTests/ServiceControl.Audit.UnitTests.csproj b/src/ServiceControl.Audit.UnitTests/ServiceControl.Audit.UnitTests.csproj index 10d2e30cfc..80ba33276a 100644 --- a/src/ServiceControl.Audit.UnitTests/ServiceControl.Audit.UnitTests.csproj +++ b/src/ServiceControl.Audit.UnitTests/ServiceControl.Audit.UnitTests.csproj @@ -4,11 +4,11 @@ net472 ServiceControl.runsettings - + + - diff --git a/src/ServiceControl.Audit.UnitTests/ServiceControl.runsettings b/src/ServiceControl.Audit.UnitTests/ServiceControl.runsettings index ea2e767f89..624cd65002 100644 --- a/src/ServiceControl.Audit.UnitTests/ServiceControl.runsettings +++ b/src/ServiceControl.Audit.UnitTests/ServiceControl.runsettings @@ -1,7 +1,7 @@  - - - x64 - + + + x64 + diff --git a/src/ServiceControl.Infrastructure/ServiceControl.Infrastructure.csproj b/src/ServiceControl.Infrastructure/ServiceControl.Infrastructure.csproj index 643937d08c..a5c1475468 100644 --- a/src/ServiceControl.Infrastructure/ServiceControl.Infrastructure.csproj +++ b/src/ServiceControl.Infrastructure/ServiceControl.Infrastructure.csproj @@ -9,5 +9,5 @@ - + \ No newline at end of file diff --git a/src/ServiceControl.LoadTests.AuditGenerator/ServiceControl.LoadTests.AuditGenerator.csproj b/src/ServiceControl.LoadTests.AuditGenerator/ServiceControl.LoadTests.AuditGenerator.csproj index 67c9906027..0786dbcd5d 100644 --- a/src/ServiceControl.LoadTests.AuditGenerator/ServiceControl.LoadTests.AuditGenerator.csproj +++ b/src/ServiceControl.LoadTests.AuditGenerator/ServiceControl.LoadTests.AuditGenerator.csproj @@ -4,7 +4,7 @@ net472 Exe AuditGenerator - 8 + 8.0 diff --git a/src/ServiceControl.Monitoring.AcceptanceTests/ServiceControl.Monitoring.AcceptanceTests.csproj b/src/ServiceControl.Monitoring.AcceptanceTests/ServiceControl.Monitoring.AcceptanceTests.csproj index 23c078953d..d8f69b3844 100644 --- a/src/ServiceControl.Monitoring.AcceptanceTests/ServiceControl.Monitoring.AcceptanceTests.csproj +++ b/src/ServiceControl.Monitoring.AcceptanceTests/ServiceControl.Monitoring.AcceptanceTests.csproj @@ -5,7 +5,6 @@ 8 - diff --git a/src/ServiceControl.MultiInstance.AcceptanceTests/ServiceControl.runsettings b/src/ServiceControl.MultiInstance.AcceptanceTests/ServiceControl.runsettings index ea2e767f89..624cd65002 100644 --- a/src/ServiceControl.MultiInstance.AcceptanceTests/ServiceControl.runsettings +++ b/src/ServiceControl.MultiInstance.AcceptanceTests/ServiceControl.runsettings @@ -1,7 +1,7 @@  - - - x64 - + + + x64 + diff --git a/src/ServiceControl.Persistence.RavenDb5/ServiceControl.Persistence.RavenDb5.csproj b/src/ServiceControl.Persistence.RavenDb5/ServiceControl.Persistence.RavenDb5.csproj index 85fe63bef3..a507ef682d 100644 --- a/src/ServiceControl.Persistence.RavenDb5/ServiceControl.Persistence.RavenDb5.csproj +++ b/src/ServiceControl.Persistence.RavenDb5/ServiceControl.Persistence.RavenDb5.csproj @@ -6,14 +6,14 @@ - + - + diff --git a/src/ServiceControl.Persistence.Tests.RavenDb5/ServiceControl.Persistence.Tests.RavenDb5.csproj b/src/ServiceControl.Persistence.Tests.RavenDb5/ServiceControl.Persistence.Tests.RavenDb5.csproj index 1aa7242079..ad0944943d 100644 --- a/src/ServiceControl.Persistence.Tests.RavenDb5/ServiceControl.Persistence.Tests.RavenDb5.csproj +++ b/src/ServiceControl.Persistence.Tests.RavenDb5/ServiceControl.Persistence.Tests.RavenDb5.csproj @@ -5,12 +5,9 @@ ServiceControl.runsettings - - - - + @@ -18,15 +15,15 @@ + - - + diff --git a/src/ServiceControl.Persistence.Tests.RavenDb5/ServiceControl.runsettings b/src/ServiceControl.Persistence.Tests.RavenDb5/ServiceControl.runsettings index ea2e767f89..624cd65002 100644 --- a/src/ServiceControl.Persistence.Tests.RavenDb5/ServiceControl.runsettings +++ b/src/ServiceControl.Persistence.Tests.RavenDb5/ServiceControl.runsettings @@ -1,7 +1,7 @@  - - - x64 - + + + x64 + diff --git a/src/ServiceControl.Persistence/ServiceControl.Persistence.csproj b/src/ServiceControl.Persistence/ServiceControl.Persistence.csproj index fd6857877f..a8a9989c7d 100644 --- a/src/ServiceControl.Persistence/ServiceControl.Persistence.csproj +++ b/src/ServiceControl.Persistence/ServiceControl.Persistence.csproj @@ -4,18 +4,19 @@ net472 + + + + + - + - - - - \ No newline at end of file diff --git a/src/ServiceControl.Transports.ASB/ServiceControl.Transports.ASB.csproj b/src/ServiceControl.Transports.ASB/ServiceControl.Transports.ASB.csproj index a0ca58b37d..56513e9cd0 100644 --- a/src/ServiceControl.Transports.ASB/ServiceControl.Transports.ASB.csproj +++ b/src/ServiceControl.Transports.ASB/ServiceControl.Transports.ASB.csproj @@ -14,11 +14,11 @@ - + - + \ No newline at end of file diff --git a/src/ServiceControl.Transports.ASBEndpointTopology.Tests/ServiceControl.Transports.ASBEndpointTopology.Tests.csproj b/src/ServiceControl.Transports.ASBEndpointTopology.Tests/ServiceControl.Transports.ASBEndpointTopology.Tests.csproj index d0ec0d26e7..5fd518683d 100644 --- a/src/ServiceControl.Transports.ASBEndpointTopology.Tests/ServiceControl.Transports.ASBEndpointTopology.Tests.csproj +++ b/src/ServiceControl.Transports.ASBEndpointTopology.Tests/ServiceControl.Transports.ASBEndpointTopology.Tests.csproj @@ -2,27 +2,25 @@ net472 - false + + + + + + - - - - - - - + - \ No newline at end of file diff --git a/src/ServiceControl.Transports.ASBForwardingTopology.Tests/ServiceControl.Transports.ASBForwardingTopology.Tests.csproj b/src/ServiceControl.Transports.ASBForwardingTopology.Tests/ServiceControl.Transports.ASBForwardingTopology.Tests.csproj index 9799830b13..33c09df6f6 100644 --- a/src/ServiceControl.Transports.ASBForwardingTopology.Tests/ServiceControl.Transports.ASBForwardingTopology.Tests.csproj +++ b/src/ServiceControl.Transports.ASBForwardingTopology.Tests/ServiceControl.Transports.ASBForwardingTopology.Tests.csproj @@ -2,27 +2,25 @@ net472 - false + + + + + + - - - - - - - + - \ No newline at end of file diff --git a/src/ServiceControl.Transports.ASBS.Tests/ServiceControl.Transports.ASBS.Tests.csproj b/src/ServiceControl.Transports.ASBS.Tests/ServiceControl.Transports.ASBS.Tests.csproj index c9254cf4e2..d0deb53b83 100644 --- a/src/ServiceControl.Transports.ASBS.Tests/ServiceControl.Transports.ASBS.Tests.csproj +++ b/src/ServiceControl.Transports.ASBS.Tests/ServiceControl.Transports.ASBS.Tests.csproj @@ -2,27 +2,26 @@ net472 - false + + + + + + + - - - - - - - + - diff --git a/src/ServiceControl.Transports.ASBS/ServiceControl.Transports.ASBS.csproj b/src/ServiceControl.Transports.ASBS/ServiceControl.Transports.ASBS.csproj index 72d28e4c23..0030a9638e 100644 --- a/src/ServiceControl.Transports.ASBS/ServiceControl.Transports.ASBS.csproj +++ b/src/ServiceControl.Transports.ASBS/ServiceControl.Transports.ASBS.csproj @@ -15,11 +15,11 @@ - + - + \ No newline at end of file diff --git a/src/ServiceControl.Transports.ASQ.Tests/ServiceControl.Transports.ASQ.Tests.csproj b/src/ServiceControl.Transports.ASQ.Tests/ServiceControl.Transports.ASQ.Tests.csproj index 2b06001bc7..a370581049 100644 --- a/src/ServiceControl.Transports.ASQ.Tests/ServiceControl.Transports.ASQ.Tests.csproj +++ b/src/ServiceControl.Transports.ASQ.Tests/ServiceControl.Transports.ASQ.Tests.csproj @@ -2,27 +2,25 @@ net472 - false + + + + + + - - - - - - - + - \ No newline at end of file diff --git a/src/ServiceControl.Transports.ASQ/ServiceControl.Transports.ASQ.csproj b/src/ServiceControl.Transports.ASQ/ServiceControl.Transports.ASQ.csproj index 15cb68d906..60dec855f3 100644 --- a/src/ServiceControl.Transports.ASQ/ServiceControl.Transports.ASQ.csproj +++ b/src/ServiceControl.Transports.ASQ/ServiceControl.Transports.ASQ.csproj @@ -13,11 +13,11 @@ - + - + diff --git a/src/ServiceControl.Transports.Learning/ServiceControl.Transports.Learning.csproj b/src/ServiceControl.Transports.Learning/ServiceControl.Transports.Learning.csproj index ec57ecfa82..773bb37ec0 100644 --- a/src/ServiceControl.Transports.Learning/ServiceControl.Transports.Learning.csproj +++ b/src/ServiceControl.Transports.Learning/ServiceControl.Transports.Learning.csproj @@ -9,11 +9,11 @@ - + - + \ No newline at end of file diff --git a/src/ServiceControl.Transports.Msmq.Tests/ServiceControl.Transports.Msmq.Tests.csproj b/src/ServiceControl.Transports.Msmq.Tests/ServiceControl.Transports.Msmq.Tests.csproj index e4e436e979..4a3798364f 100644 --- a/src/ServiceControl.Transports.Msmq.Tests/ServiceControl.Transports.Msmq.Tests.csproj +++ b/src/ServiceControl.Transports.Msmq.Tests/ServiceControl.Transports.Msmq.Tests.csproj @@ -3,21 +3,22 @@ net472 + + + + + + + - - - - - - - + @@ -25,6 +26,6 @@ - + diff --git a/src/ServiceControl.Transports.Msmq/ServiceControl.Transports.Msmq.csproj b/src/ServiceControl.Transports.Msmq/ServiceControl.Transports.Msmq.csproj index 8b757b14db..8d35f8ded1 100644 --- a/src/ServiceControl.Transports.Msmq/ServiceControl.Transports.Msmq.csproj +++ b/src/ServiceControl.Transports.Msmq/ServiceControl.Transports.Msmq.csproj @@ -14,11 +14,11 @@ - + - + diff --git a/src/ServiceControl.Transports.RabbitMQ/ServiceControl.Transports.RabbitMQ.csproj b/src/ServiceControl.Transports.RabbitMQ/ServiceControl.Transports.RabbitMQ.csproj index 28dd5f110c..19e6524e09 100644 --- a/src/ServiceControl.Transports.RabbitMQ/ServiceControl.Transports.RabbitMQ.csproj +++ b/src/ServiceControl.Transports.RabbitMQ/ServiceControl.Transports.RabbitMQ.csproj @@ -13,11 +13,11 @@ - + - + \ No newline at end of file diff --git a/src/ServiceControl.Transports.RabbitMQClassicConventionalRouting.Tests/ServiceControl.Transports.RabbitMQClassicConventionalRoutingTests.csproj b/src/ServiceControl.Transports.RabbitMQClassicConventionalRouting.Tests/ServiceControl.Transports.RabbitMQClassicConventionalRoutingTests.csproj index 2c481cd13e..1be9f368d0 100644 --- a/src/ServiceControl.Transports.RabbitMQClassicConventionalRouting.Tests/ServiceControl.Transports.RabbitMQClassicConventionalRoutingTests.csproj +++ b/src/ServiceControl.Transports.RabbitMQClassicConventionalRouting.Tests/ServiceControl.Transports.RabbitMQClassicConventionalRoutingTests.csproj @@ -2,27 +2,25 @@ net472 - false + + + + + + - - - - - - - + - \ No newline at end of file diff --git a/src/ServiceControl.Transports.RabbitMQClassicDirectRouting.Tests/ServiceControl.Transports.RabbitMQClassicDirectRouting.Tests.csproj b/src/ServiceControl.Transports.RabbitMQClassicDirectRouting.Tests/ServiceControl.Transports.RabbitMQClassicDirectRouting.Tests.csproj index 2c481cd13e..1be9f368d0 100644 --- a/src/ServiceControl.Transports.RabbitMQClassicDirectRouting.Tests/ServiceControl.Transports.RabbitMQClassicDirectRouting.Tests.csproj +++ b/src/ServiceControl.Transports.RabbitMQClassicDirectRouting.Tests/ServiceControl.Transports.RabbitMQClassicDirectRouting.Tests.csproj @@ -2,27 +2,25 @@ net472 - false + + + + + + - - - - - - - + - \ No newline at end of file diff --git a/src/ServiceControl.Transports.RabbitMQQuorumConventionalRouting.Tests/ServiceControl.Transports.RabbitMQQuorumConventionalRouting.Tests.csproj b/src/ServiceControl.Transports.RabbitMQQuorumConventionalRouting.Tests/ServiceControl.Transports.RabbitMQQuorumConventionalRouting.Tests.csproj index 479fba8815..b570abbaab 100644 --- a/src/ServiceControl.Transports.RabbitMQQuorumConventionalRouting.Tests/ServiceControl.Transports.RabbitMQQuorumConventionalRouting.Tests.csproj +++ b/src/ServiceControl.Transports.RabbitMQQuorumConventionalRouting.Tests/ServiceControl.Transports.RabbitMQQuorumConventionalRouting.Tests.csproj @@ -2,27 +2,25 @@ net472 - false + + + + + + - - - - - - - + - diff --git a/src/ServiceControl.Transports.RabbitMQQuorumDirectRouting.Tests/ServiceControl.Transports.RabbitMQQuorumDirectRouting.Tests.csproj b/src/ServiceControl.Transports.RabbitMQQuorumDirectRouting.Tests/ServiceControl.Transports.RabbitMQQuorumDirectRouting.Tests.csproj index 2c481cd13e..1be9f368d0 100644 --- a/src/ServiceControl.Transports.RabbitMQQuorumDirectRouting.Tests/ServiceControl.Transports.RabbitMQQuorumDirectRouting.Tests.csproj +++ b/src/ServiceControl.Transports.RabbitMQQuorumDirectRouting.Tests/ServiceControl.Transports.RabbitMQQuorumDirectRouting.Tests.csproj @@ -2,27 +2,25 @@ net472 - false + + + + + + - - - - - - - + - \ No newline at end of file diff --git a/src/ServiceControl.Transports.SQS.Tests/ServiceControl.Transports.SQS.Tests.csproj b/src/ServiceControl.Transports.SQS.Tests/ServiceControl.Transports.SQS.Tests.csproj index 70bfa641b1..cebcd325a8 100644 --- a/src/ServiceControl.Transports.SQS.Tests/ServiceControl.Transports.SQS.Tests.csproj +++ b/src/ServiceControl.Transports.SQS.Tests/ServiceControl.Transports.SQS.Tests.csproj @@ -2,25 +2,23 @@ net472 - false + + + + + + - - - - - - - - + diff --git a/src/ServiceControl.Transports.SQS/ServiceControl.Transports.SQS.csproj b/src/ServiceControl.Transports.SQS/ServiceControl.Transports.SQS.csproj index 24434d2573..ae94a61a17 100644 --- a/src/ServiceControl.Transports.SQS/ServiceControl.Transports.SQS.csproj +++ b/src/ServiceControl.Transports.SQS/ServiceControl.Transports.SQS.csproj @@ -13,11 +13,11 @@ - + - + \ No newline at end of file diff --git a/src/ServiceControl.Transports.SqlServer.Tests/ServiceControl.Transports.SqlServer.Tests.csproj b/src/ServiceControl.Transports.SqlServer.Tests/ServiceControl.Transports.SqlServer.Tests.csproj index 9536fb1219..39eba65cec 100644 --- a/src/ServiceControl.Transports.SqlServer.Tests/ServiceControl.Transports.SqlServer.Tests.csproj +++ b/src/ServiceControl.Transports.SqlServer.Tests/ServiceControl.Transports.SqlServer.Tests.csproj @@ -2,27 +2,25 @@ net472 - false + + + + + + - - - - - - - + - diff --git a/src/ServiceControl.Transports.SqlServer/ServiceControl.Transports.SqlServer.csproj b/src/ServiceControl.Transports.SqlServer/ServiceControl.Transports.SqlServer.csproj index 4a7540227a..8544613fa7 100644 --- a/src/ServiceControl.Transports.SqlServer/ServiceControl.Transports.SqlServer.csproj +++ b/src/ServiceControl.Transports.SqlServer/ServiceControl.Transports.SqlServer.csproj @@ -13,11 +13,11 @@ - + - + diff --git a/src/ServiceControl.UnitTests/ServiceControl.runsettings b/src/ServiceControl.UnitTests/ServiceControl.runsettings index ea2e767f89..624cd65002 100644 --- a/src/ServiceControl.UnitTests/ServiceControl.runsettings +++ b/src/ServiceControl.UnitTests/ServiceControl.runsettings @@ -1,7 +1,7 @@  - - - x64 - + + + x64 + diff --git a/src/ServiceControl.runsettings b/src/ServiceControl.runsettings index 7a67eed179..cf4838b8a9 100644 --- a/src/ServiceControl.runsettings +++ b/src/ServiceControl.runsettings @@ -1,6 +1,6 @@  - - x64 - + + x64 + diff --git a/src/ServiceControl/ServiceControl.csproj b/src/ServiceControl/ServiceControl.csproj index 2dddfbfa34..51b05296a1 100644 --- a/src/ServiceControl/ServiceControl.csproj +++ b/src/ServiceControl/ServiceControl.csproj @@ -9,11 +9,6 @@ - - - - - diff --git a/src/Transports.Includes.props b/src/Transports.Includes.props index 879d64d39b..ebf9c3d4b6 100644 --- a/src/Transports.Includes.props +++ b/src/Transports.Includes.props @@ -1,12 +1,14 @@ - - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file From 86616edeb712212c84409f223f0ac5fa3ddd2c12 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Fri, 20 Oct 2023 18:11:44 -0400 Subject: [PATCH 06/11] Rename build ordering props and clean up usage --- ... ProjectReferences.Persisters.Audit.props} | 0 ...rojectReferences.Persisters.Primary.props} | 0 ...ops => ProjectReferences.Transports.props} | 0 ...viceControl.Audit.Persistence.Tests.csproj | 14 +------------- .../ServiceControl.Audit.csproj | 5 +++-- .../ServiceControl.Monitoring.csproj | 3 ++- .../ServiceControl.Transports.Tests.csproj | 19 ++----------------- src/ServiceControl.sln | 6 +++--- src/ServiceControl/ServiceControl.csproj | 5 +++-- 9 files changed, 14 insertions(+), 38 deletions(-) rename src/{Persisters.Audit.Includes.props => ProjectReferences.Persisters.Audit.props} (100%) rename src/{Persisters.Primary.Includes.props => ProjectReferences.Persisters.Primary.props} (100%) rename src/{Transports.Includes.props => ProjectReferences.Transports.props} (100%) diff --git a/src/Persisters.Audit.Includes.props b/src/ProjectReferences.Persisters.Audit.props similarity index 100% rename from src/Persisters.Audit.Includes.props rename to src/ProjectReferences.Persisters.Audit.props diff --git a/src/Persisters.Primary.Includes.props b/src/ProjectReferences.Persisters.Primary.props similarity index 100% rename from src/Persisters.Primary.Includes.props rename to src/ProjectReferences.Persisters.Primary.props diff --git a/src/Transports.Includes.props b/src/ProjectReferences.Transports.props similarity index 100% rename from src/Transports.Includes.props rename to src/ProjectReferences.Transports.props diff --git a/src/ServiceControl.Audit.Persistence.Tests/ServiceControl.Audit.Persistence.Tests.csproj b/src/ServiceControl.Audit.Persistence.Tests/ServiceControl.Audit.Persistence.Tests.csproj index 1b785ba1f1..381edcf9e0 100644 --- a/src/ServiceControl.Audit.Persistence.Tests/ServiceControl.Audit.Persistence.Tests.csproj +++ b/src/ServiceControl.Audit.Persistence.Tests/ServiceControl.Audit.Persistence.Tests.csproj @@ -4,20 +4,8 @@ net472 - - - - - - - - - - - - - + diff --git a/src/ServiceControl.Audit/ServiceControl.Audit.csproj b/src/ServiceControl.Audit/ServiceControl.Audit.csproj index 5ab74fcccf..e47edf652e 100644 --- a/src/ServiceControl.Audit/ServiceControl.Audit.csproj +++ b/src/ServiceControl.Audit/ServiceControl.Audit.csproj @@ -6,8 +6,9 @@ Operations.ico - - + + + diff --git a/src/ServiceControl.Monitoring/ServiceControl.Monitoring.csproj b/src/ServiceControl.Monitoring/ServiceControl.Monitoring.csproj index 3b56feeedd..9ec7eb594b 100644 --- a/src/ServiceControl.Monitoring/ServiceControl.Monitoring.csproj +++ b/src/ServiceControl.Monitoring/ServiceControl.Monitoring.csproj @@ -6,7 +6,8 @@ Operations.ico - + + diff --git a/src/ServiceControl.Transports.Tests/ServiceControl.Transports.Tests.csproj b/src/ServiceControl.Transports.Tests/ServiceControl.Transports.Tests.csproj index 03e03bbb27..7d6b0235a6 100644 --- a/src/ServiceControl.Transports.Tests/ServiceControl.Transports.Tests.csproj +++ b/src/ServiceControl.Transports.Tests/ServiceControl.Transports.Tests.csproj @@ -4,20 +4,11 @@ net472 - - - - - - - - - - + + - @@ -28,10 +19,4 @@ - - - - - - diff --git a/src/ServiceControl.sln b/src/ServiceControl.sln index 2c6de35bad..fd6b635bdf 100644 --- a/src/ServiceControl.sln +++ b/src/ServiceControl.sln @@ -46,9 +46,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Custom.Build.props = Custom.Build.props Directory.Build.targets = Directory.Build.targets Directory.Packages.props = Directory.Packages.props - Persisters.Audit.Includes.props = Persisters.Audit.Includes.props - Persisters.Primary.Includes.props = Persisters.Primary.Includes.props - Transports.Includes.props = Transports.Includes.props + ProjectReferences.Persisters.Audit.props = ProjectReferences.Persisters.Audit.props + ProjectReferences.Persisters.Primary.props = ProjectReferences.Persisters.Primary.props + ProjectReferences.Transports.props = ProjectReferences.Transports.props EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceControl.Transports", "ServiceControl.Transports\ServiceControl.Transports.csproj", "{3D9E3A53-164F-4430-A6A4-D35551F5DC88}" diff --git a/src/ServiceControl/ServiceControl.csproj b/src/ServiceControl/ServiceControl.csproj index 51b05296a1..ecef688e15 100644 --- a/src/ServiceControl/ServiceControl.csproj +++ b/src/ServiceControl/ServiceControl.csproj @@ -7,8 +7,9 @@ true - - + + + From d1f46039e6812027edd5dd4d30a037d15b422cf7 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Fri, 20 Oct 2023 18:13:51 -0400 Subject: [PATCH 07/11] Simplify Packaging because of build ordering props --- .../ServiceControlInstaller.Packaging.csproj | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/ServiceControlInstaller.Packaging/ServiceControlInstaller.Packaging.csproj b/src/ServiceControlInstaller.Packaging/ServiceControlInstaller.Packaging.csproj index dab9e16cde..d14e4ea6fa 100644 --- a/src/ServiceControlInstaller.Packaging/ServiceControlInstaller.Packaging.csproj +++ b/src/ServiceControlInstaller.Packaging/ServiceControlInstaller.Packaging.csproj @@ -10,26 +10,6 @@ - - - - - - - - - - - - - - - - - - - - From a07cbf788e97803f0018f11199073b3c9d8e5e87 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Mon, 23 Oct 2023 17:10:59 -0400 Subject: [PATCH 08/11] Rename method --- src/ServiceControl.Audit/Program.cs | 10 +++++----- src/ServiceControl.Monitoring/Program.cs | 8 ++++---- src/ServiceControl/Program.cs | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ServiceControl.Audit/Program.cs b/src/ServiceControl.Audit/Program.cs index 453b2e5714..a03354abcc 100644 --- a/src/ServiceControl.Audit/Program.cs +++ b/src/ServiceControl.Audit/Program.cs @@ -54,23 +54,23 @@ static Assembly ResolveAssembly(string name) if (assembly == null && settings != null) { var transportFolder = TransportManifestLibrary.GetTransportFolder(settings.TransportType); - assembly = TryLoadTypeFromSubdirectory(transportFolder, requestingName); + assembly = TryLoadAssembly(transportFolder, requestingName); } if (assembly == null && settings != null) { var persistenceFolder = PersistenceManifestLibrary.GetPersistenceFolder(settings.PersistenceType); - assembly = TryLoadTypeFromSubdirectory(persistenceFolder, requestingName); + assembly = TryLoadAssembly(persistenceFolder, requestingName); } return assembly; } - static Assembly TryLoadTypeFromSubdirectory(string subFolderPath, string requestingName) + static Assembly TryLoadAssembly(string folderPath, string requestingName) { - if (subFolderPath != null) + if (folderPath != null) { - var path = Path.Combine(subFolderPath, $"{requestingName}.dll"); + var path = Path.Combine(folderPath, $"{requestingName}.dll"); if (File.Exists(path)) { diff --git a/src/ServiceControl.Monitoring/Program.cs b/src/ServiceControl.Monitoring/Program.cs index fa224cf75c..703dd3686a 100644 --- a/src/ServiceControl.Monitoring/Program.cs +++ b/src/ServiceControl.Monitoring/Program.cs @@ -51,17 +51,17 @@ static Assembly ResolveAssembly(string name) if (assembly == null && settings != null) { var transportFolder = TransportManifestLibrary.GetTransportFolder(settings.TransportType); - assembly = TryLoadTypeFromSubdirectory(transportFolder, requestingName); + assembly = TryLoadAssembly(transportFolder, requestingName); } return assembly; } - static Assembly TryLoadTypeFromSubdirectory(string subFolderPath, string requestingName) + static Assembly TryLoadAssembly(string folderPath, string requestingName) { - if (subFolderPath != null) + if (folderPath != null) { - var path = Path.Combine(subFolderPath, $"{requestingName}.dll"); + var path = Path.Combine(folderPath, $"{requestingName}.dll"); if (File.Exists(path)) { diff --git a/src/ServiceControl/Program.cs b/src/ServiceControl/Program.cs index 260792f784..8a491398ae 100644 --- a/src/ServiceControl/Program.cs +++ b/src/ServiceControl/Program.cs @@ -52,23 +52,23 @@ static Assembly ResolveAssembly(string name) if (assembly == null && settings != null) { var transportFolder = TransportManifestLibrary.GetTransportFolder(settings.TransportType); - assembly = TryLoadTypeFromSubdirectory(transportFolder, requestingName); + assembly = TryLoadAssembly(transportFolder, requestingName); } if (assembly == null && settings != null) { var persistenceFolder = PersistenceManifestLibrary.GetPersistenceFolder(settings.PersistenceType); - assembly = TryLoadTypeFromSubdirectory(persistenceFolder, requestingName); + assembly = TryLoadAssembly(persistenceFolder, requestingName); } return assembly; } - static Assembly TryLoadTypeFromSubdirectory(string subFolderPath, string requestingName) + static Assembly TryLoadAssembly(string folderPath, string requestingName) { - if (subFolderPath != null) + if (folderPath != null) { - var path = Path.Combine(subFolderPath, $"{requestingName}.dll"); + var path = Path.Combine(folderPath, $"{requestingName}.dll"); if (File.Exists(path)) { From e9648546e6e8ec8433420fc5147217b9af70d325 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Mon, 23 Oct 2023 18:47:15 -0400 Subject: [PATCH 09/11] Store manifest locations when manifests are found --- .../PersistenceManifestLibraryTests.cs | 43 +++------ .../DevelopmentPersistenceLocations.cs | 47 ++++------ .../PersistenceManifest.cs | 86 ++++++----------- .../DevelopmentPersistenceLocations.cs | 45 ++++----- .../PersistenceManifestLibrary.cs | 86 ++++++----------- .../TransportManifestLibraryTests.cs | 38 +++----- .../DevelopmentTransportLocations.cs | 59 +++++------- .../TransportManifest.cs | 92 +++++++++---------- 8 files changed, 188 insertions(+), 308 deletions(-) diff --git a/src/ServiceControl.Audit.Persistence.Tests/PersistenceManifestLibraryTests.cs b/src/ServiceControl.Audit.Persistence.Tests/PersistenceManifestLibraryTests.cs index aacb1baae7..4df40b6583 100644 --- a/src/ServiceControl.Audit.Persistence.Tests/PersistenceManifestLibraryTests.cs +++ b/src/ServiceControl.Audit.Persistence.Tests/PersistenceManifestLibraryTests.cs @@ -11,7 +11,6 @@ public class PersistenceManifestLibraryTests { const string persistenceName = "RavenDB5"; const string persistenceType = "ServiceControl.Audit.Persistence.RavenDb.RavenDbPersistenceConfiguration, ServiceControl.Audit.Persistence.RavenDb5"; - const string persistenceFolder = "RavenDB5"; [Test] public void Should_find_persistence_type_by_name() @@ -22,7 +21,7 @@ public void Should_find_persistence_type_by_name() } [Test] - public void Should_find_tpersistence_type_by_type() + public void Should_find_persistence_type_by_type() { var _persistenceType = PersistenceManifestLibrary.Find(persistenceType); @@ -43,15 +42,15 @@ public void Should_find_persistence_type_folder_by_name() { var _persistenceTypeFolder = PersistenceManifestLibrary.GetPersistenceFolder(persistenceName); - Assert.AreEqual(persistenceFolder, _persistenceTypeFolder); + Assert.IsNotNull(_persistenceTypeFolder); } [Test] - public void Should_find_tpersistence_type_folder_by_type() + public void Should_find_persistence_type_folder_by_type() { var _persistenceTypeFolder = PersistenceManifestLibrary.GetPersistenceFolder(persistenceType); - Assert.AreEqual(persistenceFolder, _persistenceTypeFolder); + Assert.IsNotNull(_persistenceTypeFolder); } [Test] @@ -66,38 +65,24 @@ public void Should_return_null_for_not_found_persistence_type() [Test] public void All_types_defined_in_manifest_files_exist_in_specified_assembly() { - var assemblyLocation = Assembly.GetExecutingAssembly().Location; - var appDirectory = Path.GetDirectoryName(assemblyLocation); - PersistenceManifestLibrary.GetPersistenceFolder("dummy"); //to initialise the collection + var count = 0; - var supportedManifests = PersistenceManifestLibrary.PersistenceManifests.Where(p => p.IsSupported).ToList(); - Assert.True(supportedManifests.Count >= 1); - - supportedManifests.ForEach(p => + foreach (var definition in PersistenceManifestLibrary.PersistenceManifests) { - var persistenceFolder = PersistenceManifestLibrary.GetPersistenceFolder(p.Name); - var subFolderPath = Path.Combine(appDirectory, "Persisters", persistenceFolder); - var assemblyName = p.TypeName.Split(',')[1].Trim(); - var assembly = TryLoadTypeFromSubdirectory(subFolderPath, assemblyName); + count++; + var persistenceFolder = PersistenceManifestLibrary.GetPersistenceFolder(definition.Name); + var assemblyName = definition.TypeName.Split(',')[1].Trim(); + var assemblyFile = Path.Combine(persistenceFolder, assemblyName + ".dll"); + var assembly = Assembly.LoadFrom(assemblyFile); Assert.IsNotNull(assembly, $"Could not load assembly {assemblyName}"); //NOTE not checking namespace here as it doesn't match for RavenDb5 - //Assert.IsTrue(assembly.GetTypes().Any(a => a.FullName == p.TypeName.Split(',').FirstOrDefault() && a.Namespace == assemblyName), $"Persistence type {p.TypeName} not found in assembly {assemblyName}"); - Assert.IsTrue(assembly.GetTypes().Any(a => a.FullName == p.TypeName.Split(',').FirstOrDefault()), $"Persistence type {p.TypeName} not found in assembly {assemblyName}"); - }); - } - - Assembly TryLoadTypeFromSubdirectory(string subFolderPath, string requestingName) - { - //look into any subdirectory - var file = Directory.EnumerateFiles(subFolderPath, requestingName + ".dll", SearchOption.AllDirectories).SingleOrDefault(); - if (file != null) - { - return Assembly.LoadFrom(file); + //Assert.IsTrue(assembly.GetTypes().Any(a => a.FullName == definition.TypeName.Split(',').FirstOrDefault() && a.Namespace == assemblyName), $"Persistence type {definition.TypeName} not found in assembly {assemblyName}"); + Assert.IsTrue(assembly.GetTypes().Any(a => a.FullName == definition.TypeName.Split(',').FirstOrDefault()), $"Persistence type {definition.TypeName} not found in assembly {assemblyName}"); } - return null; + Assert.NotZero(count, "No persistence manifests found."); } } } \ No newline at end of file diff --git a/src/ServiceControl.Audit.Persistence/DevelopmentPersistenceLocations.cs b/src/ServiceControl.Audit.Persistence/DevelopmentPersistenceLocations.cs index 685daa8ef4..4cc8f13cb0 100644 --- a/src/ServiceControl.Audit.Persistence/DevelopmentPersistenceLocations.cs +++ b/src/ServiceControl.Audit.Persistence/DevelopmentPersistenceLocations.cs @@ -1,11 +1,28 @@ namespace ServiceControl.Persistence { - using System; using System.Collections.Generic; using System.IO; static class DevelopmentPersistenceLocations { + public static List ManifestFiles { get; } = new List(); + + static DevelopmentPersistenceLocations() + { + var assembly = typeof(DevelopmentPersistenceLocations).Assembly.Location; + var assemblyDirectory = Path.GetDirectoryName(assembly); + + var srcFolder = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyDirectory)))); + + if (!string.IsNullOrWhiteSpace(srcFolder) && srcFolder.EndsWith("src")) + { + ManifestFiles.Add(BuildManifestPath(srcFolder, "ServiceControl.Audit.Persistence.InMemory")); + ManifestFiles.Add(BuildManifestPath(srcFolder, "ServiceControl.Audit.Persistence.RavenDb5")); + } + } + + static string BuildManifestPath(string srcFolder, string projectName) => Path.Combine(srcFolder, projectName, "bin", configuration, framework, "persistence.manifest"); + #if DEBUG const string configuration = "Debug"; #else @@ -15,33 +32,5 @@ static class DevelopmentPersistenceLocations #if NET472 const string framework = "net472"; #endif - - public static bool TryGetPersistenceFolder(string transportName, out string persistenceFolder) - { - persistenceFolder = null; - - if (transportName.Contains(".")) - { - transportName = transportName.Split('.')[0]; - } - - var found = projects.TryGetValue(transportName, out var projectFolder); - - if (found) - { - var assemblyPath = typeof(DevelopmentPersistenceLocations).Assembly.Location; - var assemblyFolder = Path.GetDirectoryName(assemblyPath); - var srcFolder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyFolder)))))); - persistenceFolder = Path.Combine(srcFolder, projectFolder, "bin", configuration, framework); - } - - return found; - } - - static readonly Dictionary projects = new Dictionary(StringComparer.OrdinalIgnoreCase) - { - {"InMemory", "ServiceControl.Audit.Persistence.InMemory" }, - {"RavenDB5", "ServiceControl.Audit.Persistence.RavenDb5" } - }; } } diff --git a/src/ServiceControl.Audit.Persistence/PersistenceManifest.cs b/src/ServiceControl.Audit.Persistence/PersistenceManifest.cs index 35a10158a8..e476e7eef0 100644 --- a/src/ServiceControl.Audit.Persistence/PersistenceManifest.cs +++ b/src/ServiceControl.Audit.Persistence/PersistenceManifest.cs @@ -12,6 +12,8 @@ public class PersistenceManifest { public string Version { get; set; } + public string Location { get; set; } + public string Name { get; set; } public string DisplayName { get; set; } @@ -29,46 +31,43 @@ internal bool IsMatch(string persistenceType) => public static class PersistenceManifestLibrary { - public static List PersistenceManifests { get; set; } + public static List PersistenceManifests { get; } = new List(); - static bool initialized; + static PersistenceManifestLibrary() + { + var assemblyDirectory = GetAssemblyDirectory(); - static bool usingDevelopmentLocation; + try + { + foreach (var manifestFile in Directory.EnumerateFiles(assemblyDirectory, "persistence.manifest", SearchOption.AllDirectories)) + { + var manifest = JsonSerializer.Deserialize(File.ReadAllText(manifestFile)); + manifest.Location = Path.GetDirectoryName(manifestFile); - static void Initialize(string persistenceType) - { - if (PersistenceManifests == null) + PersistenceManifests.Add(manifest); + } + } + catch (Exception ex) { - PersistenceManifests = new List(); + logger.Warn($"Failed to load persistence manifests from {assemblyDirectory}", ex); } - if (!initialized) + try { - initialized = true; - var persistenceFolder = GetAssemblyDirectory(); - - try + foreach (var manifestFile in DevelopmentPersistenceLocations.ManifestFiles) { - PersistenceManifests.AddRange( - Directory.EnumerateFiles(persistenceFolder, "persistence.manifest", SearchOption.AllDirectories) - .Select(manifest => JsonSerializer.Deserialize(File.ReadAllText(manifest))) - ); - - if (PersistenceManifests.Count == 0 && DevelopmentPersistenceLocations.TryGetPersistenceFolder(persistenceType, out persistenceFolder)) - { - var manifest = Path.Combine(persistenceFolder, "persistence.manifest"); - PersistenceManifests.Add(JsonSerializer.Deserialize(File.ReadAllText(manifest))); + var manifest = JsonSerializer.Deserialize(File.ReadAllText(manifestFile)); + manifest.Location = Path.GetDirectoryName(manifestFile); - usingDevelopmentLocation = true; - } - - PersistenceManifests.ForEach(m => logger.Info($"Found persistence manifest for {m.DisplayName}")); - } - catch (Exception ex) - { - logger.Warn($"Failed to load persistence manifests from {persistenceFolder}", ex); + PersistenceManifests.Add(manifest); } } + catch (Exception ex) + { + logger.Warn($"Failed to load persistence manifests from development locations", ex); + } + + PersistenceManifests.ForEach(m => logger.Info($"Found persistence manifest for {m.DisplayName}")); } static string GetAssemblyDirectory() @@ -84,16 +83,9 @@ public static string Find(string persistenceType) throw new Exception("No persistenceType has been configured. Either provide a Type or Name in the PersistenceType setting."); } - Initialize(persistenceType); - var persistenceManifestDefinition = PersistenceManifests.FirstOrDefault(w => w.IsMatch(persistenceType)); - if (persistenceManifestDefinition != null) - { - return persistenceManifestDefinition.TypeName; - } - - return persistenceType; + return persistenceManifestDefinition?.TypeName ?? persistenceType; } public static string GetPersistenceFolder(string persistenceType) @@ -103,27 +95,9 @@ public static string GetPersistenceFolder(string persistenceType) throw new Exception("No persistenceType has been configured. Either provide a Type or Name in the PersistenceType setting."); } - Initialize(persistenceType); - var persistenceManifestDefinition = PersistenceManifests.FirstOrDefault(w => w.IsMatch(persistenceType)); - string persistenceFolder = null; - - if (persistenceManifestDefinition != null) - { - if (usingDevelopmentLocation) - { - _ = DevelopmentPersistenceLocations.TryGetPersistenceFolder(persistenceManifestDefinition.Name, out persistenceFolder); - } - else - { - var appDirectory = GetAssemblyDirectory(); - var persistenceName = persistenceManifestDefinition.Name.Split('.').FirstOrDefault(); - persistenceFolder = Path.Combine(appDirectory, "Persisters", persistenceName); - } - } - - return persistenceFolder; + return persistenceManifestDefinition?.Location; } static readonly ILog logger = LogManager.GetLogger(typeof(PersistenceManifestLibrary)); diff --git a/src/ServiceControl.Persistence/DevelopmentPersistenceLocations.cs b/src/ServiceControl.Persistence/DevelopmentPersistenceLocations.cs index 17fb865f04..71c62eabf5 100644 --- a/src/ServiceControl.Persistence/DevelopmentPersistenceLocations.cs +++ b/src/ServiceControl.Persistence/DevelopmentPersistenceLocations.cs @@ -1,11 +1,27 @@ namespace ServiceControl.Persistence { - using System; using System.Collections.Generic; using System.IO; static class DevelopmentPersistenceLocations { + public static List ManifestFiles { get; } = new List(); + + static DevelopmentPersistenceLocations() + { + var assembly = typeof(DevelopmentPersistenceLocations).Assembly.Location; + var assemblyDirectory = Path.GetDirectoryName(assembly); + + var srcFolder = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyDirectory)))); + + if (!string.IsNullOrWhiteSpace(srcFolder) && srcFolder.EndsWith("src")) + { + ManifestFiles.Add(BuildManifestPath(srcFolder, "ServiceControl.Persistence.RavenDb5")); + } + } + + static string BuildManifestPath(string srcFolder, string projectName) => Path.Combine(srcFolder, projectName, "bin", configuration, framework, "persistence.manifest"); + #if DEBUG const string configuration = "Debug"; #else @@ -15,32 +31,5 @@ static class DevelopmentPersistenceLocations #if NET472 const string framework = "net472"; #endif - - public static bool TryGetPersistenceFolder(string transportName, out string persistenceFolder) - { - persistenceFolder = null; - - if (transportName.Contains(".")) - { - transportName = transportName.Split('.')[0]; - } - - var found = projects.TryGetValue(transportName, out var projectFolder); - - if (found) - { - var assemblyPath = typeof(DevelopmentPersistenceLocations).Assembly.Location; - var assemblyFolder = Path.GetDirectoryName(assemblyPath); - var srcFolder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyFolder)))))); - persistenceFolder = Path.Combine(srcFolder, projectFolder, "bin", configuration, framework); - } - - return found; - } - - static readonly Dictionary projects = new Dictionary(StringComparer.OrdinalIgnoreCase) - { - {"RavenDB5", "ServiceControl.Persistence.RavenDb5" } - }; } } diff --git a/src/ServiceControl.Persistence/PersistenceManifestLibrary.cs b/src/ServiceControl.Persistence/PersistenceManifestLibrary.cs index 24e91b5706..56009dc84e 100644 --- a/src/ServiceControl.Persistence/PersistenceManifestLibrary.cs +++ b/src/ServiceControl.Persistence/PersistenceManifestLibrary.cs @@ -11,6 +11,8 @@ public class PersistenceManifest { public string Version { get; set; } + public string Location { get; set; } + public string Name { get; set; } public string DisplayName { get; set; } @@ -28,46 +30,43 @@ internal bool IsMatch(string persistenceType) => public static class PersistenceManifestLibrary { - public static List PersistenceManifests { get; set; } + public static List PersistenceManifests { get; } = new List(); - static bool initialized; + static PersistenceManifestLibrary() + { + var assemblyDirectory = GetAssemblyDirectory(); - static bool usingDevelopmentLocation; + try + { + foreach (var manifestFile in Directory.EnumerateFiles(assemblyDirectory, "persistence.manifest", SearchOption.AllDirectories)) + { + var manifest = JsonSerializer.Deserialize(File.ReadAllText(manifestFile)); + manifest.Location = Path.GetDirectoryName(manifestFile); - static void Initialize(string persistenceType) - { - if (PersistenceManifests == null) + PersistenceManifests.Add(manifest); + } + } + catch (Exception ex) { - PersistenceManifests = new List(); + logger.Warn($"Failed to load persistence manifests from {assemblyDirectory}", ex); } - if (!initialized) + try { - initialized = true; - var persistenceFolder = GetAssemblyDirectory(); - - try + foreach (var manifestFile in DevelopmentPersistenceLocations.ManifestFiles) { - PersistenceManifests.AddRange( - Directory.EnumerateFiles(persistenceFolder, "persistence.manifest", SearchOption.AllDirectories) - .Select(manifest => JsonSerializer.Deserialize(File.ReadAllText(manifest))) - ); - - if (PersistenceManifests.Count == 0 && DevelopmentPersistenceLocations.TryGetPersistenceFolder(persistenceType, out persistenceFolder)) - { - var manifest = Path.Combine(persistenceFolder, "persistence.manifest"); - PersistenceManifests.Add(JsonSerializer.Deserialize(File.ReadAllText(manifest))); + var manifest = JsonSerializer.Deserialize(File.ReadAllText(manifestFile)); + manifest.Location = Path.GetDirectoryName(manifestFile); - usingDevelopmentLocation = true; - } - - PersistenceManifests.ForEach(m => logger.Info($"Found persistence manifest for {m.DisplayName}")); - } - catch (Exception ex) - { - logger.Warn($"Failed to load persistence manifests from {persistenceFolder}", ex); + PersistenceManifests.Add(manifest); } } + catch (Exception ex) + { + logger.Warn($"Failed to load persistence manifests from development locations", ex); + } + + PersistenceManifests.ForEach(m => logger.Info($"Found persistence manifest for {m.DisplayName}")); } static string GetAssemblyDirectory() @@ -83,16 +82,9 @@ public static string Find(string persistenceType) throw new Exception("No persistenceType has been configured. Either provide a Type or Name in the PersistenceType setting."); } - Initialize(persistenceType); - var persistenceManifestDefinition = PersistenceManifests.FirstOrDefault(w => w.IsMatch(persistenceType)); - if (persistenceManifestDefinition != null) - { - return persistenceManifestDefinition.TypeName; - } - - return persistenceType; + return persistenceManifestDefinition?.TypeName ?? persistenceType; } public static string GetPersistenceFolder(string persistenceType) @@ -102,27 +94,9 @@ public static string GetPersistenceFolder(string persistenceType) throw new Exception("No persistenceType has been configured. Either provide a Type or Name in the PersistenceType setting."); } - Initialize(persistenceType); - var persistenceManifestDefinition = PersistenceManifests.FirstOrDefault(w => w.IsMatch(persistenceType)); - string persistenceFolder = null; - - if (persistenceManifestDefinition != null) - { - if (usingDevelopmentLocation) - { - _ = DevelopmentPersistenceLocations.TryGetPersistenceFolder(persistenceManifestDefinition.Name, out persistenceFolder); - } - else - { - var appDirectory = GetAssemblyDirectory(); - var persistenceName = persistenceManifestDefinition.Name.Split('.').FirstOrDefault(); - persistenceFolder = Path.Combine(appDirectory, "Persisters", persistenceName); - } - } - - return persistenceFolder; + return persistenceManifestDefinition?.Location; } static readonly ILog logger = LogManager.GetLogger(typeof(PersistenceManifestLibrary)); diff --git a/src/ServiceControl.Transports.Tests/TransportManifestLibraryTests.cs b/src/ServiceControl.Transports.Tests/TransportManifestLibraryTests.cs index 7f9a6f62e3..73b9189db2 100644 --- a/src/ServiceControl.Transports.Tests/TransportManifestLibraryTests.cs +++ b/src/ServiceControl.Transports.Tests/TransportManifestLibraryTests.cs @@ -12,7 +12,6 @@ public class TransportManifestLibraryTests const string transportName = "AzureServiceBus.EndpointOriented"; const string transportType = "ServiceControl.Transports.ASB.ASBEndpointTopologyTransportCustomization, ServiceControl.Transports.ASB"; const string transportAlias = "ServiceControl.Transports.LegacyAzureServiceBus.EndpointOrientedTopologyAzureServiceBusTransport, ServiceControl.Transports.LegacyAzureServiceBus"; - const string transportFolderName = "AzureServiceBus"; [Test] public void Should_find_transport_type_by_name() @@ -52,7 +51,7 @@ public void Should_find_transport_type_folder_by_name() { var _transportTypeFolder = TransportManifestLibrary.GetTransportFolder(transportName); - Assert.AreEqual(transportFolderName, _transportTypeFolder); + Assert.IsNotNull(_transportTypeFolder); } [Test] @@ -60,7 +59,7 @@ public void Should_find_transport_type_folder_by_type() { var _transportTypeFolder = TransportManifestLibrary.GetTransportFolder(transportType); - Assert.AreEqual(transportFolderName, _transportTypeFolder); + Assert.IsNotNull(_transportTypeFolder); } [Test] @@ -68,7 +67,7 @@ public void Should_find_transport_type_folder_by_alias() { var _transportTypeFolder = TransportManifestLibrary.GetTransportFolder(transportAlias); - Assert.AreEqual(transportFolderName, _transportTypeFolder); + Assert.IsNotNull(_transportTypeFolder); } [Test] @@ -83,32 +82,21 @@ public void Should_return_null_for_not_found_transport_type() [Test] public void All_types_defined_in_manifest_files_exist_in_specified_assembly() { - var assemblyLocation = Assembly.GetExecutingAssembly().Location; - var appDirectory = Path.GetDirectoryName(assemblyLocation); - TransportManifestLibrary.GetTransportFolder("dummy"); //to initialise the collection - TransportManifestLibrary.TransportManifests.SelectMany(t => t.Definitions).ToList().ForEach(t => + var count = 0; + + foreach (var definition in TransportManifestLibrary.TransportManifests.SelectMany(t => t.Definitions)) { - var transportFolder = TransportManifestLibrary.GetTransportFolder(t.Name); - var subFolderPath = Path.Combine(appDirectory, "Transports", transportFolder); - var assemblyName = t.TypeName.Split(',')[1].Trim(); - var assembly = TryLoadTypeFromSubdirectory(subFolderPath, assemblyName); + count++; + var transportFolder = TransportManifestLibrary.GetTransportFolder(definition.Name); + var assemblyName = definition.TypeName.Split(',')[1].Trim(); + var assemblyFile = Path.Combine(transportFolder, assemblyName + ".dll"); + var assembly = Assembly.LoadFrom(assemblyFile); Assert.IsNotNull(assembly, $"Could not load assembly {assemblyName}"); - - Assert.IsTrue(assembly.GetTypes().Any(a => a.FullName == t.TypeName.Split(',').FirstOrDefault() && a.Namespace == assemblyName), $"Transport type {t.TypeName} not found in assembly {assemblyName}"); - }); - } - - Assembly TryLoadTypeFromSubdirectory(string subFolderPath, string requestingName) - { - //look into any subdirectory - var file = Directory.EnumerateFiles(subFolderPath, requestingName + ".dll", SearchOption.AllDirectories).SingleOrDefault(); - if (file != null) - { - return Assembly.LoadFrom(file); + Assert.IsTrue(assembly.GetTypes().Any(a => a.FullName == definition.TypeName.Split(',').FirstOrDefault() && a.Namespace == assemblyName), $"Transport type {definition.TypeName} not found in assembly {assemblyName}"); } - return null; + Assert.NotZero(count, "No transport manifests found."); } } } \ No newline at end of file diff --git a/src/ServiceControl.Transports/DevelopmentTransportLocations.cs b/src/ServiceControl.Transports/DevelopmentTransportLocations.cs index c9bca56537..a3c83bfc7f 100644 --- a/src/ServiceControl.Transports/DevelopmentTransportLocations.cs +++ b/src/ServiceControl.Transports/DevelopmentTransportLocations.cs @@ -1,11 +1,34 @@ namespace ServiceControl.Transports { - using System; using System.Collections.Generic; using System.IO; static class DevelopmentTransportLocations { + public static List ManifestFiles { get; } = new List(); + + static DevelopmentTransportLocations() + { + var assembly = typeof(DevelopmentTransportLocations).Assembly.Location; + var assemblyDirectory = Path.GetDirectoryName(assembly); + + var srcFolder = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyDirectory)))); + + if (!string.IsNullOrWhiteSpace(srcFolder) && srcFolder.EndsWith("src")) + { + ManifestFiles.Add(BuildManifestPath(srcFolder, "ServiceControl.Transports.ASB")); + ManifestFiles.Add(BuildManifestPath(srcFolder, "ServiceControl.Transports.ASBS")); + ManifestFiles.Add(BuildManifestPath(srcFolder, "ServiceControl.Transports.ASQ")); + ManifestFiles.Add(BuildManifestPath(srcFolder, "ServiceControl.Transports.Learning")); + ManifestFiles.Add(BuildManifestPath(srcFolder, "ServiceControl.Transports.Msmq")); + ManifestFiles.Add(BuildManifestPath(srcFolder, "ServiceControl.Transports.RabbitMQ")); + ManifestFiles.Add(BuildManifestPath(srcFolder, "ServiceControl.Transports.SqlServer")); + ManifestFiles.Add(BuildManifestPath(srcFolder, "ServiceControl.Transports.SQS")); + } + } + + static string BuildManifestPath(string srcFolder, string projectName) => Path.Combine(srcFolder, projectName, "bin", configuration, framework, "transport.manifest"); + #if DEBUG const string configuration = "Debug"; #else @@ -15,39 +38,5 @@ static class DevelopmentTransportLocations #if NET472 const string framework = "net472"; #endif - - public static bool TryGetTransportFolder(string transportName, out string transportFolder) - { - transportFolder = null; - - if (transportName.Contains(".")) - { - transportName = transportName.Split('.')[0]; - } - - var found = projects.TryGetValue(transportName, out var projectFolder); - - if (found) - { - var assemblyPath = typeof(DevelopmentTransportLocations).Assembly.Location; - var assemblyFolder = Path.GetDirectoryName(assemblyPath); - var srcFolder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyFolder)))))); - transportFolder = Path.Combine(srcFolder, projectFolder, "bin", configuration, framework); - } - - return found; - } - - static readonly Dictionary projects = new Dictionary(StringComparer.OrdinalIgnoreCase) - { - {"AmazonSQS", "ServiceControl.Transports.SQS" }, - {"AzureServiceBus", "ServiceControl.Transports.ASB" }, - {"AzureStorageQueue", "ServiceControl.Transports.ASQ" }, - {"LearningTransport", "ServiceControl.Transports.Learning" }, - {"MSMQ", "ServiceControl.Transports.Msmq" }, - {"NetStandardAzureServiceBus", "ServiceControl.Transports.ASBS" }, - {"RabbitMQ", "ServiceControl.Transports.RabbitMQ" }, - {"SQLServer", "ServiceControl.Transports.SqlServer" } - }; } } diff --git a/src/ServiceControl.Transports/TransportManifest.cs b/src/ServiceControl.Transports/TransportManifest.cs index 434394d6be..4456e7a5d7 100644 --- a/src/ServiceControl.Transports/TransportManifest.cs +++ b/src/ServiceControl.Transports/TransportManifest.cs @@ -11,6 +11,8 @@ public class TransportManifest { public string Version { get; set; } + public string Location { get; set; } + public TransportManifestDefinition[] Definitions { get; set; } } @@ -42,46 +44,43 @@ bool AliasesContain(string transportType) public static class TransportManifestLibrary { - public static List TransportManifests { get; set; } + public static List TransportManifests { get; } = new List(); - static bool initialized; + static TransportManifestLibrary() + { + var assemblyDirectory = GetAssemblyDirectory(); - static bool usingDevelopmentLocation; + try + { + foreach (var manifestFile in Directory.EnumerateFiles(assemblyDirectory, "transport.manifest", SearchOption.AllDirectories)) + { + var manifest = JsonSerializer.Deserialize(File.ReadAllText(manifestFile)); + manifest.Location = Path.GetDirectoryName(manifestFile); - static void Initialize(string transportType) - { - if (TransportManifests == null) + TransportManifests.Add(manifest); + } + } + catch (Exception ex) { - TransportManifests = new List(); + logger.Warn($"Failed to load transport manifests from {assemblyDirectory}", ex); } - if (!initialized) + try { - initialized = true; - var transportFolder = GetAssemblyDirectory(); - - try + foreach (var manifestFile in DevelopmentTransportLocations.ManifestFiles) { - TransportManifests.AddRange( - Directory.EnumerateFiles(transportFolder, "transport.manifest", SearchOption.AllDirectories) - .Select(manifest => JsonSerializer.Deserialize(File.ReadAllText(manifest))) - ); + var manifest = JsonSerializer.Deserialize(File.ReadAllText(manifestFile)); + manifest.Location = Path.GetDirectoryName(manifestFile); - if (TransportManifests.Count == 0 && DevelopmentTransportLocations.TryGetTransportFolder(transportType, out transportFolder)) - { - var manifest = Path.Combine(transportFolder, "transport.manifest"); - TransportManifests.Add(JsonSerializer.Deserialize(File.ReadAllText(manifest))); - - usingDevelopmentLocation = true; - } - - TransportManifests.SelectMany(t => t.Definitions).ToList().ForEach(m => logger.Info($"Found transport manifest for {m.DisplayName}")); - } - catch (Exception ex) - { - logger.Warn($"Failed to load transport manifests from {transportFolder}", ex); + TransportManifests.Add(manifest); } } + catch (Exception ex) + { + logger.Warn($"Failed to load transport manifests from development locations", ex); + } + + TransportManifests.SelectMany(t => t.Definitions).ToList().ForEach(m => logger.Info($"Found transport manifest for {m.DisplayName}")); } static string GetAssemblyDirectory() @@ -97,18 +96,11 @@ public static string Find(string transportType) throw new Exception("No transport has been configured. Either provide a Type or Name in the TransportType setting."); } - Initialize(transportType); - var transportManifestDefinition = TransportManifests .SelectMany(t => t.Definitions) .FirstOrDefault(w => w.IsMatch(transportType)); - if (transportManifestDefinition != null) - { - return transportManifestDefinition.TypeName; - } - - return transportType; + return transportManifestDefinition?.TypeName ?? transportType; } public static string GetTransportFolder(string transportType) @@ -118,25 +110,25 @@ public static string GetTransportFolder(string transportType) throw new Exception("No transport has been configured. Either provide a Type or Name in the TransportType setting."); } - Initialize(transportType); - - var transportManifestDefinition = TransportManifests - .SelectMany(t => t.Definitions) - .FirstOrDefault(w => w.IsMatch(transportType)); - string transportFolder = null; - if (transportManifestDefinition != null) + foreach (var manifest in TransportManifests) { - if (usingDevelopmentLocation) + var match = false; + + foreach (var definition in manifest.Definitions) { - _ = DevelopmentTransportLocations.TryGetTransportFolder(transportManifestDefinition.Name, out transportFolder); + if (definition.IsMatch(transportType)) + { + match = true; + break; + } } - else + + if (match) { - var appDirectory = GetAssemblyDirectory(); - var transportName = transportManifestDefinition.Name.Split('.').FirstOrDefault(); - transportFolder = Path.Combine(appDirectory, "Transports", transportName); + transportFolder = manifest.Location; + break; } } From f8759bd8b8bd6dabc2831acdec19cd4e75c93f4d Mon Sep 17 00:00:00 2001 From: David Boike Date: Tue, 24 Oct 2023 11:33:51 -0500 Subject: [PATCH 10/11] Apply suggestions from code review --- .../DevelopmentPersistenceLocations.cs | 1 + .../DevelopmentPersistenceLocations.cs | 1 + src/ServiceControl.Transports/DevelopmentTransportLocations.cs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/ServiceControl.Audit.Persistence/DevelopmentPersistenceLocations.cs b/src/ServiceControl.Audit.Persistence/DevelopmentPersistenceLocations.cs index 4cc8f13cb0..a193528577 100644 --- a/src/ServiceControl.Audit.Persistence/DevelopmentPersistenceLocations.cs +++ b/src/ServiceControl.Audit.Persistence/DevelopmentPersistenceLocations.cs @@ -12,6 +12,7 @@ static DevelopmentPersistenceLocations() var assembly = typeof(DevelopmentPersistenceLocations).Assembly.Location; var assemblyDirectory = Path.GetDirectoryName(assembly); + // Becomes null if it navigates past the root of a drive var srcFolder = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyDirectory)))); if (!string.IsNullOrWhiteSpace(srcFolder) && srcFolder.EndsWith("src")) diff --git a/src/ServiceControl.Persistence/DevelopmentPersistenceLocations.cs b/src/ServiceControl.Persistence/DevelopmentPersistenceLocations.cs index 71c62eabf5..9ae7cb7a0c 100644 --- a/src/ServiceControl.Persistence/DevelopmentPersistenceLocations.cs +++ b/src/ServiceControl.Persistence/DevelopmentPersistenceLocations.cs @@ -12,6 +12,7 @@ static DevelopmentPersistenceLocations() var assembly = typeof(DevelopmentPersistenceLocations).Assembly.Location; var assemblyDirectory = Path.GetDirectoryName(assembly); + // Becomes null if it navigates past the root of a drive var srcFolder = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyDirectory)))); if (!string.IsNullOrWhiteSpace(srcFolder) && srcFolder.EndsWith("src")) diff --git a/src/ServiceControl.Transports/DevelopmentTransportLocations.cs b/src/ServiceControl.Transports/DevelopmentTransportLocations.cs index a3c83bfc7f..c6006c2d0a 100644 --- a/src/ServiceControl.Transports/DevelopmentTransportLocations.cs +++ b/src/ServiceControl.Transports/DevelopmentTransportLocations.cs @@ -12,6 +12,7 @@ static DevelopmentTransportLocations() var assembly = typeof(DevelopmentTransportLocations).Assembly.Location; var assemblyDirectory = Path.GetDirectoryName(assembly); + // Becomes null if it navigates past the root of a drive var srcFolder = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(assemblyDirectory)))); if (!string.IsNullOrWhiteSpace(srcFolder) && srcFolder.EndsWith("src")) From d59352ea805b9ff5e4a5a12cbf09d814b7826e2e Mon Sep 17 00:00:00 2001 From: David Boike Date: Tue, 24 Oct 2023 11:37:50 -0500 Subject: [PATCH 11/11] approval file --- .../APIApprovals.ServiceControlTransport.approved.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ServiceControl.Transports.Tests/ApprovalFiles/APIApprovals.ServiceControlTransport.approved.txt b/src/ServiceControl.Transports.Tests/ApprovalFiles/APIApprovals.ServiceControlTransport.approved.txt index 061de48e55..1cad24fd90 100644 --- a/src/ServiceControl.Transports.Tests/ApprovalFiles/APIApprovals.ServiceControlTransport.approved.txt +++ b/src/ServiceControl.Transports.Tests/ApprovalFiles/APIApprovals.ServiceControlTransport.approved.txt @@ -50,6 +50,7 @@ namespace ServiceControl.Transports { public TransportManifest() { } public ServiceControl.Transports.TransportManifestDefinition[] Definitions { get; set; } + public string Location { get; set; } public string Version { get; set; } } public class TransportManifestDefinition @@ -62,7 +63,7 @@ namespace ServiceControl.Transports } public static class TransportManifestLibrary { - public static System.Collections.Generic.List TransportManifests { get; set; } + public static System.Collections.Generic.List TransportManifests { get; } public static string Find(string transportType) { } public static string GetTransportFolder(string transportType) { } }