-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- passing apk with namedpipe server & client - bring older window to front
- Loading branch information
1 parent
af68af0
commit 697de0e
Showing
5 changed files
with
143 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.IO.Pipes; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ApkManager.Lib | ||
{ | ||
class PipeClient | ||
{ | ||
private string pipename; | ||
|
||
public PipeClient(string pipename) | ||
{ | ||
this.pipename = pipename; | ||
} | ||
|
||
public async Task SendMessage(string message) | ||
{ | ||
using (var client = new NamedPipeClientStream(pipename)) | ||
{ | ||
await Task.Run(()=> client.Connect(1000)); | ||
using (var sw = new StreamWriter(client)) | ||
{ | ||
sw.AutoFlush = true; | ||
sw.WriteLine(message); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.IO.Pipes; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ApkManager.Lib | ||
{ | ||
class PipeServer | ||
{ | ||
public delegate void MessageEventHander(string message); | ||
public event MessageEventHander OnMessageReceived; | ||
|
||
NamedPipeServerStream server; | ||
private string pipename; | ||
|
||
public PipeServer(string pipename) | ||
{ | ||
this.pipename = pipename; | ||
} | ||
|
||
public async void StartListening() | ||
{ | ||
if (server != null) return; | ||
server = new NamedPipeServerStream(pipename); | ||
|
||
while(true) | ||
{ | ||
try | ||
{ | ||
await Task.Run(() => server.WaitForConnection()); | ||
using (var sr = new StreamReader(server)) | ||
{ | ||
OnMessageReceived?.Invoke(sr.ReadLine()); | ||
} | ||
server?.Disconnect(); | ||
} | ||
catch(Exception) | ||
{ | ||
break; | ||
} | ||
finally | ||
{ | ||
server?.Dispose(); | ||
server = null; | ||
} | ||
} | ||
} | ||
|
||
public void StopListening() | ||
{ | ||
server?.Dispose(); | ||
server = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters