프로젝트

일반

사용자정보

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

markus / KCOM / Services / BaseServices.cs @ a860bafc

이력 | 보기 | 이력해설 | 다운로드 (67.6 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
                CompareDisplay(e.Result);
142
            }
143
        }
144

    
145

    
146
        /// <summary>
147
        /// FinalPDF를 수행 후 관련 메시지를 표시한다.
148
        /// </summary>
149
        /// <param name="sender"></param>
150
        /// <param name="e"></param>
151
        private void BaseClient_SetFinalPDFCompleted(object sender, SetFinalPDFCompletedEventArgs e)
152
        {
153
            if (e.Error != null || e.Result.Status == FinalStatus.Error)
154
            {
155
                string errormsg = CommonLib.Common.GetAlertMessageString("SetFinalPDFError", "MSG", $"최종 파일을 만드는데 문제가 발생하였습니다{System.Environment.NewLine}{e.Result.Exception}");
156
                DialogMessage_Alert(errormsg, "안내");
157
            }
158
            else
159
            {
160
                string successmsg = CommonLib.Common.GetAlertMessageString("SetFinalPDFSuccess", "MSG", "최종 파일 생성 중입니다. 문서관리시스템을 확인해주세요");
161
                DialogMessage_Alert(successmsg, "안내");
162
            }
163
        }
164

    
165
        private void BaseClient_GetVPRevisionHistoryCompleted(object sender, GetVPRevisionHistoryCompletedEventArgs e)
166
        {
167
            //Logger.sendResLog("GetVPRevisionHistoryCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.Count + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
168

    
169
            if (e.Result != null && e.Error == null)
170
            {
171
                List<VPRevision> list = e.Result;
172
                foreach (var item in list)
173
                {
174

    
175
                    if (App.isExternal)
176
                    {
177
                        var sBaseServiceURL = CommonLib.Common.GetConfigString("ExternalOriginalFileUrl", "URL", "", App.isExternal);
178

    
179
                        if (!string.IsNullOrWhiteSpace(item.TO_VENDOR))
180
                        {
181
                            var toUri = new Uri(HttpUtility.UrlDecode(item.TO_VENDOR));
182
                            item.TO_VENDOR = $"{sBaseServiceURL}{toUri.LocalPath}";
183
                        }
184

    
185
                        if (!string.IsNullOrWhiteSpace(item.FROM_VENDOR))
186
                        {
187
                            var fromUri = new Uri(HttpUtility.UrlDecode(item.FROM_VENDOR));
188
                            item.FROM_VENDOR = $"{sBaseServiceURL}{fromUri.LocalPath}";
189
                        }
190
                    }
191
                    else
192
                    {
193
                        item.TO_VENDOR = HttpUtility.UrlDecode(item.TO_VENDOR);
194
                        item.FROM_VENDOR = HttpUtility.UrlDecode(item.FROM_VENDOR);
195
                        item.EnsembleLink = HttpUtility.UrlDecode(item.EnsembleLink);
196
                    }
197
                }
198
                //int result;
199
                //bool iCheck = true;
200
                //foreach (var li in list)
201
                //{                    
202
                //    iCheck = int.TryParse(li.GroupNo, out result);
203
                //    if (!iCheck)
204
                //        break;
205
                //}
206
                //if(iCheck)
207
                    gridViewHistory.ItemsSource = list.OrderByDescending(x => x.GroupNo); //20240611 LJY string 인거 전달드림 slip no 내림차순으로 그냥 해달라고 요청
208
                //else
209
                //    gridViewHistory.ItemsSource = list.OrderByDescending(x => x.RevNo);
210

    
211
            }
212
            //TempFile.TempLoad();
213
        }
214

    
215
        private void BaseClient_DeleteMarkupCompleted(object sender, DeleteMarkupCompletedEventArgs e)
216
        {
217
            //Logger.sendResLog("DeleteMarkupCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
218

    
219
            foreach(var info in ViewerDataModel.Instance._markupInfoList)
220
            {
221
                if(info.UserID == App.ViewInfo.UserID)
222
                {
223
                    info.userDelete = true;
224
                    info.DisplayColor = "#FFFF0000";
225
                }
226
                else
227
                {
228
                    info.userDelete = false;
229
                }
230
            }
231
        }
232

    
233
        private void BaseClient_GetDeptDataCompleted(object sender, GetDeptDataCompletedEventArgs e)
234
        {
235
            if (e.Error == null)
236
            {
237
                //Logger.sendResLog("GetDeptDataCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.Count + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
238
            }
239
            else
240
            {
241
                //Logger.sendResLog("GetDeptDataCompleted",  "\r Error :" + e.Error, 1);
242
            }
243

    
244
            if (e.Result != null)
245
            {
246
                e.Result.Sort();
247
                //cbSymbolPublic.ItemsSource = e.Result.ToList();
248
            }
249
        }
250

    
251
        /// <summary>
252
        /// ???
253
        /// </summary>
254
        public MarkupInfoItem PreviewUserMarkupInfoItem { get; set; }
255

    
256
        /// <summary>
257
        /// 문서 정보를 가져온다
258
        /// </summary>
259
        /// <param name="sender"></param>
260
        /// <param name="e"></param>
261
        private async void BaseClient_GetDocInfoCompleted(object sender, GetDocInfoCompletedEventArgs e)
