A Swiss Army knife for developers.
C# blazorcross-platformcsharpdesktopdesktop-appdesktop-applicationdeveloper-toolsextensiblefluentfluent-designlinuxmacosmicasyntax-highlightingtypescriptwindowswindows-10windows-11winui
Minor bug fixes
Etienne Baudouxe4e3a2896ea3
diff --git a/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs b/src/app/dev/DevToys.Core/Tools/GuiToolProvider.csindex df2b7f615..5d16f8be3 100644--- a/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs+++ b/src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs@@ -1,5 +1,6 @@using System.Collections.ObjectModel;using System.Reflection;+using DevToys.Api;using DevToys.Core.Tools.Metadata;using DevToys.Core.Tools.ViewItems;using DevToys.Localization;@@ -409,11 +410,19 @@ public sealed partial class GuiToolProvidervar bodyToolInstances = new List<GuiToolInstance>();// Order all the tools.- guiTools- = ExtensionOrderer.Order(- guiTools- .OrderBy(tool => tool.Metadata.MenuPlacement)- .ThenBy(tool => tool.Metadata.InternalComponentName));+ try+ {+ guiTools+ = ExtensionOrderer.Order(+ guiTools+ .OrderBy(tool => tool.Metadata.MenuPlacement)+ .ThenBy(tool => tool.Metadata.InternalComponentName));+ }+ catch (Exception ex)+ {+ // TODO: We should let the user know that something went wrong.+ LogOrderingToolsFailed(ex);+ }foreach (Lazy<IGuiTool, GuiToolMetadata> guiToolDefinition in guiTools){@@ -587,11 +596,22 @@ public sealed partial class GuiToolProvider}// Order tools groups.- IEnumerable<GroupViewItem> orderedGroups- = ExtensionOrderer.Order(- groups.Values.OrderBy(g => g.Value.DisplayTitle))- .Select(g => g.Value);- return orderedGroups;+ try+ {+ IEnumerable<GroupViewItem> orderedGroups+ = ExtensionOrderer.Order(+ groups.Values.OrderBy(g => g.Value.DisplayTitle))+ .Select(g => g.Value);+ return orderedGroups;+ }+ catch (Exception ex)+ {+ // TODO: We should let the user know that something went wrong.+ LogOrderingGroupsFailed(ex);+ }++ // Fallback+ return groups.Values.Select(g => g.Value);}private Assembly GetResourceManagerAssembly(string resourceManagerAssemblyIdentifier)@@ -743,4 +763,10 @@ public sealed partial class GuiToolProvider[LoggerMessage(0, LogLevel.Information, "Set '{toolName}' as the most recently used tool.")]partial void LogSetMostRecentUsedTool(string toolName);++ [LoggerMessage(1, LogLevel.Error, "Error while ordering tools.")]+ partial void LogOrderingToolsFailed(Exception ex);++ [LoggerMessage(2, LogLevel.Error, "Error while ordering groups.")]+ partial void LogOrderingGroupsFailed(Exception ex);}diff --git a/src/app/dev/DevToys.Core/Tools/SmartDetectionService.cs b/src/app/dev/DevToys.Core/Tools/SmartDetectionService.csindex b789f4bba..a54587e67 100644--- a/src/app/dev/DevToys.Core/Tools/SmartDetectionService.cs+++ b/src/app/dev/DevToys.Core/Tools/SmartDetectionService.cs@@ -184,37 +184,45 @@ public sealed partial class SmartDetectionService/// </summary>/// <param name="detectors">The collection of detectors.</param>/// <returns>A list of root detector nodes.</returns>- private static List<DetectorNode> BuildDetectorNodeHierarchy(IEnumerable<Lazy<IDataTypeDetector, DataTypeDetectorMetadata>> detectors)+ private List<DetectorNode> BuildDetectorNodeHierarchy(IEnumerable<Lazy<IDataTypeDetector, DataTypeDetectorMetadata>> detectors){- // Create a dictionary that maps data type names to detector nodes- var lookup- = detectors.ToDictionary(- node => node.Metadata.DataTypeName,- node => new DetectorNode(node));var result = new List<DetectorNode>();- foreach (KeyValuePair<string, DetectorNode> node in lookup)+ try{- // Check if the current detector is supported by the current operating system- if (!OSHelper.IsOsSupported(node.Value.Detector.Metadata.TargetPlatforms))- {- // If not supported, ignore it.- Debug.WriteLine($"Ignoring '{node.Value.Detector.Metadata.DataTypeName}' data type detector as it isn't supported by the current OS.");- }- else if (string.IsNullOrEmpty(node.Value.Detector.Metadata.DataTypeBaseName))- {- // If the current detector does not have a base data type name, add it to the result list as a root node- result.Add(node.Value);- }- else if (lookup.TryGetValue(node.Value.Detector.Metadata.DataTypeBaseName, out DetectorNode? parentNode))+ // Create a dictionary that maps data type names to detector nodes+ var lookup+ = detectors.ToDictionary(+ node => node.Metadata.DataTypeName,+ node => new DetectorNode(node));++ foreach (KeyValuePair<string, DetectorNode> node in lookup){- // If the current detector has a base data type name and its parent node exists in the dictionary,- // add it as a child to its parent node- parentNode.ChildrenDetectors ??= new();+ // Check if the current detector is supported by the current operating system+ if (!OSHelper.IsOsSupported(node.Value.Detector.Metadata.TargetPlatforms))+ {+ // If not supported, ignore it.+ Debug.WriteLine($"Ignoring '{node.Value.Detector.Metadata.DataTypeName}' data type detector as it isn't supported by the current OS.");+ }+ else if (string.IsNullOrEmpty(node.Value.Detector.Metadata.DataTypeBaseName))+ {+ // If the current detector does not have a base data type name, add it to the result list as a root node+ result.Add(node.Value);+ }+ else if (lookup.TryGetValue(node.Value.Detector.Metadata.DataTypeBaseName, out DetectorNode? parentNode))+ {+ // If the current detector has a base data type name and its parent node exists in the dictionary,+ // add it as a child to its parent node+ parentNode.ChildrenDetectors ??= new();- parentNode.ChildrenDetectors.Add(node.Value);+ parentNode.ChildrenDetectors.Add(node.Value);+ }}}+ catch (Exception ex)+ {+ LogBuildDetectorNodeHierarchyError(ex);+ }return result;}@@ -251,9 +259,12 @@ public sealed partial class SmartDetectionServicereturn dataTypeToToolInstanceMap;}- [LoggerMessage(0, LogLevel.Error, $"Error in {nameof(DetectAsync)}.")]+ [LoggerMessage(0, LogLevel.Error, $"Error while running Smart Detection.")]partial void LogDetectAsyncError(Exception ex);+ [LoggerMessage(1, LogLevel.Error, $"Error while building data detectors.")]+ partial void LogBuildDetectorNodeHierarchyError(Exception ex);+private sealed class DetectorNode{/// <summary>