private void ResetApplicationDefaultDevice(DataFlow dataFlow) { ObservableProcess process = (cb_applications.SelectedItem as ObservableProcess); AudioInterfaceCollection.ClearApplicationDefaultDevice(dataFlow, process); UpdateApplicationAudioDevices(cb_applications.SelectedItem as ObservableProcess, true); }
private void Processes_CollectionEnumerated(object sender, EventArgs e) { int currentProcessId = Process.GetCurrentProcess().Id; ObservableProcess thisProcess = ProcessCollection.Processes.FirstOrDefault(x => x.Id == currentProcessId); cb_applications.SelectedItem = thisProcess; UpdateApplicationAudioDevices(thisProcess, false); }
private void SetApplicationDefaultDevice() { ObservableProcess process = (cb_applications.SelectedItem as ObservableProcess); AudioInterface currentInterface = (cb_interfaces.SelectedItem as AudioInterface); AudioInterfaceCollection.ChangeDefaultApplicationDevice(currentInterface, process); UpdateApplicationAudioDevices(process, true); }
private void ApplicationsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count > 0) { currentSelectedProcess = e.AddedItems[0] as ObservableProcess; UpdateApplicationAudioDevices(currentSelectedProcess, false); AnnounceVisualElementChanged(current_application); } }
public void DelayedWriter() { var seen = new List <string>(); var process = new ObservableProcess(TestCaseArguments(nameof(DelayedWriter))); var subscription = process.SubscribeLines(c => seen.Add(c.Line)); subscription.Dispose(); process.WaitForCompletion(WaitTimeout); //disposing the subscription did not kill the process process.ExitCode.Should().Be(20); seen.Should().BeEmpty(string.Join(Environment.NewLine, seen)); }
public void SubscribeLinesSeesAllLines() { var args = TestCaseArguments("MoreText"); var o = new ObservableProcess(args); var seen = new List <LineOut>(); o.SubscribeLines(l => seen.Add(l)); o.WaitForCompletion(WaitTimeout); seen.Should().NotBeEmpty().And.HaveCount(_expectedLines.Length, string.Join("\r\n", seen.Select(s => s.Line))); for (var i = 0; i < seen.Count; i++) { seen[i].Line.Should().Be(_expectedLines[i], i.ToString()); } }
public void DelayedWriterStopWaitToShort() { var seen = new List <string>(); var args = TestCaseArguments(nameof(DelayedWriter)); args.WaitForExit = TimeSpan.FromMilliseconds(200); var process = new ObservableProcess(args); process.SubscribeLines(c => seen.Add(c.Line)); process.Dispose(); process.ExitCode.Should().NotHaveValue(); seen.Should().BeEmpty(string.Join(Environment.NewLine, seen)); }
public void DelayedWriterRunsToCompletion() { var seen = new List <string>(); Exception ex = null; var process = new ObservableProcess(TestCaseArguments(nameof(DelayedWriter))); var subscription = process.SubscribeLines(c => seen.Add(c.Line), e => ex = e); process.WaitForCompletion(WaitTimeout); process.ExitCode.Should().Be(20); ex.Should().BeNull(); seen.Should().NotBeEmpty().And.HaveCount(1, string.Join(Environment.NewLine, seen)); seen[0].Should().Be(nameof(DelayedWriter)); }
public void DelayedWriterStopNoWaitDispose() { var seen = new List <string>(); var args = TestCaseArguments(nameof(DelayedWriter)); args.WaitForExit = null; //never wait for exit var process = new ObservableProcess(args); process.SubscribeLines(c => seen.Add(c.Line)); process.Dispose(); //disposing the process itself will stop the underlying Process process.ExitCode.Should().NotHaveValue(); seen.Should().BeEmpty(string.Join(Environment.NewLine, seen)); }
public static int Main() { var tessCase = TestBinary.TestCaseArguments("ControlC"); var process = new ObservableProcess(tessCase); process.SubscribeLines(c => { //if (c.Line.EndsWith("4")) { process.SendControlC(); } Console.WriteLine(c.Line); }, e => Console.Error.WriteLine(e)); process.WaitForCompletion(TimeSpan.FromSeconds(20)); return(0); }
/// <summary> /// Creates a process to run the dotnet project that will start when subscribed to. /// </summary> /// <param name="startupHookZipPath">The path to the startup hook zip file</param> /// <param name="environmentVariables">The environment variables to start the project with. The DOTNET_STARTUP_HOOKS environment variable will be added.</param> /// <returns></returns> public ObservableProcess CreateProcess(string startupHookZipPath, IDictionary <string, string> environmentVariables = null) { Publish(); var startupHookAssembly = UnzipStartupHook(startupHookZipPath); environmentVariables ??= new Dictionary <string, string>(); environmentVariables["DOTNET_STARTUP_HOOKS"] = startupHookAssembly; var arguments = new StartArguments("dotnet", $"{Name}.dll") { WorkingDirectory = Path.Combine(Directory, _publishDirectory), SendControlCFirst = true, Environment = environmentVariables }; _process = new ObservableProcess(arguments); return(_process); }
private void UpdateApplicationAudioDevices(ObservableProcess process, bool announceChanges) { AudioInterface applicationRender = AudioInterfaceCollection.GetDefaultApplicationDevice(DataFlow.Render, process); AudioInterface applicationCapture = AudioInterfaceCollection.GetDefaultApplicationDevice(DataFlow.Capture, process); string previousAppRenderText = app_render.Text; app_render.Text = applicationRender?.FriendlyName ?? Properties.Resources.text_default; if (announceChanges && app_render.Text != previousAppRenderText) { AnnounceVisualElementChanged(app_render); } string previousAppCaptureText = app_capture.Text; app_capture.Text = applicationCapture?.FriendlyName ?? Properties.Resources.text_default; if (announceChanges && app_capture.Text != previousAppCaptureText) { AnnounceVisualElementChanged(app_capture); } }
private void Processes_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { ObservableProcess currentProcess = cb_applications.SelectedItem as ObservableProcess; if (e.OldItems == null) { return; } if (currentProcess == null && e.Action == NotifyCollectionChangedAction.Move && currentSelectedProcess != null) { currentProcess = currentSelectedProcess; cb_applications.SelectedItem = currentProcess; } if (currentSelectedProcess == null || (e.OldItems.Contains(currentProcess) && e.Action == NotifyCollectionChangedAction.Remove)) { cb_applications.SelectedItem = ProcessCollection.Processes.FirstOrDefault(x => x.Id == Process.GetCurrentProcess().Id); AnnounceVisualElementChanged(cb_applications); } }
public void ControlCNoWait() { var args = TestCaseArguments(nameof(ControlCNoWait)); args.SendControlCFirst = true; var process = new ObservableProcess(args); var seen = new List <string>(); process.SubscribeLines(c => { seen.Add(c.Line); }); process.WaitForCompletion(TimeSpan.FromSeconds(1)); //process exits before its control c handler is invoked seen.Should().NotBeEmpty().And.HaveCount(1, string.Join(Environment.NewLine, seen)); seen[0].Should().Be("Written before control+c"); }
public void SlowOutput() { var args = TestCaseArguments(nameof(SlowOutput)); var process = new ObservableProcess(args); var consoleOut = new List <LineOut>(); Exception seenException = null; bool? readingBeforeCancelling = null; bool? readingAfterCancelling = null; process.SubscribeLines(c => { consoleOut.Add(c); if (!c.Line.EndsWith("3")) { return; } readingBeforeCancelling = process.IsActivelyReading; process.CancelAsyncReads(); Task.Run(async() => { await Task.Delay(TimeSpan.FromSeconds(2)); readingAfterCancelling = process.IsActivelyReading; process.StartAsyncReads(); }); }, e => seenException = e); process.WaitForCompletion(TimeSpan.FromSeconds(20)); process.ExitCode.Should().HaveValue().And.Be(121); seenException.Should().BeNull(); consoleOut.Should().NotBeEmpty() .And.Contain(l => l.Line.EndsWith("9")); readingBeforeCancelling.Should().HaveValue().And.BeTrue(); readingAfterCancelling.Should().HaveValue().And.BeFalse(); }
public async Task<int> ProcessSingleBuild(BuildQueueItem queueItem, IObserver<string> stdout = null) { var target = queueItem.GetBuildDirectory(); var repo = default(LibGit2Sharp.Repository); try { repo = new LibGit2Sharp.Repository(target); var dontcare = repo.Info.IsHeadUnborn; // NB: We just want to test if the repo is valid } catch (Exception) { repo = null; } var creds = new LibGit2Sharp.Credentials() { Username = client.Credentials.Login, Password = client.Credentials.Password }; await cloneOrResetRepo(queueItem, target, repo, creds); // XXX: This needs to be way more secure await validateBuildUrl(queueItem.BuildScriptUrl); var buildScriptPath = await getBuildScriptPath(queueItem, target); var process = new ObservableProcess(createStartInfoForScript(buildScriptPath, target)); if (stdout != null) { process.Output.Subscribe(stdout); } var exitCode = await process; if (exitCode != 0) { var ex = new Exception("Build failed with code: " + exitCode.ToString()); ex.Data["ExitCode"] = exitCode; throw ex; } return exitCode; }
public void Start() { this.Stop(); var classPath = $"{this.ElasticsearchJar};{Path.Combine(this.LibDirectory, "*")}"; var arguments = JavaOptions.Split(' ') .Concat(new string[] { $"-Delasticsearch", $"-Des.path.home=\"{this.HomeDirectory}\"", $"-cp \"{classPath}\" org.elasticsearch.bootstrap.Elasticsearch", $"-E path.conf=\"{this.ConfigDirectory}\"" }) .Concat(this.AdditionalArguments) .ToList(); this._process = new ObservableProcess(this.JavaExe, arguments.ToArray()); //Create a hot observer on process that does not disposbe itself (Stop() method does this) var observable = Observable.Create <ConsoleOut>(observer => { this._disposables.Add(this._process.Start().Subscribe(observer)); return(Disposable.Empty); }) .Publish(); //promote to connectable observable //subscribe underlying observable stream this._disposables.Add(observable.Connect()); if (Environment.UserInteractive) { //subscribe to all messages and write them to console this._disposables.Add(observable.Subscribe(c => { if (c.Error) { ElasticsearchConsole.WriteLine(ConsoleColor.Red, c.Data); } else { ElasticsearchConsole.WriteLine(c.Data); } })); } //subscribe as long we are not in started state and attempt to read console out for this confirmation var handle = new ManualResetEvent(false); this._disposables.Add(observable .TakeWhile(c => !this.Started) .Select(consoleLine => new ElasticsearchMessage(this.Started, consoleLine.Data)) .Subscribe(onNext: s => HandleConsoleMessage(s, handle)) ); var timeout = TimeSpan.FromSeconds(120); if (!handle.WaitOne(TimeSpan.FromSeconds(120), true)) { this.Stop(); throw new Exception($"Could not start Elasticsearch within ({timeout}): {this.JavaExe} {string.Join(" ", arguments)}"); } }