Skip to content

Commit 87e8cd2

Browse files
committed
WIP on .NET Core support
* Created dnxcore50 section in project.json, filled in most required dependencies * Disabled many parts in the code which don't appears to be compatible with .NET Core at this time (#if DNXCORE50) * Many actual errors remain Relates to #471
1 parent d427fdf commit 87e8cd2

35 files changed

Lines changed: 315 additions & 73 deletions

src/Npgsql/NpgsqlBuffer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ internal void Seek(int offset, SeekOrigin origin)
160160
default:
161161
throw new ArgumentOutOfRangeException("origin");
162162
}
163-
Debug.Assert(absoluteOffset >= 0 && absoluteOffset <= _filledBytes);
163+
Contract.Assert(absoluteOffset >= 0 && absoluteOffset <= _filledBytes);
164164

165165
ReadPosition = absoluteOffset;
166166
}

src/Npgsql/NpgsqlCommand.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ namespace Npgsql
5151
#if WITHDESIGN
5252
[System.Drawing.ToolboxBitmapAttribute(typeof(NpgsqlCommand)), ToolboxItem(true)]
5353
#endif
54+
#if DNXCORE50
55+
public sealed partial class NpgsqlCommand : DbCommand
56+
#else
5457
[System.ComponentModel.DesignerCategory("")]
5558
public sealed partial class NpgsqlCommand : DbCommand, ICloneable
59+
#endif
5660
{
5761
#region Fields
5862

@@ -168,7 +172,10 @@ void Init(string cmdText)
168172
/// Gets or sets the SQL statement or function (stored procedure) to execute at the data source.
169173
/// </summary>
170174
/// <value>The Transact-SQL statement or stored procedure to execute. The default is an empty string.</value>
171-
[Category("Data"), DefaultValue("")]
175+
[DefaultValue("")]
176+
#if !DNXCORE50
177+
[Category("Data")]
178+
#endif
172179
public override String CommandText
173180
{
174181
get { return _commandText; }
@@ -213,7 +220,10 @@ public override int CommandTimeout
213220
/// <see cref="NpgsqlCommand.CommandText">CommandText</see> property is to be interpreted.
214221
/// </summary>
215222
/// <value>One of the <see cref="System.Data.CommandType">CommandType</see> values. The default is <see cref="System.Data.CommandType">CommandType.Text</see>.</value>
216-
[Category("Data"), DefaultValue(CommandType.Text)]
223+
[DefaultValue(CommandType.Text)]
224+
#if !DNXCORE50
225+
[Category("Data")]
226+
#endif
217227
public override CommandType CommandType { get; set; }
218228

219229
/// <summary>
@@ -230,7 +240,10 @@ protected override DbConnection DbConnection
230240
/// used by this instance of the <see cref="NpgsqlCommand">NpgsqlCommand</see>.
231241
/// </summary>
232242
/// <value>The connection to a data source. The default value is a null reference.</value>
233-
[Category("Behavior"), DefaultValue(null)]
243+
[DefaultValue(null)]
244+
#if !DNXCORE50
245+
[Category("Behavior")]
246+
#endif
234247
public new NpgsqlConnection Connection
235248
{
236249
get { return _connection; }
@@ -1623,6 +1636,7 @@ void Prechecks()
16231636
Contract.Assume(_connector.Buffer.WritePosition == 0, "WritePosition should be 0");
16241637
}
16251638

1639+
#if !DNXCORE50
16261640
/// <summary>
16271641
/// Create a new command based on this one.
16281642
/// </summary>
@@ -1631,6 +1645,7 @@ Object ICloneable.Clone()
16311645
{
16321646
return Clone();
16331647
}
1648+
#endif
16341649

16351650
/// <summary>
16361651
/// Create a new command based on this one.

src/Npgsql/NpgsqlCommandBuilder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// NpgsqlCommandBuilder.cs
1+
#if !DNXCORE50
2+
// NpgsqlCommandBuilder.cs
23
//
34
// Author:
45
// Pedro Martínez Juliá (yoros@wanadoo.es)
@@ -520,3 +521,4 @@ public override string UnquoteIdentifier(string quotedIdentifier)
520521
}
521522
}
522523
}
524+
#endif

src/Npgsql/NpgsqlConnection.cs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
using System.Net.Security;
3636
using System.Security.Cryptography;
3737
using System.Security.Cryptography.X509Certificates;
38+
#if !DNXCORE50
3839
using System.Transactions;
40+
#endif
3941
using Npgsql.Logging;
4042
using IsolationLevel = System.Data.IsolationLevel;
4143

