Skip to content

Commit d3d05c2

Browse files
committed
relac process match
1 parent d220050 commit d3d05c2

3 files changed

Lines changed: 35 additions & 24 deletions

File tree

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ A tool can be launched using the following:
6969
```cs
7070
DiffRunner.Launch(tempFile, targetFile);
7171
```
72-
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L14-L16' title='File snippet `diffrunnerlaunch` was extracted from'>snippet source</a> | <a href='#snippet-diffrunnerlaunch' title='Navigate to start of snippet `diffrunnerlaunch`'>anchor</a></sup>
72+
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L16-L18' title='File snippet `diffrunnerlaunch` was extracted from'>snippet source</a> | <a href='#snippet-diffrunnerlaunch' title='Navigate to start of snippet `diffrunnerlaunch`'>anchor</a></sup>
7373
<!-- endsnippet -->
7474

7575
Note that this method will respect the above [difference behavior](/docs/diff-tool.md#detected-difference-behavior) in terms of Auto refresh and MDI behaviors.
@@ -84,7 +84,7 @@ A tool can be closed using the following:
8484
```cs
8585
DiffRunner.Kill(tempFile, targetFile);
8686
```
87-
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L25-L27' title='File snippet `diffrunnerkill` was extracted from'>snippet source</a> | <a href='#snippet-diffrunnerkill' title='Navigate to start of snippet `diffrunnerkill`'>anchor</a></sup>
87+
<sup><a href='/src/DiffEngine.Tests/DiffRunnerTests.cs#L27-L29' title='File snippet `diffrunnerkill` was extracted from'>snippet source</a> | <a href='#snippet-diffrunnerkill' title='Navigate to start of snippet `diffrunnerkill`'>anchor</a></sup>
8888
<!-- endsnippet -->
8989

9090
Note that this method will respect the above [difference behavior](/docs/diff-tool.md#detected-difference-behavior) in terms of MDI behavior.

src/DiffEngine.Tests/DiffRunnerTests.cs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System.IO;
2+
using System.Linq;
3+
using System.Threading;
24
using DiffEngine;
35
using Xunit;
46
using Xunit.Abstractions;
@@ -26,27 +28,36 @@ public void Kill()
2628
DiffRunner.Kill(tempFile, targetFile);
2729
#endregion
2830
}
31+
#if NETCOREAPP3_1
2932

30-
//static string diffToolPath = Path.GetFullPath(Path.Combine(AssemblyLocation.CurrentDirectory, "../../../../FakeDiffTool/bin/FakeDiffTool.exe"));
33+
static string diffToolPath = Path.GetFullPath(Path.Combine(AssemblyLocation.CurrentDirectory, "../../../../FakeDiffTool/bin/FakeDiffTool.exe"));
3134

32-
//[Fact]
33-
//public void LaunchAndKill()
34-
//{
35-
// DiffTools.AddCustomTool(
36-
// supportsAutoRefresh: true,
37-
// isMdi: false,
38-
// supportsText: true,
39-
// requiresTarget: true,
40-
// buildArguments: (path1, path2) => $"\"{path1}\" \"{path2}\"",
41-
// exePath: diffToolPath,
42-
// binaryExtensions: new[] {"knownBin"});
43-
// var tempFile = Path.Combine(SourceDirectory, "DiffRunner.file1.txt");
44-
// var targetFile = Path.Combine(SourceDirectory, "DiffRunner.file2.txt");
45-
// DiffRunner.Launch(tempFile, targetFile);
46-
// Assert.NotEmpty(ProcessCleanup.FindAll());
47-
// DiffRunner.Kill(tempFile, targetFile);
48-
// Assert.Empty(ProcessCleanup.FindAll());
49-
//}
35+
[Fact]
36+
public void LaunchAndKill()
37+
{
38+
DiffTools.AddCustomTool(
39+
supportsAutoRefresh: true,
40+
isMdi: false,
41+
supportsText: true,
42+
requiresTarget: true,
43+
buildArguments: (path1, path2) => $"\"{path1}\" \"{path2}\"",
44+
exePath: diffToolPath,
45+
binaryExtensions: new[] {"knownBin"});
46+
var tempFile = Path.Combine(SourceDirectory, "DiffRunner.file1.txt");
47+
var targetFile = Path.Combine(SourceDirectory, "DiffRunner.file2.txt");
48+
DiffRunner.Launch(tempFile, targetFile);
49+
Thread.Sleep(100);
50+
Assert.True(IsRunning());
51+
DiffRunner.Kill(tempFile, targetFile);
52+
Thread.Sleep(100);
53+
Assert.False(IsRunning());
54+
}
55+
56+
static bool IsRunning()
57+
{
58+
return ProcessCleanup.FindAll().Any(x => x.Command.Contains("FakeDiffTool"));
59+
}
60+
#endif
5061

5162
public DiffRunnerTests(ITestOutputHelper output) :
5263
base(output)

src/DiffEngine/ProcessCleanup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static bool IsRunning(string command)
6363

6464
static void TerminalProcessIfExists(ProcessCommand processCommand)
6565
{
66-
var processId = (int) processCommand.Process;
66+
var processId = processCommand.Process;
6767
using var processHandle = OpenProcess(4097, false, processId);
6868
if (processHandle.IsInvalid)
6969
{
@@ -74,14 +74,14 @@ static void TerminalProcessIfExists(ProcessCommand processCommand)
7474
}
7575

7676
/// <summary>
77-
/// Find all processes with `.received.` in the command line.
77+
/// Find all processes with `% %.%.%` in the command line.
7878
/// </summary>
7979
public static IEnumerable<ProcessCommand> FindAll()
8080
{
8181
var wmiQuery = @"
8282
select CommandLine, ProcessId
8383
from Win32_Process
84-
where CommandLine like '%.received.%'";
84+
where CommandLine like '% %.%.%'";
8585
using var searcher = new ManagementObjectSearcher(wmiQuery);
8686
using var collection = searcher.Get();
8787
foreach (var process in collection)

0 commit comments

Comments
 (0)