프로젝트

일반

사용자정보

개정판 d39b2473

IDd39b2473d903f7d5bce5e74d2eb8df89c88b25b1
상위 90566004
하위 7b04eddd, 6e5f7eaf

김동진이(가) 5년 이상 전에 추가함

issue #1115: wait, working 을 구분하고 dequeue 시 현재 작업중인 쓰레드가 있으면 대기 쓰레드에 보관. 작업 종료 후 작업 쓰레드에서 삭제할때 대기 쓰레드에 있는것이 있으면 enqueue. 변환중에 체크 로직 삭제.

Change-Id: I90fdd90fa5d08e9dc9cb346068f79d122767871a

차이점 보기:

FinalService/KCOM_FinalService/KCOM_FinalService/Remoting/RemFinalPDFStation.cs
25 25
        int _TypeName = 1;
26 26
        Properties.Settings _SettingPlace = null;
27 27

  
28
        Queue<FINAL_PDF> _WorkItem = new Queue<FINAL_PDF>();
29
        ConcurrentQueue<FINAL_PDF> PdfQueue = null;
30
        List<FINAL_PDF> _Thread = new List<FINAL_PDF>();
28
        //Queue<FINAL_PDF> _WorkItem = new Queue<FINAL_PDF>();
29
        ConcurrentQueue<FINAL_PDF> WorkingQueue = null;
30
        List<FINAL_PDF> WaitThread = null;
31
        List<FINAL_PDF> WorkingThread = null;
31 32
        #endregion
32 33

  
33 34
        public RemFinalPDFStation()
......
69 70
                _Channel = new TcpChannel(Properties.Settings.Default.RemotingPort);
70 71
                System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(_Channel, false);
71 72
                System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemFinalPDFObject), "remFinalPDF", System.Runtime.Remoting.WellKnownObjectMode.Singleton);
72
                PdfQueue = new ConcurrentQueue<FINAL_PDF>();
73

  
73
                WorkingQueue = new ConcurrentQueue<FINAL_PDF>();                
74
                WorkingThread = new List<FINAL_PDF>();
75
                WaitThread = new List<FINAL_PDF>();                
74 76
            }
75 77
            catch (Exception EX)
76 78
            {
......
117 119
        {
118 120
            Task tEnq = Task.Factory.StartNew(() =>
119 121
            {
120
                PdfQueue.Enqueue(pdf);
122
                WorkingQueue.Enqueue(pdf);
121 123
                Thread.Sleep(100);                
122 124
            });
123
        }
124
        private void FinalPDFThreadStart()
125
            FinalPDFDequeueThreadStart();
126
        }        
127
        private void FinalPDFDequeueThreadStart()
125 128
        {
126 129
            _FinalPDFThread = new Thread(new ThreadStart(FinalPDFDequeueandProcessing));
127 130
            _FinalPDFThread.SetApartmentState(ApartmentState.STA);
128 131
            _FinalPDFThread.Start();
129
        }
132
        }        
133
        
130 134
        private void FinalPDFDequeueandProcessing()
131 135
        {
132 136
            Task tDeq = Task.Factory.StartNew(() =>
......
134 138
                FINAL_PDF _item;
135 139
                try
136 140
                {
137
                    while (PdfQueue.Count > 0)
141
                    while (WorkingQueue.Count > 0)
138 142
                    {
139
                        if (PdfQueue.TryDequeue(out _item))
143
                        if (WorkingQueue.TryDequeue(out _item))
140 144
                        {
141
                            if (_Thread.Count() < Properties.Settings.Default.MultipleFinalCount)
145
                            if (WorkingThread.Count() < Properties.Settings.Default.MultipleFinalCount)
142 146
                            {
143 147
                                if (_item.STATUS == (int)FinalStatus.Insert)
144 148
                                {
......
152 156
                                        _entity.SaveChanges();
153 157
                                    }
154 158
                                }
155
                                var _identPathItem = _Thread.Where(item => item.DOCINFO_ID == _item.DOCINFO_ID);
159
                                var _identPathItem = WorkingThread.Where(item => item.DOCUMENT_ID == _item.DOCUMENT_ID);                                
156 160

  
157 161
                                if (_identPathItem.Count() > 0)
158 162
                                {
159
                                    FinalPDFEnqueue(_item);
163
                                    WaitThread.Add(_item);
160 164
                                }
161 165
                                else
162 166
                                {
......
169 173
                                    //_stathread.Priority = ThreadPriority.Normal;
170 174
                                    _stathread.SetApartmentState(ApartmentState.STA);
171 175
                                    _stathread.Start(_item);
172
                                    _Thread.Add(_item);
176
                                    WorkingThread.Add(_item);
173 177
                                }
174 178
                            }
175 179
                        }
......
190 194
                var finalpdf = _entity.FINAL_PDF.Where(final => final.ID == FinalID).FirstOrDefault();
191 195
                FinalPDFEnqueue(finalpdf);
192 196
                //FinalPDFProcessStart(finalList.ToList());
193
            }
194
            _FinalPDFThread = new Thread(new ThreadStart(FinalPDFDequeueandProcessing));
195
            _FinalPDFThread.SetApartmentState(ApartmentState.STA);
196
            _FinalPDFThread.Start();
197
            }            
197 198
            ///TODO: why return FinalPDFResult?
198 199
            return new FinalPDFResult();
199 200
        }
