public InteractiveHostTests() { _host = new InteractiveHost(typeof(CSharpReplServiceProvider), GetInteractiveHostPath(), ".", millisecondsTimeout: -1); RedirectOutput(); _host.ResetAsync(new InteractiveHostOptions(initializationFile: null, culture: CultureInfo.InvariantCulture)).Wait(); var remoteService = _host.TryGetService(); Assert.NotNull(remoteService); _host.SetPathsAsync(new[] { s_fxDir }, new[] { s_homeDir }, s_homeDir).Wait(); // assert and remove logo: var output = SplitLines(ReadOutputToEnd()); var errorOutput = ReadErrorOutputToEnd(); Assert.Equal("", errorOutput); Assert.Equal(2, output.Length); Assert.Equal("Microsoft (R) Roslyn C# Compiler version " + FileVersionInfo.GetVersionInfo(_host.GetType().Assembly.Location).FileVersion, output[0]); // "Type "#help" for more information." Assert.Equal(FeaturesResources.TypeHelpForMoreInformation, output[1]); // remove logo: ClearOutput(); }
public InteractiveHostTests() { Host = new InteractiveHost(typeof(CSharpRepl), GetInteractiveHostPath(), ".", millisecondsTimeout: -1); RedirectOutput(); Host.ResetAsync(InteractiveHostOptions.Default).Wait(); var remoteService = Host.TryGetService(); Assert.NotNull(remoteService); remoteService.SetTestObjectFormattingOptions(); // assert and remove logo: var output = ReadOutputToEnd().Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); var errorOutput = ReadErrorOutputToEnd(); Assert.Equal("", errorOutput); Assert.Equal(2, output.Length); Assert.Equal("Microsoft (R) Roslyn C# Compiler version " + FileVersionInfo.GetVersionInfo(Host.GetType().Assembly.Location).FileVersion, output[0]); // "Type "#help" for more information." Assert.Equal(FeaturesResources.TypeHelpForMoreInformation, output[1]); // remove logo: ClearOutput(); }
internal InteractiveEvaluator( IContentType contentType, HostServices hostServices, IViewClassifierAggregatorService classifierAggregator, IInteractiveWindowCommandsFactory commandsFactory, ImmutableArray <IInteractiveWindowCommand> commands, string responseFilePath, string initialWorkingDirectory, string interactiveHostPath, Type replType) { Debug.Assert(responseFilePath == null || PathUtilities.IsAbsolute(responseFilePath)); _contentType = contentType; _responseFilePath = responseFilePath; _workspace = new InteractiveWorkspace(hostServices, this); _contentTypeChangedHandler = new EventHandler <ContentTypeChangedEventArgs>(LanguageBufferContentTypeChanged); _classifierAggregator = classifierAggregator; _initialWorkingDirectory = initialWorkingDirectory; _commandsFactory = commandsFactory; _commands = commands; // The following settings will apply when the REPL starts without .rsp file. // They are discarded once the REPL is reset. ReferenceSearchPaths = ImmutableArray <string> .Empty; SourceSearchPaths = ImmutableArray <string> .Empty; WorkingDirectory = initialWorkingDirectory; var metadataService = _workspace.CurrentSolution.Services.MetadataService; _metadataReferenceResolver = CreateMetadataReferenceResolver(metadataService, ReferenceSearchPaths, _initialWorkingDirectory); _sourceReferenceResolver = CreateSourceReferenceResolver(SourceSearchPaths, _initialWorkingDirectory); _interactiveHost = new InteractiveHost(replType, interactiveHostPath, initialWorkingDirectory); _interactiveHost.ProcessStarting += ProcessStarting; }
public InteractiveHostTests() { Host = new InteractiveHost(typeof(CSharpRepl), GetInteractiveHostPath(), ".", millisecondsTimeout: -1); RedirectOutput(); Host.ResetAsync(InteractiveHostOptions.Default).Wait(); var remoteService = Host.TryGetService(); Assert.NotNull(remoteService); remoteService.ObjectFormattingOptions = new ObjectFormattingOptions( memberFormat: MemberDisplayFormat.Inline, quoteStrings: true, useHexadecimalNumbers: false, maxOutputLength: int.MaxValue, memberIndentation: " "); // assert and remove logo: var output = ReadOutputToEnd().Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); var errorOutput = ReadErrorOutputToEnd(); Assert.Equal("", errorOutput); Assert.Equal(2, output.Length); Assert.Equal("Microsoft (R) Roslyn C# Compiler version " + FileVersionInfo.GetVersionInfo(Host.GetType().Assembly.Location).FileVersion, output[0]); // "Type "#help" for more information." Assert.Equal(FeaturesResources.TypeHelpForMoreInformation, output[1]); // remove logo: ClearOutput(); }
public InteractiveHostTests() { _host = new InteractiveHost(typeof(CSharpReplServiceProvider), GetInteractiveHostPath(), ".", millisecondsTimeout: -1); RedirectOutput(); _host.ResetAsync(new InteractiveHostOptions(initializationFile: null, culture: CultureInfo.InvariantCulture)).Wait(); var remoteService = _host.TryGetService(); Assert.NotNull(remoteService); _host.SetPathsAsync(new[] { s_fxDir }, new[] { s_homeDir }, s_homeDir).Wait(); // assert and remove logo: var output = SplitLines(ReadOutputToEnd()); var errorOutput = ReadErrorOutputToEnd(); Assert.Equal("", errorOutput); Assert.Equal(2, output.Length); Assert.Equal("Microsoft (R) Roslyn C# Compiler version " + FileVersionInfo.GetVersionInfo(_host.GetType().Assembly.Location).FileVersion, output[0]); // "Type "#help" for more information." Assert.Equal(FeaturesResources.Type_Sharphelp_for_more_information, output[1]); // remove logo: ClearOutput(); }
private async Task TestKillAfterAsync(int milliseconds) { using var host = new InteractiveHost(typeof(CSharpReplServiceProvider), ".", millisecondsTimeout: 1, joinOutputWritingThreadsOnDisposal: true); var options = InteractiveHostOptions.CreateFromDirectory(TestUtils.HostRootPath, initializationFileName: null, CultureInfo.InvariantCulture, InteractiveHostPlatform.Desktop64); host.InteractiveHostProcessCreated += new Action <Process>(proc => { _ = Task.Run(async() => { await Task.Delay(milliseconds).ConfigureAwait(false); try { proc.Kill(); } catch { } }); }); await host.ResetAsync(options).ConfigureAwait(false); for (int j = 0; j < 10; j++) { await host.ExecuteAsync("1+1").ConfigureAwait(false); } }
private async Task TestKillAfterAsync(int milliseconds) { using var host = new InteractiveHost(typeof(CSharpReplServiceProvider), ".", millisecondsTimeout: 1, joinOutputWritingThreadsOnDisposal: true); host.InteractiveHostProcessCreated += new Action <Process>(proc => { _ = Task.Run(async() => { await Task.Delay(milliseconds).ConfigureAwait(false); try { proc.Kill(); } catch { } }); }); await host.ResetAsync(new InteractiveHostOptions(GetInteractiveHostDirectory())).ConfigureAwait(false); for (int j = 0; j < 10; j++) { await host.ExecuteAsync("1+1").ConfigureAwait(false); } }
internal InteractiveEvaluator( IContentType contentType, HostServices hostServices, IViewClassifierAggregatorService classifierAggregator, IInteractiveWindowCommandsFactory commandsFactory, IInteractiveWindowCommand[] commands, string responseFilePath, string initialWorkingDirectory, string interactiveHostPath, Type replType) { Debug.Assert(responseFilePath == null || PathUtilities.IsAbsolute(responseFilePath)); _contentType = contentType; _responseFilePath = responseFilePath; _workspace = new InteractiveWorkspace(this, hostServices); _contentTypeChangedHandler = new EventHandler <ContentTypeChangedEventArgs>(LanguageBufferContentTypeChanged); _classifierAggregator = classifierAggregator; _initialWorkingDirectory = initialWorkingDirectory; _commandsFactory = commandsFactory; _commands = commands.ToImmutableArray(); var hostPath = interactiveHostPath; _interactiveHost = new InteractiveHost(replType, hostPath, initialWorkingDirectory); _interactiveHost.ProcessStarting += ProcessStarting; }
internal static void DisposeInteractiveHostProcess(InteractiveHost process) { IpcServerChannel serverChannel = process._ServerChannel; process.Dispose(joinThreads: true); var listenerThread = (Thread)s_ipcServerChannelListenerThread.GetValue(serverChannel); listenerThread.Join(); }
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; }
protected AbstractInteractiveHostTests() { Host = new InteractiveHost(typeof(CSharpReplServiceProvider), ".", millisecondsTimeout: -1, joinOutputWritingThreadsOnDisposal: true); Host.InteractiveHostProcessCreationFailed += (exception, exitCode) => Assert.False(true, (exception?.Message ?? "Host process terminated unexpectedly.") + $" Exit code: {exitCode?.ToString() ?? "<unknown>"}"); RedirectOutput(); }
internal static void DisposeInteractiveHostProcess(InteractiveHost host) { var serverChannel = host._ServerChannel; host.Dispose(); var listenerThread = (Thread)s_ipcServerChannelListenerThread.GetValue(serverChannel); listenerThread.Join(); }
internal static void DisposeInteractiveHostProcess(InteractiveHost process) { IpcServerChannel serverChannel = process._ServerChannel; process.Dispose(); var listenerThread = (Thread)s_ipcServerChannelListenerThread.GetValue(serverChannel); listenerThread.Join(); }
/// <summary> /// Find a Vector3InteractiveTheme by tag /// </summary> /// <param name="tag"></param> /// <returns></returns> public Vector3InteractiveTheme GetVector3Theme(string tag) { // search locally Vector3InteractiveTheme[] vector3Themes = InteractiveHost.GetComponentsInChildren <Vector3InteractiveTheme>(); Vector3InteractiveTheme theme = FindVector3Theme(vector3Themes, tag); // search globally if (theme == null) { vector3Themes = FindObjectsOfType <Vector3InteractiveTheme>(); theme = FindVector3Theme(vector3Themes, tag); } return(theme); }
/// <summary> /// Find a TextureInteractiveTheme by tag /// </summary> /// <param name="tag"></param> /// <returns></returns> public TextureInteractiveTheme GetTextureTheme(string tag) { // search locally TextureInteractiveTheme[] textureThemes = InteractiveHost.GetComponentsInChildren <TextureInteractiveTheme>(); TextureInteractiveTheme theme = FindTextureTheme(textureThemes, tag); // search globally if (theme == null) { textureThemes = FindObjectsOfType <TextureInteractiveTheme>(); theme = FindTextureTheme(textureThemes, tag); } return(theme); }
/// <summary> /// Find a ColorInteractiveTheme by tag /// </summary> /// <param name="tag"></param> /// <returns></returns> public ColorInteractiveTheme GetColorTheme(string tag) { // search locally ColorInteractiveTheme[] colorThemes = InteractiveHost.GetComponentsInChildren <ColorInteractiveTheme>(); ColorInteractiveTheme theme = FindColorTheme(colorThemes, tag); // search globally if (theme == null) { colorThemes = FindObjectsOfType <ColorInteractiveTheme>(); theme = FindColorTheme(colorThemes, tag); } return(theme); }
private InteractiveHost _host; // nulled on dispose internal RemoteService(InteractiveHost host, Process process, int processId, Service service) { Debug.Assert(host != null); Debug.Assert(process != null); Debug.Assert(service != null); _host = host; this.Process = process; _processId = processId; this.Service = service; // 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(); }
internal InteractiveEvaluator( IContentType contentType, HostServices hostServices, IViewClassifierAggregatorService classifierAggregator, IInteractiveWindowCommandsFactory commandsFactory, ImmutableArray<IInteractiveWindowCommand> commands, string responseFilePath, string initialWorkingDirectory, string interactiveHostPath, Type replType) { Debug.Assert(responseFilePath == null || PathUtilities.IsAbsolute(responseFilePath)); _contentType = contentType; _responseFilePath = responseFilePath; _workspace = new InteractiveWorkspace(this, hostServices); _contentTypeChangedHandler = new EventHandler<ContentTypeChangedEventArgs>(LanguageBufferContentTypeChanged); _classifierAggregator = classifierAggregator; _initialWorkingDirectory = initialWorkingDirectory; _commandsFactory = commandsFactory; _commands = commands; // The following settings will apply when the REPL starts without .rsp file. // They are discarded once the REPL is reset. ReferenceSearchPaths = ImmutableArray<string>.Empty; SourceSearchPaths = ImmutableArray<string>.Empty; WorkingDirectory = initialWorkingDirectory; var metadataService = _workspace.CurrentSolution.Services.MetadataService; _metadataReferenceResolver = CreateMetadataReferenceResolver(metadataService, ReferenceSearchPaths, _initialWorkingDirectory); _sourceReferenceResolver = CreateSourceReferenceResolver(SourceSearchPaths, _initialWorkingDirectory); _interactiveHost = new InteractiveHost(replType, interactiveHostPath, initialWorkingDirectory); _interactiveHost.ProcessStarting += ProcessStarting; }
internal InteractiveEvaluator( IContentType contentType, HostServices hostServices, IViewClassifierAggregatorService classifierAggregator, IInteractiveWindowCommandsFactory commandsFactory, ImmutableArray<IInteractiveWindowCommand> commands, string responseFilePath, string initialWorkingDirectory, string interactiveHostPath, Type replType) { Debug.Assert(responseFilePath == null || PathUtilities.IsAbsolute(responseFilePath)); _contentType = contentType; _responseFilePath = responseFilePath; _workspace = new InteractiveWorkspace(this, hostServices); _contentTypeChangedHandler = new EventHandler<ContentTypeChangedEventArgs>(LanguageBufferContentTypeChanged); _classifierAggregator = classifierAggregator; _initialWorkingDirectory = initialWorkingDirectory; _commandsFactory = commandsFactory; _commands = commands; var hostPath = interactiveHostPath; _interactiveHost = new InteractiveHost(replType, hostPath, initialWorkingDirectory); _interactiveHost.ProcessStarting += ProcessStarting; }
private InteractiveHost CreateProcess() { var p = new InteractiveHost(typeof(CSharpReplServiceProvider), ".", millisecondsTimeout: 1); _processes.Add(p); return p; }
internal void Dispose(bool joinThreads) { // null the host so that we don't attempt to restart or write to the buffer anymore: _host = null; InitiateTermination(Process, _processId); // only tests require joining the threads, so we can wait synchronously if (joinThreads) { if (_readOutputThread != null) { try { _readOutputThread.Join(); } catch (ThreadStateException) { // thread hasn't started } } if (_readErrorOutputThread != null) { try { _readErrorOutputThread.Join(); } catch (ThreadStateException) { // thread hasn't started } } } _readOutputThread = _readErrorOutputThread = null; }
public InteractiveHostTests() { _host = new InteractiveHost(typeof(CSharpReplServiceProvider), ".", millisecondsTimeout: -1, joinOutputWritingThreadsOnDisposal: true); RedirectOutput(); }
public static void Run(InteractiveHost plot) { // All the toolkit specific code does is one of these lines: // InteractiveHost plot = new Florence.GtkSharp.InteractiveHost(); // InteractiveHost plot = new Florence.WinForms.InteractiveHost(); // Start the interactive host; this starts up a GUI thread // and otherwise gets the GUI ready to go. plot.Start(); // Generate some data to plot! var rand = new Random(0); var x = new double[100]; for (int ii = 0; ii < x.Length; ++ii) x[ii] = rand.NextNormal(0.0, 1.0); var y = new double[x.Length]; for (int ii = 0; ii < y.Length; ++ii) y[ii] = 2.0 + 3.0 * x[ii] + rand.NextNormal(0.0, 2.5); var t = new DateTime[15]; var s = new double[t.Length]; t[0] = new DateTime(2013,12,1); s[0] = 100.0; for (int ii = 1; ii < t.Length; ++ii) { t[ii] = t[ii-1].AddDays(1); s[ii] = s[ii - 1]*Math.Exp(rand.NextNormal(0.05 / 365.0, 0.15 / Math.Sqrt(365.0))); } // Create our first plot var plot1 = new PointPlot() { AbscissaData = x, OrdinateData = y }; plot.Add(plot1); plot.XAxis1.Label = "Love of Graphs"; plot.YAxis1.Label = "Overall Awesomeness"; plot.Title = "Effect of Graph Affinity on Overall Awesomeness"; // Pause execution. In an interactive environment, (C#/F# REPL) this would not be necessary Console.ReadLine(); // Try putting your mouse over the numbers on either the X or Y axis, // pressing the mouse button then dragging left and right (for the X) // or up and down (for the Y). // Now try clicking and dragging in the main plot area. // Now press enter, to move on to the next example plot.newFigure(); plot.Title = "A new one!"; Console.ReadLine(); plot.previous(); plot.Title = "First one again!"; Console.ReadLine(); plot.next(); plot.closeFigure(); var line_plot = plot.newFigure(); line_plot.Add(new LinePlot() { AbscissaData = t, OrdinateData = s }); //var plot2 = new LinePlot() { AbscissaData = x, OrdinateData = y }; //plot.Title = "Test Plot 2"; //plot.XAxis1.Label = "X2"; //plot.YAxis1.Label = "Y2"; //plot.Add(plot2); Console.ReadLine(); plot.Stop(); }
private InteractiveHost CreateProcess() { var p = new InteractiveHost(typeof(CSharpReplServiceProvider), GetInteractiveHostPath(), ".", millisecondsTimeout: 1); _processes.Add(p); return p; }
public static void Run(InteractiveHost plot) { // All the toolkit specific code does is one of these lines: // InteractiveHost plot = new Florence.GtkSharp.InteractiveHost(); // InteractiveHost plot = new Florence.WinForms.InteractiveHost(); // Start the interactive host; this starts up a GUI thread // and otherwise gets the GUI ready to go. plot.Start(); // Generate some data to plot! var rand = new Random(0); var x = new double[100]; for (int ii = 0; ii < x.Length; ++ii) { x[ii] = rand.NextNormal(0.0, 1.0); } var y = new double[x.Length]; for (int ii = 0; ii < y.Length; ++ii) { y[ii] = 2.0 + 3.0 * x[ii] + rand.NextNormal(0.0, 2.5); } var t = new DateTime[15]; var s = new double[t.Length]; t[0] = new DateTime(2013, 12, 1); s[0] = 100.0; for (int ii = 1; ii < t.Length; ++ii) { t[ii] = t[ii - 1].AddDays(1); s[ii] = s[ii - 1] * Math.Exp(rand.NextNormal(0.05 / 365.0, 0.15 / Math.Sqrt(365.0))); } // Create our first plot var plot1 = new PointPlot() { AbscissaData = x, OrdinateData = y }; plot.Add(plot1); plot.XAxis1.Label = "Love of Graphs"; plot.YAxis1.Label = "Overall Awesomeness"; plot.Title = "Effect of Graph Affinity on Overall Awesomeness"; // Pause execution. In an interactive environment, (C#/F# REPL) this would not be necessary Console.ReadLine(); // Try putting your mouse over the numbers on either the X or Y axis, // pressing the mouse button then dragging left and right (for the X) // or up and down (for the Y). // Now try clicking and dragging in the main plot area. // Now press enter, to move on to the next example plot.newFigure(); plot.Title = "A new one!"; Console.ReadLine(); plot.previous(); plot.Title = "First one again!"; Console.ReadLine(); plot.next(); plot.closeFigure(); var line_plot = plot.newFigure(); line_plot.Add(new LinePlot() { AbscissaData = t, OrdinateData = s }); //var plot2 = new LinePlot() { AbscissaData = x, OrdinateData = y }; //plot.Title = "Test Plot 2"; //plot.XAxis1.Label = "X2"; //plot.YAxis1.Label = "Y2"; //plot.Add(plot2); Console.ReadLine(); plot.Stop(); }