public async Task TestTakeNeverEnding() { var array = await AsyncEnumerable.Neverending(1, asyncProvider : DefaultAsyncProvider.Instance).Take(3).ToArrayAsync(); Assert.IsTrue(ArrayEqualityComparer <Int32> .ArrayEquality(array, Enumerable.Repeat(1, 3).ToArray())); }
public static int GetArrayHashCode <T> (this T[] array) { return(ArrayEqualityComparer <T> .GetHashCode(array)); }
public void ArrayEqualityComparerInitialisesWithSpecifiedElementComparer() { var comparer = new ArrayEqualityComparer <int>(EqualityComparer <int> .Default); Assert.IsNotNull(comparer); }
public void ArrayEqualityComparerInitialises() { var comparer = new ArrayEqualityComparer <int>(); Assert.IsNotNull(comparer); }
protected override async Task <TStatementExecutionSimpleTaskParameter> ExecuteStatementAsBatch(StatementBuilder statement, ReservedForStatement reservedState) { // TODO somehow make statement name and chunk size parametrizable (var parameterIndices, var typeInfos, var typeIDs) = GetVariablesForExtendedQuerySequence(statement, this.TypeRegistry, (stmt, idx) => stmt.GetBatchParameterInfo(0, idx)); var ioArgs = this.GetIOArgs(); var stmtName = ((PgReservedForStatement)reservedState).StatementName; var chunkSize = 1000; // Send a parse message with statement name await new ParseMessage(statement.SQL, parameterIndices, typeIDs, stmtName).SendMessageAsync(ioArgs, true); // Now send describe message await new DescribeMessage(true, stmtName).SendMessageAsync(ioArgs, true); // And then Flush message for backend to send responses await FrontEndMessageWithNoContent.FLUSH.SendMessageAsync(ioArgs, false); // Receive first batch of messages BackendMessageObject msg = null; SQLStatementExecutionResult current = null; List <PgSQLError> notices = new List <PgSQLError>(); var sendBatch = true; while (msg == null) { msg = (await this.ReadMessagesUntilMeaningful(notices)).Item1; switch (msg) { case MessageWithNoContents nc: switch (nc.Code) { case BackendMessageCode.ParseComplete: // Continue reading messages msg = null; break; case BackendMessageCode.EmptyQueryResponse: // The statement does not produce any data, we are done sendBatch = false; break; case BackendMessageCode.NoData: // Do nothing, thus causing batch messages to be sent break; default: throw new PgSQLException("Unrecognized response at this point: " + msg.Code); } break; case RowDescription rd: throw new PgSQLException("Batch statements may only be used for non-query statements."); case ParameterDescription pd: if (!ArrayEqualityComparer <Int32> .ArrayEquality(pd.ObjectIDs, typeIDs)) { throw new PgSQLException("Backend required certain amount of parameters, but either they were not supplied, or were of wrong type."); } // Continue to RowDescription/NoData message msg = null; break; default: throw new PgSQLException("Unrecognized response at this point: " + msg.Code); } } if (sendBatch) { var batchCount = statement.BatchParameterCount; var affectedRowsArray = new Int32[batchCount]; // Send and receive messages asynchronously var commandTag = new String[1]; await Task.WhenAll( this.SendMessagesForBatch( statement, typeInfos, stmtName, ioArgs, chunkSize, batchCount ), this.ReceiveMessagesForBatch( notices, affectedRowsArray, commandTag ) ); current = new BatchCommandExecutionResultImpl( commandTag[0], new Lazy <SQLException[]>(() => notices?.Select(n => new PgSQLException(n))?.ToArray()), affectedRowsArray ); } return(current, null); }
bool _ReferenceMatchesDefinition(AssemblyName reference, AssemblyName definition) => reference.Name.Equals(definition.Name, StringComparison.OrdinalIgnoreCase) && _ReferenceMatchesDefinition(reference.Version, definition.Version) && ArrayEqualityComparer.Equals(reference.GetPublicKeyToken(), definition.GetPublicKeyToken()) && #if NET40 (reference.CultureInfo is null && definition.CultureInfo is null || (reference.CultureInfo?.Equals(definition.CultureInfo) ?? false))