Skip to content

Commit

Permalink
export csv with SaveFileDialog (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaylo-matov authored Jul 16, 2024
1 parent 5ec3826 commit ee93525
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
12 changes: 11 additions & 1 deletion TuneUp/TuneUpWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,17 @@
IsEnabled="{Binding Path=IsRecomputeEnabled}"
Click="RecomputeGraph_Click"
Padding="5,2,5,2">
Force Re-execute
Run All
</Button>
<Button
Name="ExportTimes"
Width="Auto"
Height="Auto"
Margin="2,1,1,10"
Padding="5,2,5,2"
IsEnabled="{Binding Path=IsRecomputeEnabled}"
Click="ExportTimes_Click">
Export
</Button>
<Label Foreground="White">Total Graph Execution Time: </Label>
<Label Foreground="White"
Expand Down
5 changes: 5 additions & 0 deletions TuneUp/TuneUpWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,10 @@ private void RecomputeGraph_Click(object sender, RoutedEventArgs e)
{
(NodeAnalysisTable.DataContext as TuneUpWindowViewModel).ResetProfiling();
}

private void ExportTimes_Click(object sender, RoutedEventArgs e)
{
(NodeAnalysisTable.DataContext as TuneUpWindowViewModel).ExportToCsv();
}
}
}
29 changes: 29 additions & 0 deletions TuneUp/TuneUpWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Data;
Expand All @@ -12,6 +13,7 @@
using Dynamo.Graph.Workspaces;
using Dynamo.ViewModels;
using Dynamo.Wpf.Extensions;
using Microsoft.Win32;

namespace TuneUp
{
Expand Down Expand Up @@ -448,5 +450,32 @@ public void Dispose()
}

#endregion

#region Export Node times

/// <summary>
/// Exports the ProfiledNodesCollection to a CSV file.
/// </summary>
public void ExportToCsv()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
//saveFileDialog.RestoreDirectory = false;
saveFileDialog.Filter = "CSV file (*.csv)|*.csv|All files (*.*)|*.*";

if (saveFileDialog.ShowDialog() == true)
{
using (var writer = new StreamWriter(saveFileDialog.FileName))
{
writer.WriteLine("Execution Order,Name,Execution Time (ms)");

foreach (ProfiledNodeViewModel node in ProfiledNodesCollection.View.Cast<ProfiledNodeViewModel>())
{
writer.WriteLine($"{node.ExecutionOrderNumber},{node.Name},{node.ExecutionMilliseconds}");
}
}
}
}

#endregion
}
}

0 comments on commit ee93525

Please sign in to comment.