프로젝트

일반

사용자정보

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

markus / KCOM / Services / BaseServices.cs @ 0c575433

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

1
using Microsoft.AspNet.SignalR.Client;
2
using IKCOM;
3
using KCOM.Common;
4
using KCOM.ServiceDeepView;
5
using KCOMDataModel.DataModel;
6
using Newtonsoft.Json;
7
using System;
8
using System.Collections.Generic;
9
using System.Collections.ObjectModel;
10
using System.ComponentModel;
11
using System.Linq;
12
using System.Runtime.CompilerServices;
13
using System.Text;
14
using System.Windows;
15
using System.Windows.Controls;
16
using Telerik.Windows.Controls;
17
using MarkupToPDF.Controls.Parsing;
18
using Telerik.Windows.Data;
19
using System.Web;
20
using System.ServiceModel.Security;
21

    
22
namespace KCOM.Views
23
{
24
    public partial class MainMenu : UserControl, INotifyPropertyChanged
25
    {
26
        //const string DeepZoomUrl = @"http://{baseUrl}/TileSource/{TileSourcePath}/{ItemsPath}/{SharepointItemID}/{PageNo}.jpg";
27
        public ServiceDeepViewClient BaseClient;
28
        public KcomService.ServiceDeepViewClient BaseTaskClient
29
        {
30
            get {
31
                var service = new KcomService.ServiceDeepViewClient(App._binding, App._EndPoint);
32
                return service;
33
            }
34
        }
35

    
36
        public ViewInfo _ViewInfo;
37
        public DOCINFO _DocInfo;
38
        public DOCUMENT_ITEM _DocItem;
39
        public MEMBER userData { get; set; }
40

    
41
        public event PropertyChangedEventHandler PropertyChanged;
42
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
43
        {
44
            if (PropertyChanged != null)
45
            {
46
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
47
            }
48
        }
49

    
50
        private Common.DocumentSet _CurrentDoc { get; set; }
51
        public Common.DocumentSet CurrentDoc
52
        {
53
            get
54
            {
55
                return _CurrentDoc;
56
            }
57
            set
58
            {
59
                if (value != CurrentDoc)
60
                {
61
                    _CurrentDoc = value;
62
                    NotifyPropertyChanged();
63
                }
64
            }
65
        }
66
        public void ServiceOn()
67
        {
68
            //BaseTaskClient = new KcomService.ServiceDeepViewClient(App._binding, App._EndPoint);
69
            BaseClient = new ServiceDeepViewClient(App._binding, App._EndPoint);
70

    
71
            #region 이벤트 핸들러 등록
72
            BaseClient.GetDocInfoCompleted += BaseClient_GetDocInfoCompleted; //문서 섬네일, 페이지크기, 마크업 정보 [3]
73
            BaseClient.GetConversionStateCompleted += BaseClient_GetConversionStateCompleted;  //컨버팅의 여부 [2] 
74
            BaseClient.GetSystemDataCompleted += BaseClient_GetSystemDataCompleted; //시스템 정보 [1] 
75
            BaseClient.GetDocumentItemInfoCompleted += BaseClient_GetDocumentItemInfoCompleted; // 문서 자체의 정보 [4]
76
            BaseClient.GetMarkupInfoItemsCompleted += BaseClient_GetMarkupInfoItemsCompleted;
77
            BaseClient.GetDeptDataCompleted += BaseClient_GetDeptDataCompleted;
78
            BaseClient.DeleteMarkupCompleted += BaseClient_DeleteMarkupCompleted;
79
            BaseClient.GetVPRevisionHistoryCompleted += BaseClient_GetVPRevisionHistoryCompleted;
80
            BaseClient.SetFinalPDFCompleted += BaseClient_SetFinalPDFCompleted;
81
            BaseClient.GetCompareRectsTargetSizeCompleted += BaseClient_GetCompareRectsTargetSizeCompleted;
82
            BaseClient.DeleteMarkupCompleted += BaseClient_DeleteMarkupCompleted;
83
            BaseClient.DelFavoriteVPCompleted += BaseClient_DelFavoriteVPCompleted;
84
            BaseClient.EditFavoriteVPCompleted += BaseClient_EditFavoriteVPCompleted;
85

    
86
            BaseClient.SaveSymbolCompleted += BaseClient_SaveSymbolCompleted;
87
            BaseClient.AddPublicSymbolCompleted += BaseClient_AddPublicSymbolCompleted;
88
            #endregion
89
        }
90

    
91
        private void BaseClient_EditFavoriteVPCompleted(object sender, EditFavoriteVPCompletedEventArgs e)
92
        {
93
            //Logger.sendResLog("EditFavoriteVPCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
94
            
95
            if (e.Error == null && e.Result != false)
96
            {
97
                //Logger.sendReqLog("GetFavoriteVPAsync", App.ViewInfo.ProjectNO + "," + App.ViewInfo.UserID + "," + App.ViewInfo.DocumentItemID, 1);
98
                BaseClient.GetFavoriteVPAsync(App.ViewInfo.ProjectNO, App.ViewInfo.UserID, App.ViewInfo.DocumentItemID);
99
            }
100
            else
101
            {
102
                DialogMessage_Alert("Unable to delete the file due to a system failure", "Warning");
103
            }
104
        }
105

    
106
        private void BaseClient_DelFavoriteVPCompleted(object sender, DelFavoriteVPCompletedEventArgs e)
107
        {
108
            //Logger.sendResLog("DelFavoriteVPCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
109

    
110
            if (e.Error == null && e.Result != false)
111
            {
112
                //Logger.sendReqLog("GetFavoriteVPAsync", App.ViewInfo.ProjectNO + "," + App.ViewInfo.UserID + "," + App.ViewInfo.DocumentItemID, 1);
113
                BaseClient.GetFavoriteVPAsync(App.ViewInfo.ProjectNO, App.ViewInfo.UserID, App.ViewInfo.DocumentItemID);
114
            }
115
            else
116
            {
117
                DialogMessage_Alert("Unable to delete the file due to a system failure", "Warning");
118
            }
119
        }
120

    
121
        /// <summary>
122
        /// Compare 결과를 받아 화면에 표시한다
123
        /// </summary>
124
        /// <param name="sender"></param>
125
        /// <param name="e"></param>
126
        private void BaseClient_GetCompareRectsTargetSizeCompleted(object sender, GetCompareRectsTargetSizeCompletedEventArgs e)
127
        {
128
            if (e.Error != null || e.Result == null)
129
            {
130
                if (e.Error != null)
131
                {
132
                    DialogMessage_Alert(e.Error.ToString(), "Error");
133
                }
134
                else
135
                {
136
                    DialogMessage_Alert("Compare 기능을 원활히 실행하기 위한 데이터가 부족합니다", "안내");
137
                }
138
            }
139
            else
140
            {
141
                e.Result.ForEach(d =>
142
                {
143
                    d.Inflate(new Size(10, 10));
144

    
145
                    var point = MarkupToPDF.Controls.Common.MathSet.getRectMiddlePoint(d);
146
                    System.Windows.Shapes.Rectangle myEllipse = new System.Windows.Shapes.Rectangle();
147
                    myEllipse.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(150, 33, 215, 119));
148
                    myEllipse.Opacity = 1;
149
                    //myEllipse.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Green);
150
                    //myEllipse.StrokeThickness = 2;
151
                    myEllipse.Width = d.Width;
152
                    myEllipse.Height = d.Height;
153
                    Canvas.SetLeft(myEllipse, d.X - ((point.X - d.X) / 2.0));
154
                    Canvas.SetTop(myEllipse, d.Y - ((point.Y - d.Y) / 2.0));
155
                    myEllipse.RenderTransformOrigin = point;
156
                    canvas_compareBorder.Children.Add(myEllipse);
157
                });
158
                canvas_compareBorder.Visibility = Visibility.Visible;
159
                da.From = 1;
160
                da.To = 0.5;
161
                da.Duration = new Duration(TimeSpan.FromSeconds(1));
162
                da.AutoReverse = true;
163
                canvas_compareBorder.BeginAnimation(OpacityProperty, da);
164
            }
165
        }
166

    
167
        /// <summary>
168
        /// FinalPDF를 수행 후 관련 메시지를 표시한다.
169
        /// </summary>
170
        /// <param name="sender"></param>
171
        /// <param name="e"></param>
172
        private void BaseClient_SetFinalPDFCompleted(object sender, SetFinalPDFCompletedEventArgs e)
173
        {
174
            if (e.Error != null || e.Result.Status == FinalStatus.Error)
175
            {
176
                string errormsg = CommonLib.Common.GetAlertMessageString("SetFinalPDFError", "MSG", $"최종 파일을 만드는데 문제가 발생하였습니다{System.Environment.NewLine}{e.Result.Exception}");
177
                DialogMessage_Alert(errormsg, "안내");
178
            }
179
            else
180
            {
181
                string successmsg = CommonLib.Common.GetAlertMessageString("SetFinalPDFSuccess", "MSG", "최종 파일 생성 중입니다. 문서관리시스템을 확인해주세요");
182
                DialogMessage_Alert(successmsg, "안내");
183
            }
184
        }
185

    
186
        private void BaseClient_GetVPRevisionHistoryCompleted(object sender, GetVPRevisionHistoryCompletedEventArgs e)
187
        {
188
            //Logger.sendResLog("GetVPRevisionHistoryCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.Count + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
189

    
190
            if (e.Result != null && e.Error == null)
191
            {
192
                List<VPRevision> list = e.Result;
193
                foreach (var item in list)
194
                {
195

    
196
                    if (App.isExternal)
197
                    {
198
                        var sBaseServiceURL = CommonLib.Common.GetConfigString("ExternalOriginalFileUrl", "URL", "", App.isExternal);
199

    
200
                        if (!string.IsNullOrWhiteSpace(item.TO_VENDOR))
201
                        {
202
                            var toUri = new Uri(HttpUtility.UrlDecode(item.TO_VENDOR));
203
                            item.TO_VENDOR = $"{sBaseServiceURL}{toUri.LocalPath}";
204
                        }
205

    
206
                        if (!string.IsNullOrWhiteSpace(item.FROM_VENDOR))
207
                        {
208
                            var fromUri = new Uri(HttpUtility.UrlDecode(item.FROM_VENDOR));
209
                            item.FROM_VENDOR = $"{sBaseServiceURL}{fromUri.LocalPath}";
210
                        }
211
                    }
212
                    else
213
                    {
214
                        item.TO_VENDOR = HttpUtility.UrlDecode(item.TO_VENDOR);
215
                        item.FROM_VENDOR = HttpUtility.UrlDecode(item.FROM_VENDOR);
216
                        item.EnsembleLink = HttpUtility.UrlDecode(item.EnsembleLink);
217
                    }
218
                }
219
                //int result;
220
                //bool iCheck = true;
221
                //foreach (var li in list)
222
                //{                    
223
                //    iCheck = int.TryParse(li.GroupNo, out result);
224
                //    if (!iCheck)
225
                //        break;
226
                //}
227
                //if(iCheck)
228
                    gridViewHistory.ItemsSource = list.OrderByDescending(x => x.GroupNo); //20240611 LJY string 인거 전달드림 slip no 내림차순으로 그냥 해달라고 요청
229
                //else
230
                //    gridViewHistory.ItemsSource = list.OrderByDescending(x => x.RevNo);
231

    
232
            }
233
            //TempFile.TempLoad();
234
        }
235

    
236
        private void BaseClient_DeleteMarkupCompleted(object sender, DeleteMarkupCompletedEventArgs e)
237
        {
238
            //Logger.sendResLog("DeleteMarkupCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
239

    
240
            foreach(var info in ViewerDataModel.Instance._markupInfoList)
241
            {
242
                if(info.UserID == App.ViewInfo.UserID)
243
                {
244
                    info.userDelete = true;
245
                    info.DisplayColor = "#FFFF0000";
246
                }
247
                else
248
                {
249
                    info.userDelete = false;
250
                }
251
            }
252
        }
253

    
254
        private void BaseClient_GetDeptDataCompleted(object sender, GetDeptDataCompletedEventArgs e)
255
        {
256
            if (e.Error == null)
257
            {
258
                //Logger.sendResLog("GetDeptDataCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.Count + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
259
            }
260
            else
261
            {
262
                //Logger.sendResLog("GetDeptDataCompleted",  "\r Error :" + e.Error, 1);
263
            }
264

    
265
            if (e.Result != null)
266
            {
267
                e.Result.Sort();
268
                //cbSymbolPublic.ItemsSource = e.Result.ToList();
269
            }
270
        }
271

    
272
        /// <summary>
273
        /// ???
274
        /// </summary>
275
        public MarkupInfoItem PreviewUserMarkupInfoItem { get; set; }
276

    
277
        /// <summary>
278
        /// 문서 정보를 가져온다
279
        /// </summary>
280
        /// <param name="sender"></param>
281
        /// <param name="e"></param>
282
        private async void BaseClient_GetDocInfoCompleted(object sender, GetDocInfoCompletedEventArgs e)
283
        {
284
            ////Logger.sendResLog("GetDocInfoCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
285

    
286
            if (e.Error != null)
287
            {
288
                DialogMessage_Alert("The page cannot be displayed.", "Alert");
289
            }
290
            else if (e.Result == null)
291
            {
292
                DialogMessage_Alert("Document information is missing.", "Alert");
293
            }
294
            else
295
            {
296
                string sFolder = _ViewInfo.DocumentItemID.All(char.IsDigit) ? (Convert.ToUInt64(_ViewInfo.DocumentItemID) / 100).ToString() : (_ViewInfo.DocumentItemID.Length >= 5 ? _ViewInfo.DocumentItemID.Substring(0, 5) : _ViewInfo.DocumentItemID);
297

    
298
                /// 화면의 좌측 Thumbnail의 주소
299
                var MainUrl = string.Format(CommonLib.Common.GetConfigString("mainServerImageWebPath", "URL", "", App.isExternal).Replace("png", "jpg"), _ViewInfo.ProjectNO, sFolder, _ViewInfo.DocumentItemID, "{PageNo}");
300
                _DocInfo = e.Result;
301
                _DocInfo.ORIGINAL_FILE = HttpUtility.UrlDecode(_DocInfo.ORIGINAL_FILE);
302
                foreach (var item in _DocInfo.DOCPAGE.OrderBy(order => order.PAGE_NUMBER))
303
                {
304
                    ViewerDataModel.Instance.Document_Info.Add(item);
305
                }
306
                //Logger.sendReqLog("GetMarkupInfoItemsAsync", _ViewInfo.ProjectNO + "," + _DocInfo.ID, 1);
307
                CurrentDoc = new Common.DocumentSet
308
                {
309
                    docInfo = _DocInfo,
310
                    Document_Id = _DocInfo.DOCUMENT_ID,
311
                    File_Original = _DocInfo.ORIGINAL_FILE,
312

    
313
                    Document_NO = _DocItem?.DOCUMENT_NO,
314
                    File_Result = _DocItem?.RESULT_FILE,
315
                    Group_No = _DocItem?.GROUP_NO,
316
                    ProjectNo = _DocItem?.PROJECT_NO,
317
                    Revision = _DocItem?.REVISION,
318
                };
319

    
320
                var instanceMain = this.ParentOfType<MainWindow>();
321
                string firstpage = "1";
322
                string lastpage = _DocInfo.PAGE_COUNT.ToString();
323
                instanceMain.dzTopMenu.tlcurrentPage.Text = firstpage;
324
                instanceMain.dzTopMenu.tlcurrentPage_readonly.Text = lastpage;
325
                App.MarkusVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
326

    
327
                string apptitle = string.Format("MARKUS(ver.{2}) - {0}(Rev.{1})", _DocItem?.DOCUMENT_NO, _DocItem?.REVISION, App.MarkusVersion);
328

    
329
                instanceMain.Title = apptitle;
330

    
331
                #region 페이지 이미지를 로컬에 저장
332
                string tempStoragePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "MARKUS", System.IO.Path.GetRandomFileName());
333

    
334
                //.Replace("jpg", "png")을 붙이는 이유는 MainUrl에 확장명이 jpg로 설정한 경우가 있기 때문
335

    
336
                #endregion
337

    
338
                App.PageStorage = new PageManager.PageStorage(MainUrl.Replace("jpg", "png"), tempStoragePath, "png", _DocInfo.PAGE_COUNT, 1);
339

    
340
                //App.SamplePageStorage = new PageManager.PageStorage(MainUrl.Replace("png", "jpg"), tempStoragePath, "jpg", _DocInfo.PAGE_COUNT);
341
                await this.pageNavigator.SetPageNaviAsync(CurrentDoc.docInfo.DOCPAGE.ToList(), MainUrl);
342
            }
343
        }
344

    
345
        private void pageNavigator_ThumbInitialized(object sender,EventArgs e)
346
        {
347
            BaseClient.GetMarkupInfoItemsAsync(_ViewInfo.ProjectNO, _DocInfo.ID);
348

    
349
            ViewerDataModel.Instance.MarkupControls_USER.Clear();
350
            //ViewerDataModel.Instance.SystemMain.dzMainMenu.TempLoad();
351

    
352
            /// 기존 임시파일 정리
353
            #region 단어 검색용 파일 다운로드
354

    
355
            DownloadOriginalFile();
356

    
357
            #endregion
358

    
359
            //Logger.sendReqLog("GetVPRevisionHistoryAsync", CurrentDoc.ProjectNo + "," + CurrentDoc.Document_NO + "," + CurrentDoc.Document_Id, 1);
360
            BaseClient.GetVPRevisionHistoryAsync(CurrentDoc.ProjectNo, CurrentDoc.Document_NO, CurrentDoc.Document_Id);
361

    
362
        }
363

    
364

    
365
        /// <summary>
366
        /// get markupinfo and markupitem from database
367
        ///  - 1. called when document is loaded
368
        ///  - 2. called when user do consolidation
369
        /// </summary>
370
        /// <param name="sender"></param>
371
        /// <param name="e"></param>