262
        {
263
            ////Logger.sendResLog("GetDocInfoCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
264

    
265
            if (e.Error != null)
266
            {
267
                DialogMessage_Alert("The page cannot be displayed.", "Alert");
268
            }
269
            else if (e.Result == null)
270
            {
271
                DialogMessage_Alert("Document information is missing.", "Alert");
272
            }
273
            else
274
            {
275
                string sFolder = _ViewInfo.DocumentItemID.All(char.IsDigit) ? (Convert.ToUInt64(_ViewInfo.DocumentItemID) / 100).ToString() : (_ViewInfo.DocumentItemID.Length >= 5 ? _ViewInfo.DocumentItemID.Substring(0, 5) : _ViewInfo.DocumentItemID);
276

    
277
                /// 화면의 좌측 Thumbnail의 주소
278
                var MainUrl = string.Format(CommonLib.Common.GetConfigString("mainServerImageWebPath", "URL", "", App.isExternal).Replace("png", "jpg"), _ViewInfo.ProjectNO, sFolder, _ViewInfo.DocumentItemID, "{PageNo}");
279
                _DocInfo = e.Result;
280
                _DocInfo.ORIGINAL_FILE = HttpUtility.UrlDecode(_DocInfo.ORIGINAL_FILE);
281
                foreach (var item in _DocInfo.DOCPAGE.OrderBy(order => order.PAGE_NUMBER))
282
                {
283
                    ViewerDataModel.Instance.Document_Info.Add(item);
284
                }
285
                //Logger.sendReqLog("GetMarkupInfoItemsAsync", _ViewInfo.ProjectNO + "," + _DocInfo.ID, 1);
286
                CurrentDoc = new Common.DocumentSet
287
                {
288
                    docInfo = _DocInfo,
289
                    Document_Id = _DocInfo.DOCUMENT_ID,
290
                    File_Original = _DocInfo.ORIGINAL_FILE,
291

    
292
                    Document_NO = _DocItem?.DOCUMENT_NO,
293
                    File_Result = _DocItem?.RESULT_FILE,
294
                    Group_No = _DocItem?.GROUP_NO,
295
                    ProjectNo = _DocItem?.PROJECT_NO,
296
                    Revision = _DocItem?.REVISION,
297
                };
298

    
299
                var instanceMain = this.ParentOfType<MainWindow>();
300
                string firstpage = "1";
301
                string lastpage = _DocInfo.PAGE_COUNT.ToString();
302
                instanceMain.dzTopMenu.tlcurrentPage.Text = firstpage;
303
                instanceMain.dzTopMenu.tlcurrentPage_readonly.Text = lastpage;
304
                App.MarkusVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
305

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

    
308
                instanceMain.Title = apptitle;
309

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

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

    
315
                #endregion
316

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

    
319
                //App.SamplePageStorage = new PageManager.PageStorage(MainUrl.Replace("png", "jpg"), tempStoragePath, "jpg", _DocInfo.PAGE_COUNT);
320
                await this.pageNavigator.SetPageNaviAsync(CurrentDoc.docInfo.DOCPAGE.ToList(), MainUrl);
321
            }
322
        }
323

    
324
        private void pageNavigator_ThumbInitialized(object sender,EventArgs e)
325
        {
326
            BaseClient.GetMarkupInfoItemsAsync(_ViewInfo.ProjectNO, _DocInfo.ID);
327

    
328
            ViewerDataModel.Instance.MarkupControls_USER.Clear();
329
            //ViewerDataModel.Instance.SystemMain.dzMainMenu.TempLoad();
330

    
331
            /// 기존 임시파일 정리
332
            #region 단어 검색용 파일 다운로드
333

    
334
            DownloadOriginalFile();
335

    
336
            #endregion
337

    
338
            //Logger.sendReqLog("GetVPRevisionHistoryAsync", CurrentDoc.ProjectNo + "," + CurrentDoc.Document_NO + "," + CurrentDoc.Document_Id, 1);
339
            BaseClient.GetVPRevisionHistoryAsync(CurrentDoc.ProjectNo, CurrentDoc.Document_NO, CurrentDoc.Document_Id);
340

    
341
        }
342

    
343

    
344
        /// <summary>
345
        /// get markupinfo and markupitem from database
346
        ///  - 1. called when document is loaded
347
        ///  - 2. called when user do consolidation
348
        /// </summary>
349
        /// <param name="sender"></param>
350
        /// <param name="e"></param>
351
        private void BaseClient_GetMarkupInfoItemsCompleted(object sender, GetMarkupInfoItemsCompletedEventArgs e)
