Skip to content

Commit 07f17c8

Browse files
committed
2016-01-29
- Updating nuget packages - PreOrderTreeTraversal - Fixing navigation to results after 'schema only' execution - LogResultWriter: adding logging of schema table - Fixing navigation to results after singe row execution - Mouse middle button closes resultset tab page
1 parent 093b955 commit 07f17c8

File tree

9 files changed

+126
-22
lines changed

9 files changed

+126
-22
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
namespace DataCommander.Foundation.Collections
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Diagnostics.Contracts;
6+
7+
/// <summary>
8+
///
9+
/// </summary>
10+
public static class PreOrderTreeTraversal
11+
{
12+
/// <summary>
13+
///
14+
/// </summary>
15+
/// <typeparam name="T"></typeparam>
16+
/// <param name="rootNode"></param>
17+
/// <param name="getChildNodes"></param>
18+
/// <param name="action"></param>
19+
public static void ForEach<T>(T rootNode, Func<T, IEnumerable<T>> getChildNodes, Action<T> action)
20+
{
21+
Contract.Requires<ArgumentNullException>(rootNode != null);
22+
Contract.Requires<ArgumentNullException>(getChildNodes != null);
23+
Contract.Requires<ArgumentNullException>(action != null);
24+
25+
action(rootNode);
26+
27+
foreach (var childNode in getChildNodes(rootNode))
28+
{
29+
ForEach(childNode, getChildNodes, action);
30+
}
31+
}
32+
33+
/// <summary>
34+
///
35+
/// </summary>
36+
/// <typeparam name="T"></typeparam>
37+
/// <param name="rootNode"></param>
38+
/// <param name="getChildNodes"></param>
39+
/// <param name="predicate"></param>
40+
/// <returns></returns>
41+
public static T FirstOrDefault<T>(T rootNode, Func<T, IEnumerable<T>> getChildNodes, Func<T, bool> predicate) where T : class
42+
{
43+
Contract.Requires<ArgumentNullException>(rootNode != null);
44+
Contract.Requires<ArgumentNullException>(getChildNodes != null);
45+
Contract.Requires<ArgumentNullException>(predicate != null);
46+
47+
T firstOrDefault = null;
48+
49+
if (predicate(rootNode))
50+
{
51+
firstOrDefault = rootNode;
52+
}
53+
else
54+
{
55+
foreach (var childNode in getChildNodes(rootNode))
56+
{
57+
firstOrDefault = FirstOrDefault<T>(childNode, getChildNodes, predicate);
58+
if (firstOrDefault != null)
59+
{
60+
break;
61+
}
62+
}
63+
}
64+
65+
return firstOrDefault;
66+
}
67+
}
68+
}

DataCommander.Foundation/DataCommander.Foundation.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@
321321
<Compile Include="Collections\ConcurrentQueue.cs" />
322322
<Compile Include="Collections\EmptyArray.cs" />
323323
<Compile Include="Collections\LargeObjectHeap.cs" />
324+
<Compile Include="Collections\PreOrderTreeTraversal.cs" />
324325
<Compile Include="Collections\SegmentedArrayBuilder.cs" />
325326
<Compile Include="Collections\DisposableCollection.cs" />
326327
<Compile Include="Collections\DynamicArray.cs" />

DataCommander.Foundation/Linq/IEnumerableExtensions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,23 @@ public static IEnumerable<PreviousAndCurrent<TKey>> SelectPreviousAndCurrentKey<
196196
return source.Select(keySelector).SelectPreviousAndCurrent();
197197
}
198198

199+
/// <summary>
200+
///
201+
/// </summary>
202+
/// <typeparam name="TSource"></typeparam>
203+
/// <param name="source"></param>
204+
/// <param name="action"></param>
205+
public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSource> action)
206+
{
207+
Contract.Requires<ArgumentNullException>(source != null);
208+
Contract.Requires<ArgumentNullException>(action != null);
209+
210+
foreach (var item in source)
211+
{
212+
action(item);
213+
}
214+
}
215+
199216
/// <summary>
200217
///
201218
/// </summary>

DataCommander.Providers.PostgreSql/DataCommander.Providers.PostgreSql.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
<WarningLevel>4</WarningLevel>
7777
</PropertyGroup>
7878
<ItemGroup>
79-
<Reference Include="Npgsql, Version=3.0.4.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
80-
<HintPath>..\packages\Npgsql.3.0.4\lib\net45\Npgsql.dll</HintPath>
79+
<Reference Include="Npgsql, Version=3.0.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
80+
<HintPath>..\packages\Npgsql.3.0.5\lib\net45\Npgsql.dll</HintPath>
8181
<Private>True</Private>
8282
</Reference>
8383
<Reference Include="System" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Npgsql" version="3.0.4" targetFramework="net46" />
3+
<package id="Npgsql" version="3.0.5" targetFramework="net46" />
44
</packages>

DataCommander.Providers/DataCommander.Providers.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@
194194
<SpecificVersion>False</SpecificVersion>
195195
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
196196
</Reference>
197-
<Reference Include="EPPlus, Version=4.0.4.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
198-
<HintPath>..\packages\EPPlus.4.0.4\lib\net20\EPPlus.dll</HintPath>
197+
<Reference Include="EPPlus, Version=4.0.5.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
198+
<HintPath>..\packages\EPPlus.4.0.5\lib\net20\EPPlus.dll</HintPath>
199199
<Private>True</Private>
200200
</Reference>
201201
<Reference Include="Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">

