diff --git a/LaaProductionWeb/LaaProduction.Console/LaaProduction.Console.csproj b/LaaProductionWeb/LaaProduction.Console/LaaProduction.Console.csproj new file mode 100644 index 00000000..c8a4a96c --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Console/LaaProduction.Console.csproj @@ -0,0 +1,114 @@ + + + + + Debug + AnyCPU + {04680623-CDA8-4830-9B09-D47187C10F99} + Exe + LaaProduction.Console + LaaProduction.Console + v4.8.1 + 512 + true + true + false + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 1 + 1.0.0.%2a + false + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + 6E0C81C2391616844BCD6B66C1D0E0E3344D25DC + + + LaaProduction.Console_TemporaryKey.pfx + + + true + + + true + + + + ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + + + + + + + + + ..\packages\System.IO.FileSystem.AccessControl.5.0.0\lib\net461\System.IO.FileSystem.AccessControl.dll + + + + + ..\packages\System.Security.AccessControl.6.0.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Permissions.7.0.0\lib\net462\System.Security.Permissions.dll + + + ..\packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll + + + + + + + + + + + + + + + + + + + + + + + False + .NET Framework 3.5 SP1 + false + + + + \ No newline at end of file diff --git a/LaaProductionWeb/LaaProduction.Console/Program.cs b/LaaProductionWeb/LaaProduction.Console/Program.cs new file mode 100644 index 00000000..4db68f8e --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Console/Program.cs @@ -0,0 +1,111 @@ +namespace LaaProduction.Console +{ + using Newtonsoft.Json; + + using System; + using System.Collections; + using System.Collections.Generic; + using System.DirectoryServices; + using System.DirectoryServices.AccountManagement; + using System.Linq; + + public static class Program + { + public static void Main() + { + var software = Software(); + + Console.WriteLine(JsonConvert.SerializeObject(software, Formatting.Indented)); + + Console.Write("Press any key for exit: "); + Console.ReadKey(); + } + + public static Software Software() + { + var assembly = typeof(T).Assembly.GetName(); + + return new Software + { + Assembly = assembly.Name, + Version = assembly.Version.ToString(), + CurrentUser = SoftwareUser() + }; + } + + public static SoftwareUser SoftwareUser() + { + var softwareUser = new SoftwareUser(); + var userPrincipal = UserPrincipal.Current; + + userPrincipal.DistinguishedName.ParseSearchResultProperties(softwareUser.Values); + + softwareUser.Values = softwareUser.Values.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value); + + + if (softwareUser.Values.TryGetValue("manager", out string adspath)) + { + softwareUser.Manager = new SoftwareUser(); + + adspath.ParseSearchResultProperties(softwareUser.Manager.Values); + + softwareUser.Manager.Values = softwareUser.Manager.Values.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value); + } + + return softwareUser; + } + + private static void ParseSearchResultProperties(this string absPath, IDictionary values) + { + try + { + var exclude = new[] { "comment", "userparameters" }; + + using (var directoryEntry = new DirectoryEntry($"LDAP://{absPath}")) + { + using (var directorySearcher = new DirectorySearcher(directoryEntry)) + { + var searchResult = directorySearcher.FindOne(); + + foreach (DictionaryEntry dictionaryEntry in searchResult.Properties) + { + if (dictionaryEntry.Key is string property && !exclude.Contains(property)) + { + if (dictionaryEntry.Value is ResultPropertyValueCollection dictionaryEntryValues) + { + if (dictionaryEntryValues.Count > 0 && dictionaryEntryValues[0] is string value) + { + values[property] = value; + } + } + } + } + } + } + } + catch (Exception e) + { + values[nameof(e.Message)] = e.Message; + } + } + } + + public class Software + { + public string Assembly { get; set; } + + public string Version { get; set; } + + public SoftwareUser CurrentUser { get; set; } + } + + public class SoftwareUser + { + public SoftwareUser() + => this.Values = new Dictionary(); + + public SoftwareUser Manager { get; set; } + + public IDictionary Values { get; set; } + } +} diff --git a/LaaProductionWeb/LaaProduction.Console/Properties/AssemblyInfo.cs b/LaaProductionWeb/LaaProduction.Console/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..0b05169f --- /dev/null +++ b/LaaProductionWeb/LaaProduction.Console/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("LaaProduction.Console")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("LaaProduction.Console")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("04680623-cda8-4830-9b09-d47187c10f99")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/LaaProductionWeb/LaaProduction.Web/LaaProduction.Web.csproj b/LaaProductionWeb/LaaProduction.Web/LaaProduction.Web.csproj index e36b33e9..145ba9ac 100644 --- a/LaaProductionWeb/LaaProduction.Web/LaaProduction.Web.csproj +++ b/LaaProductionWeb/LaaProduction.Web/LaaProduction.Web.csproj @@ -50,8 +50,8 @@ ..\packages\LaaProductionHttp.1.0.0\lib\netstandard2.0\LaaProductionHttp.dll - - ..\packages\LaaProductionSQL.1.0.0\lib\netstandard2.0\LaaProductionSQL.dll + + ..\packages\LaaProductionSQL.1.0.1\lib\netstandard2.0\LaaProductionSQL.dll ..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll @@ -77,6 +77,7 @@ ..\packages\System.Data.SqlClient.4.8.5\lib\net461\System.Data.SqlClient.dll + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.9\lib\net45\System.Net.Http.Formatting.dll @@ -84,6 +85,9 @@ ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + ..\packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll diff --git a/LaaProductionWeb/LaaProductionWeb.sln b/LaaProductionWeb/LaaProductionWeb.sln index c627e572..2c97e376 100644 --- a/LaaProductionWeb/LaaProductionWeb.sln +++ b/LaaProductionWeb/LaaProductionWeb.sln @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProduction.Web", "LaaPro EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProduction.Personalization.Updater", "LaaProduction.Personalization.Updater\LaaProduction.Personalization.Updater.csproj", "{4B7F1659-2A57-414C-A192-FA0A822B6612}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProduction.Console", "LaaProduction.Console\LaaProduction.Console.csproj", "{04680623-CDA8-4830-9B09-D47187C10F99}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +47,10 @@ Global {4B7F1659-2A57-414C-A192-FA0A822B6612}.Debug|Any CPU.Build.0 = Debug|Any CPU {4B7F1659-2A57-414C-A192-FA0A822B6612}.Release|Any CPU.ActiveCfg = Release|Any CPU {4B7F1659-2A57-414C-A192-FA0A822B6612}.Release|Any CPU.Build.0 = Release|Any CPU + {04680623-CDA8-4830-9B09-D47187C10F99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {04680623-CDA8-4830-9B09-D47187C10F99}.Debug|Any CPU.Build.0 = Debug|Any CPU + {04680623-CDA8-4830-9B09-D47187C10F99}.Release|Any CPU.ActiveCfg = Release|Any CPU + {04680623-CDA8-4830-9B09-D47187C10F99}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE