프로젝트

일반

사용자정보

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

markus / KCOM / Services / BaseServices.cs @ ef9ddca4

이력 | 보기 | 이력해설 | 다운로드 (68.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;
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
            #region 이벤트 핸들러 등록
73
            BaseClient.GetDocInfoCompleted += BaseClient_GetDocInfoCompleted; //문서 섬네일, 페이지크기, 마크업 정보 [3]
74
            BaseClient.GetConversionStateCompleted += BaseClient_GetConversionStateCompleted;  //컨버팅의 여부 [2] 
75
            BaseClient.GetSystemDataCompleted += BaseClient_GetSystemDataCompleted; //시스템 정보 [1] 
76
            BaseClient.GetDocumentItemInfoCompleted += BaseClient_GetDocumentItemInfoCompleted; // 문서 자체의 정보 [4]
77
            BaseClient.GetMarkupInfoItemsCompleted += BaseClient_GetMarkupInfoItemsCompleted;
78
            BaseClient.GetDeptDataCompleted += BaseClient_GetDeptDataCompleted;
79
            BaseClient.DeleteMarkupCompleted += BaseClient_DeleteMarkupCompleted;
80
            BaseClient.GetVPRevisionHistoryCompleted += BaseClient_GetVPRevisionHistoryCompleted;
81
            BaseClient.SetFinalPDFCompleted += BaseClient_SetFinalPDFCompleted;
82
            BaseClient.GetCompareRectCompleted += BaseClient_GetCompareRectCompleted;
83
            BaseClient.DeleteMarkupCompleted += BaseClient_DeleteMarkupCompleted;
84
            BaseClient.DelFavoriteVPCompleted += BaseClient_DelFavoriteVPCompleted;
85
            BaseClient.EditFavoriteVPCompleted += BaseClient_EditFavoriteVPCompleted;
86

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
328
                instanceMain.Title = apptitle;
329

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

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

    
335
                #endregion
336

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

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

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

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

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

    
354
            DownloadOriginalFile();
355

    
356
            #endregion
357

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

    
361
        }
362

    
363

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

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

    
378
            try
379
            {
380

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

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

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

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

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

    
422
                    userInfoList.ToList().ForEach(x => ViewerDataModel.Instance._markupUserList.Add(x));
423

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

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

    
510
                            App.Custom_ViewInfoId = infoId;
511

    
512
                            ViewerDataModel.Instance._markupInfoList.Insert(0, PreviewUserMarkupInfoItem);
513
                        }
514
                    }
515
                    else
516
                    {
517
                        App.Custom_ViewInfoId = currentUser.MarkupInfoID;
518
                    }
519

    
520
                    ViewerDataModel.Instance.SyncPageNumber = 1;
521

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

    
525
                    gridViewMarkup.ItemsSource = ViewerDataModel.Instance._markupInfoList;
526

    
527
                    SetCommentPages(null);
528

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

    
542
                    GridViewMarkup_Sorting(gridViewMarkup, new GridViewSortingEventArgs(gridViewMarkup.Columns[0], SortingState.None, SortingState.None));
543

    
544
                    SelectInitialMarkupInfo();
545
                }
546
            }
547
            catch (Exception ex) 
548
            {
549
                App.FileLogger.Fatal(ex);
550
            }
551
            finally
552
            {
553
                if(!ViewerDataModel.Instance.SystemMain.dzMainMenu.btnFinalPDF.IsEnabled)
554
                {
555
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.btnFinalPDF.IsEnabled = true;
556
                }
557

    
558
                if (!ViewerDataModel.Instance.SystemMain.dzMainMenu.btnConsolidate.IsEnabled)
559
                {
560
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.btnConsolidate.IsEnabled = true;
561
                }
562
            }
563
        }
564

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

    
584
                    #region Team consolidate 항목 선택
585
                    var Candidates = MarkupInfoColl.Where(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0).ToList();
586
                    MarkupInfoColl.RemoveAll(x => Candidates.Exists(y => y.UserID == x.UserID));
587
                    #endregion
588

    
589
                    #region 추가되지 않은 사용자들을 추가
590
                    foreach (var item in MarkupInfoColl.Where(x => !Candidates.Exists(y => y.UserID == x.UserID)))
591
                    {
592
                        Candidates.Add(item);
593
                    }
594
                    #endregion
595

    
596
                    Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
597
                }
598
                #endregion
599
            }
