/// <summary> /// Consumes the data reader created by <see cref="ReaderModificationCommandBatch.ExecuteAsync" />. /// </summary> /// <param name="reader"> The data reader. </param> /// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param> /// <returns> A task that represents the asynchronous operation. </returns> protected override async Task ConsumeAsync( RelationalDataReader reader, CancellationToken cancellationToken = default(CancellationToken)) { Debug.Assert(CommandResultSet.Count == ModificationCommands.Count); var commandIndex = 0; try { var actualResultSetCount = 0; do { while (commandIndex < CommandResultSet.Count && CommandResultSet[commandIndex] == ResultSetMapping.NoResultSet) { commandIndex++; } if (commandIndex < CommandResultSet.Count) { commandIndex = ModificationCommands[commandIndex].RequiresResultPropagation ? await ConsumeResultSetWithPropagationAsync(commandIndex, reader, cancellationToken) : await ConsumeResultSetWithoutPropagationAsync(commandIndex, reader, cancellationToken); actualResultSetCount++; } }while (commandIndex < CommandResultSet.Count && await reader.DbDataReader.NextResultAsync(cancellationToken)); #if DEBUG while (commandIndex < CommandResultSet.Count && CommandResultSet[commandIndex] == ResultSetMapping.NoResultSet) { commandIndex++; } Debug.Assert( commandIndex == ModificationCommands.Count, "Expected " + ModificationCommands.Count + " results, got " + commandIndex); var expectedResultSetCount = CommandResultSet.Count(e => e == ResultSetMapping.LastInResultSet); Debug.Assert( actualResultSetCount == expectedResultSetCount, "Expected " + expectedResultSetCount + " result sets, got " + actualResultSetCount); #endif } catch (DbUpdateException) { throw; } catch (Exception ex) { throw new DbUpdateException( RelationalStrings.UpdateStoreException, ex, ModificationCommands[commandIndex].Entries); } }
/// <summary> /// Consumes the data reader created by <see cref="ReaderModificationCommandBatch.Execute" />. /// </summary> /// <param name="reader"> The data reader. </param> protected override void Consume(RelationalDataReader reader) { Check.DebugAssert( CommandResultSet.Count == ModificationCommands.Count, $"CommandResultSet.Count of {CommandResultSet.Count} != ModificationCommands.Count of {ModificationCommands.Count}"); var commandIndex = 0; try { var actualResultSetCount = 0; do { while (commandIndex < CommandResultSet.Count && CommandResultSet[commandIndex] == ResultSetMapping.NoResultSet) { commandIndex++; } if (commandIndex < CommandResultSet.Count) { commandIndex = ModificationCommands[commandIndex].RequiresResultPropagation ? ConsumeResultSetWithPropagation(commandIndex, reader) : ConsumeResultSetWithoutPropagation(commandIndex, reader); actualResultSetCount++; } }while (commandIndex < CommandResultSet.Count && reader.DbDataReader.NextResult()); #if DEBUG while (commandIndex < CommandResultSet.Count && CommandResultSet[commandIndex] == ResultSetMapping.NoResultSet) { commandIndex++; } Check.DebugAssert( commandIndex == ModificationCommands.Count, "Expected " + ModificationCommands.Count + " results, got " + commandIndex); var expectedResultSetCount = CommandResultSet.Count(e => e == ResultSetMapping.LastInResultSet); Check.DebugAssert( actualResultSetCount == expectedResultSetCount, "Expected " + expectedResultSetCount + " result sets, got " + actualResultSetCount); #endif } catch (Exception ex) when(ex is not DbUpdateException and not OperationCanceledException) { throw new DbUpdateException( RelationalStrings.UpdateStoreException, ex, ModificationCommands[commandIndex].Entries); } }
private void EnsureArgumentsParsed() { if (mCommands == null) { try { var parsedCommands = mParser.Parse(mArguments); mCommands = new CommandResultSet(mObjectConverterFactory, parsedCommands); } catch (Exception ex) { ConsoleHelper.WriteLine(ConsoleMessageType.Error, "Failed to parse command-line arguments:\n{0}", ex.Message); } } }
/// <summary> /// Executes the operations contained within the console application implementation. /// </summary> /// <param name="commands">A set of commands parsed from the given command-line arguments.</param> /// <remarks> /// <para> /// The default implementation of this method contains the algorithmic content for automatic execution of /// known and registered commands. Any overriding of this functionality should ideally call back to the /// base implementation, unless this behaviour is undesirable in the context of the application implementation. /// </para> /// </remarks> protected virtual void RunCore(CommandResultSet commands) { CheckHelpCommand(commands); PerformAutomaticCommandExecution(commands); }