Skip to content

Commit 19ab0be

Browse files
committed
2016-03-23
- Changing naming convention: data source -> database - Enhancing PostgreSQL provider (object explorer, code completion) - Reading .NET framework version from registry - Updating assembly info to 2016 - StringTable.ToString(): newline is not necessary after the last line
1 parent cf5dfe7 commit 19ab0be

File tree

32 files changed

+285
-437
lines changed

32 files changed

+285
-437
lines changed

DataCommander.Foundation/Diagnostics/AppDomainMonitor.cs

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace DataCommander.Foundation.Diagnostics
1010
using DataCommander.Foundation.Data;
1111
using DataCommander.Foundation.Linq;
1212
using DataCommander.Foundation.Text;
13+
using Microsoft.Win32;
1314

1415
/// <summary>
1516
///
@@ -29,25 +30,58 @@ public static string DotNetFrameworkVersion
2930
{
3031
string dotNetFrameworkVersion;
3132

32-
switch (Environment.Version.ToString())
33+
using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"))
3334
{
34-
case "4.0.30319.18063":
35-
dotNetFrameworkVersion = "4.5";
36-
break;
35+
int release = (int)key.GetValue("Release");
3736

38-
case "4.0.30319.34209":
39-
dotNetFrameworkVersion = "4.5.2";
40-
break;
37+
switch (release)
38+
{
39+
case 378389:
40+
dotNetFrameworkVersion = "4.5";
41+
break;
42+
43+
case 378675:
44+
case 378758:
45+
dotNetFrameworkVersion = "4.5.1";
46+
break;
47+
48+
case 379893:
49+
dotNetFrameworkVersion = "4.5.2";
50+
break;
4151

42-
case "4.0.30319.42000":
43-
dotNetFrameworkVersion = "4.6";
44-
break;
52+
case 394254:
53+
dotNetFrameworkVersion = "4.6.1 (Windows 10 November Update)";
54+
break;
4555

46-
default:
47-
dotNetFrameworkVersion = null;
48-
break;
56+
case 394271:
57+
dotNetFrameworkVersion = "4.6.1";
58+
break;
59+
60+
default:
61+
dotNetFrameworkVersion = null;
62+
break;
63+
}
4964
}
5065

66+
//switch (Environment.Version.ToString())
67+
//{
68+
// case "4.0.30319.18063":
69+
// dotNetFrameworkVersion = "4.5";
70+
// break;
71+
72+
// case "4.0.30319.34209":
73+
// dotNetFrameworkVersion = "4.5.2";
74+
// break;
75+
76+
// case "4.0.30319.42000":
77+
// dotNetFrameworkVersion = "4.6";
78+
// break;
79+
80+
// default:
81+
// dotNetFrameworkVersion = null;
82+
// break;
83+
//}
84+
5185
return dotNetFrameworkVersion;
5286
}
5387
}

DataCommander.Foundation/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[assembly: AssemblyTitle("DataCommander.Foundation")]
66
[assembly: AssemblyVersion("1.0.0.0")]
7-
[assembly: AssemblyCopyright("Copyright © 2002-2015 Csaba Bernáth")]
7+
[assembly: AssemblyCopyright("Copyright © 2002-2016 Csaba Bernáth")]
88
[assembly: AssemblyCompany("Csaba Bernáth")]
99
[assembly: CLSCompliant(true)]
1010
[assembly: ComVisible(false)]

