From 5b1cadc553e3eb576ec3cea82b44fd40f8af911c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20Ko=C5=BEelj?= Date: Wed, 7 Dec 2022 14:02:04 +0100 Subject: [PATCH] Initial commit --- TomPIT.Connected.sln | 92 +++++++++++ .../Configuration/MicroServiceDescriptor.cs | 8 + .../Configuration/SysConfiguration.cs | 49 ++++++ TomPIT.Connected/Program.cs | 67 ++++++++ .../Properties/launchSettings.json | 39 +++++ TomPIT.Connected/TomPIT.Connected.csproj | 15 ++ TomPIT.Connected/appsettings.Development.json | 8 + TomPIT.Connected/appsettings.json | 9 ++ TomPIT.Connected/sys.json | 153 ++++++++++++++++++ 9 files changed, 440 insertions(+) create mode 100644 TomPIT.Connected.sln create mode 100644 TomPIT.Connected/Configuration/MicroServiceDescriptor.cs create mode 100644 TomPIT.Connected/Configuration/SysConfiguration.cs create mode 100644 TomPIT.Connected/Program.cs create mode 100644 TomPIT.Connected/Properties/launchSettings.json create mode 100644 TomPIT.Connected/TomPIT.Connected.csproj create mode 100644 TomPIT.Connected/appsettings.Development.json create mode 100644 TomPIT.Connected/appsettings.json create mode 100644 TomPIT.Connected/sys.json diff --git a/TomPIT.Connected.sln b/TomPIT.Connected.sln new file mode 100644 index 0000000..4b7954a --- /dev/null +++ b/TomPIT.Connected.sln @@ -0,0 +1,92 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32901.215 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TomPIT.Connected", "TomPIT.Connected\TomPIT.Connected.csproj", "{A2A01D43-0CEE-4E49-8EC1-F16CA92F3C30}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dependencies", "Dependencies", "{D875F828-05A0-4A52-9A36-6F5B0370171D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Data", "..\Framework\Connected.Data\Connected.Data.csproj", "{67532F27-3F13-404D-AD65-34317719059D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common.Types", "..\Common.Types\Common.Types\Common.Types.csproj", "{216E4481-92B6-4E52-8877-3C6D547803ED}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Rest", "..\Framework\Connected.Rest\Connected.Rest.csproj", "{AD931DF4-9695-4D9A-8E08-8A5041175755}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Entities", "..\Framework\Connected.Entities\Connected.Entities.csproj", "{DB941857-07B7-4CD0-B43F-32EC51B5F195}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Expressions", "..\Framework\Connected.Expressions\Connected.Expressions.csproj", "{6FCD7B5E-A42C-433A-8C2E-5BA412736F99}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Interop", "..\Framework\Connected.Interop\Connected.Interop.csproj", "{84D0EAE0-724F-421A-BDA2-5DEC2D9A254C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.ServiceModel.Client.Data", "..\Framework.ServiceModel.Client\Connected.ServiceModel.Client.Data\Connected.ServiceModel.Client.Data.csproj", "{EBBECB6F-C996-41C4-B05A-39309A03839E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connected.Instance", "..\Framework\Connected.Instance\Connected.Instance.csproj", "{5312A990-8797-44E2-9BA9-858D51DE3825}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common.Notes", "..\Common\Common.Notes\Common.Notes.csproj", "{28F99091-B4CB-43BF-A6DF-4D47621420D0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A2A01D43-0CEE-4E49-8EC1-F16CA92F3C30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A2A01D43-0CEE-4E49-8EC1-F16CA92F3C30}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A2A01D43-0CEE-4E49-8EC1-F16CA92F3C30}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A2A01D43-0CEE-4E49-8EC1-F16CA92F3C30}.Release|Any CPU.Build.0 = Release|Any CPU + {67532F27-3F13-404D-AD65-34317719059D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {67532F27-3F13-404D-AD65-34317719059D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {67532F27-3F13-404D-AD65-34317719059D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {67532F27-3F13-404D-AD65-34317719059D}.Release|Any CPU.Build.0 = Release|Any CPU + {216E4481-92B6-4E52-8877-3C6D547803ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {216E4481-92B6-4E52-8877-3C6D547803ED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {216E4481-92B6-4E52-8877-3C6D547803ED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {216E4481-92B6-4E52-8877-3C6D547803ED}.Release|Any CPU.Build.0 = Release|Any CPU + {AD931DF4-9695-4D9A-8E08-8A5041175755}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AD931DF4-9695-4D9A-8E08-8A5041175755}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AD931DF4-9695-4D9A-8E08-8A5041175755}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AD931DF4-9695-4D9A-8E08-8A5041175755}.Release|Any CPU.Build.0 = Release|Any CPU + {DB941857-07B7-4CD0-B43F-32EC51B5F195}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DB941857-07B7-4CD0-B43F-32EC51B5F195}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DB941857-07B7-4CD0-B43F-32EC51B5F195}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DB941857-07B7-4CD0-B43F-32EC51B5F195}.Release|Any CPU.Build.0 = Release|Any CPU + {6FCD7B5E-A42C-433A-8C2E-5BA412736F99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6FCD7B5E-A42C-433A-8C2E-5BA412736F99}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6FCD7B5E-A42C-433A-8C2E-5BA412736F99}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6FCD7B5E-A42C-433A-8C2E-5BA412736F99}.Release|Any CPU.Build.0 = Release|Any CPU + {84D0EAE0-724F-421A-BDA2-5DEC2D9A254C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84D0EAE0-724F-421A-BDA2-5DEC2D9A254C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84D0EAE0-724F-421A-BDA2-5DEC2D9A254C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84D0EAE0-724F-421A-BDA2-5DEC2D9A254C}.Release|Any CPU.Build.0 = Release|Any CPU + {EBBECB6F-C996-41C4-B05A-39309A03839E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EBBECB6F-C996-41C4-B05A-39309A03839E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EBBECB6F-C996-41C4-B05A-39309A03839E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EBBECB6F-C996-41C4-B05A-39309A03839E}.Release|Any CPU.Build.0 = Release|Any CPU + {5312A990-8797-44E2-9BA9-858D51DE3825}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5312A990-8797-44E2-9BA9-858D51DE3825}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5312A990-8797-44E2-9BA9-858D51DE3825}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5312A990-8797-44E2-9BA9-858D51DE3825}.Release|Any CPU.Build.0 = Release|Any CPU + {28F99091-B4CB-43BF-A6DF-4D47621420D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {28F99091-B4CB-43BF-A6DF-4D47621420D0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {28F99091-B4CB-43BF-A6DF-4D47621420D0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {28F99091-B4CB-43BF-A6DF-4D47621420D0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {67532F27-3F13-404D-AD65-34317719059D} = {D875F828-05A0-4A52-9A36-6F5B0370171D} + {216E4481-92B6-4E52-8877-3C6D547803ED} = {D875F828-05A0-4A52-9A36-6F5B0370171D} + {AD931DF4-9695-4D9A-8E08-8A5041175755} = {D875F828-05A0-4A52-9A36-6F5B0370171D} + {DB941857-07B7-4CD0-B43F-32EC51B5F195} = {D875F828-05A0-4A52-9A36-6F5B0370171D} + {6FCD7B5E-A42C-433A-8C2E-5BA412736F99} = {D875F828-05A0-4A52-9A36-6F5B0370171D} + {84D0EAE0-724F-421A-BDA2-5DEC2D9A254C} = {D875F828-05A0-4A52-9A36-6F5B0370171D} + {EBBECB6F-C996-41C4-B05A-39309A03839E} = {D875F828-05A0-4A52-9A36-6F5B0370171D} + {5312A990-8797-44E2-9BA9-858D51DE3825} = {D875F828-05A0-4A52-9A36-6F5B0370171D} + {28F99091-B4CB-43BF-A6DF-4D47621420D0} = {D875F828-05A0-4A52-9A36-6F5B0370171D} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8E8D9F6F-68E1-466C-8D83-5ECB3AA3FC76} + EndGlobalSection +EndGlobal diff --git a/TomPIT.Connected/Configuration/MicroServiceDescriptor.cs b/TomPIT.Connected/Configuration/MicroServiceDescriptor.cs new file mode 100644 index 0000000..90c8108 --- /dev/null +++ b/TomPIT.Connected/Configuration/MicroServiceDescriptor.cs @@ -0,0 +1,8 @@ +namespace TomPIT.Connected.Configuration +{ + internal class MicroServiceDescriptor + { + public string Name { get; set; } + public string Version { get; set; } + } +} diff --git a/TomPIT.Connected/Configuration/SysConfiguration.cs b/TomPIT.Connected/Configuration/SysConfiguration.cs new file mode 100644 index 0000000..a63f32e --- /dev/null +++ b/TomPIT.Connected/Configuration/SysConfiguration.cs @@ -0,0 +1,49 @@ +namespace TomPIT.Connected.Configuration +{ + internal static class SysConfiguration + { + private const string DefaultStart = "Connected.Instance.Start, Connected.Instance"; + + private static List _microServices; + private static List _locations; + private static string _start; + public static List MicroServices => _microServices; + public static List Locations => _locations; + public static string Start => _start; + public static void Build() + { + var cb = new ConfigurationBuilder(); + var appPath = AppContext.BaseDirectory; + var segments = new Uri(appPath).Segments; + + segments = segments.Select(e => e.Replace("%20", " ")).ToArray(); + + for (var i = 1; i <= segments.Length; i++) + { + var pathBase = Path.Combine(segments[0..i]); + var filePath = Path.Combine(pathBase, "sys.json"); + + if (File.Exists(filePath)) + { + cb.AddJsonFile(filePath, true, false); + break; + } + } + + cb.AddEnvironmentVariables(); + + var config = cb.Build(); + + _microServices = new List(); + _locations = new List(); + + config.Bind("microServices", _microServices); + config.Bind("locations", _locations); + + _start = config["start"]; + + if (string.IsNullOrWhiteSpace(_start)) + _start = DefaultStart; + } + } +} diff --git a/TomPIT.Connected/Program.cs b/TomPIT.Connected/Program.cs new file mode 100644 index 0000000..eedb880 --- /dev/null +++ b/TomPIT.Connected/Program.cs @@ -0,0 +1,67 @@ +using System.Reflection; +using TomPIT.Connected.Configuration; + +namespace TomPIT.Connected +{ + public static class Program + { + public static void Main(params string[] args) + { + SysConfiguration.Build(); + + Start(ParseArguments(args)); + } + + private static void Start(Dictionary args) + { + foreach (var microService in SysConfiguration.MicroServices) + LoadMicroServiceAssembly(microService); + + if (Type.GetType(SysConfiguration.Start) is not Type startupType) + throw new Exception($"Cannot resolve startup type. ({SysConfiguration.Start})."); + + if (startupType.GetMethod("ConfigureAsync", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) is not MethodInfo configureMethod) + throw new Exception($"ConfigureAsync does not exists in the startup type {startupType}. Startup must have static 'async Task ConfigureAsync(params string[] args)' method."); + + if (configureMethod.Invoke(null, new object[] { args }) is not Task task) + throw new Exception($"ConfigureAsync of type {startupType} must return Task."); + + task.ConfigureAwait(false); + + task.GetType().GetProperty("Result")?.GetValue(task); + } + + private static Assembly? LoadMicroServiceAssembly(MicroServiceDescriptor descriptor) + { + var assemblyFile = descriptor.Name.EndsWith(".dll") ? descriptor.Name : $"{descriptor.Name}.dll"; + + foreach (var location in SysConfiguration.Locations) + { + var assemblyPath = Path.Combine(location, assemblyFile); + + if (File.Exists(assemblyPath)) + return Assembly.LoadFrom(assemblyPath); + } + + return Assembly.Load(AssemblyName.GetAssemblyName(assemblyFile)); + } + + private static Dictionary ParseArguments(params string[] args) + { + var result = new Dictionary(StringComparer.OrdinalIgnoreCase); + + foreach (var i in args) + { + var tokens = i.Split('=', 2); + + if (tokens.Length == 1) + result.Add(tokens[0].Trim(), string.Empty); + else + result.Add(tokens[0].Trim(), tokens[1].Trim()); + } + + return result; + } + + } +} \ No newline at end of file diff --git a/TomPIT.Connected/Properties/launchSettings.json b/TomPIT.Connected/Properties/launchSettings.json new file mode 100644 index 0000000..9f0a68e --- /dev/null +++ b/TomPIT.Connected/Properties/launchSettings.json @@ -0,0 +1,39 @@ +{ + "profiles": { + "TomPIT.Connected": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5063" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Synchronize Entities": { + "commandName": "Project", + "commandLineArgs": "entitySynchronization=rebuild" + }, + "Synchronize Entity": { + "commandName": "Project", + "commandLineArgs": "entitySynchronization=type:Logistics.Documents/Logistics.Documents.Receive.ReceivePlannedItem" + } + }, + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:14733", + "sslPort": 44321 + } + } +} \ No newline at end of file diff --git a/TomPIT.Connected/TomPIT.Connected.csproj b/TomPIT.Connected/TomPIT.Connected.csproj new file mode 100644 index 0000000..42a7025 --- /dev/null +++ b/TomPIT.Connected/TomPIT.Connected.csproj @@ -0,0 +1,15 @@ + + + + net7.0 + enable + enable + + + + + + + + + diff --git a/TomPIT.Connected/appsettings.Development.json b/TomPIT.Connected/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/TomPIT.Connected/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/TomPIT.Connected/appsettings.json b/TomPIT.Connected/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/TomPIT.Connected/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/TomPIT.Connected/sys.json b/TomPIT.Connected/sys.json new file mode 100644 index 0000000..32a009e --- /dev/null +++ b/TomPIT.Connected/sys.json @@ -0,0 +1,153 @@ +{ + "microServices": [ + { + "name": "Connected", + "version": "1.0.0.0" + }, + { + "name": "Connected.Caching", + "version": "1.0.0.0" + }, + { + "name": "Connected.Collections", + "version": "1.0.0.0" + }, + { + "name": "Connected.Configuration", + "version": "1.0.0.0" + }, + { + "name": "Connected.Data", + "version": "1.0.0.0" + }, + { + "name": "Connected.Entities", + "version": "1.0.0.0" + }, + { + "name": "Connected.Globalization", + "version": "1.0.0.0" + }, + { + "name": "Connected.Hosting", + "version": "1.0.0.0" + }, + { + "name": "Connected.Interop", + "version": "1.0.0.0" + }, + { + "name": "Connected.Middleware", + "version": "1.0.0.0" + }, + { + "name": "Connected.Net", + "version": "1.0.0.0" + }, + { + "name": "Connected.Notifications", + "version": "1.0.0.0" + }, + { + "name": "Connected.Rest", + "version": "1.0.0.0" + }, + { + "name": "Connected.Runtime", + "version": "1.0.0.0" + }, + { + "name": "Connected.Security", + "version": "1.0.0.0" + }, + { + "name": "Connected.ServiceModel", + "version": "1.0.0.0" + }, + { + "name": "Connected.Services", + "version": "1.0.0.0" + }, + { + "name": "Connected.Threading", + "version": "1.0.0.0" + }, + { + "name": "Connected.Validation", + "version": "1.0.0.0" + }, + { + "name": "Connected.Instance", + "version": "1.0.0.0" + }, + { + "name": "Common", + "version": "1.0.0.0" + }, + { + "name": "Common.Model", + "version": "1.0.0.0" + }, + { + "name": "Common.Types", + "version": "1.0.0.0" + }, + { + "name": "Common.Types.Model", + "version": "1.0.0.0" + }, + { + "name": "Logistics.Documents", + "version": "1.0.0.0" + }, + { + "name": "Logistics.Processes.Receive", + "version": "1.0.0.0" + }, + { + "name": "Contacts.Types", + "version": "1.0.0.0" + }, + { + "name": "Logistics.Types", + "version": "1.0.0.0" + }, + { + "name": "Logistics.Stock", + "version": "1.0.0.0" + }, + { + "name": "Common.Notes", + "version": "1.0.0.0" + }, + { + "name": "Common.Notes.Model", + "version": "1.0.0.0" + }, + { + "name": "Connected.ServiceModel.Client.Data", + "version": "1.0.0.0" + }, + { + "name": "Connected.ServiceModel.Client", + "version": "1.0.0.0" + } + ], + "locations": [ + "C:\\Solutions\\TomPIT.Connected\\Framework\\Connected.Instance\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Framework\\Connected.Entities\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Framework\\Connected.Rest\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Framework.ServiceModel\\Connected.ServiceModel\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Common\\Common\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Common.Types\\Common.Types\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Common\\Common.Notes\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Logistics\\Logistics.Processes.Receive\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Logistics\\Logistics.Documents\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Logistics\\Logistics.Types\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Logistics\\Logistics.Stock\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Customers\\Contacts.Types\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Framework.ServiceModel.Client\\Connected.ServiceModel.Client\\bin\\Debug\\net7.0", + "C:\\Solutions\\TomPIT.Connected\\Framework.ServiceModel.Client\\Connected.ServiceModel.Client.Data\\bin\\Debug\\net7.0" + ], + "start": "Connected.Instance.Start, Connected.Instance" +}