History

GSF.InstallerActions: Updated company info actions to include a SystemName parameters and acronym validation

J. Ritchie Carroll committed 6 years ago

Commit 9110c381 parent 02a9e7d1 file · +24 −2Browse files

Unified · Split

Source/Libraries/GSF.InstallerActions/CustomActions.cs+24−2
@@ -229,7 +229,7 @@ namespace GSF.InstallerActions · 228 unmodified lines
229229 }
230230
231231 /// <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.
233233 /// </summary>
234234 /// <param name="session">Session object containing data from the installer.</param>
235235 /// <returns>Result of the custom action.</returns>
@@ -261,6 +261,7 @@ namespace GSF.InstallerActions · 25 unmodified lines
261261 {
262262 setPropertyValue(systemSettings, "CompanyName", "COMPANYNAME");
263263 setPropertyValue(systemSettings, "CompanyAcronym", "COMPANYACRONYM");
264+ setPropertyValue(systemSettings, "SystemName", "SYSTEMNAME");
264265 }
265266 }
266267
@@ -270,7 +271,7 @@ namespace GSF.InstallerActions · 3 unmodified lines
270271 }
271272
272273 /// <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.
274275 /// </summary>
275276 /// <param name="session">Session object containing data from the installer.</param>
276277 /// <returns>Result of the custom action.</returns>
@@ -284,6 +285,12 @@ namespace GSF.InstallerActions · 7 unmodified lines
284285 string serviceName = GetPropertyValue(session, "SERVICENAME");
285286 string configPath = Path.Combine(GetPropertyValue(session, "INSTALLDIR"), $"{serviceName}.exe.config");
286287
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+
287294 if (File.Exists(configPath))
288295 {
289296 XDocument config = XDocument.Load(configPath);
@@ -298,6 +305,10 @@ namespace GSF.InstallerActions · 8 unmodified lines
298305 foreach (XElement companyAcronymElement in systemSettings.Elements("add").Where(element => element.Attributes("name").Any(nameAttribute => string.Compare(nameAttribute.Value, "CompanyAcronym", StringComparison.OrdinalIgnoreCase) == 0)))
299306 companyAcronymElement.Attributes("value").ToList().ForEach(valueAttribute => valueAttribute.Value = GetPropertyValue(session, "COMPANYACRONYM"));
300307
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+
301312 // Add CompanyName setting if no such setting exists
302313 if (!systemSettings.Elements("add").Any(element => element.Attributes("name").Any(nameAttribute => string.Compare(nameAttribute.Value, "CompanyName", StringComparison.OrdinalIgnoreCase) == 0)))
303314 {
@@ -319,6 +330,17 @@ namespace GSF.InstallerActions · 15 unmodified lines
319330 new XAttribute("encrypted", "false")
320331 ));
321332 }
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+ }
322344 }
323345
324346 config.Save(configPath);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t