Unified · Split
| @@ -229,7 +229,7 @@ namespace GSF.InstallerActions · 228 unmodified lines | |||
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | /// <summary> | 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 | /// </summary> | 233 | /// </summary> |
| 234 | /// <param name="session">Session object containing data from the installer.</param> | 234 | /// <param name="session">Session object containing data from the installer.</param> |
| 235 | /// <returns>Result of the custom action.</returns> | 235 | /// <returns>Result of the custom action.</returns> |
| @@ -261,6 +261,7 @@ namespace GSF.InstallerActions · 25 unmodified lines | |||
| 261 | { | 261 | { |
| 262 | setPropertyValue(systemSettings, "CompanyName", "COMPANYNAME"); | 262 | setPropertyValue(systemSettings, "CompanyName", "COMPANYNAME"); |
| 263 | setPropertyValue(systemSettings, "CompanyAcronym", "COMPANYACRONYM"); | 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 | /// <summary> | 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 | /// </summary> | 275 | /// </summary> |
| 275 | /// <param name="session">Session object containing data from the installer.</param> | 276 | /// <param name="session">Session object containing data from the installer.</param> |
| 276 | /// <returns>Result of the custom action.</returns> | 277 | /// <returns>Result of the custom action.</returns> |
| @@ -284,6 +285,12 @@ namespace GSF.InstallerActions · 7 unmodified lines | |||
| 284 | string serviceName = GetPropertyValue(session, "SERVICENAME"); | 285 | string serviceName = GetPropertyValue(session, "SERVICENAME"); |
| 285 | string configPath = Path.Combine(GetPropertyValue(session, "INSTALLDIR"), $"{serviceName}.exe.config"); | 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 | if (File.Exists(configPath)) | 294 | if (File.Exists(configPath)) |
| 288 | { | 295 | { |
| 289 | XDocument config = XDocument.Load(configPath); | 296 | XDocument config = XDocument.Load(configPath); |
| @@ -298,6 +305,10 @@ namespace GSF.InstallerActions · 8 unmodified lines | |||
| 298 | foreach (XElement companyAcronymElement in systemSettings.Elements("add").Where(element => element.Attributes("name").Any(nameAttribute => string.Compare(nameAttribute.Value, "CompanyAcronym", StringComparison.OrdinalIgnoreCase) == 0))) | 305 | foreach (XElement companyAcronymElement in systemSettings.Elements("add").Where(element => element.Attributes("name").Any(nameAttribute => string.Compare(nameAttribute.Value, "CompanyAcronym", StringComparison.OrdinalIgnoreCase) == 0))) |
| 299 | companyAcronymElement.Attributes("value").ToList().ForEach(valueAttribute => valueAttribute.Value = GetPropertyValue(session, "COMPANYACRONYM")); | 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 | // Add CompanyName setting if no such setting exists | 312 | // Add CompanyName setting if no such setting exists |
| 302 | if (!systemSettings.Elements("add").Any(element => element.Attributes("name").Any(nameAttribute => string.Compare(nameAttribute.Value, "CompanyName", StringComparison.OrdinalIgnoreCase) == 0))) | 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 | new XAttribute("encrypted", "false") | 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 | config.Save(configPath); | 346 | config.Save(configPath); |