diff --git a/csharp/Core/Revenj.Core/DatabasePersistence/Postgres/Npgsql/ByteBuffer.cs b/csharp/Core/Revenj.Core/DatabasePersistence/Postgres/Npgsql/ByteBuffer.cs index 2137a771..d6b0155c 100644 --- a/csharp/Core/Revenj.Core/DatabasePersistence/Postgres/Npgsql/ByteBuffer.cs +++ b/csharp/Core/Revenj.Core/DatabasePersistence/Postgres/Npgsql/ByteBuffer.cs @@ -12,6 +12,8 @@ internal class ByteBuffer public readonly byte[] Large = new byte[65536]; + private readonly char[] Chars = new char[256]; + public void Add(byte value) { if (Position == Buffer.Length) @@ -27,14 +29,26 @@ public void Add(byte value) public int GetPosition() { return Position; } public bool AreSame(byte[] compare) { + if (compare.Length != Position) return false; for (int i = 0; i < compare.Length && i < Buffer.Length; i++) if (compare[i] != Buffer[i]) return false; - return compare.Length == Position; + return true; } public string GetUtf8String() { + if (Position == 0) return string.Empty; + else if (Position < 256) + { + for (var i = 0; i < Position; i++) + { + var ch = Buffer[i]; + if (ch > 126) return UTF8.GetString(Buffer, 0, Position); + Chars[i] = (char)ch; + } + return new string(Chars, 0, Position); + } return UTF8.GetString(Buffer, 0, Position); } diff --git a/csharp/Core/Revenj.Core/DatabasePersistence/Postgres/Npgsql/NpgsqlCommand.cs b/csharp/Core/Revenj.Core/DatabasePersistence/Postgres/Npgsql/NpgsqlCommand.cs index 1e321ef6..28f9eecd 100644 --- a/csharp/Core/Revenj.Core/DatabasePersistence/Postgres/Npgsql/NpgsqlCommand.cs +++ b/csharp/Core/Revenj.Core/DatabasePersistence/Postgres/Npgsql/NpgsqlCommand.cs @@ -83,6 +83,7 @@ public sealed class NpgsqlCommand : DbCommand, ICloneable private Boolean commandTimeoutSet = false; private UpdateRowSource updateRowSource = UpdateRowSource.Both; + internal readonly ForwardsOnlyDataReader forwardReader; // Constructors @@ -107,6 +108,7 @@ internal NpgsqlCommand(Stream stream, string template) CommandType = System.Data.CommandType.Text; timeout = 20; ReaderBehavior = CommandBehavior.SequentialAccess; + forwardReader = new ForwardsOnlyDataReader(this, ReaderBehavior); } internal NpgsqlCommand(Stream stream, string template, string preparedQuery, string preparedParams) @@ -118,6 +120,7 @@ internal NpgsqlCommand(Stream stream, string template, string preparedQuery, str ReaderBehavior = CommandBehavior.SequentialAccess; this.PreparedQuery = preparedQuery; this.PreparedParams = preparedParams; + forwardReader = new ForwardsOnlyDataReader(this, ReaderBehavior); } /// @@ -159,6 +162,7 @@ public NpgsqlCommand(String cmdText, NpgsqlConnection connection, NpgsqlTransact type = CommandType.Text; this.Transaction = transaction; + forwardReader = new ForwardsOnlyDataReader(this, ReaderBehavior); SetCommandTimeout(); } @@ -173,6 +177,7 @@ internal NpgsqlCommand(string cmdText, NpgsqlConnector connector) text = cmdText; this.m_Connector = connector; type = CommandType.Text; + forwardReader = new ForwardsOnlyDataReader(this, ReaderBehavior); // Removed this setting. It was causing too much problem. // Do internal commands really need different timeout setting? @@ -585,8 +590,7 @@ internal ForwardsOnlyDataReader GetReader(CommandBehavior cb) ForwardsOnlyDataReader reader; if (parse == null) { - reader = new ForwardsOnlyDataReader(connector.QueryEnum(this), cb, this, - connector.BlockNotificationThread(), false); + reader = forwardReader.Process(connector.QueryEnum(this), cb, connector.BlockNotificationThread(), false); if (type == CommandType.StoredProcedure && reader.FieldCount == 1 && reader.GetDataTypeName(0) == "refcursor") @@ -616,8 +620,7 @@ internal ForwardsOnlyDataReader GetReader(CommandBehavior cb) else { BindParameters(); - reader = new ForwardsOnlyDataReader(connector.ExecuteEnum(new NpgsqlExecute(bind.PortalName, 0)), cb, this, - connector.BlockNotificationThread(), true); + reader = forwardReader.Process(connector.ExecuteEnum(new NpgsqlExecute(bind.PortalName, 0)), cb, connector.BlockNotificationThread(), true); } return reader; } diff --git a/csharp/Core/Revenj.Core/DatabasePersistence/Postgres/Npgsql/NpgsqlDataReader.cs b/csharp/Core/Revenj.Core/DatabasePersistence/Postgres/Npgsql/NpgsqlDataReader.cs index f2df7a10..cc8eee01 100644 --- a/csharp/Core/Revenj.Core/DatabasePersistence/Postgres/Npgsql/NpgsqlDataReader.cs +++ b/csharp/Core/Revenj.Core/DatabasePersistence/Postgres/Npgsql/NpgsqlDataReader.cs @@ -53,21 +53,21 @@ public abstract class NpgsqlDataReader : DbDataReader //the differences between the two is hidden from the user. Because CachingDataReader is a less efficient //class supplied only to resolve some backwards-compatibility issues that are possible with some code, all //internal use uses ForwardsOnlyDataReader directly. - internal NpgsqlConnector _connector; - internal NpgsqlConnection _connection; internal DataTable _currentResultsetSchema; internal CommandBehavior _behavior; - internal NpgsqlCommand _command; + internal readonly NpgsqlCommand _command; internal static Version Npgsql205 = new Version("2.0.5"); internal NpgsqlDataReader(NpgsqlCommand command, CommandBehavior behavior) { _behavior = behavior; - _connection = (_command = command).Connection; - _connector = command.Connector; + _command = command; } + internal NpgsqlConnector Connector { get { return _command.Connector; } } + internal NpgsqlConnection Connection { get { return _command.Connection; } } + internal bool _isClosed = false; /// @@ -125,7 +125,7 @@ public override Int32 FieldCount { get { - if (_connector.CompatVersion <= Npgsql205) + if (Connector.CompatVersion <= Npgsql205) return CurrentDescription == null ? -1 : CurrentDescription.NumFields; else // We read msdn documentation and bug report #1010649 that the common return value is 0. @@ -663,7 +663,7 @@ private IEnumerable GetPrimaryKeys(String tablename) String getPKColumns = "select a.attname from pg_catalog.pg_class ct, pg_catalog.pg_class ci, pg_catalog.pg_attribute a, pg_catalog.pg_index i WHERE ct.oid=i.indrelid AND ci.oid=i.indexrelid AND a.attrelid=ci.oid AND i.indisprimary AND ct.relname = :tablename"; - using (NpgsqlConnection metadataConn = _connection.Clone()) + using (NpgsqlConnection metadataConn = Connection.Clone()) { using (NpgsqlCommand c = new NpgsqlCommand(getPKColumns, metadataConn)) { @@ -712,7 +712,7 @@ private KeyLookup GetKeys(Int32 tableOid) KeyLookup lookup = new KeyLookup(); - using (NpgsqlConnection metadataConn = _connection.Clone()) + using (NpgsqlConnection metadataConn = Connection.Clone()) { NpgsqlCommand c = new NpgsqlCommand(getKeys, metadataConn); c.Parameters.Add(new NpgsqlParameter("tableOid", NpgsqlDbType.Integer)).Value = tableOid; @@ -867,7 +867,7 @@ private Dictionary GetTablesFromOids(List oids) } sb.Append(')'); - using (NpgsqlConnection connection = _connection.Clone()) + using (NpgsqlConnection connection = Connection.Clone()) { using (NpgsqlCommand command = new NpgsqlCommand(sb.ToString(), connection)) { @@ -942,7 +942,7 @@ private Dictionary GetColumns() return null; } - using (NpgsqlConnection connection = _connection.Clone()) + using (NpgsqlConnection connection = Connection.Clone()) { using (NpgsqlCommand command = new NpgsqlCommand(sb.ToString(), connection)) { @@ -976,7 +976,7 @@ public override IEnumerator GetEnumerator() /// internal class ForwardsOnlyDataReader : NpgsqlDataReader, IStreamOwner { - private readonly IEnumerator _dataEnumerator; + private IEnumerator _dataEnumerator; private NpgsqlRowDescription _currentDescription; private NpgsqlRow _currentRow = null; private int? _recordsAffected = null; @@ -984,8 +984,8 @@ internal class ForwardsOnlyDataReader : NpgsqlDataReader, IStreamOwner private long? _lastInsertOID = null; private long? _nextInsertOID = null; internal bool _cleanedUp = false; - private readonly NpgsqlConnector.NotificationThreadBlock _threadBlock; - private readonly bool _synchOnReadError; //maybe this should always be done? + private NpgsqlConnector.NotificationThreadBlock _threadBlock; + private bool _synchOnReadError; //maybe this should always be done? //Unfortunately we sometimes don't know we're going to be dealing with //a description until it comes when we look for a row or a message, and @@ -997,21 +997,33 @@ internal class ForwardsOnlyDataReader : NpgsqlDataReader, IStreamOwner // Logging related values private static readonly String CLASSNAME = MethodBase.GetCurrentMethod().DeclaringType.Name; - internal ForwardsOnlyDataReader( + internal ForwardsOnlyDataReader(NpgsqlCommand command, CommandBehavior readerBehavior) + : base(command, readerBehavior) { } + + internal ForwardsOnlyDataReader Process( IEnumerable dataEnumeration, CommandBehavior behavior, - NpgsqlCommand command, NpgsqlConnector.NotificationThreadBlock threadBlock, bool synchOnReadError) - : base(command, behavior) { + _currentDescription = null; + _currentRow = null; + _recordsAffected = null; + _nextRecordsAffected = null; + _lastInsertOID = null; + _nextInsertOID = null; + _pendingDescription = null; + _pendingRow = null; + _cleanedUp = false; + _behavior = behavior; _dataEnumerator = dataEnumeration.GetEnumerator(); - _connector.CurrentReader = this; + _command.Connector.CurrentReader = this; _threadBlock = threadBlock; _synchOnReadError = synchOnReadError; //DataReaders always start prepared to read from the first Resultset (if any). NextResult(); UpdateOutputParameters(); + return this; } internal override NpgsqlRowDescription CurrentDescription @@ -1141,7 +1153,7 @@ private IServerResponseObject GetNextResponseObject() // Sync is reached, then issues ReadyForQuery and returns to normal message processing.[...]" // So, send a sync command if we get any problems. - _connector.Sync(); + Connector.Sync(); } throw; } @@ -1311,13 +1323,13 @@ private void CleanUp(bool finishedMessages) { if ((Thread.CurrentThread.ThreadState & (ThreadState.Aborted | ThreadState.AbortRequested)) != 0) { - _connection.EmergencyClose(); + Connection.EmergencyClose(); return; } } while (GetNextResponseObject() != null); } - _connector.CurrentReader = null; + Connector.CurrentReader = null; _threadBlock.Dispose(); } @@ -1329,7 +1341,7 @@ public override void Close() CleanUp(false); if ((_behavior & CommandBehavior.CloseConnection) == CommandBehavior.CloseConnection) { - _connection.Close(); + Connection.Close(); } _isClosed = true; SendClosedEvent(); @@ -1381,7 +1393,7 @@ public override Object GetValue(Int32 Index) { return ExpectedTypeConverter.ChangeType(providerValue, _command.ExpectedTypes[Index]); } - else if ((_connection == null || !_connection.UseExtendedTypes) && TryGetTypeInfo(Index, out backendTypeInfo)) + else if ((Connection == null || !Connection.UseExtendedTypes) && TryGetTypeInfo(Index, out backendTypeInfo)) return backendTypeInfo.ConvertToFrameworkType(providerValue); return providerValue; } @@ -1592,7 +1604,7 @@ public override void Close() { if ((_behavior & CommandBehavior.CloseConnection) == CommandBehavior.CloseConnection) { - _connection.Close(); + Connection.Close(); } _isClosed = true; SendClosedEvent(); diff --git a/csharp/Dependencies/Templater/NGS.Templater.dll b/csharp/Dependencies/Templater/NGS.Templater.dll index 86109cc7..dc6c3dd2 100644 Binary files a/csharp/Dependencies/Templater/NGS.Templater.dll and b/csharp/Dependencies/Templater/NGS.Templater.dll differ diff --git a/csharp/Dependencies/Templater/NGS.Templater.xml b/csharp/Dependencies/Templater/NGS.Templater.xml index 9cc31d78..f006f148 100644 --- a/csharp/Dependencies/Templater/NGS.Templater.xml +++ b/csharp/Dependencies/Templater/NGS.Templater.xml @@ -116,6 +116,14 @@ replacer plugin itself + + + Customize tag matcher. Default tag regex is [-+@\w\s.,!?]+ + Full matcher consists from more elements, this is just the base tag element. + + custom tag matcher + itself + Build document factory instance using default 'templater.lic' license file. diff --git a/csharp/SharedAssemblyInfo.cs b/csharp/SharedAssemblyInfo.cs index 6e69e4fe..4113d123 100644 --- a/csharp/SharedAssemblyInfo.cs +++ b/csharp/SharedAssemblyInfo.cs @@ -3,10 +3,10 @@ using System.Runtime.InteropServices; [assembly: AssemblyCompany("DSL Platform")] -[assembly: AssemblyCopyright("Copyright © DSL Platform 2016")] +[assembly: AssemblyCopyright("Copyright © DSL Platform 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] -[assembly: AssemblyVersion("1.4.1.0")] -[assembly: AssemblyFileVersion("1.4.1.0")] +[assembly: AssemblyVersion("1.4.2.0")] +[assembly: AssemblyFileVersion("1.4.2.0")] [assembly: CLSCompliant(true)]