Exemple #1
0
        private bool Execute(string code)
        {
            var task = Host.ExecuteAsync(code);

            task.Wait();
            return(task.Result.Success);
        }
Exemple #2
0
        public async Task <ExecutionResult> ExecuteTextAsync(string text)
        {
            try
            {
                if (InteractiveCommands.InCommand)
                {
                    var cmdResult = InteractiveCommands.TryExecuteCommand();
                    if (cmdResult != null)
                    {
                        return(await cmdResult.ConfigureAwait(false));
                    }
                }

                var result = await _interactiveHost.ExecuteAsync(text).ConfigureAwait(false);

                if (result.Success)
                {
                    SubmissionSuccessfullyExecuted(result);
                }

                return(new ExecutionResult(result.Success));
            }
            catch (Exception e) when(FatalError.Report(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
        public async Task <ExecutionResult> ExecuteCodeAsync(string text)
        {
            try
            {
                if (InteractiveCommands.InCommand)
                {
                    var cmdResult = InteractiveCommands.TryExecuteCommand();
                    if (cmdResult != null)
                    {
                        return(await cmdResult.ConfigureAwait(false));
                    }
                }

                var result = await _interactiveHost.ExecuteAsync(text).ConfigureAwait(false);

                if (result.Success)
                {
                    // We are not executing a command (the current content type is not "Interactive Command"),
                    // so the source document should not have been removed.
                    Debug.Assert(_workspace.CurrentSolution.GetProject(_currentSubmissionProjectId).HasDocuments);

                    SubmissionSuccessfullyExecuted(result);
                }

                return(new ExecutionResult(result.Success));
            }
            catch (Exception e) when(FatalError.Report(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
        private async Task TestKillAfterAsync(int milliseconds)
        {
            using var host = new InteractiveHost(typeof(CSharpReplServiceProvider), ".", millisecondsTimeout: 1, joinOutputWritingThreadsOnDisposal: true);
            var options = InteractiveHostOptions.CreateFromDirectory(TestUtils.HostRootPath, initializationFileName: null, CultureInfo.InvariantCulture, InteractiveHostPlatform.Desktop64);

            host.InteractiveHostProcessCreated += new Action <Process>(proc =>
            {
                _ = Task.Run(async() =>
                {
                    await Task.Delay(milliseconds).ConfigureAwait(false);

                    try
                    {
                        proc.Kill();
                    }
                    catch
                    {
                    }
                });
            });

            await host.ResetAsync(options).ConfigureAwait(false);

            for (int j = 0; j < 10; j++)
            {
                await host.ExecuteAsync("1+1").ConfigureAwait(false);
            }
        }
Exemple #5
0
        private async Task TestKillAfterAsync(int milliseconds)
        {
            using var host = new InteractiveHost(typeof(CSharpReplServiceProvider), ".", millisecondsTimeout: 1, joinOutputWritingThreadsOnDisposal: true);

            host.InteractiveHostProcessCreated += new Action <Process>(proc =>
            {
                _ = Task.Run(async() =>
                {
                    await Task.Delay(milliseconds).ConfigureAwait(false);

                    try
                    {
                        proc.Kill();
                    }
                    catch
                    {
                    }
                });
            });

            await host.ResetAsync(new InteractiveHostOptions(GetInteractiveHostDirectory())).ConfigureAwait(false);

            for (int j = 0; j < 10; j++)
            {
                await host.ExecuteAsync("1+1").ConfigureAwait(false);
            }
        }
Exemple #6
0
        public async Task <ExecutionResult> ExecuteCodeAsync(string text)
        {
            try
            {
                if (InteractiveCommands.InCommand)
                {
                    var cmdResult = InteractiveCommands.TryExecuteCommand();
                    if (cmdResult != null)
                    {
                        return(await cmdResult.ConfigureAwait(false));
                    }
                }

                var result = await _interactiveHost.ExecuteAsync(text).ConfigureAwait(false);

                if (result.Success)
                {
                    // We are not executing a command (the current content type is not "Interactive Command"),
                    // so the source document should not have been removed.
                    Debug.Assert(_workspace.CurrentSolution.GetProject(_currentSubmissionProjectId).HasDocuments);

                    // only remember the submission if we compiled successfully, otherwise we
                    // ignore it's id so we don't reference it in the next submission.
                    _previousSubmissionProjectId = _currentSubmissionProjectId;

                    // Grab any directive references from it
                    var compilation = await _workspace.CurrentSolution.GetProject(_previousSubmissionProjectId).GetCompilationAsync().ConfigureAwait(false);

                    _references = _references.Union(compilation.DirectiveReferences);

                    // update local search paths - remote paths has already been updated
                    UpdateResolvers(result);
                }

                return(new ExecutionResult(result.Success));
            }
            catch (Exception e) when(FatalError.Report(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
        public async Task <bool> Execute(string code)
        {
            var task = await Host.ExecuteAsync(code);

            return(task.Success);
        }
Exemple #8
0
        private async Task <bool> Execute(string code)
        {
            var task = await _host.ExecuteAsync(code);

            return(task.Success);
        }