public void InitializeContextAsync(RemoteAsyncOperation <RemoteExecutionResult> operation, string initializationFile, bool isRestarting) { Debug.Assert(operation != null); lock (_lastTaskGuard) { _lastTask = InitializeContextAsync(_lastTask, operation, initializationFile, isRestarting); } }
public void ExecuteFileAsync(RemoteAsyncOperation <RemoteExecutionResult> operation, string path) { Debug.Assert(operation != null); Debug.Assert(path != null); lock (_lastTaskGuard) { _lastTask = ExecuteFileAsync(operation, _lastTask, options => ResolveRelativePath(path, options.BaseDirectory, displayPath: false)); } }
public void ExecuteFileAsync(RemoteAsyncOperation <RemoteExecutionResult> operation, string path) { Debug.Assert(operation != null); Debug.Assert(path != null); lock (_lastTaskGuard) { _lastTask = ExecuteFileAsync(operation, _lastTask, path); } }
public void AddReferenceAsync(RemoteAsyncOperation <bool> operation, string reference) { Debug.Assert(operation != null); Debug.Assert(reference != null); lock (_lastTaskGuard) { _lastTask = AddReferenceAsync(_lastTask, operation, reference); } }
public void ExecuteAsync(RemoteAsyncOperation <RemoteExecutionResult> operation, string text) { Debug.Assert(operation != null); Debug.Assert(text != null); lock (_lastTaskGuard) { _lastTask = ExecuteAsync(_lastTask, operation, text); } }
public void SetPaths( RemoteAsyncOperation <RemoteExecutionResult> operation, string[] referenceSearchPaths, string[] sourceSearchPaths, string baseDirectory) { lock (_lastTaskGuard) { _lastTask = SetPathsAsync(_lastTask, operation, referenceSearchPaths, sourceSearchPaths, baseDirectory); } }
public void SetPathsAsync( RemoteAsyncOperation <RemoteExecutionResult> operation, string[] referenceSearchPaths, string[] sourceSearchPaths, string baseDirectory) { Debug.Assert(operation != null); Debug.Assert(referenceSearchPaths != null); Debug.Assert(sourceSearchPaths != null); Debug.Assert(baseDirectory != null); lock (_lastTaskGuard) { _lastTask = SetPathsAsync(_lastTask, operation, referenceSearchPaths, sourceSearchPaths, baseDirectory); } }
private EvaluationState CompleteExecution(EvaluationState state, RemoteAsyncOperation <RemoteExecutionResult> operation, bool success) { // send any updates to the host object and current directory back to the client: var globals = GetServiceState().Globals; var currentSourcePaths = globals.SourcePaths.ToArray(); var currentReferencePaths = globals.ReferencePaths.ToArray(); var currentWorkingDirectory = Directory.GetCurrentDirectory(); var changedSourcePaths = currentSourcePaths.SequenceEqual(state.SourceSearchPaths) ? null : currentSourcePaths; var changedReferencePaths = currentReferencePaths.SequenceEqual(state.ReferenceSearchPaths) ? null : currentReferencePaths; var changedWorkingDirectory = currentWorkingDirectory == state.WorkingDirectory ? null : currentWorkingDirectory; operation.Completed(new RemoteExecutionResult(success, changedSourcePaths, changedReferencePaths, changedWorkingDirectory)); // no changes in resolvers: if (changedReferencePaths == null && changedSourcePaths == null && changedWorkingDirectory == null) { return(state); } var newSourcePaths = ImmutableArray.CreateRange(currentSourcePaths); var newReferencePaths = ImmutableArray.CreateRange(currentReferencePaths); var newWorkingDirectory = currentWorkingDirectory; ScriptOptions newOptions = state.ScriptOptions; if (changedReferencePaths != null || changedWorkingDirectory != null) { newOptions = newOptions.WithMetadataResolver(CreateMetadataReferenceResolver(newReferencePaths, newWorkingDirectory)); } if (changedSourcePaths != null || changedWorkingDirectory != null) { newOptions = newOptions.WithSourceResolver(CreateSourceReferenceResolver(newSourcePaths, newWorkingDirectory)); } return(new EvaluationState( state.ScriptState, newOptions, newSourcePaths, newReferencePaths, workingDirectory: newWorkingDirectory)); }
public void ExecuteAsync(RemoteAsyncOperation <RemoteExecutionResult> operation, string text) { Debug.Assert(operation != null); Debug.Assert(text != null); var success = false; try { success = Execute(text); } catch (Exception e) { ReportUnhandledException(e); } finally { CompleteExecution(operation, success); } }
public void InitializeContextAsync(RemoteAsyncOperation <RemoteExecutionResult> operation, string initializationFile, bool isRestarting) { Debug.Assert(operation != null); var success = false; try { InitializeContext(initializationFile, isRestarting); success = true; } catch (Exception e) { ReportUnhandledException(e); } finally { CompleteExecution(operation, success); } }
private async Task <EvaluationState> ExecuteFileAsync( RemoteAsyncOperation <RemoteExecutionResult> operation, Task <EvaluationState> lastTask, string path) { var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); string fullPath = ResolveRelativePath(path, state.WorkingDirectory, state.SourceSearchPaths, displayPath: false); if (fullPath != null) { var newScriptState = await TryExecuteFileAsync(state, fullPath).ConfigureAwait(false); if (newScriptState != null) { return(CompleteExecution(state.WithScriptState(newScriptState), operation, success: newScriptState.Exception == null)); } } return(CompleteExecution(state, operation, success: false)); }
public void ExecuteFileAsync(RemoteAsyncOperation <RemoteExecutionResult> operation, string path) { Debug.Assert(operation != null); Debug.Assert(path != null); string fullPath = null; bool success = false; try { fullPath = ResolveRelativePath(path, _options.BaseDirectory, displayPath: false); success = fullPath != null && ExecuteFile(fullPath); } catch (Exception e) { ReportUnhandledException(e); } finally { CompleteExecution(operation, success, fullPath); } }
private async Task <TaskResult> ExecuteFileAsync( RemoteAsyncOperation <RemoteExecutionResult> operation, Task <TaskResult> lastTask, Func <ScriptOptions, string> getFullPath) { var result = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); var success = false; try { var fullPath = getFullPath(result.Options); var executeResult = await ExecuteFileAsync(result, fullPath).ConfigureAwait(false); result = executeResult.Result; success = executeResult.Success; } finally { result = CompleteExecution(result, operation, success); } return(result); }
private async Task<TaskResult> ExecuteAsync(Task<TaskResult> lastTask, RemoteAsyncOperation<RemoteExecutionResult> operation, string text) { var result = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); var success = false; try { Script<object> script; try { var options = result.Options; var state = result.State; script = Compile(state, text, null, ref options); result = new TaskResult(options, state); } catch (CompilationErrorException e) { DisplayInteractiveErrors(e.Diagnostics, Console.Error); script = null; } if (script != null) { success = true; // successful if compiled var executeResult = await ExecuteOnUIThread(result, script).ConfigureAwait(false); result = executeResult.Result; if (executeResult.Success) { bool hasValue; var resultType = script.GetCompilation().GetSubmissionResultType(out hasValue); if (hasValue) { if (resultType != null && resultType.SpecialType == SpecialType.System_Void) { Console.Out.WriteLine(_objectFormatter.VoidDisplayString); } else { Console.Out.WriteLine(_objectFormatter.FormatObject(executeResult.Value, _formattingOptions)); } } } } } catch (Exception e) { ReportUnhandledException(e); } finally { result = CompleteExecution(result, operation, success); } return result; }
public void SetPathsAsync( RemoteAsyncOperation<object> operation, string[] referenceSearchPaths, string[] sourceSearchPaths, string baseDirectory) { Debug.Assert(operation != null); Debug.Assert(referenceSearchPaths != null); Debug.Assert(sourceSearchPaths != null); Debug.Assert(baseDirectory != null); lock (_sessionGuard) { _hostObject.ReferencePaths.Clear(); _hostObject.ReferencePaths.AddRange(referenceSearchPaths); _options = _options.WithSearchPaths(referenceSearchPaths).WithBaseDirectory(baseDirectory); _hostObject.SourcePaths.Clear(); _hostObject.SourcePaths.AddRange(sourceSearchPaths); _sourceSearchPaths = sourceSearchPaths.AsImmutable(); Directory.SetCurrentDirectory(baseDirectory); } operation.Completed(null); }
private async Task<EvaluationState> ExecuteFileAsync( RemoteAsyncOperation<RemoteExecutionResult> operation, Task<EvaluationState> lastTask, string path) { var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); string fullPath = ResolveRelativePath(path, state.WorkingDirectory, state.SourceSearchPaths, displayPath: false); if (fullPath != null) { var newScriptState = await TryExecuteFileAsync(state, fullPath).ConfigureAwait(false); if (newScriptState != null) { return CompleteExecution(state.WithScriptState(newScriptState), operation, success: newScriptState.Exception == null); } } return CompleteExecution(state, operation, success: false); }
public void ExecuteFileAsync(RemoteAsyncOperation<RemoteExecutionResult> operation, string path) { Debug.Assert(operation != null); Debug.Assert(path != null); lock (_lastTaskGuard) { _lastTask = ExecuteFileAsync(operation, _lastTask, options => ResolveRelativePath(path, options.BaseDirectory, displayPath: false)); } }
public void ExecuteAsync(RemoteAsyncOperation<RemoteExecutionResult> operation, string text) { Debug.Assert(operation != null); Debug.Assert(text != null); var success = false; try { success = Execute(text); } catch (Exception e) { ReportUnhandledException(e); } finally { CompleteExecution(operation, success); } }
private EvaluationState CompleteExecution(EvaluationState state, RemoteAsyncOperation<RemoteExecutionResult> operation, bool success) { // send any updates to the host object and current directory back to the client: var currentSourcePaths = _globals.SourcePaths.ToArray(); var currentReferencePaths = _globals.ReferencePaths.ToArray(); var currentWorkingDirectory = Directory.GetCurrentDirectory(); var changedSourcePaths = currentSourcePaths.SequenceEqual(state.SourceSearchPaths) ? null : currentSourcePaths; var changedReferencePaths = currentReferencePaths.SequenceEqual(state.ReferenceSearchPaths) ? null : currentReferencePaths; var changedWorkingDirectory = currentWorkingDirectory == state.WorkingDirectory ? null : currentWorkingDirectory; operation.Completed(new RemoteExecutionResult(success, changedSourcePaths, changedReferencePaths, changedWorkingDirectory)); // no changes in resolvers: if (changedReferencePaths == null && changedSourcePaths == null && changedWorkingDirectory == null) { return state; } var newSourcePaths = ImmutableArray.CreateRange(currentSourcePaths); var newReferencePaths = ImmutableArray.CreateRange(currentReferencePaths); var newWorkingDirectory = currentWorkingDirectory; ScriptOptions newOptions = state.ScriptOptions; if (changedReferencePaths != null || changedWorkingDirectory != null) { newOptions = newOptions.WithMetadataResolver(CreateMetadataReferenceResolver(newReferencePaths, newWorkingDirectory)); } if (changedSourcePaths != null || changedWorkingDirectory != null) { newOptions = newOptions.WithSourceResolver(CreateSourceReferenceResolver(newSourcePaths, newWorkingDirectory)); } return new EvaluationState( state.ScriptStateOpt, newOptions, newSourcePaths, newReferencePaths, workingDirectory: newWorkingDirectory); }
/// <summary> /// Loads references, set options and execute files specified in the initialization file. /// Also prints logo unless <paramref name="isRestarting"/> is true. /// </summary> private async Task <TaskResult> InitializeContextAsync( Task <TaskResult> lastTask, RemoteAsyncOperation <RemoteExecutionResult> operation, string initializationFileOpt, bool isRestarting) { Debug.Assert(initializationFileOpt == null || PathUtilities.IsAbsolute(initializationFileOpt)); var result = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); try { // TODO (tomat): this is also done in CommonInteractiveEngine, perhaps we can pass the parsed command lines to here? if (!isRestarting) { Console.Out.WriteLine(_repl.GetLogo()); } if (File.Exists(initializationFileOpt)) { Console.Out.WriteLine(string.Format(FeaturesResources.LoadingContextFrom, Path.GetFileName(initializationFileOpt))); var parser = _repl.GetCommandLineParser(); // The base directory for relative paths is the directory that contains the .rsp file. // Note that .rsp files included by this .rsp file will share the base directory (Dev10 behavior of csc/vbc). var rspDirectory = Path.GetDirectoryName(initializationFileOpt); var args = parser.Parse(new[] { "@" + initializationFileOpt }, rspDirectory, RuntimeEnvironment.GetRuntimeDirectory(), null /* TODO: pass a valid value*/); foreach (var error in args.Errors) { var writer = (error.Severity == DiagnosticSeverity.Error) ? Console.Error : Console.Out; writer.WriteLine(error.GetMessage(CultureInfo.CurrentCulture)); } if (args.Errors.Length == 0) { // TODO (tomat): other arguments // TODO (tomat): parse options var referencePaths = args.ReferencePaths; result = result.With(result.Options.AddSearchPaths(referencePaths)); _hostObject.ReferencePaths.Clear(); _hostObject.ReferencePaths.AddRange(referencePaths); // TODO (tomat): consolidate with other reference resolving foreach (CommandLineReference cmdLineReference in args.MetadataReferences) { // interactive command line parser doesn't accept modules or linked assemblies Debug.Assert(cmdLineReference.Properties.Kind == MetadataImageKind.Assembly && !cmdLineReference.Properties.EmbedInteropTypes); var options = result.Options; string fullPath = ResolveReferencePath(options, cmdLineReference.Reference, baseFilePath: null); LoadReference(fullPath, suppressWarnings: true, addReference: true, options: ref options); result = result.With(options); } foreach (CommandLineSourceFile file in args.SourceFiles) { // execute all files as scripts (matches csi/vbi semantics) string fullPath = ResolveRelativePath(file.Path, rspDirectory, displayPath: true); if (fullPath != null) { var executeResult = await ExecuteFileAsync(result, fullPath).ConfigureAwait(false); result = executeResult.Result; } } } } if (!isRestarting) { Console.Out.WriteLine(FeaturesResources.TypeHelpForMoreInformation); } } catch (Exception e) { ReportUnhandledException(e); } finally { result = CompleteExecution(result, operation, true); } return(result); }
public void InitializeContextAsync(RemoteAsyncOperation<RemoteExecutionResult> operation, string initializationFile, bool isRestarting) { Debug.Assert(operation != null); lock (_lastTaskGuard) { _lastTask = InitializeContextAsync(_lastTask, operation, initializationFile, isRestarting); } }
private async Task <TaskResult> AddReferenceAsync(Task <TaskResult> lastTask, RemoteAsyncOperation <bool> operation, string reference) { var result = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); var success = false; var options = result.Options; try { string fullPath = ResolveReferencePath(options, reference, baseFilePath: null); if (fullPath != null) { success = LoadReference(fullPath, suppressWarnings: false, addReference: true, options: ref options); } else { Console.Error.WriteLine(string.Format(FeaturesResources.CannotResolveReference, reference)); } } catch (Exception e) { ReportUnhandledException(e); } finally { operation.Completed(success); } return(result.With(options)); }
/// <summary> /// Loads references, set options and execute files specified in the initialization file. /// Also prints logo unless <paramref name="isRestarting"/> is true. /// </summary> private async Task <EvaluationState> InitializeContextAsync( Task <EvaluationState> lastTask, RemoteAsyncOperation <RemoteExecutionResult> operation, string initializationFileOpt, bool isRestarting) { Debug.Assert(initializationFileOpt == null || PathUtilities.IsAbsolute(initializationFileOpt)); var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); try { // TODO (tomat): this is also done in CommonInteractiveEngine, perhaps we can pass the parsed command lines to here? if (!isRestarting) { Console.Out.WriteLine(_replServiceProvider.Logo); } if (File.Exists(initializationFileOpt)) { Console.Out.WriteLine(string.Format(FeaturesResources.LoadingContextFrom, Path.GetFileName(initializationFileOpt))); var parser = _replServiceProvider.CommandLineParser; // The base directory for relative paths is the directory that contains the .rsp file. // Note that .rsp files included by this .rsp file will share the base directory (Dev10 behavior of csc/vbc). var rspDirectory = Path.GetDirectoryName(initializationFileOpt); var args = parser.Parse(new[] { "@" + initializationFileOpt }, rspDirectory, RuntimeEnvironment.GetRuntimeDirectory(), null /* TODO: pass a valid value*/); foreach (var error in args.Errors) { var writer = (error.Severity == DiagnosticSeverity.Error) ? Console.Error : Console.Out; writer.WriteLine(error.GetMessage(CultureInfo.CurrentCulture)); } if (args.Errors.Length == 0) { // TODO (tomat): other arguments // TODO (tomat): parse options var metadataResolver = CreateMetadataReferenceResolver(args.ReferencePaths, rspDirectory); _hostObject.ReferencePaths.Clear(); _hostObject.ReferencePaths.AddRange(args.ReferencePaths); _hostObject.SourcePaths.Clear(); var metadataReferences = new List <PortableExecutableReference>(); foreach (CommandLineReference cmdLineReference in args.MetadataReferences) { // interactive command line parser doesn't accept modules or linked assemblies Debug.Assert(cmdLineReference.Properties.Kind == MetadataImageKind.Assembly && !cmdLineReference.Properties.EmbedInteropTypes); var resolvedReferences = metadataResolver.ResolveReference(cmdLineReference.Reference, baseFilePath: null, properties: MetadataReferenceProperties.Assembly); if (!resolvedReferences.IsDefaultOrEmpty) { metadataReferences.AddRange(resolvedReferences); } } // only search for scripts next to the .rsp file: var sourceSearchPaths = ImmutableArray <string> .Empty; var rspState = new EvaluationState( state.ScriptStateOpt, state.ScriptOptions.AddReferences(metadataReferences), sourceSearchPaths, args.ReferencePaths, rspDirectory); foreach (CommandLineSourceFile file in args.SourceFiles) { // execute all files as scripts (matches csi/vbi semantics) string fullPath = ResolveRelativePath(file.Path, rspDirectory, sourceSearchPaths, displayPath: true); if (fullPath != null) { var newScriptState = await ExecuteFileAsync(rspState, fullPath).ConfigureAwait(false); if (newScriptState != null) { rspState = rspState.WithScriptState(newScriptState); } } } state = new EvaluationState( rspState.ScriptStateOpt, rspState.ScriptOptions, ImmutableArray <string> .Empty, args.ReferencePaths, state.WorkingDirectory); } } if (!isRestarting) { Console.Out.WriteLine(FeaturesResources.TypeHelpForMoreInformation); } } catch (Exception e) { ReportUnhandledException(e); } finally { state = CompleteExecution(state, operation, success: true); } return(state); }
public void InitializeContextAsync(RemoteAsyncOperation<RemoteExecutionResult> operation, string initializationFile, bool isRestarting) { Debug.Assert(operation != null); var success = false; try { InitializeContext(initializationFile, isRestarting); success = true; } catch (Exception e) { ReportUnhandledException(e); } finally { CompleteExecution(operation, success); } }
private void CompleteExecution(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 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)); }
public void ExecuteFileAsync(RemoteAsyncOperation<RemoteExecutionResult> operation, string path) { Debug.Assert(operation != null); Debug.Assert(path != null); string fullPath = null; bool success = false; try { fullPath = ResolveRelativePath(path, _options.BaseDirectory, displayPath: false); success = fullPath != null && ExecuteFile(fullPath); } catch (Exception e) { ReportUnhandledException(e); } finally { CompleteExecution(operation, success, fullPath); } }
public void SetPathsAsync( RemoteAsyncOperation<RemoteExecutionResult> operation, string[] referenceSearchPaths, string[] sourceSearchPaths, string baseDirectory) { Debug.Assert(operation != null); Debug.Assert(referenceSearchPaths != null); Debug.Assert(sourceSearchPaths != null); Debug.Assert(baseDirectory != null); lock (_lastTaskGuard) { _lastTask = SetPathsAsync(_lastTask, operation, referenceSearchPaths, sourceSearchPaths, baseDirectory); } }
private async Task<EvaluationState> AddReferenceAsync(Task<EvaluationState> lastTask, RemoteAsyncOperation<bool> operation, string reference) { var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); bool success = false; try { var resolvedReferences = state.ScriptOptions.MetadataResolver.ResolveReference(reference, baseFilePath: null, properties: MetadataReferenceProperties.Assembly); if (!resolvedReferences.IsDefaultOrEmpty) { state = state.WithOptions(state.ScriptOptions.AddReferences(resolvedReferences)); success = true; } else { Console.Error.WriteLine(string.Format(FeaturesResources.Cannot_resolve_reference_0, reference)); } } catch (Exception e) { ReportUnhandledException(e); } finally { operation.Completed(success); } return state; }
private async Task<EvaluationState> SetPathsAsync( Task<EvaluationState> lastTask, RemoteAsyncOperation<RemoteExecutionResult> operation, string[] referenceSearchPaths, string[] sourceSearchPaths, string baseDirectory) { var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); try { Directory.SetCurrentDirectory(baseDirectory); _globals.ReferencePaths.Clear(); _globals.ReferencePaths.AddRange(referenceSearchPaths); _globals.SourcePaths.Clear(); _globals.SourcePaths.AddRange(sourceSearchPaths); } finally { state = CompleteExecution(state, operation, success: true); } return state; }
private async Task<EvaluationState> ExecuteAsync(Task<EvaluationState> lastTask, RemoteAsyncOperation<RemoteExecutionResult> operation, string text) { var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); bool success = false; try { Script<object> script = TryCompile(state.ScriptStateOpt?.Script, text, null, state.ScriptOptions); if (script != null) { // successful if compiled success = true; // remove references and imports from the options, they have been applied and will be inherited from now on: state = state.WithOptions(state.ScriptOptions.RemoveImportsAndReferences()); var newScriptState = await ExecuteOnUIThread(script, state.ScriptStateOpt, displayResult: true).ConfigureAwait(false); state = state.WithScriptState(newScriptState); } } catch (Exception e) { ReportUnhandledException(e); } finally { state = CompleteExecution(state, operation, success); } return state; }
public void AddReferenceAsync(RemoteAsyncOperation<bool> operation, string reference) { Debug.Assert(operation != null); Debug.Assert(reference != null); lock (_lastTaskGuard) { _lastTask = AddReferenceAsync(_lastTask, operation, reference); } }
public void AddReferenceAsync(RemoteAsyncOperation<bool> operation, string reference) { Debug.Assert(operation != null); Debug.Assert(reference != null); var success = false; try { // TODO (tomat): This lock blocks all other session operations. // We should be able to run multiple assembly resolutions and code execution in parallel. string fullPath; lock (_sessionGuard) { fullPath = ResolveReferencePath(reference, baseFilePath: null); if (fullPath != null) { success = LoadReference(fullPath, suppressWarnings: false, addReference: true); } } if (fullPath == null) { Console.Error.WriteLine(string.Format(FeaturesResources.CannotResolveReference, reference)); } } catch (Exception e) { ReportUnhandledException(e); } finally { operation.Completed(success); } }
public void ExecuteAsync(RemoteAsyncOperation<RemoteExecutionResult> operation, string text) { Debug.Assert(operation != null); Debug.Assert(text != null); lock (_lastTaskGuard) { _lastTask = ExecuteAsync(_lastTask, operation, text); } }
private async Task<TaskResult> ExecuteFileAsync( RemoteAsyncOperation<RemoteExecutionResult> operation, Task<TaskResult> lastTask, Func<ScriptOptions, string> getFullPath) { var result = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); var success = false; try { var fullPath = getFullPath(result.Options); var executeResult = await ExecuteFileAsync(result, fullPath).ConfigureAwait(false); result = executeResult.Result; success = executeResult.Success; } finally { result = CompleteExecution(result, operation, success); } return result; }
public void ExecuteFileAsync(RemoteAsyncOperation<RemoteExecutionResult> operation, string path) { Debug.Assert(operation != null); Debug.Assert(path != null); lock (_lastTaskGuard) { _lastTask = ExecuteFileAsync(operation, _lastTask, path); } }
private async Task<TaskResult> AddReferenceAsync(Task<TaskResult> lastTask, RemoteAsyncOperation<bool> operation, string reference) { var result = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); var success = false; var options = result.Options; try { string fullPath = ResolveReferencePath(options, reference, baseFilePath: null); if (fullPath != null) { success = LoadReference(fullPath, suppressWarnings: false, addReference: true, options: ref options); } else { Console.Error.WriteLine(string.Format(FeaturesResources.CannotResolveReference, reference)); } } catch (Exception e) { ReportUnhandledException(e); } finally { operation.Completed(success); } return result.With(options); }
/// <summary> /// Loads references, set options and execute files specified in the initialization file. /// Also prints logo unless <paramref name="isRestarting"/> is true. /// </summary> private async Task<EvaluationState> InitializeContextAsync( Task<EvaluationState> lastTask, RemoteAsyncOperation<RemoteExecutionResult> operation, string initializationFileOpt, bool isRestarting) { Debug.Assert(initializationFileOpt == null || PathUtilities.IsAbsolute(initializationFileOpt)); var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); try { // TODO (tomat): this is also done in CommonInteractiveEngine, perhaps we can pass the parsed command lines to here? if (!isRestarting) { Console.Out.WriteLine(_replServiceProvider.Logo); } if (File.Exists(initializationFileOpt)) { Console.Out.WriteLine(string.Format(FeaturesResources.Loading_context_from_0, Path.GetFileName(initializationFileOpt))); var parser = _replServiceProvider.CommandLineParser; // The base directory for relative paths is the directory that contains the .rsp file. // Note that .rsp files included by this .rsp file will share the base directory (Dev10 behavior of csc/vbc). var rspDirectory = Path.GetDirectoryName(initializationFileOpt); var args = parser.Parse(new[] { "@" + initializationFileOpt }, rspDirectory, RuntimeEnvironment.GetRuntimeDirectory(), null); foreach (var error in args.Errors) { var writer = (error.Severity == DiagnosticSeverity.Error) ? Console.Error : Console.Out; writer.WriteLine(error.GetMessage(CultureInfo.CurrentCulture)); } if (args.Errors.Length == 0) { var metadataResolver = CreateMetadataReferenceResolver(args.ReferencePaths, rspDirectory); var sourceResolver = CreateSourceReferenceResolver(args.SourcePaths, rspDirectory); var metadataReferences = new List<PortableExecutableReference>(); foreach (CommandLineReference cmdLineReference in args.MetadataReferences) { // interactive command line parser doesn't accept modules or linked assemblies Debug.Assert(cmdLineReference.Properties.Kind == MetadataImageKind.Assembly && !cmdLineReference.Properties.EmbedInteropTypes); var resolvedReferences = metadataResolver.ResolveReference(cmdLineReference.Reference, baseFilePath: null, properties: MetadataReferenceProperties.Assembly); if (!resolvedReferences.IsDefaultOrEmpty) { metadataReferences.AddRange(resolvedReferences); } } var scriptPathOpt = args.SourceFiles.IsEmpty ? null : args.SourceFiles[0].Path; var rspState = new EvaluationState( state.ScriptStateOpt, state.ScriptOptions. WithFilePath(scriptPathOpt). WithReferences(metadataReferences). WithImports(CommandLineHelpers.GetImports(args)). WithMetadataResolver(metadataResolver). WithSourceResolver(sourceResolver), args.SourcePaths, args.ReferencePaths, rspDirectory); _globals.ReferencePaths.Clear(); _globals.ReferencePaths.AddRange(args.ReferencePaths); _globals.SourcePaths.Clear(); _globals.SourcePaths.AddRange(args.SourcePaths); _globals.Args.AddRange(args.ScriptArguments); if (scriptPathOpt != null) { var newScriptState = await TryExecuteFileAsync(rspState, scriptPathOpt).ConfigureAwait(false); if (newScriptState != null) { // remove references and imports from the options, they have been applied and will be inherited from now on: rspState = rspState. WithScriptState(newScriptState). WithOptions(rspState.ScriptOptions.RemoveImportsAndReferences()); } } state = rspState; } } if (!isRestarting) { Console.Out.WriteLine(FeaturesResources.Type_Sharphelp_for_more_information); } } catch (Exception e) { ReportUnhandledException(e); } finally { state = CompleteExecution(state, operation, success: true); } return state; }
private async Task<EvaluationState> ExecuteAsync(Task<EvaluationState> lastTask, RemoteAsyncOperation<RemoteExecutionResult> operation, string text) { var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); bool success = false; try { Script<object> script = TryCompile(state.ScriptStateOpt?.Script, text, null, state.ScriptOptions); if (script != null) { // successful if compiled success = true; var newScriptState = await ExecuteOnUIThread(script, state.ScriptStateOpt).ConfigureAwait(false); if (newScriptState != null) { DisplaySubmissionResult(newScriptState); state = state.WithScriptState(newScriptState); } } } catch (Exception e) { ReportUnhandledException(e); } finally { state = CompleteExecution(state, operation, success); } return state; }
/// <summary> /// Loads references, set options and execute files specified in the initialization file. /// Also prints logo unless <paramref name="isRestarting"/> is true. /// </summary> private async Task<TaskResult> InitializeContextAsync( Task<TaskResult> lastTask, RemoteAsyncOperation<RemoteExecutionResult> operation, string initializationFileOpt, bool isRestarting) { Debug.Assert(initializationFileOpt == null || PathUtilities.IsAbsolute(initializationFileOpt)); var result = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); try { // TODO (tomat): this is also done in CommonInteractiveEngine, perhaps we can pass the parsed command lines to here? if (!isRestarting) { Console.Out.WriteLine(_repl.GetLogo()); } if (File.Exists(initializationFileOpt)) { Console.Out.WriteLine(string.Format(FeaturesResources.LoadingContextFrom, Path.GetFileName(initializationFileOpt))); var parser = _repl.GetCommandLineParser(); // The base directory for relative paths is the directory that contains the .rsp file. // Note that .rsp files included by this .rsp file will share the base directory (Dev10 behavior of csc/vbc). var rspDirectory = Path.GetDirectoryName(initializationFileOpt); var args = parser.Parse(new[] { "@" + initializationFileOpt }, rspDirectory, RuntimeEnvironment.GetRuntimeDirectory(), null /* TODO: pass a valid value*/); foreach (var error in args.Errors) { var writer = (error.Severity == DiagnosticSeverity.Error) ? Console.Error : Console.Out; writer.WriteLine(error.GetMessage(CultureInfo.CurrentCulture)); } if (args.Errors.Length == 0) { // TODO (tomat): other arguments // TODO (tomat): parse options var referencePaths = args.ReferencePaths; result = result.With(result.Options.AddSearchPaths(referencePaths)); _hostObject.ReferencePaths.Clear(); _hostObject.ReferencePaths.AddRange(referencePaths); // TODO (tomat): consolidate with other reference resolving foreach (CommandLineReference cmdLineReference in args.MetadataReferences) { // interactive command line parser doesn't accept modules or linked assemblies Debug.Assert(cmdLineReference.Properties.Kind == MetadataImageKind.Assembly && !cmdLineReference.Properties.EmbedInteropTypes); var options = result.Options; string fullPath = ResolveReferencePath(options, cmdLineReference.Reference, baseFilePath: null); LoadReference(fullPath, suppressWarnings: true, addReference: true, options: ref options); result = result.With(options); } foreach (CommandLineSourceFile file in args.SourceFiles) { // execute all files as scripts (matches csi/vbi semantics) string fullPath = ResolveRelativePath(file.Path, rspDirectory, displayPath: true); if (fullPath != null) { var executeResult = await ExecuteFileAsync(result, fullPath).ConfigureAwait(false); result = executeResult.Result; } } } } if (!isRestarting) { Console.Out.WriteLine(FeaturesResources.TypeHelpForMoreInformation); } } catch (Exception e) { ReportUnhandledException(e); } finally { result = CompleteExecution(result, operation, true); } return result; }
/// <summary> /// Loads references, set options and execute files specified in the initialization file. /// Also prints logo unless <paramref name="isRestarting"/> is true. /// </summary> private async Task<EvaluationState> InitializeContextAsync( Task<EvaluationState> lastTask, RemoteAsyncOperation<RemoteExecutionResult> operation, string initializationFileOpt, bool isRestarting) { Debug.Assert(initializationFileOpt == null || PathUtilities.IsAbsolute(initializationFileOpt)); var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); try { // TODO (tomat): this is also done in CommonInteractiveEngine, perhaps we can pass the parsed command lines to here? if (!isRestarting) { Console.Out.WriteLine(_replServiceProvider.Logo); } if (File.Exists(initializationFileOpt)) { Console.Out.WriteLine(string.Format(FeaturesResources.LoadingContextFrom, Path.GetFileName(initializationFileOpt))); var parser = _replServiceProvider.CommandLineParser; // The base directory for relative paths is the directory that contains the .rsp file. // Note that .rsp files included by this .rsp file will share the base directory (Dev10 behavior of csc/vbc). var rspDirectory = Path.GetDirectoryName(initializationFileOpt); var args = parser.Parse(new[] { "@" + initializationFileOpt }, rspDirectory, RuntimeEnvironment.GetRuntimeDirectory(), null /* TODO: pass a valid value*/); foreach (var error in args.Errors) { var writer = (error.Severity == DiagnosticSeverity.Error) ? Console.Error : Console.Out; writer.WriteLine(error.GetMessage(CultureInfo.CurrentCulture)); } if (args.Errors.Length == 0) { // TODO (tomat): other arguments // TODO (tomat): parse options var metadataResolver = CreateMetadataReferenceResolver(args.ReferencePaths, rspDirectory); _hostObject.ReferencePaths.Clear(); _hostObject.ReferencePaths.AddRange(args.ReferencePaths); _hostObject.SourcePaths.Clear(); var metadataReferences = new List<PortableExecutableReference>(); foreach (CommandLineReference cmdLineReference in args.MetadataReferences) { // interactive command line parser doesn't accept modules or linked assemblies Debug.Assert(cmdLineReference.Properties.Kind == MetadataImageKind.Assembly && !cmdLineReference.Properties.EmbedInteropTypes); var resolvedReferences = metadataResolver.ResolveReference(cmdLineReference.Reference, baseFilePath: null, properties: MetadataReferenceProperties.Assembly); if (!resolvedReferences.IsDefaultOrEmpty) { metadataReferences.AddRange(resolvedReferences); } } // only search for scripts next to the .rsp file: var sourceSearchPaths = ImmutableArray<string>.Empty; var rspState = new EvaluationState( state.ScriptStateOpt, state.ScriptOptions.AddReferences(metadataReferences), sourceSearchPaths, args.ReferencePaths, rspDirectory); foreach (CommandLineSourceFile file in args.SourceFiles) { // execute all files as scripts (matches csi/vbi semantics) string fullPath = ResolveRelativePath(file.Path, rspDirectory, sourceSearchPaths, displayPath: true); if (fullPath != null) { var newScriptState = await ExecuteFileAsync(rspState, fullPath).ConfigureAwait(false); if (newScriptState != null) { rspState = rspState.WithScriptState(newScriptState); } } } state = new EvaluationState( rspState.ScriptStateOpt, rspState.ScriptOptions, ImmutableArray<string>.Empty, args.ReferencePaths, state.WorkingDirectory); } } if (!isRestarting) { Console.Out.WriteLine(FeaturesResources.TypeHelpForMoreInformation); } } catch (Exception e) { ReportUnhandledException(e); } finally { state = CompleteExecution(state, operation, success: true); } return state; }
private async Task <EvaluationState> AddReferenceAsync(Task <EvaluationState> lastTask, RemoteAsyncOperation <bool> operation, string reference) { var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); bool success = false; try { var resolvedReferences = state.ScriptOptions.MetadataResolver.ResolveReference(reference, baseFilePath: null, properties: MetadataReferenceProperties.Assembly); if (!resolvedReferences.IsDefaultOrEmpty) { state = state.WithOptions(state.ScriptOptions.AddReferences(resolvedReferences)); success = true; } else { Console.Error.WriteLine(string.Format(FeaturesResources.CannotResolveReference, reference)); } } catch (Exception e) { ReportUnhandledException(e); } finally { operation.Completed(success); } return(state); }
private async Task<EvaluationState> ExecuteFileAsync( RemoteAsyncOperation<RemoteExecutionResult> operation, Task<EvaluationState> lastTask, string path) { var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); var success = false; try { var fullPath = ResolveRelativePath(path, state.WorkingDirectory, state.SourceSearchPaths, displayPath: false); var newScriptState = await ExecuteFileAsync(state, fullPath).ConfigureAwait(false); if (newScriptState != null) { success = true; state = state.WithScriptState(newScriptState); } } finally { state = CompleteExecution(state, operation, success); } return state; }
private async Task <EvaluationState> ExecuteAsync(Task <EvaluationState> lastTask, RemoteAsyncOperation <RemoteExecutionResult> operation, string text) { var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); bool success = false; try { Script <object> script = TryCompile(state.ScriptStateOpt?.Script, text, null, state.ScriptOptions); if (script != null) { // successful if compiled success = true; // remove references and imports from the options, they have been applied and will be inherited from now on: state = state.WithOptions(state.ScriptOptions.RemoveImportsAndReferences()); var newScriptState = await ExecuteOnUIThread(script, state.ScriptStateOpt).ConfigureAwait(false); if (newScriptState != null) { DisplaySubmissionResult(newScriptState); state = state.WithScriptState(newScriptState); } } } catch (Exception e) { ReportUnhandledException(e); } finally { state = CompleteExecution(state, operation, success); } return(state); }
private async Task <EvaluationState> ExecuteAsync(Task <EvaluationState> lastTask, RemoteAsyncOperation <RemoteExecutionResult> operation, string text) { var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); bool success = false; try { Script <object> script = TryCompile(state.ScriptStateOpt?.Script, text, null, state.ScriptOptions); if (script != null) { // successful if compiled success = true; var newScriptState = await ExecuteOnUIThread(script, state.ScriptStateOpt).ConfigureAwait(false); if (newScriptState != null) { DisplaySubmissionResult(newScriptState); state = state.WithScriptState(newScriptState); } } } catch (Exception e) { ReportUnhandledException(e); } finally { state = CompleteExecution(state, operation, success); } return(state); }
/// <summary> /// Loads references, set options and execute files specified in the initialization file. /// Also prints logo unless <paramref name="isRestarting"/> is true. /// </summary> private async Task <EvaluationState> InitializeContextAsync( Task <EvaluationState> lastTask, RemoteAsyncOperation <RemoteExecutionResult> operation, string initializationFileOpt, bool isRestarting) { Debug.Assert(initializationFileOpt == null || PathUtilities.IsAbsolute(initializationFileOpt)); var state = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); try { // TODO (tomat): this is also done in CommonInteractiveEngine, perhaps we can pass the parsed command lines to here? if (!isRestarting) { Console.Out.WriteLine(_replServiceProvider.Logo); } if (File.Exists(initializationFileOpt)) { Console.Out.WriteLine(string.Format(FeaturesResources.LoadingContextFrom, Path.GetFileName(initializationFileOpt))); var parser = _replServiceProvider.CommandLineParser; // The base directory for relative paths is the directory that contains the .rsp file. // Note that .rsp files included by this .rsp file will share the base directory (Dev10 behavior of csc/vbc). var rspDirectory = Path.GetDirectoryName(initializationFileOpt); var args = parser.Parse(new[] { "@" + initializationFileOpt }, rspDirectory, RuntimeEnvironment.GetRuntimeDirectory(), null); foreach (var error in args.Errors) { var writer = (error.Severity == DiagnosticSeverity.Error) ? Console.Error : Console.Out; writer.WriteLine(error.GetMessage(CultureInfo.CurrentCulture)); } if (args.Errors.Length == 0) { var metadataResolver = CreateMetadataReferenceResolver(args.ReferencePaths, rspDirectory); var sourceResolver = CreateSourceReferenceResolver(args.SourcePaths, rspDirectory); var metadataReferences = new List <PortableExecutableReference>(); foreach (CommandLineReference cmdLineReference in args.MetadataReferences) { // interactive command line parser doesn't accept modules or linked assemblies Debug.Assert(cmdLineReference.Properties.Kind == MetadataImageKind.Assembly && !cmdLineReference.Properties.EmbedInteropTypes); var resolvedReferences = metadataResolver.ResolveReference(cmdLineReference.Reference, baseFilePath: null, properties: MetadataReferenceProperties.Assembly); if (!resolvedReferences.IsDefaultOrEmpty) { metadataReferences.AddRange(resolvedReferences); } } var scriptPathOpt = args.SourceFiles.IsEmpty ? null : args.SourceFiles[0].Path; var rspState = new EvaluationState( state.ScriptStateOpt, state.ScriptOptions. WithFilePath(scriptPathOpt). WithReferences(metadataReferences). WithImports(CommandLineHelpers.GetImports(args)). WithMetadataResolver(metadataResolver). WithSourceResolver(sourceResolver), args.SourcePaths, args.ReferencePaths, rspDirectory); _globals.ReferencePaths.Clear(); _globals.ReferencePaths.AddRange(args.ReferencePaths); _globals.SourcePaths.Clear(); _globals.SourcePaths.AddRange(args.SourcePaths); _globals.Args.AddRange(args.ScriptArguments); if (scriptPathOpt != null) { var newScriptState = await ExecuteFileAsync(rspState, scriptPathOpt).ConfigureAwait(false); if (newScriptState != null) { // remove references and imports from the options, they have been applied and will be inherited from now on: rspState = rspState. WithScriptState(newScriptState). WithOptions(rspState.ScriptOptions.RemoveImportsAndReferences()); } } state = rspState; } } if (!isRestarting) { Console.Out.WriteLine(FeaturesResources.TypeHelpForMoreInformation); } } catch (Exception e) { ReportUnhandledException(e); } finally { state = CompleteExecution(state, operation, success: true); } return(state); }
private async Task<TaskResult> SetPathsAsync( Task<TaskResult> lastTask, RemoteAsyncOperation<object> operation, string[] referenceSearchPaths, string[] sourceSearchPaths, string baseDirectory) { var result = await ReportUnhandledExceptionIfAny(lastTask).ConfigureAwait(false); var options = result.Options; try { Directory.SetCurrentDirectory(baseDirectory); _hostObject.ReferencePaths.Clear(); _hostObject.ReferencePaths.AddRange(referenceSearchPaths); options = options.WithSearchPaths(referenceSearchPaths).WithBaseDirectory(baseDirectory); _hostObject.SourcePaths.Clear(); _hostObject.SourcePaths.AddRange(sourceSearchPaths); _sourceSearchPaths = sourceSearchPaths.AsImmutable(); } finally { operation.Completed(null); } return result.With(options); }