352
        {
353
            //Logger.sendResLog("GetMarkupInfoItemsCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.Count + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
354

    
355
            ViewerDataModel.Instance.MarkupControls_USER.Clear();
356
            ViewerDataModel.Instance.MarkupControls.Clear();
357

    
358
            try
359
            {
360

    
361
                if (e.Result != null)
362
                {
363
                    ViewerDataModel.Instance._markupInfoList.Clear();
364
                    if (e.Result.Any()) ViewerDataModel.Instance.MyMarkupList.Clear();
365

    
366
                    foreach (var info in e.Result)
367
                    {
368
                        if (info.Depatment == null) info.Depatment = "Unknown";
369

    
370
                        else if (info.UserID == App.ViewInfo.UserID)
371
                        {
372
                            if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission) //조회모드는 delete 버튼 모두 비활성화
373
                            {
374
                                info.userDelete = false;
375
                            }
376
                            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가 있을 경우
377
                            {
378
                                if(App.ViewInfo.NewCommentPermission && e.Result.Where(x => x.UserID == App.ViewInfo.UserID && x.PartConsolidate == 1 && x.MarkupInfoID == info.MarkupInfoID).Count() > 0)                                
379
                                    info.userDelete = true;                                
380
                            }
381
                            else if(App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission) //Consolidation Mode 일 때는 해당 Comment Layer의 Status가 Avoid or Consolidation인 것만 Delete 버튼 활성화
382
                            {
383
                                if(info.AvoidConsolidate == 1 || info.Consolidate == 1)
384
                                    info.userDelete = true;
385
                            }
386
                            else
387
                            {
388
                                info.userDelete = true;
389
                            }                               
390
                            info.DisplayColor = "#FFFF0000";
391
                        }
392
                        else
393
                        {
394
                            info.userDelete = false;
395
                        }
396

    
397
                        ViewerDataModel.Instance._markupInfoList.Add(info);
398
                    }
399

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

    
402
                    userInfoList.ToList().ForEach(x =>
403
                    {
404
                        ViewerDataModel.Instance._markupUserList.Add(x);
405

    
406
                        if (MarkupToPDF.MarkupContext.GetUserSignItem(x.UserId) == null)
407
                        {
408
                            string signData = BaseClient.GetSignData(App.ViewInfo.ProjectNO, x.UserId);
409
                            string signStrokes = BaseClient.GetSignStrokes(App.ViewInfo.ProjectNO, x.UserId);
410

    
411
                            if (signData != null && signStrokes != null)
412
                            {
413
                                MarkupToPDF.MarkupContext.SetUserSignItem(x.UserId, signData, signStrokes);
414
                            }
415
                        }
416
                    });
417

    
418
                    e.Result.ToList().ForEach(d =>
419
                    {
420
                        if (d.MarkupList != null)
421
                        {
422
                            d.MarkupList.ForEach(p =>
423
                            {
424
                                if (d.UserID == App.ViewInfo.UserID)
425
                                {
426
                                    if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission) //조회모드는 delete 버튼 모두 비활성화
427
                                    {
428
                                        d.userDelete = false;
429
                                    }
430
                                    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가 있을 경우
431
                                    {
432
                                        if (App.ViewInfo.NewCommentPermission && e.Result.Exists(x => x.UserID == App.ViewInfo.UserID && x.PartConsolidate == 1 && x.MarkupInfoID == d.MarkupInfoID))
433
                                            d.userDelete = true;
434
                                    }
435
                                    else if (App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission) //Consolidation Mode 일 때는 해당 Comment Layer의 Status가 Avoid or Consolidation인 것만 Delete 버튼 활성화
436
                                    {
437
                                        if (d.AvoidConsolidate == 1 || d.Consolidate == 1)
438
                                            d.userDelete = true;
439
                                    }
440
                                    else
441
                                    {
442
                                        d.userDelete = true;
443
                                    }
444
                                    d.DisplayColor = "#FFFF0000";
445
                                    MarkupItemEx markup = new MarkupItemEx
446
                                    {
447
                                        Data = p.Data,
448
                                        Data_Type = p.Data_Type,
449
                                        ID = p.ID,
450
                                        IsUpdate = false,
451
                                        MarkupInfoID = d.MarkupInfoID,
452
                                        PageNumber = p.PageNumber,
453
                                        Symbol_ID = p.Symbol_ID,
454
                                        //Group_ID = p.Group_ID
455
                                    };
456
                                    ViewerDataModel.Instance.MyMarkupList.Add(markup);
457
                                }
458
                                else
459
                                {
460
                                    MarkupItemEx markup = new MarkupItemEx
461
                                    {
462
                                        Data = p.Data,
463
                                        Data_Type = p.Data_Type,
464
                                        ID = p.ID,
465
                                        IsUpdate = false,
466
                                        MarkupInfoID = d.MarkupInfoID,
467
                                        PageNumber = p.PageNumber,
468
                                        Symbol_ID = p.Symbol_ID,
469
                                        //Group_ID = p.Group_ID
470
                                    };
471
                                    ViewerDataModel.Instance.MarkupList_Pre.Add(markup);
472
                                }
473
                            });
474
                        }
475
                    });
476

    
477
                    var currentUser = e.Result.Find(data => data.UserID == App.ViewInfo.UserID && data.AvoidConsolidate == 0);
478
                    if (currentUser == null)
479
                    {
480
                        /// create a new markupinfo to do comments
481
                        if (App.ViewInfo.NewCommentPermission)
482
                        {
483
                            var infoId = Commons.ShortGuid();
484
                            PreviewUserMarkupInfoItem = new MarkupInfoItem
485
                            {
486
                                CreateTime = DateTime.Now,
487
                                UpdateTime = DateTime.Now,
488
                                Depatment = userData.DEPARTMENT,
489
                                DisplayColor = "#FFFF0000",
490
                                UserID = userData.ID,
491
                                UserName = userData.NAME,
492
                                PageCount = 1,
493
                                Description = "",
494
                                MarkupInfoID = infoId,
495
                                MarkupList = null,
496
                                MarkupVersionID = Commons.ShortGuid(),
497
                                Consolidate = 0,
498
                                PartConsolidate = 0,
499
                                userDelete = true,
500
                                AvoidConsolidate = 0,
501
                                IsPreviewUser = false
502
                            };
503

    
504
                            App.Custom_ViewInfoId = infoId;
505

    
506
                            ViewerDataModel.Instance._markupInfoList.Insert(0, PreviewUserMarkupInfoItem);
507
                        }
508
                    }
509
                    else
510
                    {
511
                        App.Custom_ViewInfoId = currentUser.MarkupInfoID;
512
                    }
513

    
514
                    ViewerDataModel.Instance.SyncPageNumber = 1;
515

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

    
519
                    gridViewMarkup.ItemsSource = ViewerDataModel.Instance._markupInfoList;
520

    
521
                    SetCommentPages(null);
522

    
523
                    // GRIDVIEW에서 팀별 GROUPING
524
                    // 효성은 안함
525
#if (Hyosung)
526
#else
527
                    /// create a group descriptor
528
                    gridViewMarkup.GroupDescriptors.Clear();
529
                    GroupDescriptor descriptor = new GroupDescriptor();
530
                    descriptor.Member = "Depatment";
531
                    descriptor.DisplayContent = "DEPT";
532
                    //descriptor.SortDirection = ListSortDirection.Ascending;
533
                    gridViewMarkup.GroupDescriptors.Add(descriptor);
534
#endif
535

    
536
                    GridViewMarkup_Sorting(gridViewMarkup, new GridViewSortingEventArgs(gridViewMarkup.Columns[0], SortingState.None, SortingState.None));
537

    
538
                    SelectInitialMarkupInfo();
539
                }
540
            }
541
            catch (Exception ex) 
542
            {
543
                App.FileLogger.Fatal(ex);
544
            }
545
            finally
546
            {
547
                if(!ViewerDataModel.Instance.SystemMain.dzMainMenu.btnFinalPDF.IsEnabled)
548
                {
549
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.btnFinalPDF.IsEnabled = true;
550
                }
551

    
552
                if (!ViewerDataModel.Instance.SystemMain.dzMainMenu.btnConsolidate.IsEnabled)
553
                {
554
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.btnConsolidate.IsEnabled = true;
555
                }
556
            }
557
        }
558

    
559
        /// <summary>
560
        /// 프로그램이 로딩되고 난 후 맨처음으로 MarkupInfo를 선택한다. 
561
        /// </summary>
562
        private void SelectInitialMarkupInfo()
563
        {
564
            if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission)
