프로젝트

일반

사용자정보

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

markus / MarkusLogview / MarkusConsoleApplication / Program.cs @ 84578b97

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

1
using MarkusDataModel.Common;
2
using MarkusDataModel.DataModel;
3
using Microsoft.AspNet.SignalR.Client;
4
using ServiceInterface;
5
using System;
6
using System.Collections;
7
using System.Collections.Generic;
8
using System.Data;
9
using System.Diagnostics;
10
using System.Linq;
11
using System.Reflection;
12
using System.Text;
13
using System.Threading.Tasks;
14
using TableDependency;
15
using TableDependency.EventArgs;
16
using TableDependency.SqlClient;
17
using static MarkusConsoleApplication.HubConfiguration;
18

    
19
namespace MarkusConsoleApplication
20
{
21
    class Program
22
    {
23
        private static SqlTableDependency<CONVERTER_DOC> _convertTableDependency;
24
        private static SqlTableDependency<FINAL_PDF> _finalTableDependency;
25
        private static string entityConnString = ConnectStringBuilder.MarkusEntitiesConnectionString().ProviderConnectionString.ToString();
26
        private static ServiceEventLogger _serviceEventLogger = new ServiceEventLogger();
27

    
28
        private static string hubBaseURL = "http://cloud.devdoftech.co.kr:5100";
29
        private static string hubName = "MarkusHub";
30
        private static ConvertSetting convSetting = new ConvertSetting();
31
        private static FinalSetting finalSetting = new FinalSetting();
32
        private static DetectedType detectedType = new DetectedType();
33

    
34

    
35
        static void Main(string[] args)
36
        {
37
            #region 메인
38

    
39
            // convert
40
            try
41
            {
42
                // config
43
                var convertMapper = new ModelToTableMapper<CONVERTER_DOC>();
44
                convertMapper.AddMapping(s => s.CURRENT_PAGE, "CURRENT_PAGE");
45
                _convertTableDependency = new SqlTableDependency<CONVERTER_DOC>(entityConnString, "CONVERTER_DOC", convertMapper);
46

    
47
                // add event 
48
                _convertTableDependency.OnError += SqlTableDependency_OnError;
49
                _convertTableDependency.OnChanged += Convert_SqlTableDependency_Changed;
50
                _convertTableDependency.Start();
51

    
52
                // log 
53
                _serviceEventLogger.WriteEventEntry(MethodBase.GetCurrentMethod().Name + " start", EventLogEntryType.SuccessAudit);
54

    
55
            }
56
            catch (Exception ex)
57
            {
58
                _serviceEventLogger.WriteEventEntry("SQL Dependency ERROR " + MethodBase.GetCurrentMethod().Name + " : " + ex.Message, EventLogEntryType.Error);
59
                throw;
60
            }
61

    
62
            // final
63
            try
64
            {
65
                var finalMapper = new ModelToTableMapper<FINAL_PDF>();
66
                finalMapper.AddMapping(s => s.CURRENT_PAGE, "CURRENT_PAGE");
67

    
68
                _finalTableDependency = new SqlTableDependency<FINAL_PDF>(entityConnString, "FINAL_PDF", finalMapper);
69

    
70
                _finalTableDependency.OnError += SqlTableDependency_OnError;
71
                _finalTableDependency.OnChanged += Final_SqlTableDependency_Changed;
72

    
73
                _serviceEventLogger.WriteEventEntry(MethodBase.GetCurrentMethod().Name + " start", EventLogEntryType.SuccessAudit);
74

    
75
                _finalTableDependency.Start();
76

    
77
            }
78
            catch (Exception ex)
79
            {
80
                _serviceEventLogger.WriteEventEntry("SQL Dependency ERROR " + MethodBase.GetCurrentMethod().Name + " : " + ex.Message, EventLogEntryType.Error);
81

    
82
                throw;
83
            }
84

    
85
            Console.ReadKey();
86

    
87
            #endregion
88
        }
89

    
90
        /// <summary>
91
        /// SQL Dependency Error code 
92
        /// </summary>
93
        /// <param name="sender"></param>
94
        /// <param name="e"></param>
95
        public static void SqlTableDependency_OnError(object sender, ErrorEventArgs e)
96
        {
97
            _serviceEventLogger.WriteEventEntry(" SQL Dependency ERROR " + MethodBase.GetCurrentMethod().Name + " :: " + e.Message, EventLogEntryType.Error);
98
            throw e.Error;
99
        }
100

    
101

    
102
        /// <summary>
103
        /// Converter Sql Dependency Changed
104
        /// </summary>
105
        /// <param name="sender"></param>
106
        /// <param name="e"></param>
107
        public static void Convert_SqlTableDependency_Changed(object sender, RecordChangedEventArgs<CONVERTER_DOC> e)
108
        {
109
            try
110
            {
111

    
112
                string changeType = e.ChangeType.ToString();
113
                DetectedMakrusConvertTable(e.ChangeType.ToString(), e.Entity);
114
                _serviceEventLogger.WriteEventEntry(MethodBase.GetCurrentMethod().Name + " changeType : " + changeType, EventLogEntryType.SuccessAudit);
115

    
116
            }
117
            catch (Exception ex)
118
            {
119
                _serviceEventLogger.WriteEventEntry("Convert_SqlTableDependency_Changed Error : " + ex, EventLogEntryType.Error);
120
                throw;
121
            }
122
        }
123

    
124
        /// <summary>
125
        /// Final Sql Dependency Changed 
126
        /// </summary>
127
        /// <param name="sender"></param>
128
        /// <param name="e"></param>
129
        public static void Final_SqlTableDependency_Changed(object sender, RecordChangedEventArgs<FINAL_PDF> e)
130
        {
131
            try
132
            {
133
                string changeType = e.ChangeType.ToString();
134
                _serviceEventLogger.WriteEventEntry(MethodBase.GetCurrentMethod().Name + " changeType : " + changeType, EventLogEntryType.SuccessAudit);
135

    
136
                DetectedMakrusFinalTable(changeType, e.Entity);
137

    
138
            }
139
            catch (Exception ex)
140
            {
141
                _serviceEventLogger.WriteEventEntry("Final_SqlTableDependency_Changed Error : " + ex, EventLogEntryType.Error);
142
                throw;
143
            }
144
        }
145

    
146
        /// <summary>
147
        /// Convert Hub Send
148
        /// </summary>
149
        /// <param name="type"></param>
150
        /// <param name="data"></param>
151
        public static void DetectedMakrusConvertTable(string type, CONVERTER_DOC data)
152
        {
153

    
154
            using (var hubConn = new HubConnection(hubBaseURL))
155
            {
156

    
157
                var hub = hubConn.CreateHubProxy(hubName);
158

    
159
                hubConn.Start().Wait();
160

    
161
                _serviceEventLogger.WriteEventEntry(MethodBase.GetCurrentMethod().Name, EventLogEntryType.SuccessAudit);
162

    
163
                if (type == detectedType.DataInsert)
164
                {
165
                    hub.Invoke(convSetting.InvokeInsert, data);
166
                }
167
                else if (type == detectedType.DataUpdate)
168
                {
169
                    hub.Invoke(convSetting.InvokeChange, data);
170
                }
171
                else if (type == detectedType.DataDelete)
172
                {
173
                    hub.Invoke(convSetting.InvokeDelete, data);
174
                }
175

    
176
            }
177

    
178
        }
179

    
180
        /// <summary>
181
        /// Final Hub Send
182
        /// </summary>
183
        /// <param name="type"></param>
184
        /// <param name="data"></param>
185
        public static void DetectedMakrusFinalTable(string type, FINAL_PDF data)
186
        {
187

    
188
            using (var hubConn = new HubConnection(hubBaseURL))
189
            {
190

    
191
                var hub = hubConn.CreateHubProxy(hubName);
192

    
193
                hubConn.Start().Wait();
194

    
195
                _serviceEventLogger.WriteEventEntry(MethodBase.GetCurrentMethod().Name, EventLogEntryType.SuccessAudit);
196

    
197
                if (type == detectedType.DataInsert)
198
                {
199
                    hub.Invoke(finalSetting.InvokeInsert, data);
200
                }
201
                else if (type == detectedType.DataUpdate)
202
                {
203
                    hub.Invoke(finalSetting.InvokeChange, data);
204
                }
205
                else if (type == detectedType.DataDelete)
206
                {
207
                    hub.Invoke(finalSetting.InvokeDelete, data);
208
                }
209

    
210
            }
211

    
212
        }
213

    
214

    
215
    }
216
}
클립보드 이미지 추가 (최대 크기: 500 MB)