프로젝트

일반

사용자정보

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

markus / FinalService / KCOM_FinalService / ConsoleApp1 / Program.cs @ 508c3ac5

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

1 e05bed4e djkim
using IFinalPDF;
2
using KCOMDataModel;
3 7ca218b3 KangIngu
using KCOMDataModel.Common;
4
using KCOMDataModel.DataModel;
5 abaa85b4 djkim
using MarkupToPDF.Common;
6 7ca218b3 KangIngu
using System;
7
using System.Collections.Generic;
8
using System.IO;
9
using System.Linq;
10
using System.Text;
11
12
namespace ConsoleApp1
13
{
14 e05bed4e djkim
    static class Program
15 7ca218b3 KangIngu
    {
16
        static void Main(string[] args)
17
        {
18
            string PdfFilePathRoot = "";
19
            string _FinalPDFStorgeLocal = "";
20
            string _FinalPDFStorgeRemote = "";
21
22
            //using (KCOMEntities _entity = new KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
23
            //{
24
            //    var _properties = _entity.PROPERTIES.Where(pro => pro.PROPERTY == "000000");
25
26
            //    if (_properties.Count() > 0)
27
            //    {
28
            //        PdfFilePathRoot = _properties.Where(t => t.TYPE == MarkupToPDF.PropertiesType.Const_TileSorcePath).First().VALUE;
29
            //        _FinalPDFStorgeLocal = _properties.Where(t => t.TYPE == MarkupToPDF.PropertiesType.Const_FinalPDFStorgeLocal).First().VALUE;
30
            //        _FinalPDFStorgeRemote = _properties.Where(t => t.TYPE == MarkupToPDF.PropertiesType.Const_FinalPDFStorgeRemote).First().VALUE;
31
            //    }
32
            //}
33
            //    using (CIEntities _entity = new CIEntities(ConnectStringBuilder.ProjectCIConnectString("000000").ToString()))
34
            //{
35
            //    var _DOCINFO = _entity.DOCINFO.Where(doc => doc.ID == "e16c382e-5c33-3883-d45b-47e4f4d4c23f");
36
37
            //    if (_DOCINFO.Count() > 0)
38
            //    {
39
            //       var  DocInfoItem = _DOCINFO.FirstOrDefault();
40
41
            //        PdfFilePathRoot = PdfFilePathRoot + @"\" + "000000" + "_Tile" + @"\"
42
            //                         + (System.Convert.ToInt64("11111111") / 100).ToString()
43
            //                         + @"\" + "11111111" + @"\";
44
            //    }
45
            //}
46 e05bed4e djkim
            try
47 7ca218b3 KangIngu
            {
48 e05bed4e djkim
                Console.WriteLine("Test Process...");
49
                Console.WriteLine("Insert Final PDF id :");
50
                string inputstr = Console.ReadLine();
51 abaa85b4 djkim
                using (DataController dc = new DataController())
52 e05bed4e djkim
                {
53 abaa85b4 djkim
                    var finals = dc.GetFinalpdfs(inputstr);
54
                    if(finals.Count > 0)
55 e05bed4e djkim
                    {
56
                        Console.WriteLine("final pdf start");
57
                        MarkupToPDF.MarkupToPDF pdf = new MarkupToPDF.MarkupToPDF();
58
                        pdf.EndFinal += Pdf_EndFinal;
59 abaa85b4 djkim
                        pdf.FinalMakeError += Pdf_FinalMakeError;                        
60
                        pdf.MakeFinalPDF(finals[0]);
61 e05bed4e djkim
                    }
62
                    else
63
                    {
64
                        Console.WriteLine("item is null");
65
                    }
66 abaa85b4 djkim
                }                
67 7ca218b3 KangIngu
68
            }
69 e05bed4e djkim
            catch (Exception ex)
70
            {
71
                Console.WriteLine("error: "+ ex.ToString());
72
            }
73
            
74 7ca218b3 KangIngu
        }
75
76
        private static void Pdf_FinalMakeError(object sender, MarkupToPDF.MakeFinalErrorArgs e)
77
        {
78
            
79
        }
80 abaa85b4 djkim
        static List<CommonLib.MARKUS_API.FINAL_PDF> _Thread = new List<CommonLib.MARKUS_API.FINAL_PDF>();
81 7ca218b3 KangIngu
        private static void Pdf_EndFinal(object sender, MarkupToPDF.EndFinalEventArgs e)
82
        {
83 8c3a888c djkim
            FINAL_PDF _item = (sender as MarkupToPDF.MarkupToPDF).FinalItem;
84 e05bed4e djkim
85
            SetFinalState(_item.ID, FinalStatus.PdfStamp);
86
87
            try
88
            {
89
                Console.WriteLine("final pdf end");
90 abaa85b4 djkim
                string soapurl = CommonLib.Common.GetConfigString("UpLoadServiceUrl", "URL", "");
91 e05bed4e djkim
                Console.WriteLine("soapurl:"+soapurl);
92
                if (!string.IsNullOrEmpty(soapurl))
93
                {
94
                    //Legacy IF
95
                    KeyValuePair<bool, string> result = UploadFinal.UploadFinal.UploadFinalPDF(e.FinalPDFPath.Replace(@"\\172.20.121.220\comment3\finalPDF\", ""), e.OriginPDFName, e.FinalPDF, soapurl);
96
                    if (result.Key)
97
                    {
98
                        SetFinalState(_item.ID, FinalStatus.Success);
99
                    }
100
                    else
101
                    {
102
                        SetFinalState(_item.ID, FinalStatus.Error);
103
                        Console.WriteLine("pram1:"+ e.FinalPDFPath.Replace(@"\\172.20.121.220\comment3\finalPDF\", "")+",pram2:"+ e.OriginPDFName);
104
                        //_Log.Write("Upload error .." + e.FinalPDFPath + ",pdfname:" + e.OriginPDFName);
105
                    }                    
106
                }
107
                else
108
                {
109
                    ///TODO: 저장할 폴더 위치를 configuration으로 빼주세요
110
                    ///Local Test 용 저장 위치
111
                    string savepath = CommonLib.Common.GetConfigString("DebugSavePath", "URL", "");
112
                    
113
                    string saveFolder = String.Format(savepath, _item.PROJECT_NO, Convert.ToInt32(_item.DOCUMENT_ID) / 100, _item.DOCUMENT_ID);
114
                    if (!System.IO.Directory.Exists(saveFolder))
115
                    {
116
                        System.IO.Directory.CreateDirectory(saveFolder);
117
                    }
118
119
                    //this._Log.Write(String.Format("saveFolder : {0}", saveFolder) + DateTime.Now);
120
                    System.IO.File.Copy(e.FinalPDFPath, saveFolder + e.OriginPDFName, true);
121 abaa85b4 djkim
                    using (DataController dataController = new DataController())
122 e05bed4e djkim
                    {
123
                        string resultpath = CommonLib.Common.GetConfigString("DebugResultUrlPath", "URL", "");
124 abaa85b4 djkim
                        string url = String.Format(resultpath, _item.PROJECT_NO, Convert.ToInt32(_item.DOCUMENT_ID) / 100, _item.DOCUMENT_ID, e.OriginPDFName);
125
                        var result = dataController.SetFinalPDFUrl(_item.PROJECT_NO, _item.DOCUMENT_ID, url);
126 e05bed4e djkim
127
                        SetFinalState(_item.ID, FinalStatus.Success);
128 abaa85b4 djkim
                    }                    
129 e05bed4e djkim
                }
130
            }
131
            catch (Exception ex)
132
            {
133
                SetFinalState(_item.ID, FinalStatus.Error);
134
                //_Log.Write("에러 .." + ex.Message);
135
                //_Thread.Remove(_T.First());
136
            }
137
        }
138
        private static void SetFinalState(string finalID, FinalStatus status)
139
        {
140
            using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
141
            {
142
                var finalList = _entity.FINAL_PDF.Where(final => final.ID == finalID);
143
144
                if (finalList.Count() > 0)
145
                {
146
                    if (status == FinalStatus.Create)
147
                    {
148
                        finalList.First().START_DATETIME = DateTime.Now;
149
                    }
150
                    if (status == FinalStatus.Success)
151
                    {
152
                        finalList.First().END_DATETIME = DateTime.Now;
153
                    }
154 7ca218b3 KangIngu
155 e05bed4e djkim
                    finalList.First().STATUS = (int)status;
156
                    _entity.SaveChanges();
157
                }
158
            };
159 7ca218b3 KangIngu
        }
160
    }
161
}
클립보드 이미지 추가 (최대 크기: 500 MB)