565
            {
566
                #region Consolidate 항목이 있으면 Consolidate 항목만 추가
567
                if (ViewerDataModel.Instance._markupInfoList.Any(x => x.Consolidate == 1 && x.AvoidConsolidate == 0))
568
                {
569
                    var Consolidates = ViewerDataModel.Instance._markupInfoList.Where(x => x.Consolidate == 1 && x.AvoidConsolidate == 0).ToList();
570
                    Consolidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
571
                }
572
                #endregion
573
                #region Consolidate 항목이 없을 경우에는 사용자 별로 AvoidConsolidate를 제외한 우선 순위가 높은(Team,Comment)항목들을 선택
574
                else
575
                {
576
                    var MarkupInfoColl = ViewerDataModel.Instance._markupInfoList.Where(x => x.AvoidConsolidate == 0).ToList();
577

    
578
                    #region Team consolidate 항목 선택
579
                    var Candidates = MarkupInfoColl.Where(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0).ToList();
580
                    MarkupInfoColl.RemoveAll(x => Candidates.Exists(y => y.UserID == x.UserID));
581
                    #endregion
582

    
583
                    #region 추가되지 않은 사용자들을 추가
584
                    foreach (var item in MarkupInfoColl.Where(x => !Candidates.Exists(y => y.UserID == x.UserID)))
585
                    {
586
                        Candidates.Add(item);
587
                    }
588
                    #endregion
589

    
590
                    Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
591
                }
592
                #endregion
593
            }
594
            else if (!App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission)   /// Eng'r Comment Mode
595
            {
596
                var MarkupInfoColl = ViewerDataModel.Instance._markupInfoList.Where(x => x.AvoidConsolidate == 0).ToList();
597

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

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

    
610
                Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
611
            }
612
            else if (App.ViewInfo.CreateFinalPDFPermission)    /// Orig Comment Model
613
            {
614
                if (ViewerDataModel.Instance._markupInfoList.Any(x => x.Consolidate == 1 && x.AvoidConsolidate == 0))
615
                {
616
                    var Consolidates = ViewerDataModel.Instance._markupInfoList.Where(x => x.Consolidate == 1 && x.AvoidConsolidate == 0).ToList();
617
                    Consolidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
618
                }
619
                else if (ViewerDataModel.Instance._markupInfoList.Any(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0))
620
                {
621
                    var MarkupInfoColl = ViewerDataModel.Instance._markupInfoList.Where(x => x.AvoidConsolidate == 0).ToList();
622

    
623
                    #region Team consolidate 항목 선택
624
                    var Candidates = MarkupInfoColl.Where(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0).ToList();
625
                    MarkupInfoColl.RemoveAll(x => Candidates.Exists(y => y.UserID == x.UserID));
626
                    #endregion
627

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

    
635
                    Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
636
                }
637
                else
638
                {
639
                    var Comments = ViewerDataModel.Instance._markupInfoList.Where(x => x.Consolidate == 0 && x.AvoidConsolidate == 0).ToList();
640
                    Comments.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
641
                }
642
            }
643

    
644
            if (!gridViewMarkup.SelectedItems.Any())
645
            {
646
                var SelectedItem = ViewerDataModel.Instance._markupInfoList.Where(info => info.UserID == App.ViewInfo.UserID).OrderByDescending(order => order.UpdateTime).FirstOrDefault();
647

    
648
                if (PreviewUserMarkupInfoItem != null)
649
                {
650
                    this.gridViewMarkup.SelectedItem = PreviewUserMarkupInfoItem;
651
                }
652
                else if (SelectedItem != null)
653
                {
654
                    this.gridViewMarkup.SelectedItem = SelectedItem;
655
                }
656
                else if (ViewerDataModel.Instance._markupInfoList.Any())
657
                {
658
                    this.gridViewMarkup.SelectedItem = ViewerDataModel.Instance._markupInfoList[0];
659
                }
660
            }
661
        }
662

    
663
        private void GridViewMarkup_Sorting(object sender, GridViewSortingEventArgs e)
664
        {
665
            IEnumerable<IKCOM.MarkupInfoItem> markuplist = e.DataControl.ItemsSource as IEnumerable<IKCOM.MarkupInfoItem>;
666

    
667
            if(markuplist == null)
668
            {
669
                e.Cancel = true;
670
                return;
671
            }
672

    
673
            if(e.NewSortingState == SortingState.None)
674
            {
675
                markuplist = markuplist.OrderByDescending(x => SortIndex(x))
676
                                            .ThenBy(x => x.Depatment)
677
                                            .ThenBy(x => x.UserID);
678

    
679
                e.DataControl.ItemsSource = markuplist.ToList();
680
            }
681
        }
682

    
683

    
684
        // 마크업 리스트 정렬
685
        private int SortIndex(IKCOM.MarkupInfoItem markupInfoItem)
686
        {
687
            int result = 0;
688

    
689
            // Consolidate은 최상단
690
            if (markupInfoItem.Consolidate == 1)
691
            {
692
                result += 2;
693
            }
694

    
695
            /// Consolidate 다음으로 우선순위
696
            if (markupInfoItem.UserID == App.ViewInfo.UserID)
697
            {
698
                result += 1;
699
            }
700

    
701
            return result;
702
        }
703

    
704

    
705
        private void GridViewMarkup_Sorted(object sender, GridViewSortedEventArgs e)
706
        {
707

    
708
        }
709

    
710
        private async void gridViewRevMarkup_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
711
        {
712
            List<MarkupInfoItem> gridSelectionItem = gridViewRevMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
713
            //if (ViewerDataModel.Instance.PageBalanceNumber == 0)
714
            //{
715
            //    ViewerDataModel.Instance.PageBalanceNumber = 1;
716
            //}
717

    
718
            if (ViewerDataModel.Instance.SyncPageNumber == 0)
719
            {
720
                ViewerDataModel.Instance.SyncPageNumber = 1;
721
            }
722
            if (e.AddedItems.Any())
723
            {
724
                foreach (var item in gridSelectionItem)
725
                {
726
                    //item.MarkupList.Where(pageItem => pageItem.PageNumber == ViewerDataModel.Instance.PageBalanceNumber).ToList().ForEach(delegate (MarkupItem markupitem)
727
                    //{
728
                    //    layerControl.markupParse(markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_Sync, item.DisplayColor, "", item.MarkupInfoID);
729
                    //});
730

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

    
733
                    foreach (var markupitem in pageItems)
734
                    {
735
                       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,
736
                           STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
737
                    }
738
                }
739
            }
740
            else if (e.RemovedItems.Any())
741
            {
742
                var _infoItem = e.RemovedItems.Cast<MarkupInfoItem>().ToList();
743

    
744
                (from A in _infoItem
745
                 from B in Common.ViewerDataModel.Instance.MarkupControls_Sync
746
                 where A.MarkupInfoID == B.MarkupInfoID
747
                 select B).ToList().ForEach(data =>
748
                 {
749
                     Common.ViewerDataModel.Instance.MarkupControls_Sync.Remove(data);
750
                 });
751
            }
752
        }
