프로젝트

일반

사용자정보

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

markus / KCOM / Services / BaseServices.cs @ 58dd9e89

이력 | 보기 | 이력해설 | 다운로드 (68.3 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;
40
        public List<int> MarkupSortList = new List<int>();
41

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

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

    
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.GetCompareRectCompleted += BaseClient_GetCompareRectCompleted;
82
            BaseClient.DeleteMarkupCompleted += BaseClient_DeleteMarkupCompleted;
83
            BaseClient.DelFavoriteVPCompleted += BaseClient_DelFavoriteVPCompleted;
84
            BaseClient.EditFavoriteVPCompleted += BaseClient_EditFavoriteVPCompleted;
85
        }
86

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

    
102
        private void BaseClient_DelFavoriteVPCompleted(object sender, DelFavoriteVPCompletedEventArgs e)
103
        {
104
            //Logger.sendResLog("DelFavoriteVPCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
105

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

    
117
        /// <summary>
118
        /// Compare 결과를 받아 화면에 표시한다
119
        /// </summary>
120
        /// <param name="sender"></param>
121
        /// <param name="e"></param>
122
        private void BaseClient_GetCompareRectCompleted(object sender, GetCompareRectCompletedEventArgs e)
123
        {
124
            if (e.Error != null || e.Result == null)
125
            {
126
                if (e.Error != null)
127
                {
128
                    DialogMessage_Alert(e.Error.ToString(), "Error");
129
                }
130
                else
131
                {
132
                    DialogMessage_Alert("Compare 기능을 원활히 실행하기 위한 데이터가 부족합니다", "안내");
133
                }
134
            }
135
            else
136
            {
137
                e.Result.ForEach(d =>
138
                {
139
                    d.Width = d.Width;
140
                    d.Height = d.Height;
141
                    var point = MarkupToPDF.Controls.Common.MathSet.getRectMiddlePoint(d);
142
                    System.Windows.Shapes.Rectangle myEllipse = new System.Windows.Shapes.Rectangle();
143
                    myEllipse.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(150, 33, 215, 119));
144
                    myEllipse.Opacity = 1;
145
                    myEllipse.Width = d.Width;
146
                    myEllipse.Height = d.Height;
147
                    Canvas.SetLeft(myEllipse, d.X - ((point.X - d.X) / 2.0));
148
                    Canvas.SetTop(myEllipse, d.Y - ((point.Y - d.Y) / 2.0));
149
                    myEllipse.RenderTransformOrigin = point;
150
                    canvas_compareBorder.Children.Add(myEllipse);
151
                });
152
                canvas_compareBorder.Visibility = Visibility.Visible;
153
                da.From = 1;
154
                da.To = 0.5;
155
                da.Duration = new Duration(TimeSpan.FromSeconds(1));
156
                da.AutoReverse = true;
157
                canvas_compareBorder.BeginAnimation(OpacityProperty, da);
158
            }
159
        }
160

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

    
180
        private void BaseClient_GetVPRevisionHistoryCompleted(object sender, GetVPRevisionHistoryCompletedEventArgs e)
181
        {
182
            //Logger.sendResLog("GetVPRevisionHistoryCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.Count + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
183

    
184
            if (e.Result != null && e.Error == null)
185
            {
186
                List<VPRevision> list = e.Result;
187
                foreach (var item in list)
188
                {
189

    
190
                    if (App.isExternal)
191
                    {
192
                        var sBaseServiceURL = CommonLib.Common.GetConfigString("ExternalOriginalFileUrl", "URL", "", App.isExternal);
193

    
194
                        if (!string.IsNullOrWhiteSpace(item.TO_VENDOR))
195
                        {
196
                            var toUri = new Uri(HttpUtility.UrlDecode(item.TO_VENDOR));
197
                            item.TO_VENDOR = $"{sBaseServiceURL}{toUri.LocalPath}";
198
                        }
199

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

    
226
            }
227
            //TempFile.TempLoad();
228
        }
229

    
230
        private void BaseClient_DeleteMarkupCompleted(object sender, DeleteMarkupCompletedEventArgs e)
231
        {
232
            //Logger.sendResLog("DeleteMarkupCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
233

    
234
            foreach(var info in ViewerDataModel.Instance._markupInfoList)
235
            {
236
                if(info.UserID == App.ViewInfo.UserID)
237
                {
238
                    info.userDelete = true;
239
                    info.DisplayColor = "#FFFF0000";
240
                }
241
                else
242
                {
243
                    info.userDelete = false;
244
                }
245
            }
246
        }
247

    
248
        private void BaseClient_GetDeptDataCompleted(object sender, GetDeptDataCompletedEventArgs e)
249
        {
250
            if (e.Error == null)
251
            {
252
                //Logger.sendResLog("GetDeptDataCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.Count + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
253
            }
254
            else
255
            {
256
                //Logger.sendResLog("GetDeptDataCompleted",  "\r Error :" + e.Error, 1);
257
            }
258

    
259
            if (e.Result != null)
260
            {
261
                e.Result.Sort();
262
                //cbSymbolPublic.ItemsSource = e.Result.ToList();
263
            }
264
        }
265

    
266
        /// <summary>
267
        /// ???
268
        /// </summary>
269
        public MarkupInfoItem PreviewUserMarkupInfoItem { get; set; }
270

    
271
        /// <summary>
272
        /// 문서 정보를 가져온다
273
        /// </summary>
274
        /// <param name="sender"></param>
275
        /// <param name="e"></param>
276
        private async void BaseClient_GetDocInfoCompleted(object sender, GetDocInfoCompletedEventArgs e)
277
        {
278
            ////Logger.sendResLog("GetDocInfoCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
279

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

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

    
307
                    Document_NO = _DocItem?.DOCUMENT_NO,
308
                    File_Result = _DocItem?.RESULT_FILE,
309
                    Group_No = _DocItem?.GROUP_NO,
310
                    ProjectNo = _DocItem?.PROJECT_NO,
311
                    Revision = _DocItem?.REVISION,
312
                };
313

    
314
                var instanceMain = this.ParentOfType<MainWindow>();
315
                string firstpage = "1";
316
                string lastpage = _DocInfo.PAGE_COUNT.ToString();
317
                instanceMain.dzTopMenu.tlcurrentPage.Text = firstpage;
318
                instanceMain.dzTopMenu.tlcurrentPage_readonly.Text = lastpage;
319
                App.MarkusVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
320

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

    
323
                instanceMain.Title = apptitle;
324

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

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

    
330
                #endregion
331

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

    
334
                //App.SamplePageStorage = new PageManager.PageStorage(MainUrl.Replace("png", "jpg"), tempStoragePath, "jpg", _DocInfo.PAGE_COUNT);
335
                await this.pageNavigator.SetPageNaviAsync(CurrentDoc.docInfo.DOCPAGE.ToList(), MainUrl);
336
            }
337
        }
