markus / ConvertService / ConverterService / RemotingTest / Form1.cs @ 87542f92
이력 | 보기 | 이력해설 | 다운로드 (15.7 KB)
1 | 7ca218b3 | KangIngu | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.ComponentModel; |
||
4 | using System.Data; |
||
5 | using System.Drawing; |
||
6 | using System.Linq; |
||
7 | using System.Text; |
||
8 | using System.Windows.Forms; |
||
9 | using System.Runtime.Remoting.Channels.Tcp; |
||
10 | using System.Runtime.Remoting.Channels; |
||
11 | using System.Runtime.Remoting; |
||
12 | using IConverterPDF; |
||
13 | using DeepViewDataModel.DataModel; |
||
14 | using System.Threading; |
||
15 | using System.IO; |
||
16 | using DZConverterLib.Auth; |
||
17 | using System.Threading.Tasks; |
||
18 | using System.Net.Cache; |
||
19 | using System.Net; |
||
20 | using DeepViewDataModel.Common; |
||
21 | |||
22 | namespace RemotingTest |
||
23 | { |
||
24 | public partial class Form1 : Form, InterfaceConverterPDF |
||
25 | { |
||
26 | public Form1() |
||
27 | { |
||
28 | InitializeComponent(); |
||
29 | } |
||
30 | |||
31 | TcpChannel channel = null; |
||
32 | List<ConverterPDF> _thread = new List<ConverterPDF>(); |
||
33 | private Thread _ConverterPdfThread = null; |
||
34 | private Queue<ConverterPDF> _WorkItems = new Queue<ConverterPDF>(); |
||
35 | |||
36 | |||
37 | private void Form1_Load(object sender, EventArgs e) |
||
38 | { |
||
39 | |||
40 | } |
||
41 | |||
42 | public ConverterPDFResult Notify(string ProjectNo, Guid ConverterID) |
||
43 | { |
||
44 | _WorkItems.Enqueue(new ConverterPDF { ID = Guid.NewGuid() }); |
||
45 | |||
46 | if (_ConverterPdfThread == null) |
||
47 | { |
||
48 | _ConverterPdfThread = new Thread(new ThreadStart(ConverterPDFProcess)); |
||
49 | _ConverterPdfThread.SetApartmentState(ApartmentState.MTA); |
||
50 | _ConverterPdfThread.Start(); |
||
51 | } |
||
52 | |||
53 | return new ConverterPDFResult(); |
||
54 | } |
||
55 | |||
56 | public void ConverterPDFProcess() |
||
57 | { |
||
58 | while (_WorkItems.Count() > 0) |
||
59 | { |
||
60 | if (_thread.Count() > 10) |
||
61 | { |
||
62 | } |
||
63 | else |
||
64 | { |
||
65 | |||
66 | } |
||
67 | } |
||
68 | } |
||
69 | |||
70 | |||
71 | public int MultiProcessCount() |
||
72 | { |
||
73 | return Properties.Settings.Default.MultipleConverterCount; |
||
74 | } |
||
75 | |||
76 | public Guid[] RunningProcessID() |
||
77 | { |
||
78 | return _WorkItems.Select(t=>t.ID).ToArray(); |
||
79 | } |
||
80 | |||
81 | private void button1_Click(object sender, EventArgs e) |
||
82 | { |
||
83 | Client(); |
||
84 | var _id = remObj[0].RunningProcessID(); |
||
85 | |||
86 | _id.ToList().ForEach(f=> System.Diagnostics.Debug.WriteLine(f.ToString())); |
||
87 | |||
88 | var _info = remObj[0].ServiceInfomation(); |
||
89 | |||
90 | if (_info.Exception == null) |
||
91 | { |
||
92 | var _space = (_info.StorageInfo.First().FreeSpace / 1024f) / 1024f / 1024f; |
||
93 | MessageBox.Show("여유공간 : " + _space + "GB"); |
||
94 | } |
||
95 | else |
||
96 | { |
||
97 | System.Diagnostics.Debug.WriteLine(_info.Exception); |
||
98 | } |
||
99 | |||
100 | //Thread _send = new Thread(new ThreadStart(SendTest)); |
||
101 | //_send.SetApartmentState(ApartmentState.MTA); |
||
102 | //_send.Start(); |
||
103 | } |
||
104 | |||
105 | private void SendTest() |
||
106 | { |
||
107 | while (true) |
||
108 | { |
||
109 | for (int i = 0; i < remObj.Count; i++) |
||
110 | { |
||
111 | var _id = remObj[i].RunningProcessID(); |
||
112 | System.Diagnostics.Debug.WriteLine(_id.First()); |
||
113 | Thread.Sleep(10); |
||
114 | } |
||
115 | |||
116 | } |
||
117 | } |
||
118 | |||
119 | |||
120 | List<RemConverterPDFObject> remObj = null; |
||
121 | |||
122 | public void Client() |
||
123 | { |
||
124 | try |
||
125 | { |
||
126 | //for (int i = 0; i < 10; i++) |
||
127 | //{ |
||
128 | |||
129 | System.Runtime.Remoting.Channels.IChannel _ch = ChannelServices.GetChannel("tcp"); |
||
130 | |||
131 | if (_ch == null) |
||
132 | { |
||
133 | TcpChannel chan = new TcpChannel(); |
||
134 | ChannelServices.RegisterChannel(chan, false); |
||
135 | } |
||
136 | // Create an instance of the remote object |
||
137 | |||
138 | RemConverterPDFObject rem2 = (RemConverterPDFObject)Activator.GetObject(typeof(RemConverterPDFObject), |
||
139 | "tcp://172.20.120.180:8090/remConverterPDF"); |
||
140 | |||
141 | if (remObj == null) |
||
142 | remObj = new List<RemConverterPDFObject>(); |
||
143 | else |
||
144 | remObj.Clear(); |
||
145 | |||
146 | |||
147 | remObj.Add(rem2); |
||
148 | |||
149 | //} |
||
150 | |||
151 | } |
||
152 | catch (Exception ex) |
||
153 | { |
||
154 | } |
||
155 | |||
156 | } |
||
157 | |||
158 | public void Client1() |
||
159 | { |
||
160 | try |
||
161 | { |
||
162 | //for (int i = 0; i < 10; i++) |
||
163 | //{ |
||
164 | |||
165 | System.Runtime.Remoting.Channels.IChannel _ch = ChannelServices.GetChannel("tcp"); |
||
166 | |||
167 | if (_ch == null) |
||
168 | { |
||
169 | TcpChannel chan = new TcpChannel(); |
||
170 | ChannelServices.RegisterChannel(chan, false); |
||
171 | } |
||
172 | // Create an instance of the remote object |
||
173 | |||
174 | |||
175 | RemConverterPDFObject rem = (RemConverterPDFObject)Activator.GetObject(typeof(RemConverterPDFObject), |
||
176 | "tcp://172.20.100.72:8090/remConverterPDF"); |
||
177 | |||
178 | if (remObj == null) |
||
179 | remObj = new List<RemConverterPDFObject>(); |
||
180 | else |
||
181 | remObj.Clear(); |
||
182 | |||
183 | remObj.Add(rem); |
||
184 | |||
185 | //} |
||
186 | |||
187 | } |
||
188 | catch (Exception ex) |
||
189 | { |
||
190 | } |
||
191 | |||
192 | } |
||
193 | |||
194 | private void button2_Click(object sender, EventArgs e) |
||
195 | { |
||
196 | try |
||
197 | { |
||
198 | int _RemotingPort = Properties.Settings.Default.RemotingPort; |
||
199 | channel = new TcpChannel(_RemotingPort); |
||
200 | ChannelServices.RegisterChannel(channel, false); |
||
201 | RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemConverterPDFObject), |
||
202 | "remConverterPDF", WellKnownObjectMode.Singleton); |
||
203 | |||
204 | if(channel.ChannelData != null) |
||
205 | if (channel.ChannelData.GetType() == typeof(ChannelDataStore)) |
||
206 | { |
||
207 | var _url = (channel.ChannelData as ChannelDataStore).ChannelUris; |
||
208 | |||
209 | foreach (var item in _url) |
||
210 | { |
||
211 | UriBuilder bl = new UriBuilder(item); |
||
212 | |||
213 | if (bl.Scheme == Uri.UriSchemeNetTcp) |
||
214 | { |
||
215 | System.Diagnostics.Debug.WriteLine("uri Scheme : " + Uri.UriSchemeNetTcp); |
||
216 | } |
||
217 | |||
218 | string _Host = bl.Host; |
||
219 | System.Diagnostics.Debug.WriteLine(_Host); |
||
220 | } |
||
221 | } |
||
222 | } |
||
223 | catch (Exception ex) |
||
224 | { |
||
225 | } |
||
226 | |||
227 | IConverterPDF.Cache.Attach(this); |
||
228 | } |
||
229 | |||
230 | private void button3_Click(object sender, EventArgs e) |
||
231 | { |
||
232 | |||
233 | } |
||
234 | |||
235 | |||
236 | int InterfaceConverterPDF.MultiProcessCount |
||
237 | { |
||
238 | get |
||
239 | { |
||
240 | throw new NotImplementedException(); |
||
241 | } |
||
242 | set |
||
243 | { |
||
244 | throw new NotImplementedException(); |
||
245 | } |
||
246 | } |
||
247 | |||
248 | public ServiceInfo ServiceInfomation() |
||
249 | { |
||
250 | throw new NotImplementedException(); |
||
251 | } |
||
252 | |||
253 | public TileSorceStorageInfo[] TileSorceStorageInfomation() |
||
254 | { |
||
255 | throw new NotImplementedException(); |
||
256 | } |
||
257 | object _lock = new object(); |
||
258 | |||
259 | void DeteteDirectory(string Path) |
||
260 | { |
||
261 | Thread _stathread = new Thread(new ParameterizedThreadStart(DeteteWork)); |
||
262 | _stathread.SetApartmentState(ApartmentState.MTA); |
||
263 | _stathread.Start(Path); |
||
264 | } |
||
265 | |||
266 | void DeteteWork(object Path) |
||
267 | { |
||
268 | DirectoryInfo _dir = new DirectoryInfo(Path.ToString()); |
||
269 | |||
270 | _dir.EnumerateDirectories().AsParallel().ForAll(d => |
||
271 | { |
||
272 | d.Delete(true); |
||
273 | }); |
||
274 | |||
275 | _dir.Delete(true); |
||
276 | } |
||
277 | |||
278 | |||
279 | private void button4_Click(object sender, EventArgs e) |
||
280 | { |
||
281 | |||
282 | string DocUri = @"http://portal.daelimplant.com/100481_app/Lists/VPLIST/Attachments/115047/VP-100481-29-001-PK8001-3700_0.pdf"; |
||
283 | string ItemPath = @"\\172.20.100.71\TileSource\000000_Tile\1050\115047_"; |
||
284 | string _delPath = ItemPath; |
||
285 | //lock (_lock) |
||
286 | //{ |
||
287 | try |
||
288 | { |
||
289 | DirectoryInfo _dir = new DirectoryInfo(ItemPath); |
||
290 | |||
291 | if (_dir.Exists) |
||
292 | { |
||
293 | for (int i = 0; i < 100; i++) |
||
294 | { |
||
295 | _delPath = ItemPath + "_" + i.ToString(); |
||
296 | if (!Directory.Exists(ItemPath + "_" + i.ToString())) |
||
297 | { |
||
298 | _dir.MoveTo(_delPath); |
||
299 | DeteteDirectory(_delPath); |
||
300 | break; |
||
301 | } |
||
302 | } |
||
303 | } |
||
304 | |||
305 | //DZConverter.DeleteDirectoryDirs(revPath); |
||
306 | Directory.CreateDirectory(ItemPath); |
||
307 | |||
308 | } |
||
309 | catch (Exception ex) |
||
310 | { |
||
311 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
312 | } |
||
313 | |||
314 | |||
315 | |||
316 | try |
||
317 | { |
||
318 | Filefactory _fileFactory = new Filefactory(); |
||
319 | HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); |
||
320 | _fileFactory.CachePolicy = policy; |
||
321 | var _auth = AuthUser(DocUri); |
||
322 | if (_auth != null) |
||
323 | { |
||
324 | _fileFactory.DownloadFile(new Uri(DocUri), ItemPath + "\\VP-100481-29-001-PK8001-3700_0.pdf"); |
||
325 | } |
||
326 | else |
||
327 | { |
||
328 | } |
||
329 | } |
||
330 | catch (Exception ex) |
||
331 | { |
||
332 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
333 | } |
||
334 | //} |
||
335 | } |
||
336 | |||
337 | private System.Net.ICredentials AuthUser(string PDFurl) |
||
338 | { |
||
339 | System.Net.NetworkCredential credentials = null; |
||
340 | try |
||
341 | { |
||
342 | var _url = new UriBuilder(new Uri(PDFurl).AbsoluteUri.Replace(new Uri(PDFurl).PathAndQuery, "/")); |
||
343 | var _dns = _url.Host.Split('.'); |
||
344 | |||
345 | if(_dns.Count() == 3) |
||
346 | if (_dns[0].ToLower() != "www") |
||
347 | { |
||
348 | _dns[0] = "www"; |
||
349 | _url.Host = _dns[0] + "." + _dns[1] + "." + _dns[2]; |
||
350 | } |
||
351 | |||
352 | System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(_url.ToString()); |
||
353 | credentials = Crediential.GetAdminCrediential(_url.ToString()); |
||
354 | request.Credentials = credentials; |
||
355 | System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); |
||
356 | response.Close(); |
||
357 | } |
||
358 | catch (Exception ex) |
||
359 | { |
||
360 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
361 | return credentials; |
||
362 | } |
||
363 | |||
364 | return credentials; |
||
365 | } |
||
366 | |||
367 | private void button5_Click(object sender, EventArgs e) |
||
368 | { |
||
369 | try |
||
370 | { |
||
371 | for (int i = 0; i < Enum.GetValues(typeof(HttpRequestCacheLevel)).Length; i++) |
||
372 | { |
||
373 | |||
374 | var _value = Enum.Parse(typeof(HttpRequestCacheLevel), i.ToString(),true); |
||
375 | System.Diagnostics.Stopwatch _watch = new System.Diagnostics.Stopwatch(); |
||
376 | _watch.Start(); |
||
377 | string DocUri = @"http://portal.daelimplant.com/100481_app/Lists/VPLIST/Attachments/115372/VP-100481-16-117-PK6101-621_5.pdf"; |
||
378 | System.Net.WebClient _fileFactory = new System.Net.WebClient(); |
||
379 | HttpRequestCachePolicy policy = new HttpRequestCachePolicy((HttpRequestCacheLevel)_value); |
||
380 | _fileFactory.CachePolicy = policy; |
||
381 | |||
382 | var _auth = AuthUser(DocUri); |
||
383 | if (_auth !=null) |
||
384 | { |
||
385 | _fileFactory.Credentials = _auth; |
||
386 | _fileFactory.DownloadFile(new Uri(DocUri), Application.StartupPath+"\\VP-100481-29-001-PK8001-3700_0.pdf"); |
||
387 | } |
||
388 | _watch.Stop(); |
||
389 | System.Diagnostics.Debug.WriteLine(_value.ToString() + " 완료시간: " + _watch.ElapsedMilliseconds); |
||
390 | |||
391 | } |
||
392 | GC.Collect(1); |
||
393 | GC.Collect(1); |
||
394 | } |
||
395 | catch (Exception ex) |
||
396 | { |
||
397 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
398 | } |
||
399 | } |
||
400 | |||
401 | private void button6_Click(object sender, EventArgs e) |
||
402 | { |
||
403 | var _name = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString(); |
||
404 | System.Diagnostics.Debug.WriteLine(_name); |
||
405 | int _RemotingPort = 8090; |
||
406 | channel = new TcpChannel(_RemotingPort); |
||
407 | ChannelServices.RegisterChannel(channel, false); |
||
408 | RemotingConfiguration.RegisterWellKnownServiceType(typeof(IntPtr), |
||
409 | "test", WellKnownObjectMode.Singleton); |
||
410 | |||
411 | } |
||
412 | |||
413 | protected override void AdjustFormScrollbars(bool displayScrollbars) |
||
414 | { |
||
415 | base.AdjustFormScrollbars(displayScrollbars); |
||
416 | } |
||
417 | |||
418 | private void button7_Click(object sender, EventArgs e) |
||
419 | { |
||
420 | |||
421 | using (DeepViewEntities _deepview = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
||
422 | { |
||
423 | Guid id = Guid.Parse("707139a8-da38-4ca8-89bb-886da27f5f92"); |
||
424 | var _converterItems = _deepview.ConverterPDF.Where(c => c.SubPassID == id |
||
425 | && c.Status != 4 && c.ReConverter == false); |
||
426 | |||
427 | foreach (var item in _converterItems) |
||
428 | { |
||
429 | item.Status = 0; |
||
430 | item.ReConverter = true; |
||
431 | item.SubPassID = null; |
||
432 | } |
||
433 | |||
434 | if (_converterItems.Count() > 0) |
||
435 | _deepview.SaveChanges(); |
||
436 | |||
437 | } |
||
438 | } |
||
439 | |||
440 | |||
441 | Uri ServiceUri() |
||
442 | { |
||
443 | Uri _result = null; |
||
444 | |||
445 | try |
||
446 | { |
||
447 | if (channel.ChannelData != null) |
||
448 | if (channel.ChannelData.GetType() == typeof(ChannelDataStore)) |
||
449 | { |
||
450 | var _uris = (channel.ChannelData as ChannelDataStore).ChannelUris; |
||
451 | |||
452 | if (_uris.Count() > 0) |
||
453 | _result = new Uri(_uris[0]); |
||
454 | } |
||
455 | } |
||
456 | catch (Exception) |
||
457 | { |
||
458 | new Exception("service Uri Eorror"); |
||
459 | } |
||
460 | |||
461 | return _result; |
||
462 | } |
||
463 | |||
464 | |||
465 | public bool ServiceOn(Guid ServiceID) |
||
466 | { |
||
467 | throw new NotImplementedException(); |
||
468 | } |
||
469 | |||
470 | private void button8_Click(object sender, EventArgs e) |
||
471 | { |
||
472 | Client1(); |
||
473 | var _id = remObj[0].RunningProcessID(); |
||
474 | |||
475 | _id.ToList().ForEach(f => System.Diagnostics.Debug.WriteLine(f.ToString())); |
||
476 | |||
477 | var _info = remObj[0].ServiceInfomation(); |
||
478 | |||
479 | if (_info.Exception == null) |
||
480 | { |
||
481 | var _space = (_info.StorageInfo.First().FreeSpace / 1024f) / 1024f / 1024f; |
||
482 | MessageBox.Show("여유공간 : " + _space + "GB"); |
||
483 | } |
||
484 | else |
||
485 | { |
||
486 | System.Diagnostics.Debug.WriteLine(_info.Exception); |
||
487 | } |
||
488 | } |
||
489 | |||
490 | private void button9_Click(object sender, EventArgs e) |
||
491 | { |
||
492 | MessageBox.Show(System.Environment.MachineName); |
||
493 | } |
||
494 | } |
||
495 | } |