markus / IIpc / WcfServer.cs @ 2007ecaa
이력 | 보기 | 이력해설 | 다운로드 (2.18 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.ServiceModel; |
5 |
using System.Text; |
6 |
using System.Threading.Tasks; |
7 |
|
8 |
namespace IIpc |
9 |
{ |
10 |
public sealed class WcfServer : IIpcServer |
11 |
{ |
12 |
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] |
13 |
private class _Server : IIpcClient |
14 |
{ |
15 |
private readonly WcfServer server; |
16 |
|
17 |
public _Server(WcfServer server) |
18 |
{ |
19 |
this.server = server; |
20 |
} |
21 |
|
22 |
public void SendFileDownloadReceived(double progress, bool isFinish) |
23 |
{ |
24 |
this.server.OnFileDownloadReceived(new IpcDownloadStatusArgs(progress, isFinish)); |
25 |
} |
26 |
|
27 |
public void SendThumbnailReceived(int pageno, string path) |
28 |
{ |
29 |
this.server.OnThumbnailReceived(new IpcThumbnailEventArgs(pageno,path)); |
30 |
} |
31 |
} |
32 |
|
33 |
private readonly ServiceHost host; |
34 |
|
35 |
private void OnThumbnailReceived(IpcThumbnailEventArgs e) |
36 |
{ |
37 |
var handler = this.IpcThumbnailReceived; |
38 |
|
39 |
if (handler != null) |
40 |
{ |
41 |
handler(this, e); |
42 |
} |
43 |
} |
44 |
|
45 |
private void OnFileDownloadReceived(IpcDownloadStatusArgs e) |
46 |
{ |
47 |
var handler = this.IpcFileDownloadReceived; |
48 |
|
49 |
if (handler != null) |
50 |
{ |
51 |
handler(this, e); |
52 |
} |
53 |
} |
54 |
|
55 |
|
56 |
/// <summary> |
57 |
/// |
58 |
/// </summary> |
59 |
/// <param name="endpoint">지정된 끝점으로 유일하게 통신한다.</param> |
60 |
public WcfServer(string endpoint) |
61 |
{ |
62 |
this.host = new ServiceHost(new _Server(this), new Uri(string.Format("net.pipe://localhost/{0}", endpoint))); |
63 |
} |
64 |
|
65 |
public event EventHandler<IpcThumbnailEventArgs> IpcThumbnailReceived; |
66 |
public event EventHandler<IpcDownloadStatusArgs> IpcFileDownloadReceived; |
67 |
|
68 |
public void Start() |
69 |
{ |
70 |
this.host.Open(); |
71 |
} |
72 |
|
73 |
public void Stop() |
74 |
{ |
75 |
this.host.Close(); |
76 |
} |
77 |
|
78 |
void IDisposable.Dispose() |
79 |
{ |
80 |
this.Stop(); |
81 |
|
82 |
(this.host as IDisposable).Dispose(); |
83 |
} |
84 |
} |
85 |
} |