600
            else if (!App.ViewInfo.CreateFinalPDFPermission && App.ViewInfo.NewCommentPermission)   /// Eng'r Comment Mode
601
            {
602
                var MarkupInfoColl = ViewerDataModel.Instance._markupInfoList.Where(x => x.AvoidConsolidate == 0).ToList();
603

    
604
                #region Team consolidate 항목 선택
605
                var Candidates = MarkupInfoColl.Where(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0).ToList();
606
                MarkupInfoColl.RemoveAll(x => Candidates.Exists(y => y.UserID == x.UserID));
607
                #endregion
608

    
609
                #region 추가되지 않은 사용자들을 추가
610
                foreach (var item in MarkupInfoColl.Where(x => !Candidates.Exists(y => y.UserID == x.UserID)))
611
                {
612
                    Candidates.Add(item);
613
                }
614
                #endregion
615

    
616
                Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
617
            }
618
            else if (App.ViewInfo.CreateFinalPDFPermission)    /// Orig Comment Model
619
            {
620
                if (ViewerDataModel.Instance._markupInfoList.Any(x => x.Consolidate == 1 && x.AvoidConsolidate == 0))
621
                {
622
                    var Consolidates = ViewerDataModel.Instance._markupInfoList.Where(x => x.Consolidate == 1 && x.AvoidConsolidate == 0).ToList();
623
                    Consolidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
624
                }
625
                else if (ViewerDataModel.Instance._markupInfoList.Any(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0))
626
                {
627
                    var MarkupInfoColl = ViewerDataModel.Instance._markupInfoList.Where(x => x.AvoidConsolidate == 0).ToList();
628

    
629
                    #region Team consolidate 항목 선택
630
                    var Candidates = MarkupInfoColl.Where(x => x.PartConsolidate == 1 && x.AvoidConsolidate == 0).ToList();
631
                    MarkupInfoColl.RemoveAll(x => Candidates.Exists(y => y.UserID == x.UserID));
632
                    #endregion
633

    
634
                    #region 추가되지 않은 사용자들을 추가
635
                    foreach (var item in MarkupInfoColl.Where(x => !Candidates.Exists(y => y.UserID == x.UserID)))
636
                    {
637
                        Candidates.Add(item);
638
                    }
639
                    #endregion
640

    
641
                    Candidates.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
642
                }
643
                else
644
                {
645
                    var Comments = ViewerDataModel.Instance._markupInfoList.Where(x => x.Consolidate == 0 && x.AvoidConsolidate == 0).ToList();
646
                    Comments.ForEach(x => gridViewMarkup.SelectedItems.Add(x));
647
                }
648
            }
649

    
650
            if (!gridViewMarkup.SelectedItems.Any())
651
            {
652
                var SelectedItem = ViewerDataModel.Instance._markupInfoList.Where(info => info.UserID == App.ViewInfo.UserID).OrderByDescending(order => order.UpdateTime).FirstOrDefault();
653

    
654
                if (PreviewUserMarkupInfoItem != null)
655
                {
656
                    this.gridViewMarkup.SelectedItem = PreviewUserMarkupInfoItem;
657
                }
658
                else if (SelectedItem != null)
659
                {
660
                    this.gridViewMarkup.SelectedItem = SelectedItem;
661
                }
662
                else if (ViewerDataModel.Instance._markupInfoList.Any())
663
                {
664
                    this.gridViewMarkup.SelectedItem = ViewerDataModel.Instance._markupInfoList[0];
665
                }
666
            }
667
        }
668

    
669
        private void GridViewMarkup_Sorting(object sender, GridViewSortingEventArgs e)
670
        {
671
            IEnumerable<IKCOM.MarkupInfoItem> markuplist = e.DataControl.ItemsSource as IEnumerable<IKCOM.MarkupInfoItem>;
672

    
673
            if(markuplist == null)
674
            {
675
                e.Cancel = true;
676
                return;
677
            }
678

    
679
            if(e.NewSortingState == SortingState.None)
680
            {
681
                markuplist = markuplist.OrderByDescending(x => SortIndex(x))
682
                                            .ThenBy(x => x.Depatment)
683
                                            .ThenBy(x => x.UserID);
684

    
685
                e.DataControl.ItemsSource = markuplist.ToList();
686
            }
687
        }
688

    
689

    
690
        // 마크업 리스트 정렬
