프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / IIpc / WcfServer.cs @ ddc223b4

이력 | 보기 | 이력해설 | 다운로드 (4.44 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.ServiceModel;
5
using System.ServiceModel.Channels;
6
using System.ServiceModel.Description;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Xml;
10

    
11
namespace IIpc
12
{
13
    public sealed class WcfServer : IIpcServer
14
    {
15
        [ServiceBehavior(IncludeExceptionDetailInFaults = true,InstanceContextMode = InstanceContextMode.Single)]
16
        private class _Server : IIpcClient
17
        {
18
            private readonly WcfServer server;
19
            
20
            public _Server(WcfServer server)
21
            {
22
                this.server = server;
23
            }
24

    
25
            public void SendFileDownloadReceived(double progress, bool isFinish)
26
            {
27
                this.server.OnFileDownloadReceived(new IpcDownloadStatusArgs(progress, isFinish));
28
            }
29

    
30
            public void SendThumbnailReceived(int pageno, string path)
31
            {
32
                this.server.OnThumbnailReceived(new IpcThumbnailEventArgs(pageno,path));
33
            }
34
        }
35

    
36
        private readonly ServiceHost host;
37

    
38
        private void OnThumbnailReceived(IpcThumbnailEventArgs e)
39
        {
40
            var handler = this.IpcThumbnailReceived;
41

    
42
            if (handler != null)
43
            {
44
                handler(this, e);
45
            }
46
        }
47

    
48
        private void OnFileDownloadReceived(IpcDownloadStatusArgs e)
49
        {
50
            var handler = this.IpcFileDownloadReceived;
51

    
52
            if (handler != null)
53
            {
54
                handler(this, e);
55
            }
56
        }
57

    
58

    
59
        /// <summary>
60
        /// 
61
        /// </summary>
62
        /// <param name="endpoint">지정된 끝점으로 유일하게 통신한다.</param>
63
        public WcfServer(string endpoint)
64
        {
65
            try
66
            {
67
                this.host = new ServiceHost(new _Server(this), new Uri(string.Format("net.pipe://localhost/{0}", endpoint)));
68

    
69
                //ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
70
                //smb.HttpGetEnabled = false;
71
                //host.Description.Behaviors.Add(smb);
72

    
73
                //var endpoints = this.host.AddDefaultEndpoints();
74
                //System.Diagnostics.Debug.WriteLine(endpoints);
75
            }
76
            catch (Exception ex)
77
            {
78
                System.Diagnostics.Debug.WriteLine(ex);
79
            }
80
            //this.host = new ServiceHost(this, new Uri(string.Format("net.pipe://localhost")));
81

    
82
            //ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior();
83
            //mBehave.HttpGetEnabled = false;
84
            //mBehave.HttpsGetEnabled = false;
85
            //this.host.Description.Behaviors.Add(mBehave);
86

    
87
            //if (endpoint != null)
88
            //{
89
            //    NetNamedPipeBinding binding = new NetNamedPipeBinding { TransferMode = TransferMode.Buffered };
90

    
91
            //    binding.CloseTimeout = new TimeSpan(0, 1, 0);
92
            //    binding.ReceiveTimeout = new TimeSpan(0, 1, 0);
93
            //    binding.SendTimeout = new TimeSpan(0, 1, 0);
94
            //    binding.OpenTimeout = new TimeSpan(0, 1, 0);
95

    
96
            //    binding.CreateBindingElements().Add(gBindingElement);
97

    
98
            //    var httpEndpoint = this.host.AddServiceEndpoint(typeof(IIpcServer), binding, endpoint);
99
            //}
100
        }
101

    
102
        public static BinaryMessageEncodingBindingElement gBindingElement = new BinaryMessageEncodingBindingElement
103
        {
104
            MaxReadPoolSize = Int16.MaxValue,
105
            MaxWritePoolSize = Int16.MaxValue,
106
            MaxSessionSize = Int16.MaxValue,
107
            ReaderQuotas = GetReaderQuotas()
108
        };
109

    
110
        public static XmlDictionaryReaderQuotas GetReaderQuotas()
111
        {
112
            return new XmlDictionaryReaderQuotas
113
            {
114
                MaxDepth = Int16.MaxValue,
115
                MaxStringContentLength = Int16.MaxValue,
116
                MaxArrayLength = Int16.MaxValue,
117
                MaxBytesPerRead = Int16.MaxValue,
118
                MaxNameTableCharCount = Int16.MaxValue
119
            };
120
        }
121

    
122

    
123
        public event EventHandler<IpcThumbnailEventArgs> IpcThumbnailReceived;
124
        public event EventHandler<IpcDownloadStatusArgs> IpcFileDownloadReceived;
125

    
126
        public void Start()
127

    
128
        {
129
            this.host.Open();
130
        }
131

    
132
        public void Stop()
133
        {
134
            this.host.Close();
135
        }
136

    
137
        void IDisposable.Dispose()
138
        {
139
            this.Stop();
140

    
141
            (this.host as IDisposable).Dispose();
142
        }
143
    }
144
}
클립보드 이미지 추가 (최대 크기: 500 MB)