コード例 #1
0
        /// <summary>
        /// Restarts and reinitializes the host process (or starts a new one if it is not running yet).
        /// </summary>
        /// <param name="optionsOpt">The options to initialize the new process with, or null to use the current options (or default options if the process isn't running yet).</param>
        public async Task <RemoteExecutionResult> ResetAsync(InteractiveHostOptions optionsOpt)
        {
            try
            {
                var options = optionsOpt ?? _lazyRemoteService?.Options ?? new InteractiveHostOptions(null, CultureInfo.CurrentUICulture);

                // replace the existing service with a new one:
                var newService = CreateRemoteService(options, skipInitialization: false);

                LazyRemoteService oldService = Interlocked.Exchange(ref _lazyRemoteService, newService);
                if (oldService != null)
                {
                    oldService.Dispose(joinThreads: false);
                }

                var initializedService = await TryGetOrCreateRemoteServiceAsync(processPendingOutput : false).ConfigureAwait(false);

                if (initializedService.ServiceOpt == null)
                {
                    return(default(RemoteExecutionResult));
                }

                return(initializedService.InitializationResult);
            }
            catch (Exception e) when(FatalError.Report(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
コード例 #2
0
            private volatile ProcessExitHandlerStatus _processExitHandlerStatus; // set to Handled on dispose

            internal RemoteService(
                InteractiveHost host,
                Process process,
                int processId,
                JsonRpc jsonRpc,
                InteractiveHostPlatformInfo platformInfo,
                InteractiveHostOptions options
                )
            {
                Process      = process;
                JsonRpc      = jsonRpc;
                PlatformInfo = platformInfo;
                Options      = options;

                _host = host;
                _joinOutputWritingThreadsOnDisposal = _host._joinOutputWritingThreadsOnDisposal;
                _processId = processId;
                _processExitHandlerStatus = ProcessExitHandlerStatus.Uninitialized;

                // TODO (tomat): consider using single-thread async readers
                _readOutputThread              = new Thread(() => ReadOutput(error: false));
                _readOutputThread.Name         = "InteractiveHost-OutputReader-" + processId;
                _readOutputThread.IsBackground = true;
                _readOutputThread.Start();

                _readErrorOutputThread              = new Thread(() => ReadOutput(error: true));
                _readErrorOutputThread.Name         = "InteractiveHost-ErrorOutputReader-" + processId;
                _readErrorOutputThread.IsBackground = true;
                _readErrorOutputThread.Start();
            }
コード例 #3
0
 public LazyRemoteService(InteractiveHost host, InteractiveHostOptions options, int instanceId, bool skipInitialization)
 {
     InitializedService = new AsyncLazy <InitializedRemoteService>(TryStartAndInitializeProcessAsync, cacheResult: true);
     CancellationSource = new CancellationTokenSource();
     InstanceId         = instanceId;
     Options            = options;
     Host = host;
     SkipInitialization = skipInitialization;
 }
コード例 #4
0
 public LazyRemoteService(InteractiveHost host, InteractiveHostOptions options, int instanceId, bool skipInitialization)
 {
     InitializedService = new AsyncLazy<InitializedRemoteService>(TryStartAndInitializeProcessAsync, cacheResult: true);
     CancellationSource = new CancellationTokenSource();
     InstanceId = instanceId;
     Options = options;
     Host = host;
     SkipInitialization = skipInitialization;
 }
コード例 #5
0
 private LazyRemoteService CreateRemoteService(
     InteractiveHostOptions options,
     bool skipInitialization
     )
 {
     return(new LazyRemoteService(
                this,
                options,
                Interlocked.Increment(ref _remoteServiceInstanceId),
                skipInitialization
                ));
 }
コード例 #6
0
        /// <summary>
        /// Restarts and reinitializes the host process (or starts a new one if it is not running yet).
        /// </summary>
        /// <param name="options">The options to initialize the new process with.</param>
        public async Task <RemoteExecutionResult> ResetAsync(InteractiveHostOptions options)
        {
            Debug.Assert(options != null);

            try
            {
                // replace the existing service with a new one:
                var newService = CreateRemoteService(options, skipInitialization: false);

                var oldService = Interlocked.Exchange(ref _lazyRemoteService, newService);
                if (oldService != null)
                {
                    oldService.Dispose(joinThreads: false);
                }

                var initializedService = await TryGetOrCreateRemoteServiceAsync(processPendingOutput : false).ConfigureAwait(false);

                if (initializedService.ServiceOpt == null)
                {
                    return(default);
コード例 #7
0
        /// <summary>
        /// Invoked by <see cref="InteractiveHost"/> when a new process is being started.
        /// </summary>
        private void ProcessStarting(InteractiveHostOptions options)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.BeginInvoke(new Action(() => ProcessStarting(options)));
                return;
            }

            // Freeze all existing classifications and then clear the list of
            // submission buffers we have.
            FreezeClassifications();
            _submissionBuffers.Clear();

            // We always start out empty
            _workspace.ClearSolution();
            _currentSubmissionProjectId = null;
            _previousSubmissionProjectId = null;

            var metadataService = _workspace.CurrentSolution.Services.MetadataService;
            ImmutableArray<string> referencePaths;

            // reset configuration:
            if (File.Exists(_responseFilePath))
            {
                // 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 rspArguments = this.CommandLineParser.Parse(new[] { "@" + _responseFilePath }, Path.GetDirectoryName(_responseFilePath), RuntimeEnvironment.GetRuntimeDirectory(), null /* TODO: pass a valid value*/);
                referencePaths = rspArguments.ReferencePaths;

                // the base directory for references specified in the .rsp file is the .rsp file directory:
                var rspMetadataReferenceResolver = new GacFileResolver(
                    referencePaths,
                    baseDirectory: rspArguments.BaseDirectory,
                    architectures: GacFileResolver.Default.Architectures,  // TODO (tomat)
                    preferredCulture: System.Globalization.CultureInfo.CurrentCulture); // TODO (tomat)

                var metadataProvider = metadataService.GetProvider();

                // ignore unresolved references, they will be reported in the interactive window:
                var rspReferences = rspArguments.ResolveMetadataReferences(new AssemblyReferenceResolver(rspMetadataReferenceResolver, metadataProvider))
                    .Where(r => !(r is UnresolvedMetadataReference));

                var interactiveHelpersRef = metadataService.GetReference(typeof(Script).Assembly.Location, MetadataReferenceProperties.Assembly);
                var interactiveHostObjectRef = metadataService.GetReference(typeof(InteractiveHostObject).Assembly.Location, MetadataReferenceProperties.Assembly);

                _references = ImmutableHashSet.Create<MetadataReference>(
                    interactiveHelpersRef,
                    interactiveHostObjectRef)
                    .Union(rspReferences);

                // we need to create projects for these:
                _rspSourceFiles = rspArguments.SourceFiles;
            }
            else
            {
                var mscorlibRef = metadataService.GetReference(typeof(object).Assembly.Location, MetadataReferenceProperties.Assembly);
                _references = ImmutableHashSet.Create<MetadataReference>(mscorlibRef);

                _rspSourceFiles = ImmutableArray.Create<CommandLineSourceFile>();
                referencePaths = ScriptOptions.Default.SearchPaths;
            }

            // reset search paths, working directory:
            _metadataReferenceResolver = new GacFileResolver(
                referencePaths,
                baseDirectory: _initialWorkingDirectory,
                architectures: GacFileResolver.Default.Architectures,  // TODO (tomat)
                preferredCulture: System.Globalization.CultureInfo.CurrentCulture); // TODO (tomat)

            _sourceSearchPaths = InteractiveHost.Service.DefaultSourceSearchPaths;

            // create the first submission project in the workspace after reset:
            if (_currentSubmissionBuffer != null)
            {
                AddSubmission(_currentTextView, _currentSubmissionBuffer, this.LanguageName);
            }
        }
コード例 #8
0
        private async Task<ExecutionResult> ResetAsyncWorker(bool initialize = true)
        {
            try
            {
                var options = new InteractiveHostOptions(
                    initializationFile: initialize ? _responseFilePath : null,
                    culture: CultureInfo.CurrentUICulture);

                var result = await _interactiveHost.ResetAsync(options).ConfigureAwait(false);

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

                return new ExecutionResult(result.Success);
            }
            catch (Exception e) when (FatalError.Report(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }