Skip to content

Commit

Permalink
Merge pull request #6 from timgblack/qol-improvements
Browse files Browse the repository at this point in the history
Quality of life improvements
  • Loading branch information
tloten authored Jul 31, 2020
2 parents 9267e43 + 11221ef commit d45d2a2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
xmlns:local="clr-namespace:BulkQuery"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
6 changes: 3 additions & 3 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
xmlns:properties="clr-namespace:BulkQuery.Properties"
mc:Ignorable="d"
Title="Bulk Query" Height="500" Width="800" Loaded="Window_Loaded" Closing="Window_Closing" KeyDown="Window_KeyDown">

<Window.Resources>
<ResourceDictionary>
<Style x:Key="TreeViewItemStyle" TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="{Binding IsExpanded}" />
<Setter Property="KeyboardNavigation.AcceptsReturn" Value="True" />
<EventSetter Event="PreviewMouseRightButtonDown" Handler="DatabasesTreeView_PreviewMouseButton" />
</Style>

<HierarchicalDataTemplate x:Key="CheckBoxItemTemplate" ItemsSource="{Binding Children, Mode=OneTime}">
<StackPanel Orientation="Horizontal">
<CheckBox Focusable="False" IsChecked="{Binding IsChecked}" VerticalAlignment="Center" />
Expand Down Expand Up @@ -56,7 +56,7 @@
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TreeView Grid.Column="0" x:Name="DatabasesTreeView"
<TreeView Grid.Column="0" x:Name="DatabasesTreeView"
ItemContainerStyle="{StaticResource TreeViewItemStyle}"
ItemTemplate="{StaticResource CheckBoxItemTemplate}" />
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" DragDelta="MainGrid_OnDragDelta" />
Expand Down
24 changes: 13 additions & 11 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class MainWindow : Window
const string githubUri = "https://github.com/tloten/bulk-query";

private readonly List<TreeViewModel<DatabaseTreeNode>> databaseTreeModel = new List<TreeViewModel<DatabaseTreeNode>>();
private readonly string[] systemDatabases = {"master", "model", "msdb", "tempdb"};
private readonly string[] systemDatabases = {"master", "model", "msdb", "tempdb", "rdsadmin"};
private readonly UserSettingsManager<BulkQueryUserSettings> settingsManager;

public MainWindow()
Expand Down Expand Up @@ -81,16 +81,11 @@ private void AddNodesForServer(ServerDefinition server)
ServerDefinition = server,
IsServerNode = true
};

try
{
var databases = QueryRunner.GetDatabasesForServer(server);

var serverNodeViewModel = new TreeViewModel<DatabaseTreeNode>(server.DisplayName, serverNode);
databaseTreeModel.Add(serverNodeViewModel);

serverNodeViewModel.IsExpanded = false;

var nodes = new List<TreeViewModel<DatabaseTreeNode>>();
foreach (var db in databases.OrderBy(db => db.DatabaseName))
{
if (Settings.HideSystemDatabases && systemDatabases.Contains(db.DatabaseName))
Expand All @@ -105,9 +100,16 @@ private void AddNodesForServer(ServerDefinition server)
};
var dbNodeViewModel = new TreeViewModel<DatabaseTreeNode>(db.DatabaseName, dbNode);
dbNodeViewModel.IsChecked = server.SelectedDatabases.Contains(db.DatabaseName);
serverNodeViewModel.Children.Add(dbNodeViewModel);
dbNodeViewModel.InitParent(serverNodeViewModel);
nodes.Add(dbNodeViewModel);
}

var serverNodeViewModel = new TreeViewModel<DatabaseTreeNode>($"{server.DisplayName} ({nodes.Count})", serverNode);
serverNodeViewModel.Children.AddRange(nodes);
serverNodeViewModel.IsExpanded = false;

nodes.ForEach(node => node.InitParent(serverNodeViewModel));

databaseTreeModel.Add(serverNodeViewModel);
}
catch(Exception)
{
Expand Down Expand Up @@ -181,7 +183,7 @@ private void DatabasesTreeView_PreviewMouseButton(object sender, MouseButtonEven
};
menu.Items.Add(menuItem);
}

(sender as TreeViewItem).ContextMenu = menu;
}

Expand All @@ -202,7 +204,7 @@ private IEnumerable<DatabaseDefinition> GetSelectedDatabases()
.SelectMany(serverNode => serverNode.Children.Where(dbNode => dbNode.IsChecked ?? true))
.Select(treeNode => treeNode.Value.DatabaseDefinition);
}

private void ButtonQuery_OnClick(object sender, RoutedEventArgs e)
{
_ = RunQuery();
Expand Down
4 changes: 2 additions & 2 deletions QueryRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class QueryResult

public static Task<QueryResult> BulkQuery(IList<DatabaseDefinition> databases, string query, int sqlTimeout)
{
// Needed to push all async code to thread pool thread (otherwise UI thread attempts to keep thread affinity
// Needed to push all async code to thread pool thread (otherwise UI thread attempts to keep thread affinity
// for each async continuation).
// http://stackoverflow.com/a/14485163/505457
return Task.Run(() => BulkQueryInternal(databases, query, sqlTimeout));
Expand Down Expand Up @@ -198,7 +198,7 @@ private static async Task<QueryResult> SingleQuery(DatabaseDefinition db, string
}
i++;
}

}
catch (Exception ex)
{
Expand Down
4 changes: 2 additions & 2 deletions TreeViewModel .cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void InitParent(TreeViewModel<T> parent)
parentNode = parent;
SyncParentState();
}

private void SetIsChecked(bool? value, bool updateChildren, bool updateParent)
{
if (value == isChecked)
Expand All @@ -43,7 +43,7 @@ private void SetIsChecked(bool? value, bool updateChildren, bool updateParent)

if (updateChildren && isChecked.HasValue)
Children.ForEach(c => c.SetIsChecked(isChecked, updateChildren:true, updateParent:false));

NotifyPropertyChanged("IsChecked");

if(updateParent && parentNode != null)
Expand Down

0 comments on commit d45d2a2

Please sign in to comment.