프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / TestDocumentInfo / DocumentInfoProcess.cs @ a5e5fff6

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

1 dfc86b71 taeseongkim
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using Markus.Service.Convert.Plugin;
7 a5e5fff6 taeseongkim
using Markus.Service.DataBase.Entities;
8
using Markus.Service.DataBase.Repositories;
9 dfc86b71 taeseongkim
using Markus.Service.Extensions;
10
11
namespace TestDocumentInfo
12
{
13
    public class DocumentInfoProcess : Markus.Service.Convert.Plugin.IPlugin
14
    {
15
        public string Name => "TestDocumentInfo";
16
17
        public string Exception { get; set; }
18
        public string gConvertID;
19
20
        private const string MARKUS_ConnectionString_KEY = "MARKUS_ConnectionString";
21
22
        bool IPlugin.Do(string ConvertID, Dictionary<string, object> Parameters)
23
        {
24
            bool result = false;
25
26
            gConvertID = ConvertID;
27
28
            try
29
            {
30
31
                if (Parameters.Keys.Count(x => x == MARKUS_ConnectionString_KEY) > 0)
32
                {
33 a5e5fff6 taeseongkim
                    string connectionString = Markus.Service.Extensions.Encrypt.AESEncrypter.Decrypt(Parameters[MARKUS_ConnectionString_KEY].ToString());
34 dfc86b71 taeseongkim
35 a5e5fff6 taeseongkim
                    using (ConvertDocRepository database = new ConvertDocRepository(connectionString))
36 dfc86b71 taeseongkim
                    {
37 a5e5fff6 taeseongkim
                        var convertItem = database.GetConvertDocSingleAsync(ConvertID: ConvertID).GetAwaiter().GetResult();
38 dfc86b71 taeseongkim
39 a5e5fff6 taeseongkim
                        if (convertItem != null)
40 dfc86b71 taeseongkim
                        {
41
                            string projectNo = convertItem.PROJECT_NO;
42
                            string documentId = convertItem.DOCUMENT_ID;
43
44 a5e5fff6 taeseongkim
                            using (DOCUMENTITEMRepository repository = new DOCUMENTITEMRepository(connectionString))
45 dfc86b71 taeseongkim
                            {
46 a5e5fff6 taeseongkim
                                DOCUMENTITEM documentItem = repository.GetFirstAsync(projectNo, documentId).GetAwaiter().GetResult();
47 dfc86b71 taeseongkim
48 a5e5fff6 taeseongkim
                                if (documentItem != null)
49 dfc86b71 taeseongkim
                                {
50 a5e5fff6 taeseongkim
                                    documentItem.DOCUMENT_NAME = documentItem.DOCUMENT_NAME;
51
                                    documentItem.REVISION = documentItem.REVISION;
52
                                    documentItem.DOCUMENT_NO = documentItem.DOCUMENT_NO;
53
                                    documentItem.ORIGINAL_FILE = convertItem.DOCUMENT_URL;
54
                                }
55
                                else
56
                                {
57
                                    string docNo = "";
58
59
                                    var filename = convertItem.DOCUMENT_URL.Split('/').LastOrDefault();
60
61
                                    if (filename.Contains('.'))
62
                                    {
63
                                        docNo = filename.Split('.').First();
64
                                    }
65
66
                                    documentItem = new DOCUMENTITEM
67
                                    { 
68
                                        ID = new Guid().CreateUniqueGuid().ToString(),
69
                                        DOCUMENT_NO = docNo,
70
                                        REVISION = "A",
71
                                        DOCUMENT_NAME = docNo,
72
                                        GROUP_NO = "11",
73
                                        ORIGINAL_FILE = convertItem.DOCUMENT_URL,
74
                                        DOCUMENT_ID = documentId,
75
                                        PROJECT_NO = projectNo,
76
                                        Link = convertItem.DOCUMENT_URL
77
                                    };
78 dfc86b71 taeseongkim
                                }
79
80 a5e5fff6 taeseongkim
                                var id =  repository.CreateOrUPdateAsync(documentItem).GetAwaiter().GetResult();
81
82
                                if(id != null)
83 dfc86b71 taeseongkim
                                {
84 a5e5fff6 taeseongkim
                                    result = true;
85
                                }
86 dfc86b71 taeseongkim
                            }
87
                        }
88
                    }
89
90
                }
91
                else
92
                {
93
                    this.Exception = "MARKUS_ConnectionString SECTION Not Found";
94
                }
95
            }
96
97
            catch (Exception ex)
98
            {
99
                this.Exception = ex.ToString();
100
                result = false;
101
            }
102
103
            return result;
104
        }
105
    }
106
}
클립보드 이미지 추가 (최대 크기: 500 MB)