Skip to content

Commit

Permalink
Update TuneUpWindowViewModel.cs (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaylo-matov authored Oct 31, 2024
1 parent 21721ef commit 7b8ee03
Showing 1 changed file with 46 additions and 44 deletions.
90 changes: 46 additions & 44 deletions TuneUp/TuneUpWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProfiledNodeViewModel>();
ProfiledNodesPreviousRun = ProfiledNodesPreviousRun ?? new ObservableCollection<ProfiledNodeViewModel>();
ProfiledNodesNotExecuted = ProfiledNodesNotExecuted ?? new ObservableCollection<ProfiledNodeViewModel>();
// Initialize observable collections and dictionaries
ProfiledNodesLatestRun = ProfiledNodesLatestRun ?? new ObservableCollection<ProfiledNodeViewModel>();
ProfiledNodesPreviousRun = ProfiledNodesPreviousRun ?? new ObservableCollection<ProfiledNodeViewModel>();
ProfiledNodesNotExecuted = ProfiledNodesNotExecuted ?? new ObservableCollection<ProfiledNodeViewModel>();
collectionMapping = new Dictionary<ObservableCollection<ProfiledNodeViewModel>, CollectionViewSource> {
collectionMapping = new Dictionary<ObservableCollection<ProfiledNodeViewModel>, CollectionViewSource> {
{ ProfiledNodesLatestRun, ProfiledNodesCollectionLatestRun },
{ProfiledNodesPreviousRun, ProfiledNodesCollectionPreviousRun },
{ProfiledNodesNotExecuted, ProfiledNodesCollectionNotExecuted }
{ProfiledNodesNotExecuted, ProfiledNodesCollectionNotExecuted }
};
nodeDictionary = new Dictionary<Guid, ProfiledNodeViewModel>();
groupDictionary = new Dictionary<Guid, ProfiledNodeViewModel>();
groupModelDictionary = new Dictionary<Guid, List<ProfiledNodeViewModel>>();
nodeDictionary = new Dictionary<Guid, ProfiledNodeViewModel>();
groupDictionary = new Dictionary<Guid, ProfiledNodeViewModel>();
groupModelDictionary = new Dictionary<Guid, List<ProfiledNodeViewModel>>();
// 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<ProfiledNodeViewModel> { 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<ProfiledNodeViewModel> { pGroup };
var groupedNodeGUIDs = group.Nodes.OfType<NodeModel>().Select(n => n.GUID);
var groupedNodeGUIDs = group.Nodes.OfType<NodeModel>().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);
}

/// <summary>
Expand Down

0 comments on commit 7b8ee03

Please sign in to comment.