691
        private int SortIndex(IKCOM.MarkupInfoItem markupInfoItem)
692
        {
693
            int result = 0;
694

    
695
            // Consolidate은 최상단
696
            if (markupInfoItem.Consolidate == 1)
697
            {
698
                result += 2;
699
            }
700

    
701
            /// Consolidate 다음으로 우선순위
702
            if (markupInfoItem.UserID == App.ViewInfo.UserID)
703
            {
704
                result += 1;
705
            }
706

    
707
            return result;
708
        }
709

    
710

    
711
        private void GridViewMarkup_Sorted(object sender, GridViewSortedEventArgs e)
712
        {
713

    
714
        }
715

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

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

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

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

    
750
                (from A in _infoItem
751
                 from B in Common.ViewerDataModel.Instance.MarkupControls_Sync
752
                 where A.MarkupInfoID == B.MarkupInfoID
753
                 select B).ToList().ForEach(data =>
754
                 {
755
                     Common.ViewerDataModel.Instance.MarkupControls_Sync.Remove(data);
756
                 });
757
            }
758
        }
759

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

    
768
            foreach (var item in e.AddedItems)
769
            {
770
                var cellToSelect = new GridViewCellInfo(item, this.gridViewMarkup.Columns["color"], this.gridViewMarkup);
771

    
772
                if(cellToSelect != null)
773
                {
774

    
775
                }
776
            }
777

    
778
            SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
779

    
780
            var dataSet = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
781
            var dataSet_User = gridViewMarkup.Items.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
782
            var resultA = (from item_Select in dataSet
783
                           from item_Non in dataSet_User
784
                           where item_Select == item_Non
785
                           select item_Non).ToList();
786

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

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

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

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

    
860
                                foreach (var markup in instance)
861
                                {
862
                                    await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "", 
863
                                        item.MarkupInfoID, markup.ID, STAMP_Contents:App.SystemInfo.STAMP_CONTENTS);
864
                                }
865
                            }
866

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

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

    
901
                    (from A in _infoItem
902
                     from B in Common.ViewerDataModel.Instance.MarkupControls
903
                     where A.MarkupInfoID == B.MarkupInfoID
904
                     select B).ToList().ForEach(data =>
905
                     {
906
                         data.Visibility = Visibility.Hidden;                         
907
                     });
908

    
909

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

    
923
        private async void gridViewMarkup_SelectedCellsChanged(object sender, Telerik.Windows.Controls.GridView.GridViewSelectedCellsChangedEventArgs e)
924
        {
925
            if (e.AddedCells.Count() > 0)
926
            {
927
                if(e.AddedCells[0].Column.Name == "color")
928
                {
929

    
930
                }
931
                else
932
                {
933
                    List<MarkupInfoItem> removeItems = new List<MarkupInfoItem>();
934

    
935
                    if (!gridViewMarkup.SelectedItems.Contains(e.AddedCells[0].Item))
936
                    {
937
                        gridViewMarkup.SelectedItems.Add(e.AddedCells[0].Item);
938
                    }
939
                    else
940
                    {
941
                        gridViewMarkup.Unselect(new[] { e.AddedCells[0].Item });
942

    
943
                        removeItems.Add(e.AddedCells[0].Item as MarkupInfoItem);
944
                    }
945

    
946
                    SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
947

    
948
                    var dataSet = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
949
                    var dataSet_User = gridViewMarkup.Items.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
950
                    var resultA = (from item_Select in dataSet
951
                                   from item_Non in dataSet_User
952
                                   where item_Select == item_Non
953
                                   select item_Non).ToList();
954

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

    
974

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

    
986
                                            if (Consolidations.Count() > 0)
987
                                            {
988
                                                gridViewMarkup.SelectedItem = Consolidations.First();
989
                                            }
990
                                        }
991

    
992
                                    }
993
                                    else
994
                                    {
995
                                        //1. Consolidations 아닌게 있다면 Change
996
                                        var notConsolidations = resultA.Where(item => !(item.Consolidate == 1 || item.PartConsolidate == 1));
997

    
998
                                        if (notConsolidations.Count() > 0)
999
                                        {
1000
                                            gridViewMarkup.SelectedItem = notConsolidations.First();
1001
                                        }
1002
                                        else
1003
                                        {//1. Consolidations 아닌게 없다면 그대로
1004
                                            gridViewMarkup.SelectedItem = instanceItem;
1005
                                        }
1006

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

    
1031
                                        foreach (var markup in instance)
1032
                                        {
1033
                                            await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, item.DisplayColor, "",
1034
                                                item.MarkupInfoID, markup.ID, STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
1035
                                        }
1036
                                    }
1037

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

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

    
1078

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

    
1094
        private void BaseClient_GetDocumentItemInfoCompleted(object sender, GetDocumentItemInfoCompletedEventArgs e)
1095
        {
1096
            //Logger.sendResLog("GetDocumentItemInfoCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result?.DOCUMENT_ID + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
1097

    
1098
            if (e.Result != null)
1099
            {
1100
                _DocItem = e.Result;
1101

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

    
1113
                BaseClient.GetCheckSystemAdminCompleted += (sen, ea) =>
1114
                {
1115
                    //Logger.sendResLog("GetCheckSystemAdminCompleted", "UserState : " + ea.UserState + "\r Result :" + ea.Result + "\r Cancelled :" + ea.Cancelled + "\r Error :" + ea.Error, 1);
1116

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

    
1132
                    }
1133
                    else
1134
                    {
1135
                        //System.Windows.Browser.HtmlPage.Window.Invoke("close");
1136
                    }
1137
                };
1138
                //Logger.sendReqLog("GetCheckSystemAdminAsync", _ViewInfo.UserID, 1);
1139
                BaseClient.GetCheckSystemAdminAsync(this._ViewInfo.UserID);
1140
            }
1141
        }
