Skip to content

Commit ec12d48

Browse files
committed
2016-05-31
- Fixing SegmentedCollection GetEnumerator bug - Extremum class - Fixing TfsDataReader schema table - Cleaning code - Enhancing FoundationContract - Fixing DbColumn
1 parent c8e6737 commit ec12d48

File tree

15 files changed

+187
-145
lines changed

15 files changed

+187
-145
lines changed

DataCommander.Foundation/Collections/SegmentedCollection.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ IEnumerator<T> IEnumerable<T>.GetEnumerator()
110110

111111
while (segment != null)
112112
{
113-
int count = segment != this.last
114-
? this.segmentLength
115-
: this.Count%this.segmentLength;
113+
int count;
114+
if (segment != this.last)
115+
count = this.segmentLength;
116+
else
117+
count = this.Count <= this.segmentLength ? this.Count : this.Count%segmentLength;
116118

117119
for (int i = 0; i < count; i++)
118120
{

DataCommander.Foundation/Configuration/ConfigurationReader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,22 @@ private object ReadAttributeValueArray(Type elementType)
145145
}
146146
}
147147

148-
Array array = Array.CreateInstance(elementType, list.Count);
149-
object[] values = (object[])array;
148+
var array = Array.CreateInstance(elementType, list.Count);
149+
var values = (object[])array;
150150
list.CopyTo(values);
151151

152152
return array;
153153
}
154154

155155
private object ReadAttributeValue(Type type)
156156
{
157-
TypeCode typeCode = Type.GetTypeCode(type);
157+
var typeCode = Type.GetTypeCode(type);
158158
object value = null;
159159
this.xmlReader.MoveToContent();
160160

161161
if (type.IsArray)
162162
{
163-
Type elementType = type.GetElementType();
163+
var elementType = type.GetElementType();
164164
typeCode = Type.GetTypeCode(elementType);
165165

166166
if (typeCode == TypeCode.Byte)

DataCommander.Foundation/Data/DbColumn.cs

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,59 @@ public DbColumn(DataRow schemaTableRow)
1818
{
1919
Contract.Requires<ArgumentNullException>(schemaTableRow != null);
2020

21-
this.AllowDBNull = schemaTableRow.Field<bool?>(SchemaTableColumn.AllowDBNull);
22-
this.BaseColumnName = schemaTableRow.Field<string>(SchemaTableColumn.BaseColumnName);
23-
this.BaseSchemaName = schemaTableRow.Field<string>(SchemaTableColumn.BaseSchemaName);
24-
this.BaseTableName = schemaTableRow.Field<string>(SchemaTableColumn.BaseTableName);
2521
this.ColumnName = schemaTableRow.Field<string>(SchemaTableColumn.ColumnName);
2622
this.ColumnOrdinal = (int)schemaTableRow[SchemaTableColumn.ColumnOrdinal];
2723
this.ColumnSize = (int)schemaTableRow[SchemaTableColumn.ColumnSize];
28-
this.DataType = (Type)schemaTableRow[SchemaTableColumn.DataType];
29-
this.IsAliased = schemaTableRow.Field<bool?>(SchemaTableColumn.IsAliased);
30-
this.IsExpression = schemaTableRow.Field<bool?>(SchemaTableColumn.IsExpression);
31-
this.IsKey = schemaTableRow.Field<bool?>(SchemaTableColumn.IsKey);
3224

3325
var columns = schemaTableRow.Table.Columns;
34-
int columnIndex = columns.IndexOf("IsIdentity");
35-
if (columnIndex >= 0)
26+
var column = columns[SchemaTableColumn.NumericPrecision];
27+
if (column != null)
3628
{
37-
this.IsIdentity = schemaTableRow.Field<bool?>(columnIndex);
29+
this.NumericPrecision = schemaTableRow.IsNull(column)
30+
? (short?)null
31+
: Convert.ToInt16(schemaTableRow[column]);
32+
}
33+
34+
column = columns[SchemaTableColumn.NumericScale];
35+
if (column != null)
36+
{
37+
this.NumericScale = schemaTableRow.IsNull(column)
38+
? (short?)null
39+
: Convert.ToInt16(schemaTableRow[column]);
3840
}
3941

40-
this.IsLong = schemaTableRow.Field<bool?>(SchemaTableColumn.IsLong);
4142
this.IsUnique = schemaTableRow.Field<bool?>(SchemaTableColumn.IsUnique);
43+
this.IsKey = schemaTableRow.Field<bool?>(SchemaTableColumn.IsKey);
44+
//BaseServerName
45+
//BaseCatalogName
46+
this.BaseColumnName = schemaTableRow.Field<string>(SchemaTableColumn.BaseColumnName);
47+
this.BaseSchemaName = schemaTableRow.Field<string>(SchemaTableColumn.BaseSchemaName);
48+
this.BaseTableName = schemaTableRow.Field<string>(SchemaTableColumn.BaseTableName);
49+
this.DataType = (Type)schemaTableRow[SchemaTableColumn.DataType];
50+
this.AllowDBNull = schemaTableRow.Field<bool?>(SchemaTableColumn.AllowDBNull);
51+
this.ProviderType = schemaTableRow.Field<int>(SchemaTableColumn.ProviderType);
52+
this.IsAliased = schemaTableRow.Field<bool?>(SchemaTableColumn.IsAliased);
53+
this.IsExpression = schemaTableRow.Field<bool?>(SchemaTableColumn.IsExpression);
4254

43-
columnIndex = columns.IndexOf(SchemaTableColumn.NonVersionedProviderType);
44-
if (columnIndex >= 0)
55+
column = columns["IsIdentity"];
56+
if (column != null)
4557
{
46-
this.NonVersionedProviderType = (int)schemaTableRow[columnIndex];
58+
this.IsIdentity = schemaTableRow.Field<bool?>(column);
4759
}
4860

49-
columnIndex = columns.IndexOf(SchemaTableColumn.NumericPrecision);
50-
if (columnIndex >= 0)
61+
//IsAutoIncrement
62+
//IsRowVersion
63+
//IsHidden
64+
this.IsLong = schemaTableRow.Field<bool?>(SchemaTableColumn.IsLong);
65+
//IsReadOnly
66+
//ProviderSpecificDataType
67+
//DataTypeName XmlSchemaCollectionDatabase XmlSchemaCollectionOwningSchema XmlSchemaCollectionName UdtAssemblyQualifiedName
68+
column = columns[SchemaTableColumn.NonVersionedProviderType];
69+
if (column != null)
5170
{
52-
this.NumericPrecision = schemaTableRow.Field<short?>(columnIndex);
71+
this.NonVersionedProviderType = (int)schemaTableRow[column];
5372
}
54-
55-
this.NumericScale = schemaTableRow.Field<short?>(SchemaTableColumn.NumericScale);
56-
this.ProviderType = schemaTableRow.Field<int>(SchemaTableColumn.ProviderType);
73+
//IsColumnSet
5774
}
5875

5976
/// <summary>

DataCommander.Foundation/Diagnostics/Contracts/FoundationContract.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public static class FoundationContract
1111
private enum ExceptionType
1212
{
1313
None,
14+
ArgumentException,
1415
ArgumentNullException,
1516
ArgumentOutOfRangeException
1617
}
@@ -19,6 +20,7 @@ private enum ExceptionType
1920

2021
static FoundationContract()
2122
{
23+
typeDictionary.Add<ArgumentException>(ExceptionType.ArgumentException);
2224
typeDictionary.Add<ArgumentNullException>(ExceptionType.ArgumentNullException);
2325
typeDictionary.Add<ArgumentOutOfRangeException>(ExceptionType.ArgumentOutOfRangeException);
2426
}
@@ -69,6 +71,9 @@ public static void Requires<TException>(bool condition, string userMessage) wher
6971
var exceptionType = typeDictionary.GetValueOrDefault<TException>();
7072
switch (exceptionType)
7173
{
74+
case ExceptionType.ArgumentException:
75+
throw new ArgumentException(userMessage);
76+
7277
case ExceptionType.ArgumentNullException:
7378
throw new ArgumentNullException(userMessage, (Exception)null);
7479

DataCommander.Foundation/Linq/IEnumerableExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace DataCommander.Foundation.Linq
22
{
33
using System;
44
using System.Collections.Generic;
5+
using System.Diagnostics;
56
using System.Diagnostics.Contracts;
67
using System.Linq;
78
using System.Text;
@@ -347,7 +348,6 @@ public static string ToString<TSource>(this IEnumerable<TSource> source, IReadOn
347348
#region Fill second row
348349

349350
var columnWidths = new int[columns.Count];
350-
351351
columnIndex = 0;
352352
foreach (var column in columns)
353353
{

DataCommander.Foundation/Linq/IEnumerableIndexedItemExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Collections.Generic;
5+
using System.Diagnostics;
56
using System.Diagnostics.Contracts;
67

78
/// <summary>

DataCommander.Providers.Tfs-14.0.0.0/TfsDataReader.cs

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ public void Close()
1414

1515
public int Depth
1616
{
17-
get { throw new NotImplementedException(); }
17+
get
18+
{
19+
throw new NotImplementedException();
20+
}
1821
}
1922

2023
public abstract DataTable GetSchemaTable();
2124

2225
public bool IsClosed
2326
{
24-
get { throw new NotImplementedException(); }
27+
get
28+
{
29+
throw new NotImplementedException();
30+
}
2531
}
2632

2733
public bool NextResult()
@@ -31,10 +37,7 @@ public bool NextResult()
3137

3238
public abstract bool Read();
3339

34-
public abstract int RecordsAffected
35-
{
36-
get;
37-
}
40+
public abstract int RecordsAffected { get; }
3841

3942
#endregion
4043

@@ -48,10 +51,7 @@ public virtual void Dispose()
4851

4952
#region IDataRecord Members
5053

51-
public abstract int FieldCount
52-
{
53-
get;
54-
}
54+
public abstract int FieldCount { get; }
5555

5656
public bool GetBoolean(int i)
5757
{
@@ -166,12 +166,18 @@ public bool IsDBNull(int i)
166166

167167
public object this[string name]
168168
{
169-
get { throw new NotImplementedException(); }
169+
get
170+
{
171+
throw new NotImplementedException();
172+
}
170173
}
171174

172175
public object this[int i]
173176
{
174-
get { throw new NotImplementedException(); }
177+
get
178+
{
179+
throw new NotImplementedException();
180+
}
175181
}
176182

177183
#endregion
@@ -183,71 +189,80 @@ internal static DataTable CreateSchemaTable()
183189
DataTable table = new DataTable();
184190
DataColumnCollection columns = table.Columns;
185191
columns.Add(SchemaTableColumn.ColumnName, typeof(string));
186-
columns.Add("ColumnSize", typeof(int));
187-
columns.Add("DataType", typeof(Type));
188-
columns.Add("ProviderType", typeof(int));
189-
columns.Add("AllowDBNull", typeof(bool));
192+
columns.Add(SchemaTableColumn.ColumnOrdinal, typeof(int));
193+
columns.Add(SchemaTableColumn.ColumnSize, typeof(int));
194+
columns.Add(SchemaTableColumn.NumericPrecision, typeof(short));
195+
columns.Add(SchemaTableColumn.NumericScale, typeof(short));
196+
columns.Add(SchemaTableColumn.IsUnique, typeof(bool));
197+
columns.Add(SchemaTableColumn.IsKey, typeof(bool));
198+
//BaseServerName
199+
//BaseCatalogName
200+
columns.Add(SchemaTableColumn.BaseColumnName, typeof(string));
201+
columns.Add(SchemaTableColumn.BaseSchemaName, typeof(string));
202+
columns.Add(SchemaTableColumn.BaseTableName, typeof(string));
203+
columns.Add(SchemaTableColumn.DataType, typeof(Type));
204+
columns.Add(SchemaTableColumn.AllowDBNull, typeof(bool));
205+
columns.Add(SchemaTableColumn.ProviderType, typeof(int));
206+
columns.Add(SchemaTableColumn.IsAliased, typeof(bool));
207+
columns.Add(SchemaTableColumn.IsExpression, typeof(bool));
208+
//IsIdentity
209+
//IsAutoIncrement
210+
//IsRowVersion
211+
//IsHidden
212+
columns.Add(SchemaTableColumn.IsLong, typeof(bool));
213+
//IsReadOnly
214+
//ProviderSpecificDataType
215+
//DataTypeName XmlSchemaCollectionDatabase XmlSchemaCollectionOwningSchema XmlSchemaCollectionName UdtAssemblyQualifiedName NonVersionedProviderType IsColumnSet
216+
190217
return table;
191218
}
192219

193-
internal static void AddSchemaRowBoolean(DataTable schemaTable, string name, bool allowDBNull)
220+
private static object[] CreateDataRowValues(string columnName, int columnSize, Type dataType, DbType providerType, bool allowDBNull)
194221
{
195-
schemaTable.Rows.Add(new object[]
222+
return new object[]
196223
{
197-
name,
198-
sizeof(bool),
199-
typeof(bool),
200-
DbType.Boolean,
224+
columnName,
225+
0,
226+
columnSize,
227+
null,
228+
null,
229+
null,
230+
null,
231+
null,
232+
null,
233+
null,
234+
dataType,
201235
allowDBNull,
202-
});
236+
providerType,
237+
null,
238+
null,
239+
null
240+
};
241+
}
242+
243+
internal static void AddSchemaRowBoolean(DataTable schemaTable, string name, bool allowDBNull)
244+
{
245+
schemaTable.Rows.Add(CreateDataRowValues(name, sizeof(bool), typeof(bool), DbType.Boolean, allowDBNull));
203246
}
204247

205248
internal static void AddSchemaRowDateTime(DataTable schemaTable, string name, bool allowDBNull)
206249
{
207-
schemaTable.Rows.Add(new object[]
208-
{
209-
name,
210-
8,
211-
typeof(DateTime),
212-
DbType.DateTime,
213-
allowDBNull
214-
});
250+
schemaTable.Rows.Add(CreateDataRowValues(name, 8, typeof(DateTime), DbType.DateTime, allowDBNull));
215251
}
216252

217253
internal static void AddSchemaRowString(DataTable schemaTable, string name, bool allowDBNull)
218254
{
219-
schemaTable.Rows.Add(new object[]
220-
{
221-
name,
222-
8096,
223-
typeof(string),
224-
DbType.String,
225-
allowDBNull
226-
});
255+
schemaTable.Rows.Add(CreateDataRowValues(name, 8096, typeof(string), DbType.String, allowDBNull));
227256
}
228257

229258
internal static void AddSchemaRowInt32(DataTable schemaTable, string name, bool allowDBNull)
230259
{
231-
schemaTable.Rows.Add(new object[]
232-
{
233-
name,
234-
sizeof(int),
235-
typeof(int),
236-
DbType.Int32,
237-
allowDBNull
238-
});
260+
schemaTable.Rows.Add(CreateDataRowValues(name, sizeof(int), typeof(int), DbType.Int32, allowDBNull));
239261
}
240262

241263
internal static void AddSchemaRowInt64(DataTable schemaTable, string name, bool allowDBNull)
242264
{
243-
schemaTable.Rows.Add(new object[]
244-
{
245-
name,
246-
sizeof(long),
247-
typeof(long),
248-
DbType.Int64,
249-
allowDBNull
250-
});
265+
schemaTable.Rows.Add(CreateDataRowValues(name, sizeof(long), typeof(long), DbType.Int64, allowDBNull));
251266
}
252267
}
253268
}

DataCommander.Providers/AboutForm.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public AboutForm()
2727
a {{text-decoration:none}}
2828
</style>
2929
<div style=""font-family:verdana;font-size:9pt"">
30-
<a href=""https://github.com/csbernath/DataCommander"">Data Commander on GitHub</a>
30+
<a href=""https://github.com/csbernath/DataCommander"">Data Commander</a>
31+
<br/>
32+
<br/>
33+
Inlcuding <a href=""https://github.com/csbernath/DataCommander/blob/master/DataCommander.Foundation/README.md"">Foundation Class Library</a>
3134
<br/>
3235
<br/>
3336
Build date: {lastWriteTime.ToString("yyyy-MM-dd")}
@@ -56,11 +59,11 @@ public AboutForm()
5659
</br>
5760
<ul style=""list-style-type:none"">
5861
<li><a href=""https://www.visualstudio.com/products/visual-studio-community-vs"">Visual Studio 2015 Community Edition</a></li>
59-
<li><a href=""https://www.jetbrains.com/resharper/"">JetBrains R# ReSharper Ultimate Free Open Source License</a></li>
60-
<li><a href=""http://epplus.codeplex.com"">EPPlus-Create advanced Excel spreadsheets on the server</a></li>
61-
<li><a href=""https://system.data.sqlite.org"">System.Data.SQLite</a></li>
62-
<li><a href=""https://www.nuget.org/packages/MySql.Data/"">ADO.NET driver for MySQL</a></li>
63-
<li><a href=""http://npgsql.projects.pgfoundry.org/"">Npgsql - .Net Data Provider for PostgreSQL</a></li>
62+
<li><a href=""https://www.jetbrains.com/resharper/"">JetBrains R# ReSharper</a></li>
63+
<li><a href=""http://epplus.codeplex.com"">EPPlus Excel generator</a></li>
64+
<li><a href=""https://system.data.sqlite.org"">SQLite provider</a></li>
65+
<li><a href=""https://www.nuget.org/packages/MySql.Data/"">MySQL provider</a></li>
66+
<li><a href=""http://npgsql.projects.pgfoundry.org/"">PostgreSQL provider</a></li>
6467
</ul>
6568
</div>";
6669

0 commit comments

Comments
 (0)