예제 #1
0
        private async Task ExportNextBatch(IDataExportContext exportContext, ExportResultInfo exportResultInfo, CancellationToken cancellationToken)
        {
            Task <IReadOnlyList <object[]> > innerTask = null;
            var batchSize = ConfigurationProvider.Configuration.ResultGrid.FetchRowsBatchSize - exportContext.CurrentRowIndex % ConfigurationProvider.Configuration.ResultGrid.FetchRowsBatchSize;
            var exception = await App.SafeActionAsync(() => innerTask = _outputViewer.ConnectionAdapter.FetchRecordsAsync(exportResultInfo.ResultInfo, (int)batchSize, cancellationToken));

            if (exception != null)
            {
                var errorMessage = Messages.GetExceptionErrorMessage(exception);
                _outputViewer.AddExecutionLog(DateTime.Now, $"Row retrieval failed: {errorMessage}");
                Messages.ShowError(errorMessage);
            }
            else
            {
                try
                {
                    await exportContext.AppendRowsAsync(innerTask.Result);
                }
                catch (OperationCanceledException)
                {
                    TraceLog.WriteLine("User has canceled export operation. ");
                    return;
                }
                finally
                {
                    exportResultInfo.RowCount = exportContext.CurrentRowIndex;
                    exportResultInfo.RefreshFileSize();
                }

                await _outputViewer.UpdateExecutionStatisticsIfEnabled();
            }
        }
예제 #2
0
        public async Task SaveExecutionResult(StatementExecutionBatchResult executionResult)
        {
            IsWaitingForResult = false;
            IsExecuting        = true;

            _exportClockTimer.Start();
            _exportResultInfoCollection.Clear();

            var commandNumber = 0;

            foreach (var statementResult in executionResult.StatementResults)
            {
                commandNumber++;

                var resultNumber = 0;
                foreach (var kvp in statementResult.ResultInfoColumnHeaders)
                {
                    resultNumber++;
                    var exportResultInfo = new ExportResultInfo(commandNumber, resultNumber, kvp.Key, kvp.Value);
                    _exportResultInfoCollection.Add(exportResultInfo);
                }
            }

            var exception = await App.SafeActionAsync(() => _outputViewer.ExecuteUsingCancellationToken(ExportRows));

            _exportClockTimer.Stop();

            IsExecuting = false;

            if (exception != null)
            {
                TraceLog.WriteLine($"Saving result to file failed: {exception}");

                CancelWaitingResults();

                Messages.ShowError(exception.Message);
            }
        }