Unified · Split
| @@ -229,7 +229,7 @@ namespace GSF.InstallerActions · 228 unmodified lines | ||
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /// <summary> |
| 232 | − /// Custom action to load any previously defined CompanyName and CompanyAcronym settings from the configuration file of an installed service. | |
| 232 | + /// Custom action to load any previously defined CompanyName, CompanyAcronym and SystemName settings from the configuration file of an installed service. | |
| 233 | 233 | /// </summary> |
| 234 | 234 | /// <param name="session">Session object containing data from the installer.</param> |
| 235 | 235 | /// <returns>Result of the custom action.</returns> |
| @@ -261,6 +261,7 @@ namespace GSF.InstallerActions · 25 unmodified lines | ||
| 261 | 261 | { |
| 262 | 262 | setPropertyValue(systemSettings, "CompanyName", "COMPANYNAME"); |
| 263 | 263 | setPropertyValue(systemSettings, "CompanyAcronym", "COMPANYACRONYM"); |
| 264 | + setPropertyValue(systemSettings, "SystemName", "SYSTEMNAME"); | |
| 264 | 265 | } |
| 265 | 266 | } |
| 266 | 267 | |
| @@ -270,7 +271,7 @@ namespace GSF.InstallerActions · 3 unmodified lines | ||
| 270 | 271 | } |
| 271 | 272 | |
| 272 | 273 | /// <summary> |
| 273 | − /// Custom action to write CompanyName and CompanyAcronym settings to the configuration file of an installed service. | |
| 274 | + /// Custom action to write CompanyName, CompanyAcronym and SystemName settings to the configuration file of an installed service. | |
| 274 | 275 | /// </summary> |
| 275 | 276 | /// <param name="session">Session object containing data from the installer.</param> |
| 276 | 277 | /// <returns>Result of the custom action.</returns> |
| @@ -284,6 +285,12 @@ namespace GSF.InstallerActions · 7 unmodified lines | ||
| 284 | 285 | string serviceName = GetPropertyValue(session, "SERVICENAME"); |
| 285 | 286 | string configPath = Path.Combine(GetPropertyValue(session, "INSTALLDIR"), $"{serviceName}.exe.config"); |
| 286 | 287 | |
| 288 | + void validateAcronymBasedPropertyValue(string propertyName) => | |
| 289 | + session[propertyName] = Regex.Replace(GetPropertyValue(session, propertyName).ToUpperInvariant(), @"[^A-Z0-9\-!_\.@#\$]+", "_", RegexOptions.Compiled); | |
| 290 | + | |
| 291 | + validateAcronymBasedPropertyValue("COMPANYACRONYM"); | |
| 292 | + validateAcronymBasedPropertyValue("SYSTEMNAME"); | |
| 293 | + | |
| 287 | 294 | if (File.Exists(configPath)) |
| 288 | 295 | { |
| 289 | 296 | XDocument config = XDocument.Load(configPath); |
| @@ -298,6 +305,10 @@ namespace GSF.InstallerActions · 8 unmodified lines | ||
| 298 | 305 | foreach (XElement companyAcronymElement in systemSettings.Elements("add").Where(element => element.Attributes("name").Any(nameAttribute => string.Compare(nameAttribute.Value, "CompanyAcronym", StringComparison.OrdinalIgnoreCase) == 0))) |
| 299 | 306 | companyAcronymElement.Attributes("value").ToList().ForEach(valueAttribute => valueAttribute.Value = GetPropertyValue(session, "COMPANYACRONYM")); |
| 300 | 307 | |
| 308 | + // Search for existing SystemName settings and update their values | |
| 309 | + foreach (XElement systemNameElement in systemSettings.Elements("add").Where(element => element.Attributes("name").Any(nameAttribute => string.Compare(nameAttribute.Value, "SystemName", StringComparison.OrdinalIgnoreCase) == 0))) | |
| 310 | + systemNameElement.Attributes("value").ToList().ForEach(valueAttribute => valueAttribute.Value = GetPropertyValue(session, "SYSTEMNAME")); | |
| 311 | + | |
| 301 | 312 | // Add CompanyName setting if no such setting exists |
| 302 | 313 | if (!systemSettings.Elements("add").Any(element => element.Attributes("name").Any(nameAttribute => string.Compare(nameAttribute.Value, "CompanyName", StringComparison.OrdinalIgnoreCase) == 0))) |
| 303 | 314 | { |
| @@ -319,6 +330,17 @@ namespace GSF.InstallerActions · 15 unmodified lines | ||
| 319 | 330 | new XAttribute("encrypted", "false") |
| 320 | 331 | )); |
| 321 | 332 | } |
| 333 | + | |
| 334 | + // Add SystemName setting if no such setting exists | |
| 335 | + if (!systemSettings.Elements("add").Any(element => element.Attributes("name").Any(nameAttribute => string.Compare(nameAttribute.Value, "SystemName", StringComparison.OrdinalIgnoreCase) == 0))) | |
| 336 | + { | |
| 337 | + systemSettings.Add(new XElement("add", | |
| 338 | + new XAttribute("name", "SystemName"), | |
| 339 | + new XAttribute("value", GetPropertyValue(session, "SYSTEMNAME")), | |
| 340 | + new XAttribute("description", $"Name of system for this instance of the {serviceName} that will be prefixed to system level tags, when defined. Value should follow tag naming conventions, e.g., no spaces and all upper case."), | |
| 341 | + new XAttribute("encrypted", "false") | |
| 342 | + )); | |
| 343 | + } | |
| 322 | 344 | } |
| 323 | 345 | |
| 324 | 346 | config.Save(configPath); |