프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (4.48 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 731c84b8 taeseongkim
        private const string DBTYPE_KEY = "DBTYPE";
21 dfc86b71 taeseongkim
        private const string MARKUS_ConnectionString_KEY = "MARKUS_ConnectionString";
22
23
        bool IPlugin.Do(string ConvertID, Dictionary<string, object> Parameters)
24
        {
25
            bool result = false;
26
27
            gConvertID = ConvertID;
28
29
            try
30
            {
31
32
                if (Parameters.Keys.Count(x => x == MARKUS_ConnectionString_KEY) > 0)
33
                {
34 731c84b8 taeseongkim
                    Parameters.TryGetValue(DBTYPE_KEY, out object dbtypeStr);
35
                    Markus.Service.DataBase.DBMSType dbtype = (Markus.Service.DataBase.DBMSType)Enum.Parse(typeof(Markus.Service.DataBase.DBMSType), dbtypeStr.ToString());
36
                   
37 a5e5fff6 taeseongkim
                    string connectionString = Markus.Service.Extensions.Encrypt.AESEncrypter.Decrypt(Parameters[MARKUS_ConnectionString_KEY].ToString());
38 dfc86b71 taeseongkim
39 731c84b8 taeseongkim
                    using (ConvertDocRepository database = new ConvertDocRepository(connectionString, dbtype))
40 dfc86b71 taeseongkim
                    {
41 a5e5fff6 taeseongkim
                        var convertItem = database.GetConvertDocSingleAsync(ConvertID: ConvertID).GetAwaiter().GetResult();
42 dfc86b71 taeseongkim
43 a5e5fff6 taeseongkim
                        if (convertItem != null)
44 dfc86b71 taeseongkim
                        {
45
                            string projectNo = convertItem.PROJECT_NO;
46
                            string documentId = convertItem.DOCUMENT_ID;
47
48 731c84b8 taeseongkim
                            using (DOCUMENTITEMRepository repository = new DOCUMENTITEMRepository(connectionString,dbtype))
49 dfc86b71 taeseongkim
                            {
50 a5e5fff6 taeseongkim
                                DOCUMENTITEM documentItem = repository.GetFirstAsync(projectNo, documentId).GetAwaiter().GetResult();
51 dfc86b71 taeseongkim
52 a5e5fff6 taeseongkim
                                if (documentItem != null)
53 dfc86b71 taeseongkim
                                {
54 a5e5fff6 taeseongkim
                                    documentItem.DOCUMENT_NAME = documentItem.DOCUMENT_NAME;
55
                                    documentItem.REVISION = documentItem.REVISION;
56
                                    documentItem.DOCUMENT_NO = documentItem.DOCUMENT_NO;
57
                                    documentItem.ORIGINAL_FILE = convertItem.DOCUMENT_URL;
58
                                }
59
                                else
60
                                {
61
                                    string docNo = "";
62
63
                                    var filename = convertItem.DOCUMENT_URL.Split('/').LastOrDefault();
64
65
                                    if (filename.Contains('.'))
66
                                    {
67
                                        docNo = filename.Split('.').First();
68
                                    }
69
70
                                    documentItem = new DOCUMENTITEM
71
                                    { 
72
                                        ID = new Guid().CreateUniqueGuid().ToString(),
73
                                        DOCUMENT_NO = docNo,
74
                                        REVISION = "A",
75
                                        DOCUMENT_NAME = docNo,
76
                                        GROUP_NO = "11",
77
                                        ORIGINAL_FILE = convertItem.DOCUMENT_URL,
78
                                        DOCUMENT_ID = documentId,
79
                                        PROJECT_NO = projectNo,
80
                                        Link = convertItem.DOCUMENT_URL
81
                                    };
82 dfc86b71 taeseongkim
                                }
83
84 a5e5fff6 taeseongkim
                                var id =  repository.CreateOrUPdateAsync(documentItem).GetAwaiter().GetResult();
85
86
                                if(id != null)
87 dfc86b71 taeseongkim
                                {
88 a5e5fff6 taeseongkim
                                    result = true;
89
                                }
90 dfc86b71 taeseongkim
                            }
91
                        }
92
                    }
93
94
                }
95
                else
96
                {
97
                    this.Exception = "MARKUS_ConnectionString SECTION Not Found";
98
                }
99
            }
100
101
            catch (Exception ex)
102
            {
103
                this.Exception = ex.ToString();
104
                result = false;
105
            }
106
107
            return result;
108
        }
109
    }
110
}
클립보드 이미지 추가 (최대 크기: 500 MB)