개정판 77cdac33
벽산 수정 후 백업
Change-Id: I8e3eb48f615478a49efa0ab4014a8ef17d273d0a
DownloadManager/Program.cs | ||
---|---|---|
1 | 1 |
|
2 | 2 |
using log4net; |
3 |
using RestSharp; |
|
3 | 4 |
using System; |
4 | 5 |
using System.Diagnostics; |
6 |
using System.IO; |
|
5 | 7 |
using System.Linq; |
8 |
using System.Net.Http; |
|
9 |
using System.Net.Http.Headers; |
|
10 |
using System.Threading.Tasks; |
|
6 | 11 |
|
7 | 12 |
namespace DownloadManager |
8 | 13 |
{ |
... | ... | |
154 | 159 |
client.DownloadFileAsync(new Uri(System.Web.HttpUtility.UrlDecode(args[3])), args[4]); |
155 | 160 |
} |
156 | 161 |
} |
162 |
else if (args[0] == IIpc.ProcessTypeDefine.DEFINE_REST_FILE) |
|
163 |
{ |
|
164 |
var result = RestDownloadAsync(System.Web.HttpUtility.UrlDecode(args[3]), args[4]).GetAwaiter().GetResult(); |
|
165 |
|
|
166 |
if (!IsDebug) |
|
167 |
wcfClient.SendFileDownloadReceived(100, true); |
|
168 |
|
|
169 |
ConsoleWrite($"Download stream {args[4]} Completed"); |
|
170 |
IsDownload = result; |
|
171 |
|
|
172 |
//var client = new RestClient(System.Web.HttpUtility.UrlDecode(args[3])); |
|
173 |
//client.Timeout = -1; |
|
174 |
//var request = new RestRequest(Method.GET); |
|
175 |
//IRestResponse response = client.Execute(request); |
|
176 |
|
|
177 |
//var fileInfo = new FileInfo(args[4]); |
|
178 |
|
|
179 |
//using (var fileStream = fileInfo.OpenWrite()) |
|
180 |
//{ |
|
181 |
// int position = 0; |
|
182 |
// int step = 300000; |
|
183 |
// int length = 300000; |
|
184 |
|
|
185 |
// while (position < response.RawBytes.Length) |
|
186 |
// { |
|
187 |
// if (position + step < response.RawBytes.Length) |
|
188 |
// { |
|
189 |
// length = position + step; |
|
190 |
// } |
|
191 |
// else |
|
192 |
// { |
|
193 |
// length = response.RawBytes.Length - position; |
|
194 |
// } |
|
195 |
|
|
196 |
// fileStream.Write(response.RawBytes, position, length); |
|
197 |
|
|
198 |
// position = position + step; |
|
199 |
// } |
|
200 |
|
|
201 |
// if (!IsDebug) |
|
202 |
// wcfClient.SendFileDownloadReceived(100, true); |
|
203 |
|
|
204 |
// ConsoleWrite($"Download stream {args[4]} Completed"); |
|
205 |
// IsDownload = true; |
|
206 |
//} |
|
207 |
} |
|
157 | 208 |
|
158 | 209 |
while (!IsDownload) |
159 | 210 |
{ |
... | ... | |
175 | 226 |
} |
176 | 227 |
} |
177 | 228 |
|
229 |
private static async Task<bool> RestDownloadAsync(string uri, string savePath) |
|
230 |
{ |
|
231 |
bool result = false; |
|
232 |
|
|
233 |
try |
|
234 |
{ |
|
235 |
var client = new RestClient(uri); |
|
236 |
client.Timeout = -1; |
|
237 |
var request = new RestRequest(Method.GET); |
|
238 |
IRestResponse response = await client.ExecuteAsync(request); |
|
239 |
|
|
240 |
if (response.StatusCode == System.Net.HttpStatusCode.OK) |
|
241 |
{ |
|
242 |
var fs = File.Create(savePath); |
|
243 |
|
|
244 |
await fs.WriteAsync(response.RawBytes, 0, response.RawBytes.Length); |
|
245 |
fs.Close(); |
|
246 |
result = true; |
|
247 |
} |
|
248 |
} |
|
249 |
catch (Exception ex) |
|
250 |
{ |
|
251 |
logger.Error($"RestDownloadAsync : {uri} {savePath}", ex); |
|
252 |
} |
|
253 |
return result; |
|
254 |
} |
|
255 |
|
|
178 | 256 |
public static void DeleteFiles(string processType, string path) |
179 | 257 |
{ |
180 | 258 |
try |
내보내기 Unified diff