コード例 #1
0
            public void InitializeContextAsync(RemoteAsyncOperation <RemoteExecutionResult> operation, string initializationFile, bool isRestarting)
            {
                Debug.Assert(operation != null);

                lock (_lastTaskGuard)
                {
                    _lastTask = InitializeContextAsync(_lastTask, operation, initializationFile, isRestarting);
                }
            }
コード例 #2
0
            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));
                }
            }
コード例 #3
0
            public void ExecuteFileAsync(RemoteAsyncOperation <RemoteExecutionResult> operation, string path)
            {
                Debug.Assert(operation != null);
                Debug.Assert(path != null);

                lock (_lastTaskGuard)
                {
                    _lastTask = ExecuteFileAsync(operation, _lastTask, path);
                }
            }
コード例 #4
0
            public void AddReferenceAsync(RemoteAsyncOperation <bool> operation, string reference)
            {
                Debug.Assert(operation != null);
                Debug.Assert(reference != null);

                lock (_lastTaskGuard)
                {
                    _lastTask = AddReferenceAsync(_lastTask, operation, reference);
                }
            }
コード例 #5
0
            public void ExecuteAsync(RemoteAsyncOperation <RemoteExecutionResult> operation, string text)
            {
                Debug.Assert(operation != null);
                Debug.Assert(text != null);

                lock (_lastTaskGuard)
                {
                    _lastTask = ExecuteAsync(_lastTask, operation, text);
                }
            }
コード例 #6
0
 public void SetPaths(
     RemoteAsyncOperation <RemoteExecutionResult> operation,
     string[] referenceSearchPaths,
     string[] sourceSearchPaths,
     string baseDirectory)
 {
     lock (_lastTaskGuard)
     {
         _lastTask = SetPathsAsync(_lastTask, operation, referenceSearchPaths, sourceSearchPaths, baseDirectory);
     }
 }
コード例 #7
0
            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);
                }
            }
コード例 #8
0
            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));
            }
コード例 #9
0
            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);
                }
            }
コード例 #10
0
            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);
                }
            }
コード例 #11
0
            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));
            }
コード例 #12
0
            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);
                }
            }
コード例 #13
0
            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);
            }
コード例 #14
0
            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;
            }
コード例 #15
0
            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);
            }
コード例 #16
0
            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);
            }
コード例 #17
0
            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));
                }
            }
コード例 #18
0
            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);
                }
            }
コード例 #19
0
            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);
            }
コード例 #20
0
            /// <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);
            }
コード例 #21
0
            public void InitializeContextAsync(RemoteAsyncOperation<RemoteExecutionResult> operation, string initializationFile, bool isRestarting)
            {
                Debug.Assert(operation != null);

                lock (_lastTaskGuard)
                {
                    _lastTask = InitializeContextAsync(_lastTask, operation, initializationFile, isRestarting);
                }
            }
コード例 #22
0
            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));
            }
コード例 #23
0
            /// <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);
            }
コード例 #24
0
            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);
                }
            }
コード例 #25
0
            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));
            }
コード例 #26
0
            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);
                }
            }
コード例 #27
0
            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);
                }
            }
コード例 #28
0
            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;
            }
コード例 #29
0
            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;
            }
コード例 #30
0
            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;
            }
コード例 #31
0
            public void AddReferenceAsync(RemoteAsyncOperation<bool> operation, string reference)
            {
                Debug.Assert(operation != null);
                Debug.Assert(reference != null);

                lock (_lastTaskGuard)
                {
                    _lastTask = AddReferenceAsync(_lastTask, operation, reference);
                }
            }
コード例 #32
0
            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);
                }
            }
コード例 #33
0
            public void ExecuteAsync(RemoteAsyncOperation<RemoteExecutionResult> operation, string text)
            {
                Debug.Assert(operation != null);
                Debug.Assert(text != null);

                lock (_lastTaskGuard)
                {
                    _lastTask = ExecuteAsync(_lastTask, operation, text);
                }
            }
コード例 #34
0
 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;
 }
コード例 #35
0
            public void ExecuteFileAsync(RemoteAsyncOperation<RemoteExecutionResult> operation, string path)
            {
                Debug.Assert(operation != null);
                Debug.Assert(path != null);

                lock (_lastTaskGuard)
                {
                    _lastTask = ExecuteFileAsync(operation, _lastTask, path);
                }
            }
コード例 #36
0
 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);
 }
コード例 #37
0
            /// <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;
            }
コード例 #38
0
            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;
            }
コード例 #39
0
            /// <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;
            }
コード例 #40
0
            /// <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;
            }
コード例 #41
0
            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);
            }
コード例 #42
0
            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;
            }
コード例 #43
0
            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);
            }
コード例 #44
0
            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);
            }
コード例 #45
0
            /// <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);
            }
コード例 #46
0
            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);
            }