372
        private void BaseClient_GetMarkupInfoItemsCompleted(object sender, GetMarkupInfoItemsCompletedEventArgs e)
373
        {
374
            //Logger.sendResLog("GetMarkupInfoItemsCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.Count + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
375

    
376
            ViewerDataModel.Instance.MarkupControls_USER.Clear();
377
            ViewerDataModel.Instance.MarkupControls.Clear();
378

    
379
            try
380
            {
381

    
382
                if (e.Result != null)
383
                {
384
                    ViewerDataModel.Instance._markupInfoList.Clear();
385
                    if (e.Result.Any()) ViewerDataModel.Instance.MyMarkupList.Clear();
386

    
387
                    foreach (var info in e.Result)
388
                    {
389
                        if (info.Depatment == null) info.Depatment = "Unknown";
390

    
391
                        else if (info.UserID == App.ViewInfo.UserID)
392
                        {
393
                            if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission) //조회모드는 delete 버튼 모두 비활성화
394
                            {
395
                                info.userDelete = false;
396
                            }
397
                            else if (!App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission && e.Result.Where(x => x.UserID == App.ViewInfo.UserID && x.PartConsolidate == 1).Count() > 0) //Team Consolidation Mode이고 Team Consolidation Layer가 있을 경우
398
                            {
399
                                if(App.ViewInfo.NewCommentPermission && e.Result.Where(x => x.UserID == App.ViewInfo.UserID && x.PartConsolidate == 1 && x.MarkupInfoID == info.MarkupInfoID).Count() > 0)                                
400
                                    info.userDelete = true;                                
401
                            }
402
                            else if(App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission) //Consolidation Mode 일 때는 해당 Comment Layer의 Status가 Avoid or Consolidation인 것만 Delete 버튼 활성화
403
                            {
404
                                if(info.AvoidConsolidate == 1 || info.Consolidate == 1)
405
                                    info.userDelete = true;
406
                            }
407
                            else
408
                            {
409
                                info.userDelete = true;
410
                            }                               
411
                            info.DisplayColor = "#FFFF0000";
412
                        }
413
                        else
414
                        {
415
                            info.userDelete = false;
416
                        }
417

    
418
                        ViewerDataModel.Instance._markupInfoList.Add(info);
419
                    }
420

    
421
                    var userInfoList = ViewerDataModel.Instance._markupInfoList.GroupBy(f => f.UserID).Select(f => new MarkupUserInfo { UserId = f.Key, UserName = f.First().UserName });
422

    
423
                    userInfoList.ToList().ForEach(x =>
424
                    {
425
                        ViewerDataModel.Instance._markupUserList.Add(x);
426

    
427
                        if (MarkupToPDF.MarkupContext.GetUserSignItem(x.UserId) == null)
428
                        {
429
                            string signData = BaseClient.GetSignData(App.ViewInfo.ProjectNO, x.UserId);
430
                            string signStrokes = BaseClient.GetSignStrokes(App.ViewInfo.ProjectNO, x.UserId);
431

    
432
                            if (signData != null && signStrokes != null)
433
                            {
434
                                MarkupToPDF.MarkupContext.SetUserSignItem(x.UserId, signData, signStrokes);
435
                            }
436
                        }
437
                    });
438

    
439
                    e.Result.ToList().ForEach(d =>
440
                    {
441
                        if (d.MarkupList != null)
442
                        {
443
                            d.MarkupList.ForEach(p =>
444
                            {
445
                                if (d.UserID == App.ViewInfo.UserID)
446
                                {
447
                                    if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission) //조회모드는 delete 버튼 모두 비활성화
448
                                    {
449
                                        d.userDelete = false;
450
                                    }
451
                                    else if (!App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission && e.Result.Where(x => x.UserID == App.ViewInfo.UserID && x.PartConsolidate == 1).Count() > 0)//Team Consolidation Mode이고 Team Consolidation Layer가 있을 경우
452
                                    {
453
                                        if (App.ViewInfo.NewCommentPermission && e.Result.Exists(x => x.UserID == App.ViewInfo.UserID && x.PartConsolidate == 1 && x.MarkupInfoID == d.MarkupInfoID))
454
                                            d.userDelete = true;
455
                                    }
456
                                    else if (App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission) //Consolidation Mode 일 때는 해당 Comment Layer의 Status가 Avoid or Consolidation인 것만 Delete 버튼 활성화
457
                                    {
458
                                        if (d.AvoidConsolidate == 1 || d.Consolidate == 1)
459
                                            d.userDelete = true;
460
                                    }
461
                                    else
462
                                    {
463
                                        d.userDelete = true;
464
                                    }
465
                                    d.DisplayColor = "#FFFF0000";
466
                                    MarkupItemEx markup = new MarkupItemEx
467
                                    {
468
                                        Data = p.Data,
469
                                        Data_Type = p.Data_Type,
470
                                        ID = p.ID,
471
                                        IsUpdate = false,
472
                                        MarkupInfoID = d.MarkupInfoID,
473
                                        PageNumber = p.PageNumber,
474
                                        Symbol_ID = p.Symbol_ID,
475
                                        //Group_ID = p.Group_ID
476
                                    };
477
                                    ViewerDataModel.Instance.MyMarkupList.Add(markup);
478
                                }
479
                                else
480
                                {
481
                                    MarkupItemEx markup = new MarkupItemEx
482
                                    {
483
                                        Data = p.Data,
484
                                        Data_Type = p.Data_Type,
485
                                        ID = p.ID,
486
                                        IsUpdate = false,
487
                                        MarkupInfoID = d.MarkupInfoID,
488
                                        PageNumber = p.PageNumber,
489
                                        Symbol_ID = p.Symbol_ID,
490
                                        //Group_ID = p.Group_ID
491
                                    };
492
                                    ViewerDataModel.Instance.MarkupList_Pre.Add(markup);
493
                                }
494
                            });
495
                        }
496
                    });
497

    
498
                    var currentUser = e.Result.Find(data => data.UserID == App.ViewInfo.UserID && data.AvoidConsolidate == 0);
499
                    if (currentUser == null)
500
                    {
501
                        /// create a new markupinfo to do comments
502
                        if (App.ViewInfo.NewCommentPermission)
503
                        {
504
                            var infoId = Commons.ShortGuid();
505
                            PreviewUserMarkupInfoItem = new MarkupInfoItem
506
                            {
507
                                CreateTime = DateTime.Now,
508
                                UpdateTime = DateTime.Now,
509
                                Depatment = userData.DEPARTMENT,
510
                                DisplayColor = "#FFFF0000",
511
                                UserID = userData.ID,
512
                                UserName = userData.NAME,
513
                                PageCount = 1,
514
                                Description = "",
515
                                MarkupInfoID = infoId,
516
                                MarkupList = null,
517
                                MarkupVersionID = Commons.ShortGuid(),
518
                                Consolidate = 0,
519
                                PartConsolidate = 0,
520
                                userDelete = true,
521
                                AvoidConsolidate = 0,
522
                                IsPreviewUser = false
523
                            };
524

    
525
                            App.Custom_ViewInfoId = infoId;
526

    
527
                            ViewerDataModel.Instance._markupInfoList.Insert(0, PreviewUserMarkupInfoItem);
528
                        }
529
                    }
530
                    else
531
                    {
532
                        App.Custom_ViewInfoId = currentUser.MarkupInfoID;
533
                    }
534

    
535
                    ViewerDataModel.Instance.SyncPageNumber = 1;
536

    
537
                    /// Consolidation 된 데이터가 최상단에 올 수 있도록 변경
538
                    //var markupItem = ViewerDataModel.Instance._markupInfoList.OrderByDescending(p => p.Consolidate == Convert.ToInt32(true)).ToList();
539

    
540
                    gridViewMarkup.ItemsSource = ViewerDataModel.Instance._markupInfoList;
541

    
542
                    SetCommentPages(null);
543

    
544
                    // GRIDVIEW에서 팀별 GROUPING
545
                    // 효성은 안함
546
#if (Hyosung)
547
#else
548
                    /// create a group descriptor
549
                    gridViewMarkup.GroupDescriptors.Clear();
550
                    GroupDescriptor descriptor = new GroupDescriptor();
551
                    descriptor.Member = "Depatment";
552
                    descriptor.DisplayContent = "DEPT";
553
                    //descriptor.SortDirection = ListSortDirection.Ascending;
554
                    gridViewMarkup.GroupDescriptors.Add(descriptor);
555
#endif
556

    
557
                    GridViewMarkup_Sorting(gridViewMarkup, new GridViewSortingEventArgs(gridViewMarkup.Columns[0], SortingState.None, SortingState.None));
558

    
559
                    SelectInitialMarkupInfo();
560
                }