DataCommander.Foundation/Text/StringTable.cs

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace DataCommander.Foundation.Text
22
{
3+
using System;
34
using System.Diagnostics.Contracts;
45
using System.IO;
56
using System.Text;
@@ -16,13 +17,13 @@ public class StringTable
1617
///
1718
/// </summary>
1819
/// <param name="columnCount"></param>
19-
public StringTable( int columnCount )
20+
public StringTable(int columnCount)
2021
{
21-
Contract.Requires( columnCount >= 0 );
22+
Contract.Requires<ArgumentOutOfRangeException>(columnCount >= 0);
2223

2324
for (int i = 0; i < columnCount; i++)
2425
{
25-
this.columns.Add( new StringTableColumn() );
26+
this.columns.Add(new StringTableColumn());
2627
}
2728
}
2829

@@ -42,17 +43,17 @@ public StringTable( int columnCount )
4243
/// <returns></returns>
4344
public StringTableRow NewRow()
4445
{
45-
return new StringTableRow( this );
46+
return new StringTableRow(this);
4647
}
4748

48-
internal int GetMaxColumnWidth( int columnIndex )
49+
internal int GetMaxColumnWidth(int columnIndex)
4950
{
5051
int rowCount = this.rows.Count;
5152
int max = 0;
5253

5354
for (int i = 0; i < rowCount; i++)
5455
{
55-
string s = this.rows[ i ][ columnIndex ];
56+
string s = this.rows[i][columnIndex];
5657
int width = s == null ? 0 : s.Length;
5758

5859
if (width > max)
@@ -70,45 +71,49 @@ internal int GetMaxColumnWidth( int columnIndex )
7071
/// <returns></returns>
7172
public override string ToString()
7273
{
73-
var sb = new StringBuilder();
74+
var stringBuilder = new StringBuilder();
7475
int count = this.columns.Count;
7576

7677
for (int i = 0; i < count; i++)
7778
{
78-
int maxColumnWidth = this.GetMaxColumnWidth( i );
79-
this.columns[ i ].Width = maxColumnWidth;
79+
int maxColumnWidth = this.GetMaxColumnWidth(i);
80+
this.columns[i].Width = maxColumnWidth;
8081
}
8182

8283
int last = count - 1;
8384

8485
for (int i = 0; i < this.rows.Count; i++)
8586
{
86-
this.WriteRow( i, sb );
87-
sb.AppendLine();
87+
if (i > 0)
88+
{
89+
stringBuilder.AppendLine();
90+
}
91+
92+
this.WriteRow(i, stringBuilder);
8893
}
8994

90-
return sb.ToString();
95+
return stringBuilder.ToString();
9196
}
9297

9398
/// <summary>
9499
///
95100
/// </summary>
96101
/// <param name="textWriter"></param>
97-
public void Write( TextWriter textWriter )
102+
public void Write(TextWriter textWriter)
98103
{
99-
Contract.Requires( textWriter != null );
104+
Contract.Requires<ArgumentNullException>(textWriter != null);
100105

101106
for (int i = 0; i < this.columns.Count; i++)
102107
{
103-
int maxColumnWidth = this.GetMaxColumnWidth( i );
104-
this.columns[ i ].Width = maxColumnWidth;
108+
int maxColumnWidth = this.GetMaxColumnWidth(i);
109+
this.columns[i].Width = maxColumnWidth;
105110
}
106111

107112
for (int i = 0; i < this.rows.Count; i++)
108113
{
109114
var sb = new StringBuilder();
110-
this.WriteRow( i, sb );
111-
textWriter.WriteLine( sb );
115+
this.WriteRow(i, sb);
116+
textWriter.WriteLine(sb);
112117
}
113118
}
114119

@@ -117,62 +122,67 @@ public void Write( TextWriter textWriter )
117122
/// </summary>
118123
/// <param name="textWriter"></param>
119124
/// <param name="indent"></param>
120-
public void Write( TextWriter textWriter, int indent )
125+
public void Write(TextWriter textWriter, int indent)
121126
{
122-
Contract.Requires( textWriter != null );
127+
Contract.Requires<ArgumentNullException>(textWriter != null);
123128

124129
int last = this.columns.Count - 1;
125130

126131
for (int i = 0; i <= last; i++)
127132
{
128-
int width = this.GetMaxColumnWidth( i );
133+
int width = this.GetMaxColumnWidth(i);
129134

130135
if (i < last)
131136
{
132-
int remainder = (width + 1) % indent;
137+
int remainder = (width + 1)%indent;
133138

134139
if (remainder != 0)
135140
{
136141
width += indent - remainder;
137142
}
138143
}
139144

140-
this.columns[ i ].Width = width;
145+
this.columns[i].Width = width;
141146
}
142147

143148
for (int i = 0; i < this.rows.Count; i++)
144149
{
145150
var sb = new StringBuilder();
146-
this.WriteRow( i, sb );
147-
textWriter.WriteLine( sb );
151+
152+
if (i > 0)
153+
{
154+
textWriter.WriteLine(sb);
155+
}
156+
157+
this.WriteRow(i, sb);
148158
}
149159
}
150160

151-
private void WriteRow( int rowIndex, StringBuilder sb )
161+
private void WriteRow(int rowIndex, StringBuilder stringBuilder)
152162
{
153-
StringTableRow row = this.rows[ rowIndex ];
163+
var row = this.rows[rowIndex];
154164
int last = this.columns.Count - 1;
155165

156166
for (int j = 0; j <= last; j++)
157167
{
158-
StringTableColumn column = this.columns[ j ];
168+
var column = this.columns[j];
159169
bool alignRight = column.Align == StringTableColumnAlign.Right;
160170
if (j < last)
161171
{
162-
string s = StringHelper.FormatColumn( row[ j ], column.Width, alignRight );
163-
sb.Append( s );
164-
sb.Append( ' ' );
172+
string s = StringHelper.FormatColumn(row[j], column.Width, alignRight);
173+
stringBuilder.Append(s);
174+
stringBuilder.Append(' ');
165175
}
166176
else
167177
{
168178
if (alignRight)
169179
{
170-
string s = StringHelper.FormatColumn( row[ j ], column.Width, alignRight );
171-
sb.Append( s );
180+
string s = StringHelper.FormatColumn(row[j], column.Width, alignRight);
181+
stringBuilder.Append(s);
172182
}
173183
else
174184
{
175-
sb.Append( row[ j ] );
185+
stringBuilder.Append(row[j]);
176186
}
177187
}
178188
}

DataCommander.Providers.Msi/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[assembly: AssemblyTitle("DataCommander.Providers.Msi")]
66
[assembly: AssemblyVersion("1.0.0.0")]
7-
[assembly: AssemblyCopyright("Copyright © 2002-2015 Csaba Bernáth")]
7+
[assembly: AssemblyCopyright("Copyright © 2002-2016 Csaba Bernáth")]
88
[assembly: AssemblyCompany("Csaba Bernáth")]
99
[assembly: CLSCompliant(true)]
1010
[assembly: ComVisible(false)]

DataCommander.Providers.MySql/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[assembly: AssemblyTitle("DataCommander.Providers.MySql")]
66
[assembly: AssemblyVersion("1.0.0.0")]
7-
[assembly: AssemblyCopyright("Copyright © 2002-2015 Csaba Bernáth")]
7+
[assembly: AssemblyCopyright("Copyright © 2002-2016 Csaba Bernáth")]
88
[assembly: AssemblyCompany("Csaba Bernáth")]
99
[assembly: CLSCompliant(true)]
1010
[assembly: ComVisible(false)]

DataCommander.Providers.OleDb/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[assembly: AssemblyTitle("DataCommander.Providers.OleDb")]
66
[assembly: AssemblyVersion("1.0.0.0")]
7-
[assembly: AssemblyCopyright("Copyright © 2002-2015 Csaba Bernáth")]
7+
[assembly: AssemblyCopyright("Copyright © 2002-2016 Csaba Bernáth")]
88
[assembly: AssemblyCompany("Csaba Bernáth")]
99
[assembly: CLSCompliant(true)]
1010
[assembly: ComVisible(false)]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
<Compile Include="DatabaseObjectMultipartName.cs" />
9696
<Compile Include="IdentifierParser.cs" />
9797
<Compile Include="NonSqlObjectName.cs" />
98+
<Compile Include="ObjectExplorer\ColumnCollectionNode.cs" />
99+
<Compile Include="ObjectExplorer\ColumnNode.cs" />
98100
<Compile Include="ObjectExplorer\ObjectExplorer.cs" />
99101
<Compile Include="ObjectExplorer\SchemaCollectionNode.cs" />
100102
<Compile Include="ObjectExplorer\SchemaNode.cs" />
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
namespace DataCommander.Providers.PostgreSql.ObjectExplorer
2+
{
3+
using System.Collections.Generic;
4+
using System.Data;
5+
using System.Windows.Forms;
6+
using Foundation.Data;
7+
using Npgsql;
8+
9+
internal sealed class ColumnCollectionNode : ITreeNode
10+
{
11+
private readonly TableNode tableNode;
12+
13+
public ColumnCollectionNode(TableNode tableNode)
14+
{
15+
this.tableNode = tableNode;
16+
}
17+
18+
string ITreeNode.Name => "Columns";
19+
20+
bool ITreeNode.IsLeaf => false;
21+
22+
IEnumerable<ITreeNode> ITreeNode.GetChildren(bool refresh)
23+
{
24+
var nodes = new List<ITreeNode>();
25+
var schemaNode = this.tableNode.TableCollectionNode.SchemaNode;
26+
27+
using (var connection = new NpgsqlConnection(schemaNode.SchemaCollectionNode.ObjectExplorer.ConnectionString))
28+
{
29+
connection.Open();
30+
var transactionScope = new DbTransactionScope(connection, null);
31+
transactionScope.ExecuteReader(new CommandDefinition
32+
{
33+
CommandText =
34+
$@"select
35+
c.column_name
36+
,c.is_nullable
37+
,c.data_type
38+
,c.character_maximum_length
39+
,c.numeric_precision
40+
,c.numeric_scale
41+
from information_schema.columns c
42+
where
43+
c.table_schema = '{this
44+
.tableNode.TableCollectionNode.SchemaNode.Name}'
45+
and c.table_name = '{this.tableNode.Name}'
46+
order by c.ordinal_position"
47+
}, CommandBehavior.Default, dataRecord =>
48+
{
49+
string columnName = dataRecord.GetString(0);
50+
string dataType = dataRecord.GetString(2);
51+
var columnNode = new ColumnNode(this, columnName, dataType);
52+
nodes.Add(columnNode);
53+
});
54+
}
55+
56+
return nodes;
57+
}
58+
59+
bool ITreeNode.Sortable => false;
60+
61+
string ITreeNode.Query => null;
62+
63+
ContextMenuStrip ITreeNode.ContextMenu => null;
64+
}
65+
}

0 commit comments

Comments
 (0)