@@ -47,8 +49,12 @@ namespace Npgsql
4749
#if WITHDESIGN
4850
[System.Drawing.ToolboxBitmapAttribute(typeof(NpgsqlConnection))]
4951
#endif
52+
#if DNXCORE50
53+
public sealed class NpgsqlConnection : DbConnection
54+
#else
5055
[System.ComponentModel.DesignerCategory("")]
5156
public sealed class NpgsqlConnection : DbConnection, ICloneable
57+
#endif
5258
{
5359
#region Fields
5460

@@ -80,7 +86,13 @@ public sealed class NpgsqlConnection : DbConnection, ICloneable
8086
/// </summary>
8187
internal int OpenCounter { get; private set; }
8288

89+
#if !DNXCORE50
90+
NpgsqlPromotableSinglePhaseNotification Promotable
91+
{
92+
get { return _promotable ?? (_promotable = new NpgsqlPromotableSinglePhaseNotification(this)); }
93+
}
8394
NpgsqlPromotableSinglePhaseNotification _promotable;
95+
#endif
8496

8597
// A cached copy of the result of `settings.ConnectionString`
8698
string _connectionString;
@@ -129,11 +141,13 @@ void Init()
129141
ProvideClientCertificatesCallbackDelegate = DefaultProvideClientCertificatesCallback;
130142
ValidateRemoteCertificateCallbackDelegate = DefaultValidateRemoteCertificateCallback;
131143

144+
#if !DNXCORE50
132145
// Fix authentication problems. See https://bugzilla.novell.com/show_bug.cgi?id=MONO77559 and
133146
// http://pgfoundry.org/forum/message.php?msg_id=1002377 for more info.
134147
RSACryptoServiceProvider.UseMachineKeyStore = true;
135148

136149
_promotable = new NpgsqlPromotableSinglePhaseNotification(this);
150+
#endif
137151
}
138152

139153
/// <summary>
@@ -184,10 +198,12 @@ public override void Open()
184198
185199
}*/
186200

201+
#if !DNXCORE50
187202
if (Enlist)
188203
{
189204
Promotable.Enlist(Transaction.Current);
190205
}
206+
#endif
191207

