프로젝트

일반

사용자정보

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

markus / FinalService / FinalServiceBase / KCOM_FinalServiceConsole / Program.cs @ 73e71c89

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

1 42d49521 taeseongkim
#if DEBUG
2
using KCOMDataModel.DataModel;
3
#endif
4
using System;
5
using System.IO;
6
using System.Reflection;
7
using System.ServiceProcess;
8
using log4net;
9
using KCOM_FinalService.Common;
10
using System.Runtime.InteropServices;
11
using System.Runtime.Remoting.Channels.Tcp;
12
using IFinalPDF;
13
using KCOMDataModel.DataModel;
14
15
namespace KCOM_FinalService.Console
16
{
17
    static class Program
18
    {
19
        // https://msdn.microsoft.com/en-us/library/windows/desktop/ms686016.aspx
20
        [DllImport("Kernel32")]
21
        private static extern bool SetConsoleCtrlHandler(SetConsoleCtrlEventHandler handler, bool add);
22
23
        // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683242.aspx
24
        private delegate bool SetConsoleCtrlEventHandler(CtrlType sig);
25
26
        private enum CtrlType
27
        {
28
            CTRL_C_EVENT = 0,
29
            CTRL_BREAK_EVENT = 1,
30
            CTRL_CLOSE_EVENT = 2,
31
            CTRL_LOGOFF_EVENT = 5,
32
            CTRL_SHUTDOWN_EVENT = 6
33
        }
34
35
        static void Main(string[] args)
36
        {
37
            SetConsoleCtrlHandler(Handler, true);
38
39
#if DEBUG
40
            sConnString = KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString();
41
42
            timer = new System.Timers.Timer();
43
            timer.Interval = new TimeSpan(0, 0, 3).TotalMilliseconds;
44
            timer.Elapsed += Timer_Elapsed;
45
            //timer.Start();
46
#endif
47
48
49
            KCOM_FinalService.Program.Main(args);
50
        }
51
        static System.Timers.Timer timer;
52
        static  string sConnString;
53
        static bool flag;
54
55
        static int count;
56
57
        private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
58
        {
59
            FINAL_PDF fINAL_PDF;
60
61
            if (flag)
62
            {
63
                flag = false;
64
65
                fINAL_PDF= new FINAL_PDF()
66
                {
67
                    ID = CommonLib.Guid.shortGuid(),
68
                    PROJECT_NO = "000000",
69
                    DOCINFO_ID = "c8bc53f3-c35e-ed2e-3f46-3ed5f283625f",
70
                    DOCUMENT_ID = "30000071",
71
                    MARKUPINFO_ID = "stQAvNq1oZ8d90df431f7e5a1",
72
                    CREATE_USER_ID = "doftech",
73
                    TOTAL_PAGE = 1,
74
                    CREATE_DATETIME = DateTime.Now,
75
                    STATUS = (int)IFinalPDF.FinalStatus.Insert
76
                };
77
            }
78
            else
79
            {
80
                flag = true;
81
                fINAL_PDF = new FINAL_PDF()
82
                {
83
                    ID = CommonLib.Guid.shortGuid(),
84
                    PROJECT_NO = "000000",
85
                    DOCINFO_ID = "ad75e7a3-9cf7-7556-c98a-59563d436bd1",
86
                    DOCUMENT_ID = "30000131",
87
                    MARKUPINFO_ID = "MxlkRXDTnJ8d916a72ae2d7b9",
88
                    CREATE_USER_ID = "doftech",
89
                    TOTAL_PAGE = 90,
90
                    CREATE_DATETIME = DateTime.Now,
91
                    STATUS = (int)IFinalPDF.FinalStatus.Insert
92
                };
93
            }
94
95
            using (KCOMEntities _entity = new KCOMEntities(sConnString))
96
            {
97
                _entity.AddToFINAL_PDF(fINAL_PDF);
98
                _entity.SaveChanges();
99
100
                SetFinalPDF(fINAL_PDF.PROJECT_NO, fINAL_PDF.ID);
101
            };
102
103
            count++;
104
105
            if(count > 100)
106
            {
107
                timer.Stop();
108
            }
109
        }
110
111
        public static void SetFinalPDF(string ProjectNo, string _finalID)
112
        {
113
            RemFinalPDFObject remObj = null;
114
            TcpChannel chan = new TcpChannel();
115
116
            try
117
            {
118
119
                System.Runtime.Remoting.Channels.IChannel _ch = System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp");
120
121
                if (_ch == null)
122
                {
123
                        string _ChanID = null;
124
                          _ChanID = chan.ChannelName;
125
                        System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan, false);
126
                }
127
128
                remObj = (RemFinalPDFObject)Activator.GetObject(typeof(RemFinalPDFObject), "tcp://localhost:9092/remFinalPDF");
129
                var result = remObj.SetFinalPDF(ProjectNo, _finalID);
130
            }
131
            catch (Exception ex)
132
            {
133
                throw ex;
134
            }
135
            finally
136
            {
137
                //remObj = null;
138
                //if (System.Runtime.Remoting.Channels.ChannelServices.GetChannel("tcp") != null)
139
                //    System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(chan);
140
141
                //GC.Collect(2);
142
            }
143
        }
144
145
146
        private static bool Handler(CtrlType signal)
147
        {
148
            switch (signal)
149
            {
150
                case CtrlType.CTRL_BREAK_EVENT:
151
                case CtrlType.CTRL_C_EVENT:
152
                case CtrlType.CTRL_LOGOFF_EVENT:
153
                case CtrlType.CTRL_SHUTDOWN_EVENT:
154
                case CtrlType.CTRL_CLOSE_EVENT:
155
156
                    KCOM_FinalService.Program.service.Stop();
157
158
                    // TODO Cleanup resources
159
                    Environment.Exit(0);
160
                    return false;
161
162
                default:
163
                    return false;
164
            }
165
        }
166
    }
167
}
클립보드 이미지 추가 (최대 크기: 500 MB)