561
            }
562
            catch (Exception ex) 
563
            {
564
                App.FileLogger.Fatal(ex);
565
            }
566
            finally
567
            {
568
                if(!ViewerDataModel.Instance.SystemMain.dzMainMenu.btnFinalPDF.IsEnabled)
569
                {
570
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.btnFinalPDF.IsEnabled = true;
571
                }
572

    
573
                if (!ViewerDataModel.Instance.SystemMain.dzMainMenu.btnConsolidate.IsEnabled)
574
                {
575
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.btnConsolidate.IsEnabled = true;
576
                }
577
            }
578
        }
579

    
580
        /// <summary>
581
        /// 프로그램이 로딩되고 난 후 맨처음으로 MarkupInfo를 선택한다. 
582
        /// </summary>
583
        private void SelectInitialMarkupInfo()
584
        {
585
            if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission)
586
            {
587
                #region Consolidate 항목이 있으면 Consolidate 항목만 추가
588
                if (ViewerDataModel.Instance._markupInfoList.Any(x => x.Consolidate == 1 && x.AvoidConsolidate == 0))
589
                {
590
                    var Consolidates = ViewerDataModel.Instance._markupInfoList.Where(x => x.Consolidate == 1 && x.AvoidConsolidate == 0).ToList();
591
                    Consolidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
592
                }
593
                #endregion
594
                #region Consolidate 항목이 없을 경우에는 사용자 별로 AvoidConsolidate를 제외한 우선 순위가 높은(Team,Comment)항목들을 선택
595
                else
596
                {
597
                    var MarkupInfoColl = ViewerDataModel.Instance._markupInfoList.Where(x => x.AvoidConsolidate == 0).ToList();
598

    
599
                    #region Team consolidate 항목 선택
600
                    var Candidates = MarkupInfoColl.Where(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0).ToList();
601
                    MarkupInfoColl.RemoveAll(x => Candidates.Exists(y => y.UserID == x.UserID));
602
                    #endregion
603

    
604
                    #region 추가되지 않은 사용자들을 추가
605
                    foreach (var item in MarkupInfoColl.Where(x => !Candidates.Exists(y => y.UserID == x.UserID)))
606
                    {
607
                        Candidates.Add(item);
608
                    }
609
                    #endregion
610

    
611
                    Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
612
                }
613
                #endregion
614
            }
615
            else if (!App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission)   /// Eng'r Comment Mode
616
            {
617
                var MarkupInfoColl = ViewerDataModel.Instance._markupInfoList.Where(x => x.AvoidConsolidate == 0).ToList();
618

    
619
                #region Team consolidate 항목 선택
620
                var Candidates = MarkupInfoColl.Where(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0).ToList();
621
                MarkupInfoColl.RemoveAll(x => Candidates.Exists(y => y.UserID == x.UserID));
622
                #endregion
623

    
624
                #region 추가되지 않은 사용자들을 추가
625
                foreach (var item in MarkupInfoColl.Where(x => !Candidates.Exists(y => y.UserID == x.UserID)))
626
                {
627
                    Candidates.Add(item);
628
                }
629
                #endregion
630

    
631
                Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
632
            }
633
            else if (App.ViewInfo.CreateFinalPDFPermission)    /// Orig Comment Model
634
            {
635
                if (ViewerDataModel.Instance._markupInfoList.Any(x => x.Consolidate == 1 && x.AvoidConsolidate == 0))
636
                {
637
                    var Consolidates = ViewerDataModel.Instance._markupInfoList.Where(x => x.Consolidate == 1 && x.AvoidConsolidate == 0).ToList();
638
                    Consolidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
639
                }
640
                else if (ViewerDataModel.Instance._markupInfoList.Any(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0))
641
                {
642
                    var MarkupInfoColl = ViewerDataModel.Instance._markupInfoList.Where(x => x.AvoidConsolidate == 0).ToList();
643

    
644
                    #region Team consolidate 항목 선택
645
                    var Candidates = MarkupInfoColl.Where(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0).ToList();
646
                    MarkupInfoColl.RemoveAll(x => Candidates.Exists(y => y.UserID == x.UserID));
647
                    #endregion
648

    
649
                    #region 추가되지 않은 사용자들을 추가
650
                    foreach (var item in MarkupInfoColl.Where(x => !Candidates.Exists(y => y.UserID == x.UserID)))
651
                    {
652
                        Candidates.Add(item);
653
                    }
654
                    #endregion
655

    
656
                    Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
657
                }
658
                else
659
                {
660
                    var Comments = ViewerDataModel.Instance._markupInfoList.Where(x => x.Consolidate == 0 && x.AvoidConsolidate == 0).ToList();
661
                    Comments.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
662
                }
663
            }