753

    
754
        /// <summary>
755
        /// 선택한 항목은 Visibility = Visible, 해제한 항목은 Visibility = Hidden 처리한다.
756
        /// </summary>
757
        /// <param name="sender"></param>
758
        /// <param name="e"></param>
759
        private async void gridViewMarkup_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
760
        {
761

    
762
            foreach (var item in e.AddedItems)
763
            {
764
                var cellToSelect = new GridViewCellInfo(item, this.gridViewMarkup.Columns["color"], this.gridViewMarkup);
765

    
766
                if(cellToSelect != null)
767
                {
768

    
769
                }
770
            }
771

    
772
            SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
773

    
774
            var dataSet = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
775
            var dataSet_User = gridViewMarkup.Items.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
776
            var resultA = (from item_Select in dataSet
777
                           from item_Non in dataSet_User
778
                           where item_Select == item_Non
779
                           select item_Non).ToList();
780

    
781
            if (resultA.Count() >= 2)
782
            {
783
                // 동일한 사용자 데이터가 두개 이상 선택됩니다. Consolidation을 선택할까요?
784
                RadWindow.Confirm(new DialogParameters
785
                {
786
                    Owner = Application.Current.MainWindow,
787
                    Header = "Info",
788
                    Content = "Selected more than two identical user data. Do you want to select consolidation?",
789
                    Closed = new EventHandler<WindowClosedEventArgs>((sen, ea) =>
790
                    {
791
                        if(ea.DialogResult == null)
792
                        {
793
                            return;
794
                        }
795
                        if (e.AddedItems.Count() == 1)
796
                        {
797
                            MarkupInfoItem instanceItem = e.AddedItems.FirstOrDefault() as MarkupInfoItem;
798
                            gridViewMarkup.SelectedItem = null;
799

    
800
                        
801
                            if (ea.DialogResult.Value)
802
                            {
803
                                if (instanceItem.Consolidate == 1 || instanceItem.PartConsolidate == 1)
804
                                {
805
                                    gridViewMarkup.SelectedItem = instanceItem;
806
                                }
807
                                else
808
                                {
809
                                    //1. Consolidations이 있다면 하나 선택
810
                                    var Consolidations = resultA.Where(item => (item.Consolidate == 1 || item.PartConsolidate == 1));
811

    
812
                                    if (Consolidations.Count() > 0)
813
                                    {
814
                                        gridViewMarkup.SelectedItem = Consolidations.First();
815
                                    }
816
                                }
817
                              
818
                            }
819
                            else {
820
                                //1. Consolidations 아닌게 있다면 Change
821
                                var notConsolidations = resultA.Where(item => !(item.Consolidate == 1 || item.PartConsolidate == 1));
822

    
823
                                if(notConsolidations.Count() > 0) {
824
                                    gridViewMarkup.SelectedItem = notConsolidations.First();
825
                                }
826
                                else {//1. Consolidations 아닌게 없다면 그대로
827
                                    gridViewMarkup.SelectedItem = instanceItem;
828
                                }
829
                                
830
                            }
831
                        }
832
                    }),
833
                    Theme = new Windows8Theme(),
834
                    ModalBackground = new System.Windows.Media.SolidColorBrush { Color = System.Windows.Media.Colors.Black, Opacity = 0.6 },
835
                });
836
            }
837
            else //파라미터로 넘어온 사용자가 걸리지 않은 경우
838
            {
839
                List<MarkupInfoItem> gridItem = gridViewMarkup.Items.Cast<MarkupInfoItem>().ToList(); //전체 마크업
840
                List<MarkupInfoItem> gridSelectionItem = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
841
                List<MarkupInfoItem> gridNonSelectionItem = gridItem.Except(gridSelectionItem).ToList(); //선택 되지 않은 마크업
842
#region 코멘트 보기
843
                if (e.AddedItems.Count() > 0 && this.pageNavigator.CurrentPage != null)
844
                {
845
                    foreach (var item in gridSelectionItem)
846
                    {
847
                        if (item.UserID == App.ViewInfo.UserID)
848
                        {
849
                            var controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
850
                            if (controls.Count == 0)
851
                            {
852
                                var instance = ViewerDataModel.Instance.MyMarkupList.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
853

    
854
                                foreach (var markup in instance)
855
                                {
856
                                    await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "", 
857
                                        item.MarkupInfoID, markup.ID, STAMP_Contents:App.SystemInfo.STAMP_CONTENTS);
858
                                }
859
                            }
860

    
861
                            controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
862
                            foreach (var control in controls)
863
                            {
864
                                Logger.sendCheckLog(String.Format("=={0}", control), 1);
865
                                control.Visibility = Visibility.Visible;
866
                            }
867
                        }
868
                        else
869
                        {
870
                            var controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
871
                            if (controls.Count == 0)
872
                            {
873
                                var instance = ViewerDataModel.Instance.MarkupList_Pre.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
874
                                foreach (var markup in instance)
875
                                {
876
                                    await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "",
877
                                        item.MarkupInfoID, markup.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
878
                                }
879
                            }
880

    
881
                            controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
882
                            foreach (var control in controls)
883
                            {
884
                                control.Visibility = Visibility.Visible;
885
                            }
886
                        }
887
                    }
888
                }
889
#endregion
890
#region 코멘트 숨기기
891
                else if (e.RemovedItems.Count > 0)
892
                {
893
                    var _infoItem = e.RemovedItems.Cast<MarkupInfoItem>().ToList();
894

    
895
                    (from A in _infoItem
896
                     from B in Common.ViewerDataModel.Instance.MarkupControls
897
                     where A.MarkupInfoID == B.MarkupInfoID
898
                     select B).ToList().ForEach(data =>
899
                     {
900
                         data.Visibility = Visibility.Hidden;                         
901
                     });
902

    
903

    
904
                    var myComment = _infoItem.Where(d => d.UserID == App.ViewInfo.UserID).FirstOrDefault();
905
                    if (myComment != null)
906
                    {
907
                        Common.ViewerDataModel.Instance.MarkupControls_USER.ToList().ForEach(delegate (MarkupToPDF.Common.CommentUserInfo markupitem)
908
                        {
909
                            markupitem.Visibility = Visibility.Hidden;
910
                        });
911
                    }
912
                }
913
#endregion
914
            }
915
        }
