Skip to content

Commit

Permalink
WIP on .NET Core support
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
roji committed Apr 1, 2015
1 parent d427fdf commit 87e8cd2
Show file tree
Hide file tree
Showing 35 changed files with 315 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/Npgsql/NpgsqlBuffer.cs
Expand Up @@ -160,7 +160,7 @@ internal void Seek(int offset, SeekOrigin origin)
default:
throw new ArgumentOutOfRangeException("origin");
}
Debug.Assert(absoluteOffset >= 0 && absoluteOffset <= _filledBytes);
Contract.Assert(absoluteOffset >= 0 && absoluteOffset <= _filledBytes);

ReadPosition = absoluteOffset;
}
Expand Down
21 changes: 18 additions & 3 deletions src/Npgsql/NpgsqlCommand.cs
Expand Up @@ -51,8 +51,12 @@ namespace Npgsql
#if WITHDESIGN
[System.Drawing.ToolboxBitmapAttribute(typeof(NpgsqlCommand)), ToolboxItem(true)]
#endif
#if DNXCORE50
public sealed partial class NpgsqlCommand : DbCommand
#else
[System.ComponentModel.DesignerCategory("")]
public sealed partial class NpgsqlCommand : DbCommand, ICloneable
#endif
{
#region Fields

Expand Down Expand Up @@ -168,7 +172,10 @@ void Init(string cmdText)
/// Gets or sets the SQL statement or function (stored procedure) to execute at the data source.
/// </summary>
/// <value>The Transact-SQL statement or stored procedure to execute. The default is an empty string.</value>
[Category("Data"), DefaultValue("")]
[DefaultValue("")]
#if !DNXCORE50
[Category("Data")]
#endif
public override String CommandText
{
get { return _commandText; }
Expand Down Expand Up @@ -213,7 +220,10 @@ public override int CommandTimeout
/// <see cref="NpgsqlCommand.CommandText">CommandText</see> property is to be interpreted.
/// </summary>
/// <value>One of the <see cref="System.Data.CommandType">CommandType</see> values. The default is <see cref="System.Data.CommandType">CommandType.Text</see>.</value>
[Category("Data"), DefaultValue(CommandType.Text)]
[DefaultValue(CommandType.Text)]
#if !DNXCORE50
[Category("Data")]
#endif
public override CommandType CommandType { get; set; }

/// <summary>
Expand All @@ -230,7 +240,10 @@ protected override DbConnection DbConnection
/// used by this instance of the <see cref="NpgsqlCommand">NpgsqlCommand</see>.
/// </summary>
/// <value>The connection to a data source. The default value is a null reference.</value>
[Category("Behavior"), DefaultValue(null)]
[DefaultValue(null)]
#if !DNXCORE50
[Category("Behavior")]
#endif
public new NpgsqlConnection Connection
{
get { return _connection; }
Expand Down Expand Up @@ -1623,6 +1636,7 @@ void Prechecks()
Contract.Assume(_connector.Buffer.WritePosition == 0, "WritePosition should be 0");
}

#if !DNXCORE50
/// <summary>
/// Create a new command based on this one.
/// </summary>
Expand All @@ -1631,6 +1645,7 @@ Object ICloneable.Clone()
{
return Clone();
}
#endif

/// <summary>
/// Create a new command based on this one.
Expand Down
4 changes: 3 additions & 1 deletion src/Npgsql/NpgsqlCommandBuilder.cs
@@ -1,4 +1,5 @@
// NpgsqlCommandBuilder.cs
#if !DNXCORE50
// NpgsqlCommandBuilder.cs
//
// Author:
// Pedro Martínez Juliá (yoros@wanadoo.es)
Expand Down Expand Up @@ -520,3 +521,4 @@ public override string UnquoteIdentifier(string quotedIdentifier)
}
}
}
#endif
54 changes: 48 additions & 6 deletions src/Npgsql/NpgsqlConnection.cs
Expand Up @@ -35,7 +35,9 @@
using System.Net.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
#if !DNXCORE50
using System.Transactions;
#endif
using Npgsql.Logging;
using IsolationLevel = System.Data.IsolationLevel;

Expand All @@ -47,8 +49,12 @@ namespace Npgsql
#if WITHDESIGN
[System.Drawing.ToolboxBitmapAttribute(typeof(NpgsqlConnection))]
#endif
#if DNXCORE50
public sealed class NpgsqlConnection : DbConnection
#else
[System.ComponentModel.DesignerCategory("")]
public sealed class NpgsqlConnection : DbConnection, ICloneable
#endif
{
#region Fields

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

#if !DNXCORE50
NpgsqlPromotableSinglePhaseNotification Promotable
{
get { return _promotable ?? (_promotable = new NpgsqlPromotableSinglePhaseNotification(this)); }
}
NpgsqlPromotableSinglePhaseNotification _promotable;
#endif

// A cached copy of the result of `settings.ConnectionString`
string _connectionString;
Expand Down Expand Up @@ -129,11 +141,13 @@ void Init()
ProvideClientCertificatesCallbackDelegate = DefaultProvideClientCertificatesCallback;
ValidateRemoteCertificateCallbackDelegate = DefaultValidateRemoteCertificateCallback;

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

_promotable = new NpgsqlPromotableSinglePhaseNotification(this);
#endif
}

/// <summary>
Expand Down Expand Up @@ -184,10 +198,12 @@ public override void Open()
}*/

#if !DNXCORE50
if (Enlist)
{
Promotable.Enlist(Transaction.Current);
}
#endif

