Ejemplo n.º 1
0
        private async Task Run()
        {
            if (IsRunning)
            {
                return;
            }

            try
            {
                await EnsureNuGetPackages().ConfigureAwait(true);
            }
            catch (Exception)
            {
                IsRunning = false;
                throw;
            }

            Reset();

            await MainViewModel.AutoSaveOpenDocuments().ConfigureAwait(true);

            SetIsRunning(true);

            var results = new ObservableCollection <ResultObject>();

            ResultsInternal = results;

            var cancellationToken = _cts.Token;

            HookDumped(results, cancellationToken);
            try
            {
                var code = await GetCode(cancellationToken).ConfigureAwait(true);

                var errorResult = await _executionHost.ExecuteAsync(code).ConfigureAwait(true);

                _onError?.Invoke(errorResult);
                if (errorResult != null)
                {
                    results.Add(errorResult);
                }
            }
            catch (CompilationErrorException ex)
            {
                foreach (var diagnostic in ex.Diagnostics)
                {
                    results.Add(ResultObject.Create(diagnostic));
                }
            }
            catch (Exception ex)
            {
                AddResult(ex, results, cancellationToken);
            }
            finally
            {
                SetIsRunning(false);
            }
        }
Ejemplo n.º 2
0
        private async Task Run()
        {
            if (IsRunning)
            {
                return;
            }

            Reset();

            await MainViewModel.AutoSaveOpenDocuments().ConfigureAwait(false);

            SetIsRunning(true);

            var results = new ObservableCollection <ResultObject>();

            Results = results;

            var cancellationToken = _cts.Token;

            if (_executionHostOnDumped != null)
            {
                _executionHost.Dumped -= _executionHostOnDumped;
            }
            _executionHostOnDumped = o => AddResult(o, results, cancellationToken);
            _executionHost.Dumped += _executionHostOnDumped;
            try
            {
                var code =
                    await
                    MainViewModel.RoslynHost.GetDocument(DocumentId)
                    .GetTextAsync(cancellationToken)
                    .ConfigureAwait(true);

                await _executionHost.ExecuteAsync(code.ToString()).ConfigureAwait(true);
            }
            catch (CompilationErrorException ex)
            {
                foreach (var diagnostic in ex.Diagnostics)
                {
                    results.Add(ResultObject.Create(diagnostic));
                }
            }
            catch (Exception ex)
            {
                AddResult(ex, results, cancellationToken);
            }
            finally
            {
                SetIsRunning(false);
            }
        }