664

    
665
            if (!gridViewMarkup.SelectedItems.Any())
666
            {
667
                var SelectedItem = ViewerDataModel.Instance._markupInfoList.Where(info => info.UserID == App.ViewInfo.UserID).OrderByDescending(order => order.UpdateTime).FirstOrDefault();
668

    
669
                if (PreviewUserMarkupInfoItem != null)
670
                {
671
                    this.gridViewMarkup.SelectedItem = PreviewUserMarkupInfoItem;
672
                }
673
                else if (SelectedItem != null)
674
                {
675
                    this.gridViewMarkup.SelectedItem = SelectedItem;
676
                }
677
                else if (ViewerDataModel.Instance._markupInfoList.Any())
678
                {
679
                    this.gridViewMarkup.SelectedItem = ViewerDataModel.Instance._markupInfoList[0];
680
                }
681
            }
682
        }
683

    
684
        private void GridViewMarkup_Sorting(object sender, GridViewSortingEventArgs e)
685
        {
686
            IEnumerable<IKCOM.MarkupInfoItem> markuplist = e.DataControl.ItemsSource as IEnumerable<IKCOM.MarkupInfoItem>;
687

    
688
            if(markuplist == null)
689
            {
690
                e.Cancel = true;
691
                return;
692
            }
693

    
694
            if(e.NewSortingState == SortingState.None)
695
            {
696
                markuplist = markuplist.OrderByDescending(x => SortIndex(x))
697
                                            .ThenBy(x => x.Depatment)
698
                                            .ThenBy(x => x.UserID);
699

    
700
                e.DataControl.ItemsSource = markuplist.ToList();
701
            }
702
        }
703

    
704

    
705
        // 마크업 리스트 정렬
706
        private int SortIndex(IKCOM.MarkupInfoItem markupInfoItem)
707
        {
708
            int result = 0;
709

    
710
            // Consolidate은 최상단
711
            if (markupInfoItem.Consolidate == 1)
712
            {
713
                result += 2;
714
            }
715

    
716
            /// Consolidate 다음으로 우선순위
717
            if (markupInfoItem.UserID == App.ViewInfo.UserID)
718
            {
719
                result += 1;
720
            }
721

    
722
            return result;
723
        }
724

    
725

    
726
        private void GridViewMarkup_Sorted(object sender, GridViewSortedEventArgs e)
727
        {
728

    
729
        }
730

    
731
        private async void gridViewRevMarkup_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
732
        {
733
            List<MarkupInfoItem> gridSelectionItem = gridViewRevMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
734
            //if (ViewerDataModel.Instance.PageBalanceNumber == 0)
735
            //{
736
            //    ViewerDataModel.Instance.PageBalanceNumber = 1;
737
            //}
738

    
739
            if (ViewerDataModel.Instance.SyncPageNumber == 0)
740
            {
741
                ViewerDataModel.Instance.SyncPageNumber = 1;
742
            }
743
            if (e.AddedItems.Any())
744
            {
745
                foreach (var item in gridSelectionItem)
746
                {
747
                    //item.MarkupList.Where(pageItem => pageItem.PageNumber == ViewerDataModel.Instance.PageBalanceNumber).ToList().ForEach(delegate (MarkupItem markupitem)
748
                    //{
749
                    //    layerControl.markupParse(markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_Sync, item.DisplayColor, "", item.MarkupInfoID);
750
                    //});
751

    
752
                    var pageItems = item.MarkupList.Where(pageItem => pageItem.PageNumber == ViewerDataModel.Instance.SyncPageNumber).ToList();
753

    
754
                    foreach (var markupitem in pageItems)
755
                    {
756
                       await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_Sync, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "", item.MarkupInfoID,
757
                           STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
758
                    }
759
                }
760
            }
761
            else if (e.RemovedItems.Any())
762
            {
763
                var _infoItem = e.RemovedItems.Cast<MarkupInfoItem>().ToList();
764

    
765
                (from A in _infoItem
766
                 from B in Common.ViewerDataModel.Instance.MarkupControls_Sync
767
                 where A.MarkupInfoID == B.MarkupInfoID
768
                 select B).ToList().ForEach(data =>
769
                 {
770
                     Common.ViewerDataModel.Instance.MarkupControls_Sync.Remove(data);
771
                 });
772
            }
773
        }
774

    
775
        /// <summary>
776
        /// 선택한 항목은 Visibility = Visible, 해제한 항목은 Visibility = Hidden 처리한다.
777
        /// </summary>
778
        /// <param name="sender"></param>
779
        /// <param name="e"></param>
780
        private async void gridViewMarkup_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
