/ src / modules / cmdpal / ext / Microsoft.CmdPal.Ext.WindowsSettings / Helpers / WindowsSettingsPathHelper.cs
WindowsSettingsPathHelper.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Linq; 6 using ManagedCommon; 7 8 namespace Microsoft.CmdPal.Ext.WindowsSettings.Helpers; 9 10 /// <summary> 11 /// Helper class to help with the path of a <see cref="WindowsSetting"/>. The settings path shows where to find a setting within Windows' user interface. 12 /// </summary> 13 internal static class WindowsSettingsPathHelper 14 { 15 /// <summary> 16 /// The symbol which is used as delimiter between the parts of the path. 17 /// </summary> 18 private const string _pathDelimiterSequence = "\u0020\u0020\u02C3\u0020\u0020"; // = "<space><space><arrow><space><space>" 19 20 /// <summary> 21 /// Generates the values for <see cref="WindowsSetting.JoinedAreaPath"/> and <see cref="WindowsSetting.JoinedFullSettingsPath"/> on all settings of the list in the given <see cref="WindowsSettings"/> class. 22 /// </summary> 23 /// <param name="windowsSettings">A class that contain all possible windows settings.</param> 24 internal static void GenerateSettingsPathValues(in Classes.WindowsSettings windowsSettings) 25 { 26 if (windowsSettings?.Settings is null) 27 { 28 return; 29 } 30 31 foreach (var settings in windowsSettings.Settings) 32 { 33 // Check if type value is filled. If not, then write log warning. 34 if (string.IsNullOrEmpty(settings.Type)) 35 { 36 // TODO GH #108 Logging is something we have to take care of 37 // Log.Warn($"The type property is not set for setting [{settings.Name}] in json. Skipping generating of settings path.", typeof(WindowsSettingsPathHelper)); 38 Logger.LogWarning($"The type property is not set for setting [{settings.Name}] in json. Skipping generating of settings path."); 39 continue; 40 } 41 42 // Check if "JoinedAreaPath" and "JoinedFullSettingsPath" are filled. Then log debug message. 43 if (!string.IsNullOrEmpty(settings.JoinedAreaPath)) 44 { 45 // Log.Debug($"The property [JoinedAreaPath] of setting [{settings.Name}] was filled from the json. This value is not used and will be overwritten.", typeof(WindowsSettingsPathHelper)); 46 Logger.LogDebug($"The property [JoinedAreaPath] of setting [{settings.Name}] was filled from the json. This value is not used and will be overwritten."); 47 } 48 49 if (!string.IsNullOrEmpty(settings.JoinedFullSettingsPath)) 50 { 51 // TODO GH #108 Logging is something we have to take care of 52 // Log.Debug($"The property [JoinedFullSettingsPath] of setting [{settings.Name}] was filled from the json. This value is not used and will be overwritten.", typeof(WindowsSettingsPathHelper)); 53 Logger.LogDebug($"The property [JoinedFullSettingsPath] of setting [{settings.Name}] was filled from the json. This value is not used and will be overwritten."); 54 } 55 56 // Generating path values. 57 if (!(settings.Areas is null) && settings.Areas.Any()) 58 { 59 var areaValue = string.Join(_pathDelimiterSequence, settings.Areas); 60 settings.JoinedAreaPath = areaValue; 61 settings.JoinedFullSettingsPath = $"{settings.Type}{_pathDelimiterSequence}{areaValue}"; 62 } 63 else 64 { 65 settings.JoinedAreaPath = string.Empty; 66 settings.JoinedFullSettingsPath = settings.Type; 67 } 68 } 69 } 70 }