DataCommander.Providers/Query/QueryForm.cs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -324,21 +324,31 @@ private void CloseResultSetTabPage_Click(object sender, EventArgs e)
324324

325325
private void resultSetsTabControl_MouseUp(object sender, MouseEventArgs e)
326326
{
327-
if (e.Button == MouseButtons.Right)
327+
var hitTestInfo = new TCHITTESTINFO(e.X, e.Y);
328+
int index = SendMessage(this.resultSetsTabControl.Handle, TCM_HITTEST, IntPtr.Zero, ref hitTestInfo);
329+
var hotTab = index >= 0 ? this.resultSetsTabControl.TabPages[index] : null;
330+
331+
switch (e.Button)
328332
{
329-
var hitTestInfo = new TCHITTESTINFO(e.X, e.Y);
330-
int index = SendMessage(this.resultSetsTabControl.Handle, TCM_HITTEST, IntPtr.Zero, ref hitTestInfo);
331-
if (index >= 0)
332-
{
333-
TabPage hotTab = this.resultSetsTabControl.TabPages[index];
334-
var contextMenu = new ContextMenuStrip(this.components);
335-
contextMenu.Items.Add(new ToolStripMenuItem("Close", null, this.CloseResultSetTabPage_Click)
333+
case MouseButtons.Middle:
334+
if (index >= 0)
336335
{
337-
Tag = hotTab
338-
});
339-
contextMenu.Items.Add(new ToolStripMenuItem("Close all", null, this.mnuCloseAllTabPages_Click, Keys.Control | Keys.Shift | Keys.F4));
340-
contextMenu.Show(this.resultSetsTabControl, e.Location);
341-
}
336+
this.CloseResultSetTabPage(hotTab);
337+
}
338+
break;
339+
340+
case MouseButtons.Right:
341+
if (index >= 0)
342+
{
343+
var contextMenu = new ContextMenuStrip(this.components);
344+
contextMenu.Items.Add(new ToolStripMenuItem("Close", null, this.CloseResultSetTabPage_Click)
345+
{
346+
Tag = hotTab
347+
});
348+
contextMenu.Items.Add(new ToolStripMenuItem("Close all", null, this.mnuCloseAllTabPages_Click, Keys.Control | Keys.Shift | Keys.F4));
349+
contextMenu.Show(this.resultSetsTabControl, e.Location);
350+
}
351+
break;
342352
}
343353
}
344354

@@ -3311,7 +3321,8 @@ private async void ExecuteReader(CommandBehavior commandBehavior)
33113321
{
33123322
this.AddInfoMessage(new InfoMessage(LocalTime.Default.Now, InfoMessageSeverity.Information, "Opening connection..."));
33133323
await this.connection.OpenAsync(CancellationToken.None);
3314-
this.AddInfoMessage(new InfoMessage(LocalTime.Default.Now, InfoMessageSeverity.Information, "Connection opened successfully."));
3324+
this.AddInfoMessage(new InfoMessage(LocalTime.Default.Now, InfoMessageSeverity.Information,
3325+
"Connection opened successfully."));
33153326
}
33163327
else
33173328
{
@@ -3341,6 +3352,7 @@ private async void ExecuteReader(CommandBehavior commandBehavior)
33413352
} while (dataReader.NextResult());
33423353

33433354
this.ShowDataSet(dataSet);
3355+
this.tabControl.SelectedTab = this.resultSetsTabPage;
33443356
}
33453357
finally
33463358
{
@@ -3381,8 +3393,8 @@ private void ExecuteQuerySingleRow()
33813393
{
33823394
do
33833395
{
3384-
DataTable schemaTable = this.provider.GetSchemaTable(dataReader);
3385-
IDataReaderHelper dataReaderHelper = this.provider.CreateDataReaderHelper(dataReader);
3396+
var schemaTable = this.provider.GetSchemaTable(dataReader);
3397+
var dataReaderHelper = this.provider.CreateDataReaderHelper(dataReader);
33863398
int rowCount = 0;
33873399

33883400
while (dataReader.Read())
@@ -3418,10 +3430,12 @@ private void ExecuteQuerySingleRow()
34183430
}
34193431
}
34203432
} while (dataReader.NextResult());
3433+
34213434
dataReader.Close();
34223435
}
34233436

34243437
this.ShowDataSet(dataSet);
3438+
this.tabControl.SelectedTab = this.resultSetsTabPage;
34253439
}
34263440
catch (Exception ex)
34273441
{

DataCommander.Providers/ResultWriter/LogResultWriter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ void IResultWriter.AfterCloseReader(int affectedRows)
7575
void IResultWriter.WriteTableBegin(DataTable schemaTable)
7676
{
7777
this.writeTableBeginTimestamp = Stopwatch.GetTimestamp();
78+
79+
DateTime now = LocalTime.Default.Now;
80+
this.addInfoMessage(new InfoMessage(now, InfoMessageSeverity.Verbose, $"SchemaTable of table[{this.tableCount}]:\r\n{schemaTable.ToStringTable()}"));
81+
7882
this.tableCount++;
7983
this.rowCount = 0;
8084
}

DataCommander.Providers/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
4-
<package id="EPPlus" version="4.0.4" targetFramework="net45" />
4+
<package id="EPPlus" version="4.0.5" targetFramework="net46" />
55
<package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net4" />
66
<package id="System.Data.SQLite" version="1.0.99.0" targetFramework="net46" />
77
<package id="System.Data.SQLite.Core" version="1.0.99.0" targetFramework="net46" />

0 commit comments

Comments
 (0)