192208
OpenCounter++;
193209
OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open));
@@ -292,7 +308,9 @@ void RefreshConnectionString()
292308
/// <summary>
293309
/// Backend server host name.
294310
/// </summary>
311+
#if !DNXCORE50
295312
[Browsable(true)]
313+
#endif
296314
public string Host
297315
{
298316
get { return _settings.Host; }
@@ -301,7 +319,9 @@ public string Host
301319
/// <summary>
302320
/// Backend server port.
303321
/// </summary>
322+
#if !DNXCORE50
304323
[Browsable(true)]
324+
#endif
305325
public int Port
306326
{
307327
get { return _settings.Port; }
@@ -310,7 +330,9 @@ public int Port
310330
/// <summary>
311331
/// If true, the connection will attempt to use SSL.
312332
/// </summary>
333+
#if !DNXCORE50
313334
[Browsable(true)]
335+
#endif
314336
public bool SSL
315337
{
316338
get { return _settings.SSL; }
@@ -446,7 +468,9 @@ public int BufferSize
446468
/// Gets the current state of the connection.
447469
/// </summary>
448470
/// <value>A bitwise combination of the <see cref="System.Data.ConnectionState">ConnectionState</see> values. The default is <b>Closed</b>.</value>
471+
#if !DNXCORE50
449472
[Browsable(false)]
473+
#endif
450474
public ConnectionState FullState
451475
{
452476
get
@@ -482,7 +506,9 @@ public ConnectionState FullState
482506
/// Gets whether the current state of the connection is Open or Closed
483507
/// </summary>
484508
/// <value>ConnectionState.Open, ConnectionState.Closed or ConnectionState.Connecting</value>
509+
#if !DNXCORE50
485510
[Browsable(false)]
511+
#endif
486512
public override ConnectionState State
487513
{
488514
get
@@ -595,6 +621,7 @@ internal void PromotableLocalTransactionEnded()
595621
ReallyClose();
596622
}
597623

624+
#if !DNXCORE50
598625
/// <summary>
599626
/// Enlist transation.
600627
/// </summary>
@@ -603,6 +630,7 @@ public override void EnlistTransaction(Transaction transaction)
603630
{
604631
Promotable.Enlist(transaction);
605632
}
633+
#endif
606634

607635
#endregion
608636

@@ -624,11 +652,13 @@ public override void Close()
624652

625653
Log.Debug("Closing connection", Connector.Id);
626654

655+
#if !DNXCORE50
627656
if (_promotable != null && _promotable.InLocalTransaction)
628657
{
629658
_postponingClose = true;
630659
return;
631660
}
661+
#endif
632662

633663
ReallyClose();
634664
}
@@ -792,7 +822,9 @@ internal bool DefaultValidateRemoteCertificateCallback(X509Certificate cert, X50
792822
/// Version of the PostgreSQL backend.
793823
/// This can only be called when there is an active connection.
794824
/// </summary>
825+
#if !DNXCORE50
795826
[Browsable(false)]
827+
#endif
796828
public Version PostgreSqlVersion
797829
{
798830
get
@@ -815,7 +847,9 @@ public override string ServerVersion
815847
/// This can only be called when there is an active connection.
816848
/// Always retuna Version3
817849
/// </summary>
850+
#if !DNXCORE50
818851
[Browsable(false)]
852+
#endif
819853
public ProtocolVersion BackendProtocolVersion
820854
{
821855
get
@@ -839,7 +873,9 @@ internal bool IsRedshift
839873
/// Process id of backend server.
840874
/// This can only be called when there is an active connection.
841875
/// </summary>
876+
#if !DNXCORE50
842877
[Browsable(false)]
878+
#endif
843879
// ReSharper disable once InconsistentNaming
844880
public int ProcessID
845881
{
@@ -856,7 +892,9 @@ public int ProcessID
856892
/// In version 8.2, Postgres began supporting standard conformant strings, but defaulted this flag to false.
857893
/// As of version 9.1, this flag defaults to true.
858894
/// </summary>
895+
#if !DNXCORE50
859896
[Browsable(false)]
897+
#endif
860898
public bool UseConformantStrings
861899
{
862900
get
@@ -869,7 +907,9 @@ public bool UseConformantStrings
869907
/// <summary>
870908
/// Report whether the backend understands the string literal E prefix (>= 8.1).
871909
/// </summary>
910+
#if !DNXCORE50
872911
[Browsable(false)]
912+
#endif
873913
public bool Supports_E_StringPrefix
874914
{
875915
get
@@ -882,7 +922,9 @@ public bool Supports_E_StringPrefix
882922
/// <summary>
883923
/// Report whether the backend understands the hex byte format (>= 9.0).
884924
/// </summary>
925+
#if !DNXCORE50
885926
[Browsable(false)]
927+
#endif
886928
public bool SupportsHexByteFormat
887929
{
888930
get
@@ -1085,11 +1127,6 @@ public static void RegisterEnumGlobally<TEnum>(string pgName = null) where TEnum
10851127

10861128
#region State checks
10871129

1088-
NpgsqlPromotableSinglePhaseNotification Promotable
1089-
{
1090-
get { return _promotable ?? (_promotable = new NpgsqlPromotableSinglePhaseNotification(this)); }
1091-
}
1092-
10931130
void CheckConnectionOpen()
10941131
{
10951132
if (_disposed) {
@@ -1153,7 +1190,7 @@ internal void CheckConnectionReady()
11531190
#endregion State checks
11541191

11551192
#region Schema operations
1156-
1193+
#if !DNXCORE50
11571194
/// <summary>
11581195
/// Returns the supported collections
11591196
/// </summary>
@@ -1224,6 +1261,7 @@ public override DataTable GetSchema(string collectionName, string[] restrictions
12241261
}
12251262
}
12261263

1264+
#endif
12271265
#endregion Schema operations
12281266

12291267
#region Misc
@@ -1258,6 +1296,7 @@ public override void ChangeDatabase(String dbName)
12581296
Open();
12591297
}
12601298

1299+
#if !DNXCORE50
12611300
/// <summary>
12621301
/// Create a new connection based on this one.
12631302
/// </summary>
@@ -1266,6 +1305,7 @@ Object ICloneable.Clone()
12661305
{
12671306
return Clone();
12681307
}
1308+
#endif
12691309

12701310
/// <summary>
12711311
/// Create a new connection based on this one.
@@ -1286,13 +1326,15 @@ public NpgsqlConnection Clone()
12861326
return clone;
12871327
}
12881328

1329+
#if !DNXCORE50
12891330
/// <summary>
12901331
/// DB provider factory.
12911332
/// </summary>
12921333
protected override DbProviderFactory DbProviderFactory
12931334
{
12941335
get { return NpgsqlFactory.Instance; }
12951336
}
1337+
#endif
12961338

12971339
/// <summary>
12981340
/// Clear connection pool.

0 commit comments

Comments
 (0)