프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / DownloadPlugin / BSENGRestDownload / BSENGRestDownloader.cs @ d91efe5c

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

1
using Markus.Service.Helper;
2
using RestSharp;
3
using System;
4
using System.Collections.Generic;
5
using System.IO;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Web;
10

    
11
namespace BSENGRestDownload
12
{
13
    public class BSENGRestDownload : Markus.Service.Convert.Plugin.IDownloadPlugin
14
    {
15
        public string Exception { get; set; }
16
        public string Name => nameof(BSENGRestDownload);
17

    
18
        /// <summary>
19
        /// PdfFileFullPath의 경로를 받아 SaveDirectory하위에 PdfFileFullPath파일명으로 저장
20
        /// </summary>
21
        /// <param name="PdfFilePath">PDF의 full path</param>
22
        /// <param name="SavePath">pdf를 다운받고자 하는 directory</param>
23
        public bool Do(string PdfFileFullPath, string SaveDirectory, ref string DownloadFilePath)
24
        {
25
            bool result = false;
26
            try
27
            {
28
                string _downloadFile = null;
29
                var client = new RestClient(PdfFileFullPath);
30
                client.Timeout = -1;
31
                var request = new RestRequest(Method.GET);
32
                IRestResponse response = client.Execute(request);
33

    
34
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
35
                {
36
                    var fileName = DownloadUri.GetFileNameInDisposition(new System.Net.Mime.ContentDisposition(response.Headers.Where(x => x.Name == "Content-Disposition").First().Value.ToString()));
37

    
38
                    _downloadFile = System.IO.Path.Combine(SaveDirectory, fileName);
39

    
40
                    var fs = File.Create(_downloadFile);
41

    
42
                    fs.Write(response.RawBytes, 0, response.RawBytes.Length);
43
                    fs.Close();
44

    
45
                    result = true;
46
                    DownloadFilePath = _downloadFile;
47
                }
48
                else
49
                {
50
                    this.Exception = $"{response.StatusCode.ToString()} {response.ErrorMessage}";
51
                }
52
            }
53
            catch (Exception ex)
54
            {
55
                this.Exception =  ex.ToString();
56
            }
57

    
58
            return result;
59
        }
60
    }
61
}
클립보드 이미지 추가 (최대 크기: 500 MB)