Files
laatzen/LaaProductionWeb/LaaProduction.Personalization.Updater/Program.cs
T
2023-08-22 14:58:05 +02:00

80 lines
2.7 KiB
C#

namespace LaaProduction.Personalization.Updater
{
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
public class Program
{
public static void Main()
{
Console.WriteLine("Updating LaaProduction.Personalization ...");
var employeesRoles = new List<string>();
var softwareFunctions = new List<string>();
using (var sqlConnection = new SqlConnection("Server=SLASQL01.emea.sensus.net; Database=Auftrag; Integrated Security=True;"))
{
sqlConnection.FireInfoMessageEventOnUserErrors = true;
sqlConnection.InfoMessage += (sender, args)
=> Console.WriteLine(args.Message);
sqlConnection.Open();
using (var sqlCommand = sqlConnection.CreateCommand())
{
sqlCommand.CommandText = "SELECT DISTINCT [Recht] FROM [MitarbeiterRechte] ORDER BY [Recht]";
using (var sqlReader = sqlCommand.ExecuteReader())
{
while (sqlReader.Read())
{
employeesRoles.Add(sqlReader.GetString(0));
}
}
}
using (var sqlCommand = sqlConnection.CreateCommand())
{
sqlCommand.CommandText = "SELECT DISTINCT [Function] FROM [SoftwareFunctions] ORDER BY [Function]";
using (var sqlReader = sqlCommand.ExecuteReader())
{
while (sqlReader.Read())
{
softwareFunctions.Add(sqlReader.GetString(0));
}
}
}
}
var employeesRolesEnumContent = $@"
namespace LaaProduction.Personalization
{{
public enum EmployeesRoles
{{
{string.Join($"{Environment.NewLine}\t", employeesRoles.Select(x => $"{x},"))}
}}
}}";
Console.WriteLine($"Update file: {employeesRolesEnumContent}");
var softwareFunctionsEnumContent = $@"
namespace LaaProduction.Personalization
{{
public enum SoftwareFunctions
{{
{string.Join($"{Environment.NewLine}\t", softwareFunctions.Select(x => $"{x},"))}
}}
}}";
Console.WriteLine($"Update file: {softwareFunctionsEnumContent}");
Console.WriteLine($"Update directory: {Environment.CurrentDirectory}");
File.WriteAllText("..\\..\\SoftwareFunctions.cs", softwareFunctionsEnumContent);
File.WriteAllText("..\\..\\EmployeesRoles.cs", employeesRolesEnumContent);
Console.ReadKey();
}
}
}