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); }
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); } }
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 = Environment.CurrentDirectory; 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)); }
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)); }
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 <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)); }
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)); }
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); }
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 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 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 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<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); }
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); }