Beispiel #1
0
        public OutputViewer(DocumentPage documentPage)
        {
            DocumentPage = documentPage;

            FileResultViewer = new FileResultViewer(this);

            InitializeComponent();

            _timerExecutionMonitor = new DispatcherTimer(DispatcherPriority.Normal, Dispatcher)
            {
                Interval = TimeSpan.FromMilliseconds(100)
            };
            _timerExecutionMonitor.Tick += TimerExecutionMonitorTickHandler;

            Application.Current.Deactivated += ApplicationDeactivatedHandler;

            Initialize();

            _providerConfiguration = WorkDocumentCollection.GetProviderConfiguration(DocumentPage.CurrentConnection.ProviderName);

            ConnectionAdapter = DocumentPage.DatabaseModel.CreateConnectionAdapter();

            StatementValidator = DocumentPage.InfrastructureFactory.CreateStatementValidator();

            ExecutionPlanViewer      = DocumentPage.InfrastructureFactory.CreateExecutionPlanViewer(this);
            TabExecutionPlan.Content = ExecutionPlanViewer.Control;

            TraceViewer      = DocumentPage.InfrastructureFactory.CreateTraceViewer(ConnectionAdapter);
            TabTrace.Content = TraceViewer.Control;

            BreakOnExceptions = DocumentPage.WorkDocument.BreakOnExceptions;
        }
Beispiel #2
0
        private async Task DisplayExecutionResult()
        {
            WriteDatabaseOutput(_executionResult.DatabaseOutput);

            var keepPreviousSelectedTab = false;

            if (_executionResult.ExecutionModel.GatherExecutionStatistics)
            {
                await ExecutionPlanViewer.ShowActualAsync(ConnectionAdapter, _statementExecutionCancellationTokenSource.Token);

                TabExecutionPlan.Visibility = Visibility.Visible;
                _sessionExecutionStatistics.MergeWith(await ConnectionAdapter.GetExecutionStatisticsAsync(_statementExecutionCancellationTokenSource.Token));
                SelectPreviousTab();
                keepPreviousSelectedTab = _previousSelectedTab.In(TabExecutionPlan, TabStatistics);
            }
            else if (IsPreviousTabAlwaysVisible)
            {
                SelectPreviousTab();
            }

            var lastStatementResult = _executionResult.StatementResults.Last();

            if (lastStatementResult.CompilationErrors.Count > 0)
            {
                var lineOffset = DocumentPage.Editor.GetLineNumberByOffset(lastStatementResult.StatementModel.ValidationModel.Statement.SourcePosition.IndexStart);
                foreach (var error in lastStatementResult.CompilationErrors)
                {
                    error.Line += lineOffset;
                    _compilationErrors.Add(error);
                }

                TabControlResult.SelectedItem = TabCompilationErrors;
            }

            if (DataOutputType == DataOutputType.File)
            {
                await FileResultViewer.SaveExecutionResult(_executionResult);

                if (!keepPreviousSelectedTab)
                {
                    TabControlResult.SelectedIndex = 0;
                }
            }
            else
            {
                await InitializeResultViewers();

                if (DataGridResultViewers.Any())
                {
                    StatusInfo.ResultGridAvailable = true;

                    if (!keepPreviousSelectedTab)
                    {
                        TabControlResult.SelectedIndex = 0;
                    }
                }
                else
                {
                    StatusInfo.SuccessfulExecutionMessage = lastStatementResult.SuccessfulExecutionMessage;
                }
            }
        }
Beispiel #3
0
        private async Task ExecuteDatabaseCommandAsyncInternal(StatementBatchExecutionModel executionModel)
        {
            if (executionModel.Statements.Count == 0)
            {
                return;
            }

            var beforeExecutionText = DocumentPage.Editor.Text;

            Initialize();

            FileResultViewer.Initialize();

            ConnectionAdapter.EnableDatabaseOutput = EnableDatabaseOutput;

            Task <StatementExecutionBatchResult> innerTask = null;
            var actionResult = await SafeTimedActionAsync(() => innerTask = ConnectionAdapter.ExecuteStatementAsync(executionModel, _statementExecutionCancellationTokenSource.Token));

            HasActiveTransaction  = ConnectionAdapter.HasActiveTransaction;
            TransactionIdentifier = ConnectionAdapter.TransanctionIdentifier;

            if (!actionResult.IsSuccessful)
            {
                if (actionResult.Exception is StatementExecutionException executionException)
                {
                    UpdateExecutionLog(executionException.BatchResult.StatementResults);
                    WriteDatabaseOutput(executionException.BatchResult.DatabaseOutput);

                    var lastStatementResult = executionException.BatchResult.StatementResults.Last();
                    var errorPosition       = lastStatementResult.ErrorPosition;
                    if (errorPosition.HasValue && String.Equals(beforeExecutionText, DocumentPage.Editor.Text))
                    {
                        DocumentPage.Editor.CaretOffset = lastStatementResult.StatementModel.Statement.RootNode.SourcePosition.IndexStart + errorPosition.Value;
                    }
                }

                Messages.ShowError(actionResult.Exception.Message);
                return;
            }

            _executionResult = innerTask.Result;

            if (ConnectionAdapter.DebuggerSession != null)
            {
                DebuggerViewer.Initialize(this, ConnectionAdapter.DebuggerSession);
                ConnectionAdapter.DebuggerSession.Attached += delegate { Dispatcher.Invoke(DebuggerSessionSynchronizedHandler); };
                ConnectionAdapter.DebuggerSession.Detached += DebuggerSessionDetachedHandler;
                var exception = await App.SafeActionAsync(() => ConnectionAdapter.DebuggerSession.Start(_statementExecutionCancellationTokenSource.Token));

                if (exception != null)
                {
                    Messages.ShowError(exception.Message);
                }

                return;
            }

            UpdateExecutionLog(_executionResult.StatementResults);

            UpdateHistoryEntries();

            if (_executionResult.StatementResults.Last().ExecutedSuccessfully == false)
            {
                NotifyExecutionCanceled();
                return;
            }

            UpdateTimerMessage(actionResult.Elapsed, false);

            await DisplayExecutionResult();
        }