781
        {
782

    
783
            foreach (var item in e.AddedItems)
784
            {
785
                var cellToSelect = new GridViewCellInfo(item, this.gridViewMarkup.Columns["color"], this.gridViewMarkup);
786

    
787
                if(cellToSelect != null)
788
                {
789

    
790
                }
791
            }
792

    
793
            SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
794

    
795
            var dataSet = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
796
            var dataSet_User = gridViewMarkup.Items.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
797
            var resultA = (from item_Select in dataSet
798
                           from item_Non in dataSet_User
799
                           where item_Select == item_Non
800
                           select item_Non).ToList();
801

    
802
            if (resultA.Count() >= 2)
803
            {
804
                // 동일한 사용자 데이터가 두개 이상 선택됩니다. Consolidation을 선택할까요?
805
                RadWindow.Confirm(new DialogParameters
806
                {
807
                    Owner = Application.Current.MainWindow,
808
                    Header = "Info",
809
                    Content = "Selected more than two identical user data. Do you want to select consolidation?",
810
                    Closed = new EventHandler<WindowClosedEventArgs>((sen, ea) =>
811
                    {
812
                        if(ea.DialogResult == null)
813
                        {
814
                            return;
815
                        }
816
                        if (e.AddedItems.Count() == 1)
817
                        {
818
                            MarkupInfoItem instanceItem = e.AddedItems.FirstOrDefault() as MarkupInfoItem;
819
                            gridViewMarkup.SelectedItem = null;
820

    
821
                        
822
                            if (ea.DialogResult.Value)
823
                            {
824
                                if (instanceItem.Consolidate == 1 || instanceItem.PartConsolidate == 1)
825
                                {
826
                                    gridViewMarkup.SelectedItem = instanceItem;
827
                                }
828
                                else
829
                                {
830
                                    //1. Consolidations이 있다면 하나 선택
831
                                    var Consolidations = resultA.Where(item => (item.Consolidate == 1 || item.PartConsolidate == 1));
832

    
833
                                    if (Consolidations.Count() > 0)
834
                                    {
835
                                        gridViewMarkup.SelectedItem = Consolidations.First();
836
                                    }
837
                                }
838
                              
839
                            }
840
                            else {
841
                                //1. Consolidations 아닌게 있다면 Change
842
                                var notConsolidations = resultA.Where(item => !(item.Consolidate == 1 || item.PartConsolidate == 1));
843

    
844
                                if(notConsolidations.Count() > 0) {
845
                                    gridViewMarkup.SelectedItem = notConsolidations.First();
846
                                }
847
                                else {//1. Consolidations 아닌게 없다면 그대로
848
                                    gridViewMarkup.SelectedItem = instanceItem;
849
                                }
850
                                
851
                            }
852
                        }
853
                    }),
854
                    Theme = new Windows8Theme(),
855
                    ModalBackground = new System.Windows.Media.SolidColorBrush { Color = System.Windows.Media.Colors.Black, Opacity = 0.6 },
856
                });
857
            }
858
            else //파라미터로 넘어온 사용자가 걸리지 않은 경우
859
            {
860
                List<MarkupInfoItem> gridItem = gridViewMarkup.Items.Cast<MarkupInfoItem>().ToList(); //전체 마크업
861
                List<MarkupInfoItem> gridSelectionItem = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
862
                List<MarkupInfoItem> gridNonSelectionItem = gridItem.Except(gridSelectionItem).ToList(); //선택 되지 않은 마크업
863
#region 코멘트 보기
864
                if (e.AddedItems.Count() > 0 && this.pageNavigator.CurrentPage != null)
865
                {
866
                    foreach (var item in gridSelectionItem)
867
                    {
868
                        if (item.UserID == App.ViewInfo.UserID)
869
                        {
870
                            var controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
871
                            if (controls.Count == 0)
872
                            {
873
                                var instance = ViewerDataModel.Instance.MyMarkupList.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
874

    
875
                                foreach (var markup in instance)
876
                                {
877
                                    await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "", 
878
                                        item.MarkupInfoID, markup.ID, STAMP_Contents:App.SystemInfo.STAMP_CONTENTS);
879
                                }
880
                            }
881

    
882
                            controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
883
                            foreach (var control in controls)
884
                            {
885
                                Logger.sendCheckLog(String.Format("=={0}", control), 1);
886
                                control.Visibility = Visibility.Visible;
887
                            }
888
                        }
889
                        else
890
                        {
891
                            var controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
892
                            if (controls.Count == 0)
893
                            {
894
                                var instance = ViewerDataModel.Instance.MarkupList_Pre.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
895
                                foreach (var markup in instance)
896
                                {
897
                                    await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "",
898
                                        item.MarkupInfoID, markup.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
899
                                }
900
                            }
901

    
902
                            controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
903
                            foreach (var control in controls)
904
                            {
905
                                control.Visibility = Visibility.Visible;
906
                            }
907
                        }
908
                    }
909
                }
910
#endregion
911
#region 코멘트 숨기기
912
                else if (e.RemovedItems.Count > 0)
913
                {
914
                    var _infoItem = e.RemovedItems.Cast<MarkupInfoItem>().ToList();
915

    
916
                    (from A in _infoItem
917
                     from B in Common.ViewerDataModel.Instance.MarkupControls
918
                     where A.MarkupInfoID == B.MarkupInfoID
919
                     select B).ToList().ForEach(data =>
920
                     {
921
                         data.Visibility = Visibility.Hidden;                         
922
                     });
923

    
924

    
925
                    var myComment = _infoItem.Where(d => d.UserID == App.ViewInfo.UserID).FirstOrDefault();
926
                    if (myComment != null)
927
                    {
928
                        Common.ViewerDataModel.Instance.MarkupControls_USER.ToList().ForEach(delegate (MarkupToPDF.Common.CommentUserInfo markupitem)
929
                        {
930
                            markupitem.Visibility = Visibility.Hidden;
931
                        });
932
                    }
933
                }
934
#endregion
935
            }
936
        }
937

    
938
        private async void gridViewMarkup_SelectedCellsChanged(object sender, Telerik.Windows.Controls.GridView.GridViewSelectedCellsChangedEventArgs e)
939
        {
940
            if (e.AddedCells.Count() > 0)
941
            {
942
                if(e.AddedCells[0].Column.Name == "color")
943
                {
944

    
945
                }
946
                else
947
                {
948
                    List<MarkupInfoItem> removeItems = new List<MarkupInfoItem>();
949

    
950
                    if (!gridViewMarkup.SelectedItems.Contains(e.AddedCells[0].Item))
951
                    {
952
                        gridViewMarkup.SelectedItems.Add(e.AddedCells[0].Item);
953
                    }
954
                    else
955
                    {
956
                        gridViewMarkup.Unselect(new[] { e.AddedCells[0].Item });
957

    
958
                        removeItems.Add(e.AddedCells[0].Item as MarkupInfoItem);
959
                    }
960

    
961
                    SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
962

    
963
                    var dataSet = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
964
                    var dataSet_User = gridViewMarkup.Items.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
965
                    var resultA = (from item_Select in dataSet
966
                                   from item_Non in dataSet_User
967
                                   where item_Select == item_Non
968
                                   select item_Non).ToList();
969

    
970
                    if (resultA.Count() >= 2)
971
                    {
972
                        // 동일한 사용자 데이터가 두개 이상 선택됩니다. Consolidation을 선택할까요?
973
                        RadWindow.Confirm(new DialogParameters
974
                        {
975
                            Owner = Application.Current.MainWindow,
976
                            Header = "Info",
977
                            Content = "Selected more than two identical user data. Do you want to select consolidation?",
978
                            Closed = new EventHandler<WindowClosedEventArgs>((sen, ea) =>
979
                            {
980
                                if (ea.DialogResult == null)
981
                                {
982
                                    return;
983
                                }
984
                                if (gridViewMarkup.SelectedItems.Count() == 1)
985
                                {
986
                                    MarkupInfoItem instanceItem = gridViewMarkup.SelectedItems.FirstOrDefault() as MarkupInfoItem;
987
                                    gridViewMarkup.SelectedItem = null;
988

    
989

    
990
                                    if (ea.DialogResult.Value)
991
                                    {
992
                                        if (instanceItem.Consolidate == 1 || instanceItem.PartConsolidate == 1)
993
                                        {
994
                                            gridViewMarkup.SelectedItem = instanceItem;
995
                                        }
996
                                        else
997
                                        {
998
                                            //1. Consolidations이 있다면 하나 선택
999
                                            var Consolidations = resultA.Where(item => (item.Consolidate == 1 || item.PartConsolidate == 1));
1000

    
1001
                                            if (Consolidations.Count() > 0)
1002
                                            {
1003
                                                gridViewMarkup.SelectedItem = Consolidations.First();
1004
                                            }
1005
                                        }
1006

    
1007
                                    }
1008
                                    else
1009
                                    {
1010
                                        //1. Consolidations 아닌게 있다면 Change
1011
                                        var notConsolidations = resultA.Where(item => !(item.Consolidate == 1 || item.PartConsolidate == 1));
1012

    
1013
                                        if (notConsolidations.Count() > 0)
1014
                                        {
1015
                                            gridViewMarkup.SelectedItem = notConsolidations.First();
1016
                                        }
1017
                                        else
1018
                                        {//1. Consolidations 아닌게 없다면 그대로
1019
                                            gridViewMarkup.SelectedItem = instanceItem;
1020
                                        }
1021

    
1022
                                    }
1023
                                }
1024
                            }),
1025
                            Theme = new Windows8Theme(),
1026
                            ModalBackground = new System.Windows.Media.SolidColorBrush { Color = System.Windows.Media.Colors.Black, Opacity = 0.6 },
1027
                        });
1028
                    }
1029
                    else //파라미터로 넘어온 사용자가 걸리지 않은 경우
1030
                    {
1031
                        List<MarkupInfoItem> gridItem = gridViewMarkup.Items.Cast<MarkupInfoItem>().ToList(); //전체 마크업
1032
                        List<MarkupInfoItem> gridSelectionItem = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
1033
                        List<MarkupInfoItem> gridNonSelectionItem = gridItem.Except(gridSelectionItem).ToList(); //선택 되지 않은 마크업
1034
                        #region 코멘트 보기
1035
                        if (gridViewMarkup.SelectedItems.Count() > 0 && this.pageNavigator.CurrentPage != null)
1036
                        {
1037
                            foreach (var item in gridSelectionItem)
1038
                            {
1039
                                if (item.UserID == App.ViewInfo.UserID)
1040
                                {
1041
                                    var controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1042
                                    if (controls.Count == 0)
1043
                                    {
1044
                                        var instance = ViewerDataModel.Instance.MyMarkupList.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
1045

    
1046
                                        foreach (var markup in instance)
1047
                                        {
1048
                                            await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "",
1049
                                                item.MarkupInfoID, markup.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1050
                                        }
1051
                                    }
1052

    
1053
                                    controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1054
                                    foreach (var control in controls)
1055
                                    {
1056
                                        Logger.sendCheckLog(String.Format("=={0}", control), 1);
1057
                                        control.Visibility = Visibility.Visible;
1058
                                    }
1059
                                }
1060
                                else
1061
                                {
1062
                                    var controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1063
                                    if (controls.Count == 0)
1064
                                    {
1065
                                        var instance = ViewerDataModel.Instance.MarkupList_Pre.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
1066
                                        foreach (var markup in instance)
1067
                                        {
1068
                                            await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "",
1069
                                                item.MarkupInfoID, markup.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1070
                                        }
1071
                                    }
1072

    
1073
                                    controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1074
                                    foreach (var control in controls)
1075
                                    {
1076
                                        control.Visibility = Visibility.Visible;
1077
                                    }
1078
                                }
1079
                            }
1080
                        }
1081
                        #endregion
1082
                        #region 코멘트 숨기기
1083
                        else if (removeItems.Count > 0)
1084
                        {
1085
                            (from A in removeItems
1086
                             from B in Common.ViewerDataModel.Instance.MarkupControls
1087
                             where A.MarkupInfoID == B.MarkupInfoID
1088
                             select B).ToList().ForEach(data =>
1089
                             {
1090
                                 data.Visibility = Visibility.Hidden;
1091
                             });
1092

    
1093

    
1094
                            var myComment = removeItems.Where(d => d.UserID == App.ViewInfo.UserID).FirstOrDefault();
1095
                            if (myComment != null)
1096
                            {
1097
                                Common.ViewerDataModel.Instance.MarkupControls_USER.ToList().ForEach(delegate (MarkupToPDF.Common.CommentUserInfo markupitem)
1098
                                {
1099
                                    markupitem.Visibility = Visibility.Hidden;
1100
                                });
1101
                            }
1102
                        }
1103
                        #endregion
1104
                    }
1105
                }
1106
            }
1107
        }