200 201

  
201
        private void FinalPDFProcessStart(List<FINAL_PDF> lstFinalPDF)
202
        {
203
            if (lstFinalPDF.Count() > 0)
204
            {
205
                foreach (var item in lstFinalPDF)
206
                {
207
                    _WorkItem.Enqueue(item);
208
                }
209

  
210
                _FinalPDFThread = new Thread(new ThreadStart(FinalPDFProcess));
211
                _FinalPDFThread.SetApartmentState(ApartmentState.STA);
212
                _FinalPDFThread.Start();
213
            }
214
        }
215

  
216
        private void FinalPDFProcess()
217
        {
218
            //CurrentCountUpdater(); 잠시보류
219
            
220
            while (_WorkItem.Count() > 0)
221
            {
222
                if (_Thread.Count() < Properties.Settings.Default.MultipleFinalCount)
223
                {
224
                    try
225
                    {
226
                        FINAL_PDF _item = _WorkItem.Dequeue();
227
                        if (_item.STATUS == (int)FinalStatus.Insert)
228
                        {
229
                            _item.STATUS = (int)(FinalStatus.Wait);
230
                            using (KCOMDataModel.DataModel.KCOMEntities _entity = new KCOMDataModel.DataModel.KCOMEntities(KCOMDataModel.Common.ConnectStringBuilder.KCOMConnectionString().ToString()))
231
                            {
232
                                var selectItem = _entity.FINAL_PDF.Where(data => data.ID == _item.ID).FirstOrDefault();
233

  
234
                                selectItem.STATUS = (int)(FinalStatus.Wait);
202
        
235 203

  
236
                                _entity.SaveChanges();
237
                            }
238
                        }
239
                        var _identPathItem = _Thread.Where(item => item.DOCINFO_ID == _item.DOCINFO_ID);
240

  
241
                        if (_identPathItem.Count() > 0)
242
                        {
243
                            _WorkItem.Enqueue(_item);
244
                        }
245
                        else
246
                        {
247
                            /// 메일 전송
248
                            //EmailClient.EmailClient _client = new EmailClient.EmailClient("H2011357");
249
                            //System.Text.StringBuilder _bl = new System.Text.StringBuilder();
250
                            //_bl.AppendLine("Project No : " + _item.ProjectNo);
251
                            //_bl.AppendLine();
252
                            //_bl.AppendLine("MarkupInfoID : " + _item.MarkupInfoID);
253
                            //_bl.AppendLine();
254
                            //_bl.AppendLine("CreateUserID : " + _item.CreateUserID);
255
                            //_bl.AppendLine();
256
                            //_bl.AppendLine("CreateUserID : " + _item.CreateUserID);
257

  
258
                            //string subject = String.Format("새로운 파이널 서비스가 들어왔습니당");
259
                            //_client.SendEmail("H2011357", "H2011357", subject, _bl.ToString(), false);
260
                            /// up to here
261
                            MarkupToPDF.MarkupToPDF _markuptoPDF = new MarkupToPDF.MarkupToPDF();
262
                            _markuptoPDF.FinalMakeError += new EventHandler<MarkupToPDF.MakeFinalErrorArgs>(_markuptoPDF_FinalMakeError);
263
                            _markuptoPDF.EndFinal += new EventHandler<MarkupToPDF.EndFinalEventArgs>(_markuptoPDF_EndFinal);
264
                            Thread _stathread = new Thread(new ParameterizedThreadStart(_markuptoPDF.MakeFinalPDF));
265
                            _stathread.Name = _item.ID.ToString();
266
                            SetFinalState(_item.ID, IFinalPDF.FinalStatus.Create);
267
                            //_stathread.Priority = ThreadPriority.Normal;
268
                            _stathread.SetApartmentState(ApartmentState.STA);
269
                            _stathread.Start(_item);
270
                            _Thread.Add(_item);
271
                        }
272
                    }
273
                    catch (Exception ex)
274
                    {
275
                        _Log.Write("FinalPDFProcess error:"+ex.ToString());
276
                    }
277
                    
278
                }
279
                
280
                
281
            }
282
        }