338

    
339
        private void pageNavigator_ThumbInitialized(object sender,EventArgs e)
340
        {
341
            BaseClient.GetMarkupInfoItemsAsync(_ViewInfo.ProjectNO, _DocInfo.ID);
342

    
343
            ViewerDataModel.Instance.MarkupControls_USER.Clear();
344
            //ViewerDataModel.Instance.SystemMain.dzMainMenu.TempLoad();
345

    
346
            /// 기존 임시파일 정리
347
            #region 단어 검색용 파일 다운로드
348

    
349
            DownloadOriginalFile();
350

    
351
            #endregion
352

    
353
            //Logger.sendReqLog("GetVPRevisionHistoryAsync", CurrentDoc.ProjectNo + "," + CurrentDoc.Document_NO + "," + CurrentDoc.Document_Id, 1);
354
            BaseClient.GetVPRevisionHistoryAsync(CurrentDoc.ProjectNo, CurrentDoc.Document_NO, CurrentDoc.Document_Id);
355

    
356
        }
357

    
358

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

    
370
            ViewerDataModel.Instance.MarkupControls_USER.Clear();
371
            ViewerDataModel.Instance.MarkupControls.Clear();
372

    
373
            try
374
            {
375

    
376
                if (e.Result != null)
377
                {
378
                    ViewerDataModel.Instance._markupInfoList.Clear();
379
                    if (e.Result.Any()) ViewerDataModel.Instance.MyMarkupList.Clear();
380

    
381
                    foreach (var info in e.Result)
382
                    {
383
                        if (info.Depatment == null) info.Depatment = "Unknown";
384

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

    
412
                        ViewerDataModel.Instance._markupInfoList.Add(info);
413
                    }
414

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

    
417
                    userInfoList.ToList().ForEach(x => ViewerDataModel.Instance._markupUserList.Add(x));
418

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

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

    
505
                            App.Custom_ViewInfoId = infoId;
506

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

    
515
                    ViewerDataModel.Instance.SyncPageNumber = 1;
516

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

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

    
522
                    SetCommentPages(null);
523

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

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

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

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

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

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

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

    
591
                    Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
592
                }
593
                #endregion
594
            }
595
            else if (!App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission)   /// Eng'r Comment Mode
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
            else if (App.ViewInfo.CreateFinalPDFPermission)    /// Orig Comment Model
614
            {
615
                if (ViewerDataModel.Instance._markupInfoList.Any(x => x.Consolidate == 1 && x.AvoidConsolidate == 0))
616
                {
617
                    var Consolidates = ViewerDataModel.Instance._markupInfoList.Where(x => x.Consolidate == 1 && x.AvoidConsolidate == 0).ToList();
618
                    Consolidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
619
                }
620
                else if (ViewerDataModel.Instance._markupInfoList.Any(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0))
621
                {
622
                    var MarkupInfoColl = ViewerDataModel.Instance._markupInfoList.Where(x => x.AvoidConsolidate == 0).ToList();
623

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

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

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

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

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

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

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

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

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

    
684

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

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

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

    
702
            return result;
703
        }
704

    
705

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

    
709
        }
