markus / ConvertService / ConverterService / ServiceTest / Form1.cs @ ce3f0d7a
이력 | 보기 | 이력해설 | 다운로드 (8.79 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.Security; |
||
10 | using System.Web; |
||
11 | using System.Net; |
||
12 | using System.Net.Cache; |
||
13 | using System.Security.Principal; |
||
14 | using CredentialAPI; |
||
15 | |||
16 | namespace ServiceTest |
||
17 | { |
||
18 | public partial class Form1 : Form |
||
19 | { |
||
20 | Queue<Uri> _lstdownurl = null; |
||
21 | int _count = 0; |
||
22 | |||
23 | public Form1() |
||
24 | { |
||
25 | InitializeComponent(); |
||
26 | this.FormClosing += new FormClosingEventHandler(Form1_FormClosing); |
||
27 | |||
28 | _lstdownurl = new Queue<Uri>(); |
||
29 | _lstdownurl.Enqueue(new Uri(@"http://portal.daelimplant.com/110670_APP/VPCS_DOCLIB/10700/10629/From Vendor/SEP-15-108-CU-P-05AB-G-0002_R01.pdf")); |
||
30 | _lstdownurl.Enqueue(new Uri(@"http://portal.daelimplant.com/100481_app/Lists/VPLIST/Attachments/115555/VP-100481-44-475-002-A01-104_R.0.pdf")); |
||
31 | //_lstdownurl.Enqueue(new Uri(@"http://portal.daelimplant.com/100481_app/Lists/VPLIST/Attachments/115510/VP-100481-44-432-001-A01-003_2.pdf")); |
||
32 | //if (cache == null) |
||
33 | //{ |
||
34 | // cache = new CredentialCache(); |
||
35 | // NetworkCredential nc = new NetworkCredential(@"daelim\esbsystem", "kdm707"); |
||
36 | // NetworkCredential ncNtlm = new NetworkCredential(@"esbsystem", "kdm707", "daelim"); |
||
37 | // cache.Add(new Uri("http://portal.daelimplant.com"), System.Net.AuthenticationSchemes.Basic.ToString(), nc); |
||
38 | // cache.Add(new Uri("http://portal.daelimplant.com"), System.Net.AuthenticationSchemes.Ntlm.ToString(), ncNtlm); |
||
39 | //} |
||
40 | //HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(new Uri("http://portal.daelimplant.com")); |
||
41 | //myHttpWebRequest.Credentials = cache; |
||
42 | //myHttpWebRequest.GetRequestStream(); |
||
43 | |||
44 | //_lstClient.Add(_client); |
||
45 | _client.Credentials = cache; |
||
46 | _client.UseDefaultCredentials = true; |
||
47 | RequestCachePolicy policy = new RequestCachePolicy(RequestCacheLevel.Revalidate); |
||
48 | _client.CachePolicy = policy; |
||
49 | _client.DownloadFileCompleted += new AsyncCompletedEventHandler(_client_DownloadFileCompleted); |
||
50 | _client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(_client_DownloadProgressChanged); |
||
51 | } |
||
52 | |||
53 | void Form1_FormClosing(object sender, FormClosingEventArgs e) |
||
54 | { |
||
55 | _lstClient.ForEach(w => w.CancelAsync()); |
||
56 | } |
||
57 | |||
58 | object _Lock = new object(); |
||
59 | CredentialCache cache = null; |
||
60 | List<WebClient> _lstClient = new List<WebClient>(); |
||
61 | System.Diagnostics.Stopwatch _Watch = new System.Diagnostics.Stopwatch(); |
||
62 | |||
63 | private void button1_Click(object sender, EventArgs e) |
||
64 | { |
||
65 | _count = 0; |
||
66 | |||
67 | //lock (_Lock) |
||
68 | //{ |
||
69 | |||
70 | // System.IO.DirectoryInfo _dir = new System.IO.DirectoryInfo(Application.StartupPath); |
||
71 | |||
72 | // _dir.EnumerateFiles("*.pdf").AsParallel().ForAll(f => |
||
73 | // { |
||
74 | // f.Delete(); |
||
75 | // f.Refresh(); |
||
76 | // if (f.Exists) |
||
77 | // { |
||
78 | // MessageBox.Show("에러"); |
||
79 | // } |
||
80 | // }); |
||
81 | |||
82 | //} |
||
83 | |||
84 | //System.Threading.Thread.Sleep(5000); |
||
85 | _Watch.Reset(); |
||
86 | _Watch.Start(); |
||
87 | |||
88 | Uri _downurl = _lstdownurl.Dequeue(); |
||
89 | _lstdownurl.Enqueue(_downurl); |
||
90 | var _savefile = _downurl.PathAndQuery.Split('/').Last(); |
||
91 | var _name = @"daelim\esbsystem".Split('\\'); |
||
92 | |||
93 | //new Uri(_downurl.AbsoluteUri.Replace(new Uri(PDFurl).PathAndQuery, "/")) |
||
94 | |||
95 | DownFile(); |
||
96 | } |
||
97 | WebClient _client = new WebClient(); |
||
98 | void DownFile() |
||
99 | { |
||
100 | Uri _downurl = _lstdownurl.Dequeue(); |
||
101 | _lstdownurl.Enqueue(_downurl); |
||
102 | //var _savefile = _downurl.PathAndQuery.Split('/').Last(); |
||
103 | //var _name = @"daelim\esbsystem".Split('\\'); |
||
104 | |||
105 | ////new Uri(_downurl.AbsoluteUri.Replace(new Uri(PDFurl).PathAndQuery, "/")) |
||
106 | //if (cache == null) |
||
107 | //{ |
||
108 | // cache = new CredentialCache(); |
||
109 | // NetworkCredential nc = new NetworkCredential(@"daelim\esbsystem", "kdm707"); |
||
110 | // NetworkCredential ncNtlm = new NetworkCredential(@"esbsystem", "kdm707", "daelim"); |
||
111 | // cache.Add(_downurl, System.Net.AuthenticationSchemes.Basic.ToString(), nc); |
||
112 | // cache.Add(_downurl, System.Net.AuthenticationSchemes.Ntlm.ToString(), ncNtlm); |
||
113 | //} |
||
114 | ////HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(_downurl); |
||
115 | ////myHttpWebRequest.Credentials = cache; |
||
116 | ////myHttpWebRequest.GetRequestStream(); |
||
117 | ////System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://www.daelimplant.com"); |
||
118 | ////request.Credentials = cache; |
||
119 | ////System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); |
||
120 | ////response.Close(); |
||
121 | // WebClient _client = new WebClient(); |
||
122 | // _lstClient.Add(_client); |
||
123 | //_client.Credentials = cache; |
||
124 | //RequestCachePolicy policy = new RequestCachePolicy(RequestCacheLevel.Default); |
||
125 | //_client.CachePolicy = policy; |
||
126 | |||
127 | //_client.DownloadFileCompleted += new AsyncCompletedEventHandler(_client_DownloadFileCompleted); |
||
128 | //_client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(_client_DownloadProgressChanged); |
||
129 | //_client.DownloadFile(_downurl, @"\\172.20.100.71\TileSource\000000_Tile\1050\" + _count.ToString() + "_Test.PDF"); //+ _savefile); |
||
130 | |||
131 | //System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(_downurl); |
||
132 | //request.Credentials = cache; |
||
133 | //System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse(); |
||
134 | //response.Close(); |
||
135 | //_Watch.Reset(); |
||
136 | //_Watch.Start(); |
||
137 | //RequestCachePolicy policy = new RequestCachePolicy((RequestCacheLevel)_count); |
||
138 | //_client.CachePolicy = policy; |
||
139 | _client.DownloadFileAsync(_downurl, @"\\172.20.100.71\TileSource\000000_Tile\1050\" + _count.ToString() + "__Test.PDF", _client.GetHashCode()); //+ _savefile); |
||
140 | } |
||
141 | |||
142 | void _client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) |
||
143 | { |
||
144 | progressBar1.Value = e.ProgressPercentage; |
||
145 | |||
146 | //_count++; |
||
147 | |||
148 | //if (_count < 3) |
||
149 | //{ |
||
150 | // _count++; |
||
151 | // DownFile(); |
||
152 | //} |
||
153 | } |
||
154 | |||
155 | void _client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) |
||
156 | { |
||
157 | //var _client = _lstClient.Where(w => w.GetHashCode() == (int)e.UserState).ToList(); |
||
158 | |||
159 | //if (_client.Count() > 0) |
||
160 | //{ |
||
161 | // _client.First().Dispose(); |
||
162 | // _lstClient.Remove(_client.First()); |
||
163 | //} |
||
164 | |||
165 | //if (_lstClient.Count() == 0) |
||
166 | //{ |
||
167 | // _Watch.Stop(); |
||
168 | // MessageBox.Show("완료 -" + _Watch.ElapsedMilliseconds); |
||
169 | //} |
||
170 | |||
171 | if (e.Error != null) |
||
172 | { |
||
173 | if (e.Error.GetType() == typeof(System.Net.WebException)) |
||
174 | { |
||
175 | MessageBox.Show(e.Error.ToString()); |
||
176 | } |
||
177 | } |
||
178 | else |
||
179 | { |
||
180 | //GC.Collect(2); |
||
181 | //GC.Collect(2); |
||
182 | //_count++; |
||
183 | |||
184 | //if(_count <= 10) |
||
185 | // DownFile(); |
||
186 | } |
||
187 | |||
188 | System.Diagnostics.Debug.WriteLine("Type : " + ((RequestCacheLevel)_count).ToString() + " Time : " + _Watch.ElapsedMilliseconds); |
||
189 | if (_count < 6) |
||
190 | { |
||
191 | _count++; |
||
192 | DownFile(); |
||
193 | } |
||
194 | else |
||
195 | { |
||
196 | _Watch.Stop(); |
||
197 | MessageBox.Show("완료 -" + _Watch.ElapsedMilliseconds); |
||
198 | } |
||
199 | |||
200 | } |
||
201 | |||
202 | private void button2_Click(object sender, EventArgs e) |
||
203 | { |
||
204 | |||
205 | } |
||
206 | |||
207 | private void button3_Click(object sender, EventArgs e) |
||
208 | { |
||
209 | CredentialAPI.Credential _cre = new Credential(); |
||
210 | |||
211 | CredentialAPI.CredentialAPI.CredRead("172.20.120.72", CRED_TYPE.DOMAIN_PASSWORD, 0, out _cre); |
||
212 | System.Diagnostics.Debug.WriteLine(_cre.UserName); |
||
213 | } |
||
214 | |||
215 | private void button4_Click(object sender, EventArgs e) |
||
216 | { |
||
217 | |||
218 | //CredentialAPI.CredentialAPI.CredSave("portal.daelimplant.com",@"daelim\esbsystem","kdm707", ref _cre); |
||
219 | //System.Diagnostics.Debug.WriteLine(_cre.wszUser); |
||
220 | } |
||
221 | } |
||
222 | } |