916

    
917
        private async void gridViewMarkup_SelectedCellsChanged(object sender, Telerik.Windows.Controls.GridView.GridViewSelectedCellsChangedEventArgs e)
918
        {
919
            if (e.AddedCells.Count() > 0)
920
            {
921
                if(e.AddedCells[0].Column.Name == "color")
922
                {
923

    
924
                }
925
                else
926
                {
927
                    List<MarkupInfoItem> removeItems = new List<MarkupInfoItem>();
928

    
929
                    if (!gridViewMarkup.SelectedItems.Contains(e.AddedCells[0].Item))
930
                    {
931
                        gridViewMarkup.SelectedItems.Add(e.AddedCells[0].Item);
932
                    }
933
                    else
934
                    {
935
                        gridViewMarkup.Unselect(new[] { e.AddedCells[0].Item });
936

    
937
                        removeItems.Add(e.AddedCells[0].Item as MarkupInfoItem);
938
                    }
939

    
940
                    SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
941

    
942
                    var dataSet = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
943
                    var dataSet_User = gridViewMarkup.Items.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
944
                    var resultA = (from item_Select in dataSet
945
                                   from item_Non in dataSet_User
946
                                   where item_Select == item_Non
947
                                   select item_Non).ToList();
948

    
949
                    if (resultA.Count() >= 2)
950
                    {
951
                        // 동일한 사용자 데이터가 두개 이상 선택됩니다. Consolidation을 선택할까요?
952
                        RadWindow.Confirm(new DialogParameters
953
                        {
954
                            Owner = Application.Current.MainWindow,
955
                            Header = "Info",
956
                            Content = "Selected more than two identical user data. Do you want to select consolidation?",
957
                            Closed = new EventHandler<WindowClosedEventArgs>((sen, ea) =>
958
                            {
959
                                if (ea.DialogResult == null)
960
                                {
961
                                    return;
962
                                }
963
                                if (gridViewMarkup.SelectedItems.Count() == 1)
964
                                {
965
                                    MarkupInfoItem instanceItem = gridViewMarkup.SelectedItems.FirstOrDefault() as MarkupInfoItem;
966
                                    gridViewMarkup.SelectedItem = null;
967

    
968

    
969
                                    if (ea.DialogResult.Value)
970
                                    {
971
                                        if (instanceItem.Consolidate == 1 || instanceItem.PartConsolidate == 1)
972
                                        {
973
                                            gridViewMarkup.SelectedItem = instanceItem;
974
                                        }
975
                                        else
976
                                        {
977
                                            //1. Consolidations이 있다면 하나 선택
978
                                            var Consolidations = resultA.Where(item => (item.Consolidate == 1 || item.PartConsolidate == 1));
979

    
980
                                            if (Consolidations.Count() > 0)
981
                                            {
982
                                                gridViewMarkup.SelectedItem = Consolidations.First();
983
                                            }
984
                                        }
985

    
986
                                    }
987
                                    else
988
                                    {
989
                                        //1. Consolidations 아닌게 있다면 Change
990
                                        var notConsolidations = resultA.Where(item => !(item.Consolidate == 1 || item.PartConsolidate == 1));
991

    
992
                                        if (notConsolidations.Count() > 0)
993
                                        {
994
                                            gridViewMarkup.SelectedItem = notConsolidations.First();
995
                                        }
996
                                        else
997
                                        {//1. Consolidations 아닌게 없다면 그대로
998
                                            gridViewMarkup.SelectedItem = instanceItem;
999
                                        }
1000

    
1001
                                    }
1002
                                }
1003
                            }),
1004
                            Theme = new Windows8Theme(),
1005
                            ModalBackground = new System.Windows.Media.SolidColorBrush { Color = System.Windows.Media.Colors.Black, Opacity = 0.6 },
1006
                        });
1007
                    }
1008
                    else //파라미터로 넘어온 사용자가 걸리지 않은 경우
1009
                    {
1010
                        List<MarkupInfoItem> gridItem = gridViewMarkup.Items.Cast<MarkupInfoItem>().ToList(); //전체 마크업
1011
                        List<MarkupInfoItem> gridSelectionItem = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
1012
                        List<MarkupInfoItem> gridNonSelectionItem = gridItem.Except(gridSelectionItem).ToList(); //선택 되지 않은 마크업
1013
                        #region 코멘트 보기
1014
                        if (gridViewMarkup.SelectedItems.Count() > 0 && this.pageNavigator.CurrentPage != null)
1015
                        {
1016
                            foreach (var item in gridSelectionItem)
1017
                            {
1018
                                if (item.UserID == App.ViewInfo.UserID)
1019
                                {
1020
                                    var controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1021
                                    if (controls.Count == 0)
1022
                                    {
1023
                                        var instance = ViewerDataModel.Instance.MyMarkupList.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
1024

    
1025
                                        foreach (var markup in instance)
1026
                                        {
1027
                                            await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "",
1028
                                                item.MarkupInfoID, markup.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1029
                                        }
1030
                                    }
1031

    
1032
                                    controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1033
                                    foreach (var control in controls)
1034
                                    {
1035
                                        Logger.sendCheckLog(String.Format("=={0}", control), 1);
1036
                                        control.Visibility = Visibility.Visible;
1037
                                    }
1038
                                }
1039
                                else
1040
                                {
1041
                                    var controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1042
                                    if (controls.Count == 0)
1043
                                    {
1044
                                        var instance = ViewerDataModel.Instance.MarkupList_Pre.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
1045
                                        foreach (var markup in instance)
1046
                                        {
1047
                                            await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "",
1048
                                                item.MarkupInfoID, markup.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1049
                                        }
1050
                                    }
1051

    
1052
                                    controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1053
                                    foreach (var control in controls)
1054
                                    {
1055
                                        control.Visibility = Visibility.Visible;
1056
                                    }
1057
                                }
1058
                            }
1059
                        }
1060
                        #endregion
1061
                        #region 코멘트 숨기기
1062
                        else if (removeItems.Count > 0)
1063
                        {
1064
                            (from A in removeItems
1065
                             from B in Common.ViewerDataModel.Instance.MarkupControls
1066
                             where A.MarkupInfoID == B.MarkupInfoID
1067
                             select B).ToList().ForEach(data =>
1068
                             {
1069
                                 data.Visibility = Visibility.Hidden;
1070
                             });
1071

    
1072

    
1073
                            var myComment = removeItems.Where(d => d.UserID == App.ViewInfo.UserID).FirstOrDefault();
1074
                            if (myComment != null)
1075
                            {
1076
                                Common.ViewerDataModel.Instance.MarkupControls_USER.ToList().ForEach(delegate (MarkupToPDF.Common.CommentUserInfo markupitem)
1077
                                {
1078
                                    markupitem.Visibility = Visibility.Hidden;
1079
                                });
1080
                            }
1081
                        }
1082
                        #endregion
1083
                    }
1084
                }
1085
            }
1086
        }