710

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

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

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

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

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

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

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

    
767
                if(cellToSelect != null)
768
                {
769

    
770
                }
771
            }
772

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

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

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

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

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

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

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

    
862
                            controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
863
                            foreach (var control in controls)
864
                            {
865
                                Logger.sendCheckLog(String.Format("=={0}", control), 1);
866
                                control.Visibility = Visibility.Visible;
867
                            }
868
                        }
869
                        else
870
                        {
871
                            var controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
872
                            if (controls.Count == 0)
873
                            {
874
                                var instance = ViewerDataModel.Instance.MarkupList_Pre.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
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, 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.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
883
                            foreach (var control in controls)
884
                            {
885
                                control.Visibility = Visibility.Visible;
886
                            }
887
                        }
888
                    }
889
                }
890
#endregion
891
#region 코멘트 숨기기
892
                else if (e.RemovedItems.Count > 0)
893
                {
894
                    var _infoItem = e.RemovedItems.Cast<MarkupInfoItem>().ToList();
895

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

    
904

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

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

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

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

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

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

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

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

    
969

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

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

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

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

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

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

    
1033
                                    controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1034
                                    foreach (var control in controls)
1035
                                    {
1036
                                        Logger.sendCheckLog(String.Format("=={0}", control), 1);
1037
                                        control.Visibility = Visibility.Visible;
1038
                                    }
1039
                                }
1040
                                else
1041
                                {
1042
                                    var controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1043
                                    if (controls.Count == 0)
1044
                                    {
1045
                                        var instance = ViewerDataModel.Instance.MarkupList_Pre.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
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, 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.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
1054
                                    foreach (var control in controls)
1055
                                    {
1056
                                        control.Visibility = Visibility.Visible;
1057
                                    }
1058
                                }
1059
                            }
1060
                        }
1061
                        #endregion
1062
                        #region 코멘트 숨기기
1063
                        else if (removeItems.Count > 0)
1064
                        {
1065
                            (from A in removeItems
1066
                             from B in Common.ViewerDataModel.Instance.MarkupControls
1067
                             where A.MarkupInfoID == B.MarkupInfoID
1068
                             select B).ToList().ForEach(data =>
1069
                             {
1070
                                 data.Visibility = Visibility.Hidden;
1071
                             });
1072

    
1073

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

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

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

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

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

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

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

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

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

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

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

    
1158
        private void BaseClient_GetConversionStateCompleted(object sender, GetConversionStateCompletedEventArgs e)
1159
        {
1160
            if (e.Error == null && e.Result)
1161
            {
1162
                //Logger.sendReqLog("GetDocumentItemInfoAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID + "," + _ViewInfo.UserID, 1);
1163

    
1164
                BaseClient.GetDocumentItemInfoAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID, userID = _ViewInfo.UserID });
1165

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

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

    
1207
                //App.FileLogger.Fatal(ex);
1208
            }
1209

    
1210
            //Logger.sendReqLog("GetSystemDataAsync", "", 1);
1211

    
1212
            BaseClient.GetSystemDataAsync();
1213
        }
1214

    
1215
        public void HubSet()
1216
        {
1217
            // 허브 연결 구성
1218
            var hubConnection = new HubConnection(CommonLib.Common.GetConfigString("HubAddress", "URL", "", App.isExternal));
1219
            IHubProxy MarkusLicenseProxy = hubConnection.CreateHubProxy("MarkusLicenseHub");
1220

    
1221

    
1222
            // 허브 연결 
1223
            hubConnection.Start().ContinueWith(task =>
1224
            {
1225
                if (task.IsFaulted)
1226
                {
1227
                    Console.WriteLine("There was an error opening the connection:{0}",
1228
                                      task.Exception.GetBaseException());
1229
                    //throw task.Exception.GetBaseException();
1230
                }
1231
                else
1232
                {
1233
                    Console.WriteLine("Connected :: " + task.Id);
1234
                }
1235

    
1236
            }).Wait();
1237

    
1238

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

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

    
1286
            //    if (status)
1287
            //    {
1288
            //        // 프로그램 시작 
1289
            //        Console.WriteLine("connection status : " + status);
1290
            //    }
1291
            //    else
1292
            //    {
1293
            //        // 프로그램 종료 ( signalr 접속 끊기 )  
1294
            //        hubConnection.Stop();
1295
            //    }
1296
            //});
1297

    
1298
            // 공지 메세지 ( 서버에서 클라이언트 호출 ) 
1299
            MarkusLicenseProxy.On<string>("MarkusNotification", msg =>
1300
                Console.WriteLine("Noficiation Message : " + msg)
1301
            );
1302

    
1303

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

    
1307
            //Console.ReadKey();
1308

    
1309
            //hubConnection.Stop();
1310
        }
1311

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

    
1352
            foreach (var item in gridSelectionItem)
1353
            {
1354

    
1355
                if (item.UserID == App.ViewInfo.UserID)
1356
                {
1357
                    var markupItems = ViewerDataModel.Instance.MyMarkupList.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList();
1358

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

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