From 69ab2f0ca75d0d9df8102818a5b441eb8b6afade Mon Sep 17 00:00:00 2001 From: Ivo Petrov Date: Thu, 31 Oct 2024 09:46:25 +0000 Subject: [PATCH] Update TuneUpWindowViewModel.cs --- TuneUp/TuneUpWindowViewModel.cs | 90 +++++++++++++++++---------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/TuneUp/TuneUpWindowViewModel.cs b/TuneUp/TuneUpWindowViewModel.cs index e5d4b7a..074b474 100644 --- a/TuneUp/TuneUpWindowViewModel.cs +++ b/TuneUp/TuneUpWindowViewModel.cs @@ -308,68 +308,70 @@ internal void ResetProfiledNodes() { if (CurrentWorkspace == null) return; - // Clear existing collections - ProfiledNodesLatestRun?.Clear(); - ProfiledNodesPreviousRun?.Clear(); - ProfiledNodesNotExecuted?.Clear(); + uiContext.Send(_ => { + // Clear existing collections + ProfiledNodesLatestRun?.Clear(); + ProfiledNodesPreviousRun?.Clear(); + ProfiledNodesNotExecuted?.Clear(); - // Reset execution time stats - LatestGraphExecutionTime = PreviousGraphExecutionTime = TotalGraphExecutionTime = defaultExecutionTime; + // Reset execution time stats + LatestGraphExecutionTime = PreviousGraphExecutionTime = TotalGraphExecutionTime = defaultExecutionTime; - // Initialize observable collections and dictionaries - ProfiledNodesLatestRun = ProfiledNodesLatestRun ?? new ObservableCollection(); - ProfiledNodesPreviousRun = ProfiledNodesPreviousRun ?? new ObservableCollection(); - ProfiledNodesNotExecuted = ProfiledNodesNotExecuted ?? new ObservableCollection(); + // Initialize observable collections and dictionaries + ProfiledNodesLatestRun = ProfiledNodesLatestRun ?? new ObservableCollection(); + ProfiledNodesPreviousRun = ProfiledNodesPreviousRun ?? new ObservableCollection(); + ProfiledNodesNotExecuted = ProfiledNodesNotExecuted ?? new ObservableCollection(); - collectionMapping = new Dictionary, CollectionViewSource> { + collectionMapping = new Dictionary, CollectionViewSource> { { ProfiledNodesLatestRun, ProfiledNodesCollectionLatestRun }, {ProfiledNodesPreviousRun, ProfiledNodesCollectionPreviousRun }, - {ProfiledNodesNotExecuted, ProfiledNodesCollectionNotExecuted } + {ProfiledNodesNotExecuted, ProfiledNodesCollectionNotExecuted } }; - nodeDictionary = new Dictionary(); - groupDictionary = new Dictionary(); - groupModelDictionary = new Dictionary>(); + nodeDictionary = new Dictionary(); + groupDictionary = new Dictionary(); + groupModelDictionary = new Dictionary>(); - // Create a profiled node for each NodeModel - foreach (var node in CurrentWorkspace.Nodes) - { - var profiledNode = new ProfiledNodeViewModel(node) { GroupName = node.Name }; - ProfiledNodesNotExecuted.Add(profiledNode); - nodeDictionary[node.GUID] = profiledNode; - } + // Create a profiled node for each NodeModel + foreach (var node in CurrentWorkspace.Nodes) + { + var profiledNode = new ProfiledNodeViewModel(node) { GroupName = node.Name }; + ProfiledNodesNotExecuted.Add(profiledNode); + nodeDictionary[node.GUID] = profiledNode; + } - // Create a profiled node for each AnnotationModel - foreach (var group in CurrentWorkspace.Annotations) - { - var pGroup = new ProfiledNodeViewModel(group); - ProfiledNodesNotExecuted.Add(pGroup); - groupDictionary[pGroup.NodeGUID] = (pGroup); - groupModelDictionary[group.GUID] = new List { pGroup }; + // Create a profiled node for each AnnotationModel + foreach (var group in CurrentWorkspace.Annotations) + { + var pGroup = new ProfiledNodeViewModel(group); + ProfiledNodesNotExecuted.Add(pGroup); + groupDictionary[pGroup.NodeGUID] = (pGroup); + groupModelDictionary[group.GUID] = new List { pGroup }; - var groupedNodeGUIDs = group.Nodes.OfType().Select(n => n.GUID); + var groupedNodeGUIDs = group.Nodes.OfType().Select(n => n.GUID); - foreach (var nodeGuid in groupedNodeGUIDs) - { - if (nodeDictionary.TryGetValue(nodeGuid, out var pNode)) + foreach (var nodeGuid in groupedNodeGUIDs) { - ApplyGroupPropertiesAndRegisterNode(pNode, pGroup); + if (nodeDictionary.TryGetValue(nodeGuid, out var pNode)) + { + ApplyGroupPropertiesAndRegisterNode(pNode, pGroup); + } } } - } - ProfiledNodesCollectionLatestRun = new CollectionViewSource { Source = ProfiledNodesLatestRun }; - ProfiledNodesCollectionPreviousRun = new CollectionViewSource { Source = ProfiledNodesPreviousRun }; - ProfiledNodesCollectionNotExecuted = new CollectionViewSource { Source = ProfiledNodesNotExecuted }; + ProfiledNodesCollectionLatestRun = new CollectionViewSource { Source = ProfiledNodesLatestRun }; + ProfiledNodesCollectionPreviousRun = new CollectionViewSource { Source = ProfiledNodesPreviousRun }; + ProfiledNodesCollectionNotExecuted = new CollectionViewSource { Source = ProfiledNodesNotExecuted }; - // Refresh UI if any changes were made - RaisePropertyChanged(nameof(ProfiledNodesCollectionNotExecuted)); - ApplyCustomSorting(ProfiledNodesCollectionNotExecuted, SortByName); + // Refresh UI if any changes were made + RaisePropertyChanged(nameof(ProfiledNodesCollectionNotExecuted)); + ApplyCustomSorting(ProfiledNodesCollectionNotExecuted, SortByName); - ApplyGroupNodeFilter(); + ApplyGroupNodeFilter(); - // Ensure table visibility is updated in case TuneUp was closed and reopened with the same graph. - UpdateTableVisibility(); + // Ensure table visibility is updated in case TuneUp was closed and reopened with the same graph. + UpdateTableVisibility(); + }, null); } ///