OpenCounter++;
OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open));
Expand Down Expand Up @@ -292,7 +308,9 @@ void RefreshConnectionString()
/// <summary>
/// Backend server host name.
/// </summary>
#if !DNXCORE50
[Browsable(true)]
#endif
public string Host
{
get { return _settings.Host; }
Expand All @@ -301,7 +319,9 @@ public string Host
/// <summary>
/// Backend server port.
/// </summary>
#if !DNXCORE50
[Browsable(true)]
#endif
public int Port
{
get { return _settings.Port; }
Expand All @@ -310,7 +330,9 @@ public int Port
/// <summary>
/// If true, the connection will attempt to use SSL.
/// </summary>
#if !DNXCORE50
[Browsable(true)]
#endif
public bool SSL
{
get { return _settings.SSL; }
Expand Down Expand Up @@ -446,7 +468,9 @@ public int BufferSize
/// Gets the current state of the connection.
/// </summary>
/// <value>A bitwise combination of the <see cref="System.Data.ConnectionState">ConnectionState</see> values. The default is <b>Closed</b>.</value>
#if !DNXCORE50
[Browsable(false)]
#endif
public ConnectionState FullState
{
get
Expand Down Expand Up @@ -482,7 +506,9 @@ public ConnectionState FullState
/// Gets whether the current state of the connection is Open or Closed
/// </summary>
/// <value>ConnectionState.Open, ConnectionState.Closed or ConnectionState.Connecting</value>
#if !DNXCORE50
[Browsable(false)]
#endif
public override ConnectionState State
{
get
Expand Down Expand Up @@ -595,6 +621,7 @@ internal void PromotableLocalTransactionEnded()
ReallyClose();
}

#if !DNXCORE50
/// <summary>
/// Enlist transation.
/// </summary>
Expand All @@ -603,6 +630,7 @@ public override void EnlistTransaction(Transaction transaction)
{
Promotable.Enlist(transaction);
}
#endif

#endregion

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

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

#if !DNXCORE50
if (_promotable != null && _promotable.InLocalTransaction)
{
_postponingClose = true;
return;
}
#endif

ReallyClose();
}
Expand Down Expand Up @@ -792,7 +822,9 @@ internal bool DefaultValidateRemoteCertificateCallback(X509Certificate cert, X50
/// Version of the PostgreSQL backend.
/// This can only be called when there is an active connection.
/// </summary>
#if !DNXCORE50
[Browsable(false)]
#endif
public Version PostgreSqlVersion
{
get
Expand All @@ -815,7 +847,9 @@ public override string ServerVersion
/// This can only be called when there is an active connection.
/// Always retuna Version3
/// </summary>
#if !DNXCORE50
[Browsable(false)]
#endif
public ProtocolVersion BackendProtocolVersion
{
get
Expand All @@ -839,7 +873,9 @@ internal bool IsRedshift
/// Process id of backend server.
/// This can only be called when there is an active connection.
/// </summary>
#if !DNXCORE50
[Browsable(false)]
#endif
// ReSharper disable once InconsistentNaming
public int ProcessID
{
Expand All @@ -856,7 +892,9 @@ public int ProcessID
/// In version 8.2, Postgres began supporting standard conformant strings, but defaulted this flag to false.
/// As of version 9.1, this flag defaults to true.
/// </summary>
#if !DNXCORE50
[Browsable(false)]
#endif
public bool UseConformantStrings
{
get
Expand All @@ -869,7 +907,9 @@ public bool UseConformantStrings
/// <summary>
/// Report whether the backend understands the string literal E prefix (>= 8.1).
/// </summary>
#if !DNXCORE50
[Browsable(false)]
#endif
public bool Supports_E_StringPrefix
{
get
Expand All @@ -882,7 +922,9 @@ public bool Supports_E_StringPrefix
/// <summary>
/// Report whether the backend understands the hex byte format (>= 9.0).
/// </summary>
#if !DNXCORE50
[Browsable(false)]
#endif
public bool SupportsHexByteFormat
{
get
Expand Down Expand Up @@ -1085,11 +1127,6 @@ public NpgsqlRawCopyStream BeginRawBinaryCopy(string copyCommand)

#region State checks

NpgsqlPromotableSinglePhaseNotification Promotable
{
get { return _promotable ?? (_promotable = new NpgsqlPromotableSinglePhaseNotification(this)); }
}

void CheckConnectionOpen()
{
if (_disposed) {
Expand Down Expand Up @@ -1153,7 +1190,7 @@ internal void CheckConnectionReady()
#endregion State checks

#region Schema operations

#if !DNXCORE50
/// <summary>
/// Returns the supported collections
/// </summary>
Expand Down Expand Up @@ -1224,6 +1261,7 @@ public override DataTable GetSchema(string collectionName, string[] restrictions
}
}

#endif
#endregion Schema operations

#region Misc
Expand Down Expand Up @@ -1258,6 +1296,7 @@ public override void ChangeDatabase(String dbName)
Open();
}

#if !DNXCORE50
/// <summary>
/// Create a new connection based on this one.
/// </summary>
Expand All @@ -1266,6 +1305,7 @@ Object ICloneable.Clone()
{
return Clone();
}
#endif

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

#if !DNXCORE50
/// <summary>
/// DB provider factory.
/// </summary>
protected override DbProviderFactory DbProviderFactory
{
get { return NpgsqlFactory.Instance; }
}
#endif

/// <summary>
/// Clear connection pool.
Expand Down

0 comments on commit 87e8cd2

Please sign in to comment.