Skip to content

Commit 2396398

Browse files
authored
Merge pull request #1064 from Particular/session-mutex
2 parents 1b2e183 + ad2b694 commit 2396398

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup .NET SDK
2121
uses: actions/setup-dotnet@v1.7.2
2222
with:
23-
dotnet-version: 5.0.x
23+
dotnet-version: 5.0.203 # should be 5.0.x when the runner image is updated to VS 16.10 or higher
2424
- name: Add msbuild to PATH
2525
uses: microsoft/setup-msbuild@v1.0.2
2626
- name: Build

src/ServiceInsight.Tests/ShellViewModelTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
using ServiceInsight.Framework.Licensing;
2222
using ServiceInsight.Framework.Settings;
2323
using ServiceInsight.Framework.UI.ScreenManager;
24+
using ServiceInsight.Startup;
2425
using Settings;
2526
using Shell;
2627
using Shouldly;
27-
using Startup;
2828

2929
public interface IShellViewStub : IShellView
3030
{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace ServiceInsight.Tests
2+
{
3+
using System;
4+
using NUnit.Framework;
5+
using ServiceInsight.Startup;
6+
7+
[TestFixture]
8+
public class PipeNameTests
9+
{
10+
[Test]
11+
public void Should_return_pipe_name_with_the_current_user_username()
12+
{
13+
Assert.AreEqual($"ServiceInsight-{Environment.UserName}", PipeName.Value);
14+
}
15+
}
16+
}

src/ServiceInsight/App.xaml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212

1313
public partial class App
1414
{
15-
bool createNew;
16-
Mutex mutex;
15+
readonly bool createNew;
16+
readonly Mutex mutex;
1717

1818
public App()
1919
{
20-
mutex = new Mutex(true, "ServiceInsight", out createNew);
20+
mutex = new Mutex(true, "Local\\ServiceInsight", out createNew);
21+
2122
if (createNew)
2223
{
2324
LoggingConfig.SetupLogging();

src/ServiceInsight/Startup/CommandLineArgParser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace ServiceInsight.Startup
22
{
33
using System;
4-
using System.IO.Pipes;
54
using System.Collections.Generic;
65
using System.IO;
6+
using System.IO.Pipes;
77
using Anotar.Serilog;
88
using ServiceInsight.Models;
99

@@ -13,8 +13,8 @@ public class CommandLineArgParser
1313
const char TokenSeparator = '&';
1414
const char KeyValueSeparator = '=';
1515

16-
EnvironmentWrapper environment;
17-
IList<string> unsupportedKeys;
16+
readonly EnvironmentWrapper environment;
17+
readonly IList<string> unsupportedKeys;
1818

1919
public CommandLineOptions ParsedOptions { get; private set; }
2020

@@ -44,7 +44,7 @@ public void SendToOtherInstance()
4444

4545
try
4646
{
47-
using (var pipe = new NamedPipeClientStream(".", "ServiceInsight", PipeDirection.Out))
47+
using (var pipe = new NamedPipeClientStream(".", PipeName.Value, PipeDirection.Out))
4848
using (var writer = new StreamWriter(pipe))
4949
{
5050
pipe.Connect(1000);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace ServiceInsight.Startup
2+
{
3+
using System;
4+
5+
/// <summary>
6+
/// NamedPipeServerStream pipe name.
7+
/// </summary>
8+
public static class PipeName
9+
{
10+
/// <summary>
11+
/// "ServiceInsight-username" where username is the Windows currently logged in user username.
12+
/// </summary>
13+
public static string Value { get; } = $"ServiceInsight-{Environment.UserName}";
14+
}
15+
}

src/ServiceInsight/Startup/StartupConfigListener.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
namespace ServiceInsight.Startup
22
{
3-
using System.IO.Pipes;
43
using System;
54
using System.IO;
6-
using System.Net;
7-
using System.Net.Sockets;
5+
using System.IO.Pipes;
86
using System.Threading;
97
using System.Threading.Tasks;
108
using Caliburn.Micro;
119
using ServiceInsight.Framework.Events;
12-
using ServiceInsight.Framework.Settings;
1310

1411
public class StartupConfigListener
1512
{
@@ -40,7 +37,7 @@ public static async Task Start(IEventAggregator eventAggregator, CommandLineArgP
4037

4138
static async Task Handle(IEventAggregator eventAggregator, CommandLineArgParser parser, CancellationToken cancellationToken)
4239
{
43-
using (var pipe = new NamedPipeServerStream("ServiceInsight", PipeDirection.In, 1, PipeTransmissionMode.Byte))
40+
using (var pipe = new NamedPipeServerStream(PipeName.Value, PipeDirection.In, 1, PipeTransmissionMode.Byte))
4441
using (cancellationToken.Register(() => Disconnect(pipe)))
4542
{
4643
await pipe.WaitForConnectionAsync(cancellationToken);

0 commit comments

Comments
 (0)