1108

    
1109
        private void BaseClient_GetDocumentItemInfoCompleted(object sender, GetDocumentItemInfoCompletedEventArgs e)
1110
        {
1111
            //Logger.sendResLog("GetDocumentItemInfoCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.DOCUMENT_ID + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
1112

    
1113
            if (e.Result != null)
1114
            {
1115
                _DocItem = e.Result;
1116

    
1117
                if (e.Result.DOCUMENT_NO == "" && e.Result.DOCUMENT_NAME == "" && e.Result.GROUP_NO == "0")
1118
                {
1119
                    _ViewInfo.UserID = _ViewInfo.UserID.Replace(@"DAELIM\", "");
1120
                }
1121
                ////Logger.sendReqLog("GetDocInfoAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
1122
                BaseClient.GetDocInfoAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
1123
            }
1124
            else
1125
            {
1126
                DialogMessage_Alert("Document Information Not Found.", "Error");
1127

    
1128
                BaseClient.GetCheckSystemAdminCompleted += (sen, ea) =>
1129
                {
1130
                    //Logger.sendResLog("GetCheckSystemAdminCompleted", "UserState : " + ea.UserState + "\r Result :" + ea.Result + "\r Cancelled :" + ea.Cancelled + "\r Error :" + ea.Error, 1);
1131

    
1132
                    if (ea.Error == null)
1133
                    {
1134
                        if (ea.Result)
1135
                        {
1136
                            this._ViewInfo.isAdmin = true;
1137
                            //Logger.sendReqLog("GetDocInfoAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
1138
                            BaseClient.GetDocInfoAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
1139
                        }
1140
                        else
1141
                        {
1142
                            //System.Windows.Forms.MessageBox.Show("해당 프로젝트에 가입되지 않은 유저입니다. 관리자에게 등록신청을 해주세요", "안내");
1143
                            DialogMessage_Alert("You are not belong to this project. Please ask admin for an authority.", "Info");
1144
                            //this.ParentOfType<MainPage>().DialogMessage_Alert("해당 프로젝트에 가입되지 않은 유저입니다. 관리자에게 등록신청을 해주세요", "안내");
1145
                        }
1146

    
1147
                    }
1148
                    else
1149
                    {
1150
                        //System.Windows.Browser.HtmlPage.Window.Invoke("close");
1151
                    }
1152
                };
1153
                //Logger.sendReqLog("GetCheckSystemAdminAsync", _ViewInfo.UserID, 1);
1154
                BaseClient.GetCheckSystemAdminAsync(this._ViewInfo.UserID);
1155
            }
1156
        }
1157

    
1158
        private void BaseClient_GetSystemDataCompleted(object sender, GetSystemDataCompletedEventArgs e)
1159
        {
1160
            //Logger.sendResLog("GetSystemDataCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
1161

    
1162
            if (e.Error == null && e.Result != null)
1163
            {
1164
                App.SystemInfo = e.Result;
1165

    
1166
                //App.urlPort_DB = App.SystemInfo.HostPort;
1167
                //App.urlHost_DB = App.SystemInfo.HostName;
1168
                //Logger.sendReqLog("GetConversionStateAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
1169
                BaseClient.GetConversionStateAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
1170

    
1171
                //if (App.urlHost.Contains("localhost"))
1172
                //{
1173
                //    App.urlHost = App.urlHost_DB;
1174
                //}
1175
            }
1176
        }
1177

    
1178
        private void BaseClient_GetConversionStateCompleted(object sender, GetConversionStateCompletedEventArgs e)
1179
        {
1180
            if (e.Error == null && e.Result)
1181
            {
1182
                BaseClient.GetDocumentItemInfoAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID, userID = _ViewInfo.UserID });
1183

    
1184
                if (App.ViewInfo != null && App.ViewInfo.ProjectNO != "")
1185
                {
1186
                    userData = BaseClient.GetMember(App.ViewInfo.ProjectNO, App.ViewInfo.UserID);
1187
                    if (userData != null)
1188
                    {
1189
                        BaseClient.GetDeptDataAsync(userData.DEPARTMENT);
1190
                    }
1191
                    else
1192
                    {
1193
                        userData = new MEMBER();
1194
                        userData.DEPARTMENT = "ALL";
1195
                        BaseClient.GetDeptDataAsync(userData.DEPARTMENT);
1196
                    }
1197
                }
1198
            }
1199
            else
1200
            {
1201
                string failedmsg = CommonLib.Common.GetAlertMessageString("GetConversionStateFailed", "MSG", "Too Many V/P Files are uploading instantaneously, This V/P file can not be open now. Please feel free to re-open wait a moment again!\n\n현재 일시적으로 많은 양의 V/P가 등록되고 있어 이 문서를 열람할 수 없습니다.\n잠시만 기다려 주신 후 다시 열람하여 주시기 바랍니다");
1202
                DialogMessage_Alert(failedmsg, "Warning");
1203
            }
1204
        }
1205

    
1206
        public void SetView(ViewInfo info)
1207
        { 
1208
            this._ViewInfo = info;
1209
            try
1210
            {
1211
                /// 대림의 경우 EnsembleID를 가지고 DocumentItemID를 구함
1212
                /// 다른 Site를 대비하여 에러 처리함
1213
                string docid = BaseClient.GetDocItemID(info.EnsembleID);
1214
                if (!string.IsNullOrEmpty(docid))
1215
                {
1216
                    this._ViewInfo.DocumentItemID = docid;
1217
                }
1218
            }
1219
            catch (Exception ex)
1220
            {
1221

    
1222
                //App.FileLogger.Fatal(ex);
1223
            }
1224

    
1225
            //Logger.sendReqLog("GetSystemDataAsync", "", 1);
1226

    
1227
            BaseClient.GetSystemDataAsync();
1228
        }
1229

    
1230
        public void HubSet()
1231
        {
1232
            // 허브 연결 구성
1233
            var hubConnection = new HubConnection(CommonLib.Common.GetConfigString("HubAddress", "URL", "", App.isExternal));
1234
            IHubProxy MarkusLicenseProxy = hubConnection.CreateHubProxy("MarkusLicenseHub");
1235

    
1236

    
1237
            // 허브 연결 
1238
            hubConnection.Start().ContinueWith(task =>
1239
            {
1240
                if (task.IsFaulted)
1241
                {
1242
                    Console.WriteLine("There was an error opening the connection:{0}",
1243
                                      task.Exception.GetBaseException());
1244
                    //throw task.Exception.GetBaseException();
1245
                }
1246
                else
1247
                {
1248
                    Console.WriteLine("Connected :: " + task.Id);
1249
                }
1250

    
1251
            }).Wait();
1252

    
1253

    
1254
            // [ 프로그램 시작 ]
1255
            // 클라이언트에서 서버를 호출 ( 접속 시 )  : 라이센스 체크
1256
            //( "method name", arg1, arg2 )
1257
            //MarkusLicenseProxy.Invoke<string>("ConnectionMarkus", "H2009115", "고동균").ContinueWith(task =>
1258
            //{
1259
            //    if (task.IsFaulted)
1260
            //    {
1261
            //        Console.WriteLine("ConnectionMarkus :: There was an error calling send: {0}", task.Exception.GetBaseException());
1262
            //    }
1263
            //    else
1264
            //    {
1265
            //        Console.WriteLine(task.Result);
1266
            //    }
1267
            //});
1268
            MarkusLicenseProxy.Invoke<string>("ConnectionMarkus", App.ViewInfo.UserID,App.ViewInfo.ProjectNO).ContinueWith(task =>
1269
            {
1270
                if (task.IsFaulted)
1271
                {
1272
                    Console.WriteLine("ConnectionMarkus :: There was an error calling send: {0}", task.Exception.GetBaseException());
1273
                    //throw task.Exception.GetBaseException();
1274
                }
1275
                else
1276
                {
1277
                    switch (task.Result)
1278
                    {
1279
                        case "2":
1280
                            {
1281
                                var result = MessageBox.Show("권한이 없습니다.");
1282
                                if (result == MessageBoxResult.OK)
1283
                                    System.Diagnostics.Process.GetCurrentProcess().Kill();
1284
                            }
1285
                            break;
1286
                        case "404":
1287
                            {
1288
                                var result = MessageBox.Show("등록된 사용자가 아닙니다.");
1289
                                if(result == MessageBoxResult.OK)
1290
                                    System.Diagnostics.Process.GetCurrentProcess().Kill();
1291
                            }
1292
                            break;
1293
                    }
1294
                }
1295
            });
1296

    
1297
            // 서버에서 클라이언트 호출 ( 프로그램 구동여부 ) : 라이센스 체크 후 응답 ( 반환값 : true, false ) 
1298
            //MarkusLicenseProxy.On<bool>("IsConnection", status =>
1299
            //{
1300

    
1301
            //    if (status)
1302
            //    {
1303
            //        // 프로그램 시작 
1304
            //        Console.WriteLine("connection status : " + status);
1305
            //    }
1306
            //    else
1307
            //    {
1308
            //        // 프로그램 종료 ( signalr 접속 끊기 )  
1309
            //        hubConnection.Stop();
1310
            //    }
1311
            //});
1312

    
1313
            // 공지 메세지 ( 서버에서 클라이언트 호출 ) 
1314
            MarkusLicenseProxy.On<string>("MarkusNotification", msg =>
1315
                Console.WriteLine("Noficiation Message : " + msg)
1316
            );
1317

    
1318

    
1319
            // 서버 메서드 호출 
1320
            //MarkusLicenseProxy.Invoke<string>("DoSomething", "I'm doing something!!!").Wait();
1321

    
1322
            //Console.ReadKey();
1323

    
1324
            //hubConnection.Stop();
1325
        }
1326

    
1327
        public async void MarkupUserListDisplay()
1328
        {
1329
            List<MarkupInfoItem> gridItem = gridViewMarkup.Items.Cast<MarkupInfoItem>().ToList(); //전체 마크업
1330
            List<MarkupInfoItem> gridSelectionItem = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
1331
            List<MarkupInfoItem> gridNonSelectionItem = gridItem.Except(gridSelectionItem).ToList(); //선택 되지 않은 마크업
1332
                                                                                                     //MarkupToPDF.Controls.Parsing.LayerControl layerControl = new MarkupToPDF.Controls.Parsing.LayerControl();
1333
            Common.ViewerDataModel.Instance.MarkupControls_USER.Clear();  //전체 제거
1334
            Common.ViewerDataModel.Instance.MarkupControls.Clear();  //전체 제거
1335
            //foreach (var item in gridSelectionItem)
1336
            //{
1337
            //    if (item.UserID == App.ViewInfo.UserID)
1338
            //    {
1339
            //        ViewerDataModel.Instance.MyMarkupList.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList().ForEach(delegate (MarkupItemEx markupitem)
1340
            //        {
1341
            //            layerControl.markupParseEx(markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, item.DisplayColor, "", item.MarkupInfoID, markupitem.ID);
1342
            //        });
1343
            //    }
1344
            //    else
1345
            //    {
1346
            //        ViewerDataModel.Instance.MarkupList_Pre.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList().ForEach(delegate (MarkupItemEx markupitem)
1347
            //        {
1348
            //            layerControl.markupParse(markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls, item.DisplayColor, "", item.MarkupInfoID);
1349
            //        });
1350
            //    }
1351
            //}
1352
                (from A in gridSelectionItem
1353
                 from B in Common.ViewerDataModel.Instance.MarkupControls_USER
1354
                 where A.MarkupInfoID == B.MarkupInfoID
1355
                 select B).ToList().ForEach(data =>
1356
                 {
1357
                     Common.ViewerDataModel.Instance.MarkupControls_USER.Remove(data);
1358
                 });
1359
            (from A in gridSelectionItem
1360
             from B in Common.ViewerDataModel.Instance.MarkupControls
1361
             where A.MarkupInfoID == B.MarkupInfoID
1362
             select B).ToList().ForEach(data =>
1363
             {
1364
                 Common.ViewerDataModel.Instance.MarkupControls.Remove(data);
1365
             });
1366

    
1367
            foreach (var item in gridSelectionItem)
1368
            {
1369

    
1370
                if (item.UserID == App.ViewInfo.UserID)
1371
                {
1372
                    var markupItems = ViewerDataModel.Instance.MyMarkupList.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList();
1373

    
1374
                    foreach (var markupitem in markupItems)
1375
                    {
1376
                        await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "", 
1377
                                item.MarkupInfoID, markupitem.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1378
                    }
1379
                }
1380
                else
1381
                {
1382
                    var markupItems = ViewerDataModel.Instance.MarkupList_Pre.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList();
1383

    
1384
                    foreach (var markupitem in markupItems)
1385
                    {
1386
                        await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "", item.MarkupInfoID,
1387
                            STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1388
                    }
1389
                }
1390
            }
1391
        }
1392
    }
1393
}
클립보드 이미지 추가 (최대 크기: 500 MB)