1087

    
1088
        private void BaseClient_GetDocumentItemInfoCompleted(object sender, GetDocumentItemInfoCompletedEventArgs e)
1089
        {
1090
            //Logger.sendResLog("GetDocumentItemInfoCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.DOCUMENT_ID + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
1091

    
1092
            if (e.Result != null)
1093
            {
1094
                _DocItem = e.Result;
1095

    
1096
                if (e.Result.DOCUMENT_NO == "" && e.Result.DOCUMENT_NAME == "" && e.Result.GROUP_NO == "0")
1097
                {
1098
                    _ViewInfo.UserID = _ViewInfo.UserID.Replace(@"DAELIM\", "");
1099
                }
1100
                ////Logger.sendReqLog("GetDocInfoAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
1101
                BaseClient.GetDocInfoAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
1102
            }
1103
            else
1104
            {
1105
                DialogMessage_Alert("Document Information Not Found.", "Error");
1106

    
1107
                BaseClient.GetCheckSystemAdminCompleted += (sen, ea) =>
1108
                {
1109
                    //Logger.sendResLog("GetCheckSystemAdminCompleted", "UserState : " + ea.UserState + "\r Result :" + ea.Result + "\r Cancelled :" + ea.Cancelled + "\r Error :" + ea.Error, 1);
1110

    
1111
                    if (ea.Error == null)
1112
                    {
1113
                        if (ea.Result)
1114
                        {
1115
                            this._ViewInfo.isAdmin = true;
1116
                            //Logger.sendReqLog("GetDocInfoAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
1117
                            BaseClient.GetDocInfoAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
1118
                        }
1119
                        else
1120
                        {
1121
                            //System.Windows.Forms.MessageBox.Show("해당 프로젝트에 가입되지 않은 유저입니다. 관리자에게 등록신청을 해주세요", "안내");
1122
                            DialogMessage_Alert("You are not belong to this project. Please ask admin for an authority.", "Info");
1123
                            //this.ParentOfType<MainPage>().DialogMessage_Alert("해당 프로젝트에 가입되지 않은 유저입니다. 관리자에게 등록신청을 해주세요", "안내");
1124
                        }
1125

    
1126
                    }
1127
                    else
1128
                    {
1129
                        //System.Windows.Browser.HtmlPage.Window.Invoke("close");
1130
                    }
1131
                };
1132
                //Logger.sendReqLog("GetCheckSystemAdminAsync", _ViewInfo.UserID, 1);
1133
                BaseClient.GetCheckSystemAdminAsync(this._ViewInfo.UserID);
1134
            }
1135
        }
1136

    
1137
        private void BaseClient_GetSystemDataCompleted(object sender, GetSystemDataCompletedEventArgs e)
1138
        {
1139
            //Logger.sendResLog("GetSystemDataCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
1140

    
1141
            if (e.Error == null && e.Result != null)
1142
            {
1143
                App.SystemInfo = e.Result;
1144

    
1145
                //App.urlPort_DB = App.SystemInfo.HostPort;
1146
                //App.urlHost_DB = App.SystemInfo.HostName;
1147
                //Logger.sendReqLog("GetConversionStateAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
1148
                BaseClient.GetConversionStateAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
1149

    
1150
                //if (App.urlHost.Contains("localhost"))
1151
                //{
1152
                //    App.urlHost = App.urlHost_DB;
1153
                //}
1154
            }
1155
        }
1156

    
1157
        private void BaseClient_GetConversionStateCompleted(object sender, GetConversionStateCompletedEventArgs e)
1158
        {
1159
            if (e.Error == null && e.Result)
1160
            {
1161
                BaseClient.GetDocumentItemInfoAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID, userID = _ViewInfo.UserID });
1162

    
1163
                if (App.ViewInfo != null && App.ViewInfo.ProjectNO != "")
1164
                {
1165
                    userData = BaseClient.GetMember(App.ViewInfo.ProjectNO, App.ViewInfo.UserID);
1166
                    if (userData != null)
1167
                    {
1168
                        BaseClient.GetDeptDataAsync(userData.DEPARTMENT);
1169
                    }
1170
                    else
1171
                    {
1172
                        userData = new MEMBER();
1173
                        userData.DEPARTMENT = "ALL";
1174
                        BaseClient.GetDeptDataAsync(userData.DEPARTMENT);
1175
                    }
1176
                }
1177
            }
1178
            else
1179
            {
1180
                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잠시만 기다려 주신 후 다시 열람하여 주시기 바랍니다");
1181
                DialogMessage_Alert(failedmsg, "Warning");
1182
            }
1183
        }
1184

    
1185
        public void SetView(ViewInfo info)
1186
        { 
1187
            this._ViewInfo = info;
1188
            try
1189
            {
1190
                /// 대림의 경우 EnsembleID를 가지고 DocumentItemID를 구함
1191
                /// 다른 Site를 대비하여 에러 처리함
1192
                string docid = BaseClient.GetDocItemID(info.EnsembleID);
1193
                if (!string.IsNullOrEmpty(docid))
1194
                {
1195
                    this._ViewInfo.DocumentItemID = docid;
1196
                }
1197
            }
1198
            catch (Exception ex)
1199
            {
1200

    
1201
                //App.FileLogger.Fatal(ex);
1202
            }
1203

    
1204
            //Logger.sendReqLog("GetSystemDataAsync", "", 1);
1205

    
1206
            BaseClient.GetSystemDataAsync();
1207
        }
1208

    
1209
        public void HubSet()
