|
1 | | -//using System; |
2 | | -//using System.IO.Pipes; |
3 | | -//using System.Text; |
4 | | -//using SPCode.UI; |
| 1 | +using System; |
| 2 | +using System.IO.Pipes; |
| 3 | +using System.Text; |
| 4 | +using SPCode.UI; |
5 | 5 |
|
6 | | -//namespace SPCode.Interop |
7 | | -//{ |
8 | | -// public class PipeInteropServer : IDisposable |
9 | | -// { |
10 | | -// private NamedPipeServerStream pipeServer; |
11 | | -// private readonly MainWindow _window; |
| 6 | +namespace SPCode.Interop |
| 7 | +{ |
| 8 | + public class PipeInteropServer : IDisposable |
| 9 | + { |
| 10 | + private NamedPipeServerStream pipeServer; |
| 11 | + private readonly MainWindow _window; |
12 | 12 |
|
13 | | -// public PipeInteropServer(MainWindow window) |
14 | | -// { |
15 | | -// _window = window; |
16 | | -// } |
| 13 | + public PipeInteropServer(MainWindow window) |
| 14 | + { |
| 15 | + _window = window; |
| 16 | + } |
17 | 17 |
|
18 | | -// public void Start() |
19 | | -// { |
20 | | -// StartInteropServer(); |
21 | | -// } |
| 18 | + public void Start() |
| 19 | + { |
| 20 | + StartInteropServer(); |
| 21 | + } |
22 | 22 |
|
23 | | -// public void Close() |
24 | | -// { |
25 | | -// pipeServer.Close(); |
26 | | -// } |
| 23 | + public void Close() |
| 24 | + { |
| 25 | + pipeServer.Close(); |
| 26 | + } |
27 | 27 |
|
28 | | -// public void Dispose() |
29 | | -// { |
30 | | -// pipeServer.Close(); |
31 | | -// } |
| 28 | + public void Dispose() |
| 29 | + { |
| 30 | + pipeServer.Close(); |
| 31 | + } |
32 | 32 |
|
33 | | -// private void StartInteropServer() |
34 | | -// { |
35 | | -// if (pipeServer != null) |
36 | | -// { |
37 | | -// pipeServer.Close(); |
38 | | -// pipeServer = null; |
39 | | -// } |
40 | | -// pipeServer = new NamedPipeServerStream("SPCodeNamedPipeServer", PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); |
41 | | -// pipeServer.BeginWaitForConnection(new AsyncCallback(PipeConnection_MessageIn), null); |
42 | | -// } |
| 33 | + private void StartInteropServer() |
| 34 | + { |
| 35 | + if (pipeServer != null) |
| 36 | + { |
| 37 | + pipeServer.Close(); |
| 38 | + pipeServer = null; |
| 39 | + } |
| 40 | + pipeServer = new NamedPipeServerStream("SPCodeNamedPipeServer", PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); |
| 41 | + pipeServer.BeginWaitForConnection(new AsyncCallback(PipeConnection_MessageIn), null); |
| 42 | + } |
43 | 43 |
|
44 | | -// private void PipeConnection_MessageIn(IAsyncResult iar) |
45 | | -// { |
46 | | -// pipeServer.EndWaitForConnection(iar); |
47 | | -// var byteBuffer = new byte[4]; |
48 | | -// pipeServer.Read(byteBuffer, 0, sizeof(int)); |
49 | | -// var length = BitConverter.ToInt32(byteBuffer, 0); |
50 | | -// byteBuffer = new byte[length]; |
51 | | -// pipeServer.Read(byteBuffer, 0, length); |
52 | | -// var data = Encoding.UTF8.GetString(byteBuffer); |
53 | | -// var files = data.Split('|'); |
54 | | -// var SelectIt = true; |
55 | | -// for (var i = 0; i < files.Length; ++i) |
56 | | -// { |
57 | | -// _window.Dispatcher.Invoke(() => |
58 | | -// { |
59 | | -// if (_window.IsLoaded) |
60 | | -// { |
61 | | -// if (_window.TryLoadSourceFile(files[i], out _, SelectIt) && _window.WindowState == System.Windows.WindowState.Minimized) |
62 | | -// { |
63 | | -// _window.WindowState = System.Windows.WindowState.Normal; |
64 | | -// SelectIt = false; |
65 | | -// } |
66 | | -// } |
67 | | -// }); |
68 | | -// } |
69 | | -// StartInteropServer(); |
70 | | -// } |
71 | | -// } |
72 | | -//} |
| 44 | + private void PipeConnection_MessageIn(IAsyncResult iar) |
| 45 | + { |
| 46 | + pipeServer.EndWaitForConnection(iar); |
| 47 | + var byteBuffer = new byte[4]; |
| 48 | + pipeServer.Read(byteBuffer, 0, sizeof(int)); |
| 49 | + var length = BitConverter.ToInt32(byteBuffer, 0); |
| 50 | + byteBuffer = new byte[length]; |
| 51 | + pipeServer.Read(byteBuffer, 0, length); |
| 52 | + var data = Encoding.UTF8.GetString(byteBuffer); |
| 53 | + var files = data.Split('|'); |
| 54 | + var SelectIt = true; |
| 55 | + for (var i = 0; i < files.Length; ++i) |
| 56 | + { |
| 57 | + _window.Dispatcher.Invoke(() => |
| 58 | + { |
| 59 | + if (_window.IsLoaded) |
| 60 | + { |
| 61 | + if (_window.TryLoadSourceFile(files[i], out _, SelectIt) && _window.WindowState == System.Windows.WindowState.Minimized) |
| 62 | + { |
| 63 | + _window.WindowState = System.Windows.WindowState.Normal; |
| 64 | + SelectIt = false; |
| 65 | + } |
| 66 | + } |
| 67 | + }); |
| 68 | + } |
| 69 | + StartInteropServer(); |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments