private async Task <ExecuteResult> ExecuteOnUIThread(TaskResult result, Script <object> script)
            {
                var executeResult = await Task.Factory.StartNew(async() =>
                {
                    try
                    {
                        var state = result.State;

                        var task = (state == null) ?
                                   script.RunAsync(_hostObject, CancellationToken.None) :
                                   script.ContinueAsync(state, CancellationToken.None);

                        state = await task.ConfigureAwait(false);

                        return(new ExecuteResult(result.With(state), state.ReturnValue, null, true));
                    }
                    catch (Exception e)
                    {
                        return(new ExecuteResult(result, null, e, false));
                    }
                },
                                                                CancellationToken.None,
                                                                TaskCreationOptions.None,
                                                                s_UIThreadScheduler).Unwrap().ConfigureAwait(false);

                var exception = executeResult.Exception;

                if (exception != null)
                {
                    // TODO (tomat): format exception
                    Console.Error.WriteLine(exception);
                }

                return(executeResult);
            }
            private TaskResult CompleteExecution(TaskResult result, RemoteAsyncOperation <RemoteExecutionResult> operation, bool success, string resolvedPath = null)
            {
                // TODO (tomat): we should be resetting this info just before the execution to ensure that the services see the same
                // as the next execution.

                // send any updates to the host object and current directory back to the client:
                var options             = result.Options;
                var newSourcePaths      = _hostObject.SourcePaths.List.GetNewContent();
                var newReferencePaths   = _hostObject.ReferencePaths.List.GetNewContent();
                var currentDirectory    = Directory.GetCurrentDirectory();
                var oldWorkingDirectory = options.BaseDirectory;
                var newWorkingDirectory = (oldWorkingDirectory != currentDirectory) ? currentDirectory : null;

                // update local search paths, the client updates theirs on operation completion:

                if (newSourcePaths != null)
                {
                    _sourceSearchPaths = newSourcePaths.AsImmutable();
                }

                if (newReferencePaths != null)
                {
                    options = options.WithSearchPaths(newReferencePaths);
                }

                options = options.WithBaseDirectory(currentDirectory);

                operation.Completed(new RemoteExecutionResult(success, newSourcePaths, newReferencePaths, newWorkingDirectory, resolvedPath));
                return(result.With(options));
            }
Exemplo n.º 3
0
            private async Task<ExecuteResult> ExecuteOnUIThread(TaskResult result, Script<object> script)
            {
                var executeResult = await Task.Factory.StartNew(async () =>
                    {
                        try
                        {
                            var state = result.State;
                            var globals = state ?? (object)_hostObject;
                            state = script.RunAsync(globals, CancellationToken.None);
                            var value = await state.ReturnValue.ConfigureAwait(false);
                            return new ExecuteResult(result.With(state), value, null, true);
                        }
                        catch (Exception e)
                        {
                            return new ExecuteResult(result, null, e, false);
                        }
                    },
                    CancellationToken.None,
                    TaskCreationOptions.None,
                    s_UIThreadScheduler).Unwrap().ConfigureAwait(false);

                var exception = executeResult.Exception;
                if (exception != null)
                {
                    // TODO (tomat): format exception
                    Console.Error.WriteLine(exception);
                }

                return executeResult;
            }
Exemplo n.º 4
0
            private TaskResult CompleteExecution(TaskResult result, RemoteAsyncOperation<RemoteExecutionResult> operation, bool success, string resolvedPath = null)
            {
                // TODO (tomat): we should be resetting this info just before the execution to ensure that the services see the same
                // as the next execution.

                // send any updates to the host object and current directory back to the client:
                var options = result.Options;
                var newSourcePaths = _hostObject.SourcePaths.List.GetNewContent();
                var newReferencePaths = _hostObject.ReferencePaths.List.GetNewContent();
                var currentDirectory = Directory.GetCurrentDirectory();
                var oldWorkingDirectory = options.BaseDirectory;
                var newWorkingDirectory = (oldWorkingDirectory != currentDirectory) ? currentDirectory : null;

                // update local search paths, the client updates theirs on operation completion:

                if (newSourcePaths != null)
                {
                    _sourceSearchPaths = newSourcePaths.AsImmutable();
                }

                if (newReferencePaths != null)
                {
                    options = options.WithSearchPaths(newReferencePaths);
                }

                options = options.WithBaseDirectory(currentDirectory);

                operation.Completed(new RemoteExecutionResult(success, newSourcePaths, newReferencePaths, newWorkingDirectory, resolvedPath));
                return result.With(options);
            }