1210
        {
1211
            // 허브 연결 구성
1212
            var hubConnection = new HubConnection(CommonLib.Common.GetConfigString("HubAddress", "URL", "", App.isExternal));
1213
            IHubProxy MarkusLicenseProxy = hubConnection.CreateHubProxy("MarkusLicenseHub");
1214

    
1215

    
1216
            // 허브 연결 
1217
            hubConnection.Start().ContinueWith(task =>
1218
            {
1219
                if (task.IsFaulted)
1220
                {
1221
                    Console.WriteLine("There was an error opening the connection:{0}",
1222
                                      task.Exception.GetBaseException());
1223
                    //throw task.Exception.GetBaseException();
1224
                }
1225
                else
1226
                {
1227
                    Console.WriteLine("Connected :: " + task.Id);
1228
                }
1229

    
1230
            }).Wait();
1231

    
1232

    
1233
            // [ 프로그램 시작 ]
1234
            // 클라이언트에서 서버를 호출 ( 접속 시 )  : 라이센스 체크
1235
            //( "method name", arg1, arg2 )
1236
            //MarkusLicenseProxy.Invoke<string>("ConnectionMarkus", "H2009115", "고동균").ContinueWith(task =>
1237
            //{
1238
            //    if (task.IsFaulted)
1239
            //    {
1240
            //        Console.WriteLine("ConnectionMarkus :: There was an error calling send: {0}", task.Exception.GetBaseException());
1241
            //    }
1242
            //    else
1243
            //    {
1244
            //        Console.WriteLine(task.Result);
1245
            //    }
1246
            //});
1247
            MarkusLicenseProxy.Invoke<string>("ConnectionMarkus", App.ViewInfo.UserID,App.ViewInfo.ProjectNO).ContinueWith(task =>
1248
            {
1249
                if (task.IsFaulted)
1250
                {
1251
                    Console.WriteLine("ConnectionMarkus :: There was an error calling send: {0}", task.Exception.GetBaseException());
1252
                    //throw task.Exception.GetBaseException();
1253
                }
1254
                else
1255
                {
1256
                    switch (task.Result)
1257
                    {
1258
                        case "2":
1259
                            {
1260
                                var result = MessageBox.Show("권한이 없습니다.");
1261
                                if (result == MessageBoxResult.OK)
1262
                                    System.Diagnostics.Process.GetCurrentProcess().Kill();
1263
                            }
1264
                            break;
1265
                        case "404":
1266
                            {
1267
                                var result = MessageBox.Show("등록된 사용자가 아닙니다.");
1268
                                if(result == MessageBoxResult.OK)
1269
                                    System.Diagnostics.Process.GetCurrentProcess().Kill();
1270
                            }
1271
                            break;
1272
                    }
1273
                }
1274
            });
1275

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

    
1280
            //    if (status)
1281
            //    {
1282
            //        // 프로그램 시작 
1283
            //        Console.WriteLine("connection status : " + status);
1284
            //    }
1285
            //    else
1286
            //    {
1287
            //        // 프로그램 종료 ( signalr 접속 끊기 )  
1288
            //        hubConnection.Stop();
1289
            //    }
1290
            //});
1291

    
1292
            // 공지 메세지 ( 서버에서 클라이언트 호출 ) 
1293
            MarkusLicenseProxy.On<string>("MarkusNotification", msg =>
1294
                Console.WriteLine("Noficiation Message : " + msg)
1295
            );
1296

    
1297

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

    
1301
            //Console.ReadKey();
1302

    
1303
            //hubConnection.Stop();
1304
        }
1305

    
1306
        public async void MarkupUserListDisplay()
1307
        {
1308
            List<MarkupInfoItem> gridItem = gridViewMarkup.Items.Cast<MarkupInfoItem>().ToList(); //전체 마크업
1309
            List<MarkupInfoItem> gridSelectionItem = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
1310
            List<MarkupInfoItem> gridNonSelectionItem = gridItem.Except(gridSelectionItem).ToList(); //선택 되지 않은 마크업
1311
                                                                                                     //MarkupToPDF.Controls.Parsing.LayerControl layerControl = new MarkupToPDF.Controls.Parsing.LayerControl();
1312
            Common.ViewerDataModel.Instance.MarkupControls_USER.Clear();  //전체 제거
1313
            Common.ViewerDataModel.Instance.MarkupControls.Clear();  //전체 제거
1314
            //foreach (var item in gridSelectionItem)
1315
            //{
1316
            //    if (item.UserID == App.ViewInfo.UserID)
1317
            //    {
1318
            //        ViewerDataModel.Instance.MyMarkupList.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList().ForEach(delegate (MarkupItemEx markupitem)
1319
            //        {
1320
            //            layerControl.markupParseEx(markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, item.DisplayColor, "", item.MarkupInfoID, markupitem.ID);
1321
            //        });
1322
            //    }
1323
            //    else
1324
            //    {
1325
            //        ViewerDataModel.Instance.MarkupList_Pre.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList().ForEach(delegate (MarkupItemEx markupitem)
1326
            //        {
1327
            //            layerControl.markupParse(markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls, item.DisplayColor, "", item.MarkupInfoID);
1328
            //        });
1329
            //    }
1330
            //}
1331
                (from A in gridSelectionItem
1332
                 from B in Common.ViewerDataModel.Instance.MarkupControls_USER
1333
                 where A.MarkupInfoID == B.MarkupInfoID
1334
                 select B).ToList().ForEach(data =>
1335
                 {
1336
                     Common.ViewerDataModel.Instance.MarkupControls_USER.Remove(data);
1337
                 });
1338
            (from A in gridSelectionItem
1339
             from B in Common.ViewerDataModel.Instance.MarkupControls
1340
             where A.MarkupInfoID == B.MarkupInfoID
1341
             select B).ToList().ForEach(data =>
1342
             {
1343
                 Common.ViewerDataModel.Instance.MarkupControls.Remove(data);
1344
             });
1345

    
1346
            foreach (var item in gridSelectionItem)
1347
            {
1348

    
1349
                if (item.UserID == App.ViewInfo.UserID)
1350
                {
1351
                    var markupItems = ViewerDataModel.Instance.MyMarkupList.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList();
1352

    
1353
                    foreach (var markupitem in markupItems)
1354
                    {
1355
                        await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "", 
1356
                                item.MarkupInfoID, markupitem.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1357
                    }
1358
                }
1359
                else
1360
                {
1361
                    var markupItems = ViewerDataModel.Instance.MarkupList_Pre.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList();
1362

    
1363
                    foreach (var markupitem in markupItems)
1364
                    {
1365
                        await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "", item.MarkupInfoID,
1366
                            STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1367
                    }
1368
                }
1369
            }
1370
        }
1371
    }
1372
}
클립보드 이미지 추가 (최대 크기: 500 MB)