File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- using System ;
1+ using PipeMethodCalls ;
2+ using PipeMethodCalls . NetJson ;
3+ using System ;
24using System . Collections . Generic ;
35using System . Diagnostics ;
46using System . Linq ;
57using System . Text ;
68using System . Threading ;
79using System . Threading . Tasks ;
8- using PipeMethodCalls ;
9- using PipeMethodCalls . NetJson ;
1010using VidCoderCommon ;
1111using VidCoderCommon . Services ;
12+ using VidCoderCommon . Utilities ;
1213
1314namespace VidCoder . Automation ;
1415
@@ -25,9 +26,10 @@ public static async void StartListening()
2526 {
2627 while ( true )
2728 {
29+ string pipeName = "VidCoderAutomation" + ( CommonUtilities . Beta ? "Beta" : string . Empty ) + PipeUtilities . UserPipeSuffix ;
2830 using ( server = new PipeServer < IVidCoderAutomation > (
2931 new NetJsonPipeSerializer ( ) ,
30- "VidCoderAutomation" + ( CommonUtilities . Beta ? "Beta" : string . Empty ) ,
32+ pipeName ,
3133 ( ) => new VidCoderAutomation ( ) ) )
3234 {
3335 await server . WaitForConnectionAsync ( ) . ConfigureAwait ( false ) ;
Original file line number Diff line number Diff line change 77using System . Text ;
88using System . Threading . Tasks ;
99using VidCoderCommon . Model ;
10+ using VidCoderCommon . Utilities ;
1011
1112namespace VidCoderCommon . Services ;
1213
@@ -38,7 +39,8 @@ public async Task<AutomationResult> TryActionAsync(Expression<Action<IVidCoderAu
3839 betaString = "Beta" ;
3940 }
4041
41- using ( var client = new PipeClient < IVidCoderAutomation > ( new NetJsonPipeSerializer ( ) , "VidCoderAutomation" + betaString ) )
42+ string pipeName = "VidCoderAutomation" + betaString + PipeUtilities . UserPipeSuffix ;
43+ using ( var client = new PipeClient < IVidCoderAutomation > ( new NetJsonPipeSerializer ( ) , pipeName ) )
4244 {
4345 await client . ConnectAsync ( ) . ConfigureAwait ( false ) ;
4446 await client . InvokeAsync ( action ) . ConfigureAwait ( false ) ;
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Text ;
5+
6+ namespace VidCoderCommon . Utilities ;
7+
8+ public static class PipeUtilities
9+ {
10+ /// <summary>
11+ /// To prevent cross-contamination of pipes between users, we append the username to the pipe name.
12+ /// We sanitize the username to ensure it only contains valid characters for a pipe name.
13+ /// </summary>
14+ public static string UserPipeSuffix => SanitizePipeSegment ( Environment . UserName ) ;
15+
16+ private static string SanitizePipeSegment ( string s )
17+ {
18+ if ( string . IsNullOrEmpty ( s ) )
19+ {
20+ return string . Empty ;
21+ }
22+
23+ return new string ( s . Select ( c => ( char . IsLetterOrDigit ( c ) || c == '_' || c == '-' || c == '.' ) ? c : '_' ) . ToArray ( ) ) ;
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments