diff --git a/RXInstanceManager/AppConfig.cs b/RXInstanceManager/AppConfig.cs new file mode 100644 index 0000000..ac6e7ec --- /dev/null +++ b/RXInstanceManager/AppConfig.cs @@ -0,0 +1,9 @@ +using System; + +namespace RXInstanceManager +{ + public class AppConfig + { + public string LogViewerPath { get; set; } + } +} diff --git a/RXInstanceManager/AppHandlers.cs b/RXInstanceManager/AppHandlers.cs index f230e13..8d4c920 100644 --- a/RXInstanceManager/AppHandlers.cs +++ b/RXInstanceManager/AppHandlers.cs @@ -81,16 +81,19 @@ public static void UpdateInstanceData(Instance instance) var protocol = yamlValues.GetConfigStringValue("variables.protocol"); var host = yamlValues.GetConfigStringValue("variables.host_fqdn"); + var dbNameFromVar = yamlValues.GetConfigStringValue("variables.database"); var dbEngine = yamlValues.GetConfigStringValue("common_config.DATABASE_ENGINE"); var connection = yamlValues.GetConfigStringValue("common_config.CONNECTION_STRING"); - var dbName = AppHelper.GetDBNameFromConnectionString(dbEngine, connection); + var dbName = AppHelper.GetDBNameFromConnectionString(dbEngine, connection, dbNameFromVar); instance.Name = yamlValues.GetConfigStringValue("variables.purpose"); instance.Port = yamlValues.GetConfigIntValue("variables.http_port") ?? 0; instance.URL = AppHelper.GetClientURL(protocol, host, instance.Port); instance.DBName = dbName ?? string.Empty; instance.StoragePath = yamlValues.GetConfigStringValue("variables.home_path"); - instance.SourcesPath = yamlValues.GetConfigStringValue("services_config.DevelopmentStudio.GIT_ROOT_DIRECTORY"); + instance.SourcesPath = AppHelper.GetSourcesPath(instance.StoragePath, yamlValues.GetConfigStringValue("services_config.DevelopmentStudio.GIT_ROOT_DIRECTORY")); + instance.LogsPath = AppHelper.GetLogsPath(instance.StoragePath, yamlValues.GetConfigStringValue("logs_path.LOGS_PATH")); + instance.ProjectPath = yamlValues.GetConfigStringValue("variables.project_config_path"); instance.PlatformVersion = GetInstancePlatformVersion(instance.InstancePath); instance.SolutionVersion = GetInstanceSolutionVersion(instance.InstancePath); instance.Save(); @@ -222,6 +225,22 @@ public static void InfoHandler(Instance instance, string message) logger.Info(logBody); } + public static void DebugHandler(Instance instance, string message) + { + var code = instance != null ? instance.Code : string.Empty; + var path = instance != null ? instance.InstancePath : string.Empty; + var logBody = string.Format($"Code: {code}, Path: {path}, Message: {message}"); + logger.Debug(logBody); + } + + public static void ErrorHandler(Instance instance, string message) + { + var code = instance != null ? instance.Code : string.Empty; + var path = instance != null ? instance.InstancePath : string.Empty; + var logBody = string.Format($"Code: {code}, Path: {path}, Message: {message}"); + logger.Error(logBody); + } + public static void ErrorHandler(Instance instance, Exception exception) { var code = instance != null ? instance.Code : string.Empty; diff --git a/RXInstanceManager/AppHelper.cs b/RXInstanceManager/AppHelper.cs index cbc34e2..1255a99 100644 --- a/RXInstanceManager/AppHelper.cs +++ b/RXInstanceManager/AppHelper.cs @@ -119,20 +119,44 @@ public static string GetClientURL(string protocol, string host, int port) return $"{protocol}://{host}:{port}/Client"; } - public static string GetDBNameFromConnectionString(string engine, string connectionString) + public static string GetLogsPath(string storagePath, string logsPath) + { + return logsPath + .Replace("{{ home_path }}", storagePath) + .Replace("{{home_path}}", storagePath); + } + + public static string GetSourcesPath(string storagePath, string sourcesPath) + { + return sourcesPath + .Replace("{{ home_path }}", storagePath) + .Replace("{{home_path}}", storagePath); + } + + public static string GetDBName(string dbName, string dbNameFromVar) + { + if (string.IsNullOrEmpty(dbNameFromVar)) + return dbName; + + return dbName + .Replace("{{ database }}", dbNameFromVar) + .Replace("{{database}}", dbNameFromVar); + } + + public static string GetDBNameFromConnectionString(string engine, string connectionString, string dbNameFromVar) { if (engine == "mssql") { var databaseNameParam = connectionString.Split(';').FirstOrDefault(x => x.ToLower().Contains("initial catalog")); if (databaseNameParam != null) - return databaseNameParam.Split('=')[1]; + return GetDBName(databaseNameParam.Split('=')[1], dbNameFromVar); } if (engine == "postgres") { var databaseNameParam = connectionString.Split(';').FirstOrDefault(x => x.ToLower().Contains("database")); if (databaseNameParam != null) - return databaseNameParam.Split('=')[1]; + return GetDBName(databaseNameParam.Split('=')[1], dbNameFromVar); } return null; diff --git a/RXInstanceManager/AppInitializer.cs b/RXInstanceManager/AppInitializer.cs new file mode 100644 index 0000000..50fb634 --- /dev/null +++ b/RXInstanceManager/AppInitializer.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.IO; +using System.Text.Json; + +namespace RXInstanceManager +{ + public static class AppInitializer + { + internal static readonly string FileName = "rxman.config"; + + public static string FilePath { get; } + public static AppConfig Config { get; set; } + + public static void Initialize() + { + if (!File.Exists(FilePath)) + { + var config = new AppConfig(); + config.LogViewerPath = ""; + + var newJson = Serialize(config); + File.WriteAllText(FilePath, newJson); + } + + var json = File.ReadAllText(FilePath); + Config = Deserialize(json); + } + + public static string Serialize(AppConfig config) + { + return JsonSerializer.Serialize(config); + } + + public static AppConfig Deserialize(string json) + { + return JsonSerializer.Deserialize(json); + } + + static AppInitializer() + { + FilePath = $"{AppContext.BaseDirectory}{FileName}"; + } + } +} diff --git a/RXInstanceManager/Entities/Models/Instance.cs b/RXInstanceManager/Entities/Models/Instance.cs index 2deac41..574dcb4 100644 --- a/RXInstanceManager/Entities/Models/Instance.cs +++ b/RXInstanceManager/Entities/Models/Instance.cs @@ -43,6 +43,12 @@ public class Instance [Field("sources", Size = 150)] public string SourcesPath { get; set; } + [Field("project", Size = 150)] + public string ProjectPath { get; set; } + + [Field("logs", Size = 150)] + public string LogsPath { get; set; } + [Field("status", Size = 12)] public string Status { get; set; } @@ -61,6 +67,8 @@ public override string ToString() builder.AppendLine("Путь до инстанса: " + InstancePath ?? string.Empty); builder.AppendLine("Путь до хранилища: " + StoragePath ?? string.Empty); builder.AppendLine("Путь до исходников: " + SourcesPath ?? string.Empty); + builder.AppendLine("Путь до логов: " + LogsPath ?? string.Empty); + builder.AppendLine("Путь до проекта: " + ProjectPath ?? string.Empty); builder.AppendLine("Имя службы: " + ServiceName ?? string.Empty); builder.AppendLine("Имя БД: " + DBName ?? string.Empty); return builder.ToString(); diff --git a/RXInstanceManager/MainWindow.xaml b/RXInstanceManager/MainWindow.xaml index 14c9f6a..c31c5b6 100644 --- a/RXInstanceManager/MainWindow.xaml +++ b/RXInstanceManager/MainWindow.xaml @@ -38,12 +38,13 @@