1142

    
1143
        private void BaseClient_GetSystemDataCompleted(object sender, GetSystemDataCompletedEventArgs e)
1144
        {
1145
            //Logger.sendResLog("GetSystemDataCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
1146

    
1147
            if (e.Error == null && e.Result != null)
1148
            {
1149
                App.SystemInfo = e.Result;
1150

    
1151
                //App.urlPort_DB = App.SystemInfo.HostPort;
1152
                //App.urlHost_DB = App.SystemInfo.HostName;
1153
                //Logger.sendReqLog("GetConversionStateAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
1154
                BaseClient.GetConversionStateAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
1155

    
1156
                //if (App.urlHost.Contains("localhost"))
1157
                //{
1158
                //    App.urlHost = App.urlHost_DB;
1159
                //}
1160
            }
1161
        }
1162

    
1163
        private void BaseClient_GetConversionStateCompleted(object sender, GetConversionStateCompletedEventArgs e)
1164
        {
1165
            if (e.Error == null && e.Result)
1166
            {
1167
                //Logger.sendReqLog("GetDocumentItemInfoAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID + "," + _ViewInfo.UserID, 1);
1168

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

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

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

    
1212
                //App.FileLogger.Fatal(ex);
1213
            }
1214

    
1215
            //Logger.sendReqLog("GetSystemDataAsync", "", 1);
1216

    
1217
            BaseClient.GetSystemDataAsync();
1218
        }
1219

    
1220
        public void HubSet()
1221
        {
1222
            // 허브 연결 구성
1223
            var hubConnection = new HubConnection(CommonLib.Common.GetConfigString("HubAddress", "URL", "", App.isExternal));
1224
            IHubProxy MarkusLicenseProxy = hubConnection.CreateHubProxy("MarkusLicenseHub");
1225

    
1226

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

    
1241
            }).Wait();
1242

    
1243

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

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

    
1291
            //    if (status)
1292
            //    {
1293
            //        // 프로그램 시작 
1294
            //        Console.WriteLine("connection status : " + status);
1295
            //    }
1296
            //    else
1297
            //    {
1298
            //        // 프로그램 종료 ( signalr 접속 끊기 )  
1299
            //        hubConnection.Stop();
1300
            //    }
1301
            //});
1302

    
1303
            // 공지 메세지 ( 서버에서 클라이언트 호출 ) 
1304
            MarkusLicenseProxy.On<string>("MarkusNotification", msg =>
1305
                Console.WriteLine("Noficiation Message : " + msg)
1306
            );
1307

    
1308

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

    
1312
            //Console.ReadKey();
1313

    
1314
            //hubConnection.Stop();
1315
        }
1316

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

    
1357
            foreach (var item in gridSelectionItem)
1358
            {
1359

    
1360
                if (item.UserID == App.ViewInfo.UserID)
1361
                {
1362
                    var markupItems = ViewerDataModel.Instance.MyMarkupList.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList();
1363

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

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