markus / DownloadManagerTest / Program.cs @ 08be599f
이력 | 보기 | 이력해설 | 다운로드 (5.45 KB)
1 | 03960fa5 | taeseongkim | using IIpc; |
---|---|---|---|
2 | using System; |
||
3 | using System.Collections.Generic; |
||
4 | using System.Diagnostics; |
||
5 | using System.IO; |
||
6 | using System.Linq; |
||
7 | using System.ServiceModel; |
||
8 | using System.Text; |
||
9 | using System.Threading.Tasks; |
||
10 | |||
11 | namespace DownloadManagerTest |
||
12 | { |
||
13 | class Program |
||
14 | { |
||
15 | static MarkusService.ServiceDeepViewClient Client; |
||
16 | |||
17 | static void Main(string[] args) |
||
18 | { |
||
19 | string downloadmanagerPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Plugin","DownloadManager.exe"); |
||
20 | |||
21 | if (!File.Exists(downloadmanagerPath)) |
||
22 | { |
||
23 | Console.WriteLine("DownloadManager.exe Not Found"); |
||
24 | } |
||
25 | else |
||
26 | { |
||
27 | var sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", false); |
||
28 | |||
29 | var _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
||
30 | Client = new MarkusService.ServiceDeepViewClient(GetBinding(), _EndPoint); |
||
31 | |||
32 | Console.WriteLine("Connection Service :" + _EndPoint.Uri); |
||
33 | |||
34 | string _projectNo = null; |
||
35 | string _documentId = null; |
||
36 | int _testLoop = 1; |
||
37 | |||
38 | projectIn: |
||
39 | Console.Write("Input Project No : "); |
||
40 | _projectNo = Console.ReadLine(); |
||
41 | |||
42 | if(string.IsNullOrWhiteSpace(_projectNo)) |
||
43 | { |
||
44 | goto projectIn; |
||
45 | } |
||
46 | |||
47 | DocumentIDIn: |
||
48 | Console.Write("Input Document Id : "); |
||
49 | _documentId = Console.ReadLine(); |
||
50 | |||
51 | if (string.IsNullOrWhiteSpace(_documentId)) |
||
52 | { |
||
53 | goto DocumentIDIn; |
||
54 | } |
||
55 | |||
56 | Console.Write("Test Loop Count(default 1) : "); |
||
57 | |||
58 | var strLoop = Console.ReadLine(); |
||
59 | int.TryParse(strLoop, out _testLoop); |
||
60 | |||
61 | |||
62 | var items = Client.GetDocInfo(new MarkusService.KCOM_BasicParam { projectNo = _projectNo, documentID = _documentId }); |
||
63 | |||
64 | if (items != null) |
||
65 | { |
||
66 | #region Page Storage Test |
||
67 | |||
68 | string tempStoragePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "MARKUS", System.IO.Path.GetRandomFileName()); |
||
69 | |||
70 | Directory.CreateDirectory(tempStoragePath); |
||
71 | |||
72 | OpenFolder(tempStoragePath); |
||
73 | |||
74 | string sFolder = _documentId.All(char.IsDigit) ? (Convert.ToUInt32(_documentId) / 100).ToString() : (_documentId.Length >= 5 ? _documentId.Substring(0, 5) : _documentId); |
||
75 | var MainUrl = string.Format(CommonLib.Common.GetConfigString("mainServerImageWebPath", "URL", "", false).Replace("png", "jpg"), _projectNo, sFolder, _documentId, "{PageNo}"); |
||
76 | |||
77 | KCOM.PageManager.PageStorage PageStorage = new KCOM.PageManager.PageStorage(MainUrl.Replace("jpg", "png"), tempStoragePath, "png", items.PAGE_COUNT); |
||
78 | |||
79 | Random rd = new Random(); |
||
80 | |||
81 | for (int j = 0; j < _testLoop; j++) |
||
82 | { |
||
83 | List<int> getPageList = Enumerable.Range(1, items.PAGE_COUNT).ToList<int>(); |
||
84 | |||
85 | for (int i = 0; i < items.PAGE_COUNT; i++) |
||
86 | { |
||
87 | int rdIndex = rd.Next(0, getPageList.Count); |
||
88 | |||
89 | var pageNo = getPageList[rdIndex]; |
||
90 | |||
91 | var getPage = PageStorage.GetPageUriAsync(null, pageNo).ConfigureAwait(false); |
||
92 | |||
93 | getPageList.RemoveAt(rdIndex); |
||
94 | |||
95 | Console.WriteLine(getPage.GetAwaiter().GetResult()); |
||
96 | } |
||
97 | } |
||
98 | |||
99 | Console.WriteLine("Page Storage Test OK."); |
||
100 | |||
101 | #endregion |
||
102 | |||
103 | #region DownloadManager Test |
||
104 | |||
105 | string endpoint = KCOM.Common.Commons.shortGuid() + "Thumbnail"; |
||
106 | IIpc.WcfServer wcfServer = new IIpc.WcfServer(endpoint); |
||
107 | wcfServer.IpcThumbnailReceived += WcfServer_IpcThumbnailReceived; |
||
108 | wcfServer.Start(); |
||
109 | |||
110 | KCOM.DownloadProcess.ThumbnailDownloader(endpoint,true, MainUrl, tempStoragePath, "jpg", items.PAGE_COUNT); |
||
111 | #endregion |
||
112 | |||
113 | } |
||
114 | else |
||
115 | { |
||
116 | Console.WriteLine("Item null"); |
||
117 | |||
118 | } |
||
119 | |||
120 | |||
121 | } |
||
122 | Console.ReadKey(); |
||
123 | } |
||
124 | |||
125 | private static void WcfServer_IpcThumbnailReceived(object sender, IpcThumbnailEventArgs e) |
||
126 | { |
||
127 | Console.WriteLine("Thumbnail : " + new Uri(e.Path, UriKind.Absolute).ToString()); |
||
128 | } |
||
129 | |||
130 | private static void OpenFolder(string folder) |
||
131 | { |
||
132 | Process.Start("explorer.exe", folder); |
||
133 | } |
||
134 | |||
135 | private static BasicHttpBinding GetBinding() |
||
136 | { |
||
137 | var _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
||
138 | _binding.MaxBufferSize = 2147483647; |
||
139 | _binding.MaxReceivedMessageSize = 2147483647; |
||
140 | _binding.OpenTimeout = new TimeSpan(0, 1, 0); |
||
141 | _binding.ReceiveTimeout = new TimeSpan(0, 10, 0); |
||
142 | _binding.CloseTimeout = new TimeSpan(0, 5, 0); |
||
143 | _binding.SendTimeout = new TimeSpan(0, 5, 0); |
||
144 | _binding.TextEncoding = System.Text.Encoding.UTF8; |
||
145 | _binding.TransferMode = TransferMode.Buffered; |
||
146 | |||
147 | return _binding; |
||
148 | } |
||
149 | } |
||
150 | } |