markus / MarkusAutoUpdate / src / IIpc / WcfServer.cs @ d8f5045e
이력 | 보기 | 이력해설 | 다운로드 (2.4 KB)
1 | d8f5045e | taeseongkim | 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 ParamReceived(string InstallPath, string tempStoragePath, string downloadFile, string KcomPath, string Param) |
||
23 | { |
||
24 | this.server.OnParamReceived(new ParamReceivedEventArgs(InstallPath, tempStoragePath, downloadFile, KcomPath, Param)); |
||
25 | } |
||
26 | |||
27 | public void ProcessStart() |
||
28 | { |
||
29 | this.server.OnProcessStart(new EventArgs()); |
||
30 | } |
||
31 | } |
||
32 | |||
33 | private readonly ServiceHost host; |
||
34 | public Uri Endpoint; |
||
35 | |||
36 | public event EventHandler<ParamReceivedEventArgs> ParamReceived; |
||
37 | public event EventHandler<EventArgs> ProcessStart; |
||
38 | |||
39 | private void OnParamReceived(ParamReceivedEventArgs e) |
||
40 | { |
||
41 | var handler = this.ParamReceived; |
||
42 | |||
43 | if (handler != null) |
||
44 | { |
||
45 | handler(this, e); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | private void OnProcessStart(EventArgs e) |
||
50 | { |
||
51 | var handler = this.ProcessStart; |
||
52 | |||
53 | if (handler != null) |
||
54 | { |
||
55 | handler(this, e); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | |||
60 | /// <summary> |
||
61 | /// |
||
62 | /// </summary> |
||
63 | /// <param name="endpoint">지정된 끝점으로 유일하게 통신한다.</param> |
||
64 | public WcfServer(string endpoint) |
||
65 | { |
||
66 | this.Endpoint = new Uri(string.Format("net.pipe://localhost/{0}", endpoint)); |
||
67 | this.host = new ServiceHost(new _Server(this), Endpoint); |
||
68 | |||
69 | //this.host.AddServiceEndpoint(typeof(IIpcServer), new NetNamedPipeBinding(), endpoint); |
||
70 | } |
||
71 | |||
72 | |||
73 | public void Start() |
||
74 | { |
||
75 | this.host.Open(); |
||
76 | } |
||
77 | |||
78 | public CommunicationState State() |
||
79 | { |
||
80 | return this.host.State; |
||
81 | } |
||
82 | |||
83 | public void Stop() |
||
84 | { |
||
85 | this.host.Close(); |
||
86 | } |
||
87 | |||
88 | void IDisposable.Dispose() |
||
89 | { |
||
90 | this.Stop(); |
||
91 | |||
92 | (this.host as IDisposable).Dispose(); |
||
93 | } |
||
94 | } |
||
95 | } |