283 204

  
284 205
        void _markuptoPDF_EndFinal(object sender, MarkupToPDF.EndFinalEventArgs e)
285 206
        {
286
            var _T = _Thread.Where(t => t == (sender as MarkupToPDF.MarkupToPDF).FinalItem);
207
            var _T = WorkingThread.Where(t => t == (sender as MarkupToPDF.MarkupToPDF).FinalItem);
287 208

  
288 209
            if (_T.Count() > 0)
289 210
            {
......
308 229
                            SetFinalState(_item.ID, FinalStatus.Error);
309 230
                            _Log.Write("Upload error .." + e.FinalPDFPath + ",pdfname:" + e.OriginPDFName);
310 231
                        }
311
                        _Thread.Remove(_T.First());
232
                        WorkingThread.Remove(_T.First());
312 233
                    }
313 234
                    else
314 235
                    {
......
342 263
                            sendReqLog("RESULT_FILE_PATH", item.RESULT_FILE);
343 264
                            _entity.SaveChanges();
344 265
                            SetFinalState(_item.ID, FinalStatus.Success);
345
                            _Thread.Remove(_T.First());
266
                            WorkingThread.Remove(_T.First());
346 267
                        }
347 268
                    }
348 269
                }
......
350 271
                {
351 272
                    SetFinalState(_item.ID, FinalStatus.Error);
352 273
                    _Log.Write("에러 .." + ex.Message);
353
                    _Thread.Remove(_T.First());
274
                    WorkingThread.Remove(_T.First());
354 275
                }
276

  
277
                var waitpdf = WaitThread.Where(t => t.DOCUMENT_ID == _item.DOCUMENT_ID).FirstOrDefault();
278
                if(waitpdf != null)
279
                {
280
                    FinalPDFEnqueue(waitpdf);
281
                    WaitThread.Remove(waitpdf);
282
                }
283
                
355 284
            }
356 285
        }
357 286

  
......
423 352
        {
424 353
            SetError(e.FinalID, e.Message);
425 354

  
426
            var _T = _Thread.Where(t => t == (sender as MarkupToPDF.MarkupToPDF).FinalItem);
355
            var _T = WorkingThread.Where(t => t == (sender as MarkupToPDF.MarkupToPDF).FinalItem);
427 356

  
428 357
            if (_T.Count() > 0)
429 358
            {
......
431 360
                (sender as MarkupToPDF.MarkupToPDF).FinalMakeError -= new EventHandler<MarkupToPDF.MakeFinalErrorArgs>(_markuptoPDF_FinalMakeError);
432 361
                (sender as MarkupToPDF.MarkupToPDF).EndFinal -= new EventHandler<MarkupToPDF.EndFinalEventArgs>(_markuptoPDF_EndFinal);
433 362
                (sender as MarkupToPDF.MarkupToPDF).Dispose();
434
                _Thread.Remove(_Item);
363
                WorkingThread.Remove(_Item);
435 364

  
436
                Console.WriteLine(_Item.ID + "의 작업 중 에러가 발생했습니다");
365
                //Console.WriteLine(_Item.ID + "의 작업 중 에러가 발생했습니다");
437 366
            }
438 367
        }
439 368

  
FinalService/KCOM_FinalService/MarkupToPDF/MarkupToPDF.cs
164 164
                        SetNotice(FinalPDF.ID, "프로퍼티를 가지고 올 수 없습니다.");
165 165
                        return;
166 166
                    }
167

  
168
                    var inglist = _entity.FINAL_PDF.Where(x => x.ID != FinalPDF.ID && x.DOCUMENT_ID == FinalPDF.DOCUMENT_ID && (x.STATUS == (int)FinalStatus.Create)).ToList();
169
                    if(inglist.Count > 0 )
170
                    {
171
                        SetNotice(FinalPDF.ID, "이미 생성중인 Final PDF가 있습니다.");
172
                        return;
173
                    }
174

  
175 167
                    var finalList = _entity.FINAL_PDF.Where(final => final.ID == FinalPDF.ID);
176 168
                    if (finalList.Count() > 0)
177 169
                    {

내보내기 Unified diff