프로젝트

일반

사용자정보

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

markus / KCOM / Services / BaseServices.cs @ 315ae55e

이력 | 보기 | 이력해설 | 다운로드 (46.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 RestSharp;
8
using System;
9
using System.Collections.Generic;
10
using System.Collections.ObjectModel;
11
using System.ComponentModel;
12
using System.Linq;
13
using System.Runtime.CompilerServices;
14
using System.Text;
15
using System.Windows;
16
using System.Windows.Controls;
17
using Telerik.Windows.Controls;
18
using MarkupToPDF.Controls.Parsing;
19
using Telerik.Windows.Data;
20
using System.Web;
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
        public ViewInfo _ViewInfo;
30
        public DOCINFO _DocInfo;
31
        public DOCUMENT_ITEM _DocItem;
32
        public MEMBER userData;
33
        public List<int> MarkupSortList = new List<int>();
34

    
35
        public event PropertyChangedEventHandler PropertyChanged;
36
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
37
        {
38
            if (PropertyChanged != null)
39
            {
40
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
41
            }
42
        }
43

    
44
        private Common.DocumentSet _CurrentDoc { get; set; }
45
        public Common.DocumentSet CurrentDoc
46
        {
47
            get
48
            {
49
                return _CurrentDoc;
50
            }
51
            set
52
            {
53
                if (value != CurrentDoc)
54
                {
55
                    _CurrentDoc = value;
56
                    NotifyPropertyChanged();
57
                }
58
            }
59
        }
60
        public void ServiceOn()
61
        {
62
            BaseTaskClient = new KcomService.ServiceDeepViewClient(App._binding, App._EndPoint);
63
            BaseClient = new ServiceDeepViewClient(App._binding, App._EndPoint);
64

    
65
            BaseClient.GetDocInfoCompleted += BaseClient_GetDocInfoCompleted; //문서 섬네일, 페이지크기, 마크업 정보 [3]
66
            BaseClient.GetConversionStateCompleted += BaseClient_GetConversionStateCompleted;  //컨버팅의 여부 [2] 
67
            BaseClient.GetSystemDataCompleted += BaseClient_GetSystemDataCompleted; //시스템 정보 [1] 
68
            BaseClient.GetDocumentItemInfoCompleted += BaseClient_GetDocumentItemInfoCompleted; // 문서 자체의 정보 [4]
69
            BaseClient.GetMarkupInfoItemsCompleted += BaseClient_GetMarkupInfoItemsCompleted;
70
            BaseClient.GetDeptDataCompleted += BaseClient_GetDeptDataCompleted;
71
            BaseClient.DeleteMarkupCompleted += BaseClient_DeleteMarkupCompleted;
72
            BaseClient.GetVPRevisionHistoryCompleted += BaseClient_GetVPRevisionHistoryCompleted;
73
            BaseClient.SetFinalPDFCompleted += BaseClient_SetFinalPDFCompleted;
74
            BaseClient.GetCompareRectCompleted += BaseClient_GetCompareRectCompleted;
75
            BaseClient.DeleteMarkupCompleted += BaseClient_DeleteMarkupCompleted;
76
            BaseClient.DelFavoriteVPCompleted += BaseClient_DelFavoriteVPCompleted;
77
            BaseClient.EditFavoriteVPCompleted += BaseClient_EditFavoriteVPCompleted;
78
        }
79

    
80

    
81

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

    
97
        private void BaseClient_DelFavoriteVPCompleted(object sender, DelFavoriteVPCompletedEventArgs e)
98
        {
99
            Logger.sendResLog("DelFavoriteVPCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
100

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

    
112
        /// <summary>
113
        /// Compare 결과를 받아 화면에 표시한다
114
        /// </summary>
115
        /// <param name="sender"></param>
116
        /// <param name="e"></param>
117
        private void BaseClient_GetCompareRectCompleted(object sender, GetCompareRectCompletedEventArgs e)
118
        {
119
            if (e.Error != null || e.Result == null)
120
            {
121
                if (e.Error != null)
122
                {
123
                    DialogMessage_Alert(e.Error.ToString(), "Error");
124
                }
125
                else
126
                {
127
                    DialogMessage_Alert("Compare 기능을 원활히 실행하기 위한 데이터가 부족합니다", "안내");
128
                }
129
            }
130
            else
131
            {
132
                e.Result.ForEach(d =>
133
                {
134
                    d.Width = d.Width * 3;
135
                    d.Height = d.Height * 3;
136
                    var point = MarkupToPDF.Controls.Common.MathSet.getRectMiddlePoint(d);
137
                    System.Windows.Shapes.Rectangle myEllipse = new System.Windows.Shapes.Rectangle();
138
                    myEllipse.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(100,255,8,0));
139
                    myEllipse.Opacity = 0.8;
140
                    myEllipse.Width = d.Width;
141
                    myEllipse.Height = d.Height;
142
                    Canvas.SetLeft(myEllipse, d.X - ((point.X - d.X) / 2.0));
143
                    Canvas.SetTop(myEllipse, d.Y - ((point.Y - d.Y) / 2.0));
144
                    myEllipse.RenderTransformOrigin = point;
145
                    canvas_compareBorder.Children.Add(myEllipse);
146
                });
147

    
148
                da.From = 0.8;
149
                da.To = 0.1;
150
                da.Duration = new Duration(TimeSpan.FromSeconds(1));
151
                da.AutoReverse = true;
152
                canvas_compareBorder.BeginAnimation(OpacityProperty, da);
153
            }
154
        }
155

    
156
        private void BaseClient_SetFinalPDFCompleted(object sender, SetFinalPDFCompletedEventArgs e)
157
        {
158
            Logger.sendResLog("SetFinalPDFCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
159
            string errormsg = CommonLib.Common.GetAlertMessageString("SetFinalPDFError", "MSG", "최종 파일을 만드는데 문제가 발생하였습니다");
160
            string successmsg = CommonLib.Common.GetAlertMessageString("SetFinalPDFSuccess", "MSG", "최종 파일 생성 중입니다. 문서관리시스템을 확인해주세요");
161
            if (e.Error != null || e.Result.Status == FinalStatus.Error)
162
            {
163
                DialogMessage_Alert(errormsg, "안내");
164
            }
165
            else
166
            {
167
                DialogMessage_Alert(successmsg, "안내");
168
            }
169
        }
170

    
171
        private void BaseClient_GetVPRevisionHistoryCompleted(object sender, GetVPRevisionHistoryCompletedEventArgs e)
172
        {
173
            Logger.sendResLog("GetVPRevisionHistoryCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
174

    
175
            if (e.Result != null && e.Error == null)
176
            {
177
                List<VPRevision> list = e.Result;
178
                foreach (var item in list)
179
                {
180

    
181
                    if (App.isExternal)
182
                    {
183
                        var sBaseServiceURL = CommonLib.Common.GetConfigString("ExternalOriginalFileUrl", "URL", "", App.isExternal);
184

    
185
                        if (!string.IsNullOrWhiteSpace(item.TO_VENDOR))
186
                        {
187
                            var toUri = new Uri(HttpUtility.UrlDecode(item.TO_VENDOR));
188
                            item.TO_VENDOR = $"{sBaseServiceURL}{toUri.LocalPath}";
189
                        }
190

    
191
                        if (!string.IsNullOrWhiteSpace(item.FROM_VENDOR))
192
                        {
193
                            var fromUri = new Uri(HttpUtility.UrlDecode(item.FROM_VENDOR));
194
                            item.FROM_VENDOR = $"{sBaseServiceURL}{fromUri.LocalPath}";
195
                        }
196
                    }
197
                    else
198
                    {
199

    
200
                        item.FROM_VENDOR = HttpUtility.UrlDecode(item.FROM_VENDOR);
201
                    }
202
                }
203
                gridViewHistory.ItemsSource = list;
204
            }
205
            //TempFile.TempLoad();
206
        }
207

    
208
        private void BaseClient_DeleteMarkupCompleted(object sender, DeleteMarkupCompletedEventArgs e)
209
        {
210
            Logger.sendResLog("DeleteMarkupCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
211

    
212
            foreach(var info in ViewerDataModel.Instance._markupInfoList)
213
            {
214
                if(info.UserID == App.ViewInfo.UserID)
215
                {
216
                    info.userDelete = true;
217
                    info.DisplayColor = "FFFF0000";
218
                }
219
                else
220
                {
221
                    info.userDelete = false;
222
                }
223
            }
224
        }
225

    
226
        private void BaseClient_GetDeptDataCompleted(object sender, GetDeptDataCompletedEventArgs e)
227
        {
228
            if (e.Error == null)
229
            {
230
                Logger.sendResLog("GetDeptDataCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
231
            }
232
            else
233
            {
234
                Logger.sendResLog("GetDeptDataCompleted",  "\r Error :" + e.Error, 1);
235
            }
236

    
237
            if (e.Result != null)
238
            {
239
                e.Result.Sort();
240
                //cbSymbolPublic.ItemsSource = e.Result.ToList();
241
            }
242
        }
243

    
244
        public MarkupInfoItem PreviewUserMarkupInfoItem { get; set; }
245

    
246
        /// <summary>
247
        /// 문서 정보를 가져온다
248
        /// </summary>
249
        /// <param name="sender"></param>
250
        /// <param name="e"></param>
251
        private async void BaseClient_GetDocInfoCompleted(object sender, GetDocInfoCompletedEventArgs e)
252
        {
253
            //Logger.sendResLog("GetDocInfoCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
254

    
255
            if (e.Error != null)
256
            {
257
                DialogMessage_Alert("The page cannot be displayed.", "Alert");
258
                return;
259
            }
260

    
261
            string sFolder = _ViewInfo.DocumentItemID.All(char.IsDigit) ? (Convert.ToUInt32(_ViewInfo.DocumentItemID) / 100).ToString() : (_ViewInfo.DocumentItemID.Length >= 5 ? _ViewInfo.DocumentItemID.Substring(0, 5) : _ViewInfo.DocumentItemID);
262
            var MainUrl = string.Format(CommonLib.Common.GetConfigString("mainServerImageWebPath", "URL", "", App.isExternal).Replace("png","jpg"), _ViewInfo.ProjectNO, sFolder, _ViewInfo.DocumentItemID, "{PageNo}");
263
            _DocInfo = e.Result;
264
            _DocInfo.ORIGINAL_FILE = HttpUtility.UrlDecode(_DocInfo.ORIGINAL_FILE);
265
            foreach (var item in _DocInfo.DOCPAGE.OrderBy(order => order.PAGE_NUMBER))
266
            {
267
                ViewerDataModel.Instance.Document_Info.Add(item);
268
            }
269
            Logger.sendReqLog("GetMarkupInfoItemsAsync", _ViewInfo.ProjectNO + "," + _DocInfo.ID, 1);
270
           CurrentDoc = new Common.DocumentSet
271
            {
272
                docInfo = _DocInfo,
273
                Document_Id = _DocInfo.DOCUMENT_ID,
274
                File_Original = _DocInfo.ORIGINAL_FILE,
275

    
276
                Document_NO = _DocItem?.DOCUMENT_NO,
277
                File_Result = _DocItem?.RESULT_FILE,
278
                Group_No = _DocItem?.GROUP_NO,
279
                ProjectNo = _DocItem?.PROJECT_NO,
280
                Revision = _DocItem?.REVISION,
281
            };
282

    
283
            var instanceMain = this.ParentOfType<MainWindow>();
284
            string firstpage = "1";
285
            string lastpage = _DocInfo.PAGE_COUNT.ToString();
286
            instanceMain.dzTopMenu.tlcurrentPage.Text = firstpage;
287
            instanceMain.dzTopMenu.tlcurrentPage_readonly.Text = lastpage;
288
            string apptitle = string.Format("MARKUS(ver.{2}) - {0}(Rev.{1})", _DocItem?.DOCUMENT_NO, _DocItem?.REVISION, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
289

    
290
            instanceMain.Title = apptitle;
291

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

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

    
297
            #endregion
298
            App.PageStorage = new PageManager.PageStorage(MainUrl.Replace("jpg","png"), tempStoragePath,"png", _DocInfo.PAGE_COUNT);
299
         
300
            await this.pageNavigator.SetPageNaviAsync(CurrentDoc.docInfo.DOCPAGE.ToList(), MainUrl);
301

    
302
        }
303

    
304
        private void pageNavigator_ThumbInitialized(object sender,EventArgs e)
305
        {
306
            BaseClient.GetMarkupInfoItemsAsync(_ViewInfo.ProjectNO, _DocInfo.ID);
307

    
308
            ViewerDataModel.Instance.MarkupControls_USER.Clear();
309
            //ViewerDataModel.Instance.SystemMain.dzMainMenu.TempLoad();
310

    
311
            #region 단어 검색용 파일 다운로드
312

    
313
            DownloadOriginalFileAsync().RunAndForget();
314

    
315
            #endregion
316

    
317
            Logger.sendReqLog("GetVPRevisionHistoryAsync", CurrentDoc.ProjectNo + "," + CurrentDoc.Document_NO + "," + CurrentDoc.Document_Id, 1);
318
            BaseClient.GetVPRevisionHistoryAsync(CurrentDoc.ProjectNo, CurrentDoc.Document_NO, CurrentDoc.Document_Id);
319

    
320
        }
321

    
322

    
323
        /// <summary>
324
        /// get markupinfo and markupitem from database
325
        ///  - 1. called when document is loaded
326
        ///  - 2. called when user do consolidation
327
        /// </summary>
328
        /// <param name="sender"></param>
329
        /// <param name="e"></param>
330
        private void BaseClient_GetMarkupInfoItemsCompleted(object sender, GetMarkupInfoItemsCompletedEventArgs e)
331
        {
332
            Logger.sendResLog("GetMarkupInfoItemsCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
333

    
334
            ViewerDataModel.Instance.MarkupControls_USER.Clear();
335
            ViewerDataModel.Instance.MarkupControls.Clear();
336

    
337
            if (e.Result != null)
338
            {
339
                ViewerDataModel.Instance._markupInfoList.Clear();
340
                if (e.Result.Count > 0) ViewerDataModel.Instance.MyMarkupList.Clear();
341

    
342
                foreach (var info in e.Result)
343
                {
344
                    if (info.Depatment == null) info.Depatment = "Unknown";
345

    
346
                    if (info.UserID == App.ViewInfo.UserID)
347
                    {
348
                        info.userDelete = true;
349
                        info.DisplayColor = "#FFFF0000";
350
                    }
351
                    else
352
                    {
353
                        info.userDelete = false;
354
                    }
355

    
356
                    ViewerDataModel.Instance._markupInfoList.Add(info);
357
                }
358

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

    
361
                userInfoList.ToList().ForEach(x => ViewerDataModel.Instance._markupUserList.Add(x));
362

    
363
                e.Result.ToList().ForEach(d =>
364
                {
365
                    if (d.MarkupList != null)
366
                    {
367
                        d.MarkupList.ForEach(p =>
368
                        {
369
                            if (d.UserID == App.ViewInfo.UserID)
370
                            {
371
                                d.userDelete = true;
372
                                d.DisplayColor = "#FFFF0000";
373

    
374
                                MarkupItemEx markup = new MarkupItemEx
375
                                {
376
                                    Data = p.Data,
377
                                    Data_Type = p.Data_Type,
378
                                    ID = p.ID,
379
                                    IsUpdate = false,
380
                                    MarkupInfoID = d.MarkupInfoID,
381
                                    PageNumber = p.PageNumber,
382
                                    Symbol_ID = p.Symbol_ID,
383
                                //Group_ID = p.Group_ID
384
                            };
385
                                ViewerDataModel.Instance.MyMarkupList.Add(markup);
386
                            }
387
                            else
388
                            {
389
                                MarkupItemEx markup = new MarkupItemEx
390
                                {
391
                                    Data = p.Data,
392
                                    Data_Type = p.Data_Type,
393
                                    ID = p.ID,
394
                                    IsUpdate = false,
395
                                    MarkupInfoID = d.MarkupInfoID,
396
                                    PageNumber = p.PageNumber,
397
                                    Symbol_ID = p.Symbol_ID,
398
                                //Group_ID = p.Group_ID
399
                            };
400
                                ViewerDataModel.Instance.MarkupList_Pre.Add(markup);
401
                            }
402
                        });
403
                    }
404
                });
405

    
406
                var currentUser = e.Result.Where(data => data.UserID == App.ViewInfo.UserID && data.AvoidConsolidate == 0).FirstOrDefault();
407

    
408
                if (currentUser == null)
409
                {
410
                    /// create a new markupinfo to do comments
411
                    //var infoId = Commons.shortGuid();
412
                    //PreviewUserMarkupInfoItem = new MarkupInfoItem
413
                    //{
414
                    //    CreateTime = DateTime.Now,
415
                    //    UpdateTime = DateTime.Now,
416
                    //    Depatment = userData.DEPARTMENT,
417
                    //    DisplayColor = "#FFFF0000",
418
                    //    UserID = userData.ID,
419
                    //    UserName = userData.NAME,
420
                    //    PageCount = 1,
421
                    //    Description = "",
422
                    //    MarkupInfoID = infoId,
423
                    //    MarkupList = null,
424
                    //    MarkupVersionID = Commons.shortGuid(),
425
                    //    Consolidate = 0,
426
                    //    PartConsolidate = 0,
427
                    //    userDelete = true,
428
                    //    AvoidConsolidate = 0,
429
                    //    IsPreviewUser = false
430
                    //};
431

    
432
                    //App.Custom_ViewInfoId = infoId;
433

    
434
                    //ViewerDataModel.Instance._markupInfoList.Insert(0, PreviewUserMarkupInfoItem);
435
                }
436
                else
437
                {
438
                    App.Custom_ViewInfoId = currentUser.MarkupInfoID;
439
                }
440

    
441
                ViewerDataModel.Instance.PageNumber = 1;
442

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

    
446
                gridViewMarkup.ItemsSource = ViewerDataModel.Instance._markupInfoList;
447
                SetCommentPages();
448

    
449

    
450
                /// create a group descriptor
451
                gridViewMarkup.GroupDescriptors.Clear();
452
                GroupDescriptor descriptor = new GroupDescriptor();
453
                descriptor.Member = "Depatment";
454
                descriptor.DisplayContent = "DEPT";
455
                //descriptor.SortDirection = ListSortDirection.Ascending;
456
                gridViewMarkup.GroupDescriptors.Add(descriptor);
457

    
458
                GridViewMarkup_Sorting(gridViewMarkup,new GridViewSortingEventArgs(gridViewMarkup.Columns[0],SortingState.None,SortingState.None));
459

    
460
                var SelectedItem = ViewerDataModel.Instance._markupInfoList.Where(info => info.UserID == App.ViewInfo.UserID).OrderByDescending(order => order.UpdateTime).FirstOrDefault();
461
                this.gridViewMarkup.SelectedItem = (PreviewUserMarkupInfoItem != null) ? PreviewUserMarkupInfoItem : SelectedItem;
462
            }
463
        }
464

    
465
        private void GridViewMarkup_Sorting(object sender, GridViewSortingEventArgs e)
466
        {
467
            IEnumerable<IKCOM.MarkupInfoItem> markuplist = e.DataControl.ItemsSource as IEnumerable<IKCOM.MarkupInfoItem>;
468

    
469
            if(markuplist == null)
470
            {
471
                e.Cancel = true;
472
                return;
473
            }
474

    
475
            if(e.NewSortingState == SortingState.None)
476
            {
477
                markuplist = markuplist.OrderByDescending(x => SortIndex(x))
478
                                            .ThenBy(x => x.Depatment)
479
                                            .ThenBy(x => x.UserID);
480

    
481
                e.DataControl.ItemsSource = markuplist.ToList();
482
            }
483
        }
484

    
485

    
486
        // 마크업 리스트 정렬
487
        private int SortIndex(IKCOM.MarkupInfoItem markupInfoItem)
488
        {
489
            int result = 0;
490

    
491
            // Consolidate은 최상단
492
            if (markupInfoItem.Consolidate == 1)
493
            {
494
                result += 2;
495
            }
496

    
497
            /// Consolidate 다음으로 우선순위
498
            if (markupInfoItem.UserID == App.ViewInfo.UserID)
499
            {
500
                result += 1;
501
            }
502

    
503
            return result;
504
        }
505

    
506

    
507
        private void GridViewMarkup_Sorted(object sender, GridViewSortedEventArgs e)
508
        {
509

    
510
        }
511

    
512
        private async void gridViewRevMarkup_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
513
        {
514
            List<MarkupInfoItem> gridSelectionItem = gridViewRevMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
515
            //if (ViewerDataModel.Instance.PageBalanceNumber == 0)
516
            //{
517
            //    ViewerDataModel.Instance.PageBalanceNumber = 1;
518
            //}
519

    
520
            if (ViewerDataModel.Instance.PageNumber == 0)
521
            {
522
                ViewerDataModel.Instance.PageNumber = 1;
523
            }
524
            if (e.AddedItems.Count() > 0)
525
            {
526
                foreach (var item in gridSelectionItem)
527
                {
528
                    //item.MarkupList.Where(pageItem => pageItem.PageNumber == ViewerDataModel.Instance.PageBalanceNumber).ToList().ForEach(delegate (MarkupItem markupitem)
529
                    //{
530
                    //    layerControl.markupParse(markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_Sync, item.DisplayColor, "", item.MarkupInfoID);
531
                    //});
532

    
533
                    var pageItems = item.MarkupList.Where(pageItem => pageItem.PageNumber == ViewerDataModel.Instance.PageNumber).ToList();
534

    
535
                    foreach (var markupitem in pageItems)
536
                    {
537
                       await MarkupParser.ParseExAsync(App.ViewInfo.ProjectNO, markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_Sync, item.DisplayColor, "", item.MarkupInfoID);
538
                    }
539
                }
540
            }
541
            else if (e.RemovedItems.Count > 0)
542
            {
543
                var _infoItem = e.RemovedItems.Cast<MarkupInfoItem>().ToList();
544

    
545
                (from A in _infoItem
546
                 from B in Common.ViewerDataModel.Instance.MarkupControls_Sync
547
                 where A.MarkupInfoID == B.MarkupInfoID
548
                 select B).ToList().ForEach(data =>
549
                 {
550
                     Common.ViewerDataModel.Instance.MarkupControls_Sync.Remove(data);
551
                 });
552
            }
553
        }
554

    
555
        /// <summary>
556
        /// 선택한 항목은 Visibility = Visible, 해제한 항목은 Visibility = Hidden 처리한다.
557
        /// </summary>
558
        /// <param name="sender"></param>
559
        /// <param name="e"></param>
560
        private async void gridViewMarkup_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
561
        {
562
            SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
563

    
564
            var dataSet = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
565
            var dataSet_User = gridViewMarkup.Items.Cast<MarkupInfoItem>().Where(data => data.UserID == _ViewInfo.UserID);
566
            var resultA = (from item_Select in dataSet
567
                           from item_Non in dataSet_User
568
                           where item_Select == item_Non
569
                           select item_Non).ToList();
570

    
571
            if (resultA.Count() >= 2)
572
            {
573
                // 동일한 사용자 데이터가 두개 이상 선택됩니다. Consolidation을 선택할까요?
574
                RadWindow.Confirm(new DialogParameters
575
                {
576
                    Owner = Application.Current.MainWindow,
577
                    Header = "Info",
578
                    Content = "Selected more than two identical user data. Do you want to select consolidation?",
579
                    Closed = new EventHandler<WindowClosedEventArgs>((sen, ea) =>
580
                    {
581
                        if (e.AddedItems.Count() == 1)
582
                        {
583
                            MarkupInfoItem instanceItem = e.AddedItems.FirstOrDefault() as MarkupInfoItem;
584
                            gridViewMarkup.SelectedItem = null;
585

    
586
                        
587
                            if (ea.DialogResult.Value)
588
                            {
589
                                if (instanceItem.Consolidate == 1 || instanceItem.PartConsolidate == 1)
590
                                {
591
                                    gridViewMarkup.SelectedItem = instanceItem;
592
                                }
593
                                else
594
                                {
595
                                    //1. Consolidations이 있다면 하나 선택
596
                                    var Consolidations = resultA.Where(item => (item.Consolidate == 1 || item.PartConsolidate == 1));
597

    
598
                                    if (Consolidations.Count() > 0)
599
                                    {
600
                                        gridViewMarkup.SelectedItem = Consolidations.First();
601
                                    }
602
                                }
603
                              
604
                            }
605
                            else {
606
                                //1. Consolidations 아닌게 있다면 Change
607
                                var notConsolidations = resultA.Where(item => !(item.Consolidate == 1 || item.PartConsolidate == 1));
608

    
609
                                if(notConsolidations.Count() > 0) {
610
                                    gridViewMarkup.SelectedItem = notConsolidations.First();
611
                                }
612
                                else {//1. Consolidations 아닌게 없다면 그대로
613
                                    gridViewMarkup.SelectedItem = instanceItem;
614
                                }
615
                                
616
                            }
617
                        }
618
                    }),
619
                    Theme = new Windows8Theme(),
620
                    ModalBackground = new System.Windows.Media.SolidColorBrush { Color = System.Windows.Media.Colors.Black, Opacity = 0.6 },
621
                });
622
            }
623
            else //파라미터로 넘어온 사용자가 걸리지 않은 경우
624
            {
625
                List<MarkupInfoItem> gridItem = gridViewMarkup.Items.Cast<MarkupInfoItem>().ToList(); //전체 마크업
626
                List<MarkupInfoItem> gridSelectionItem = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
627
                List<MarkupInfoItem> gridNonSelectionItem = gridItem.Except(gridSelectionItem).ToList(); //선택 되지 않은 마크업
628
                #region 코멘트 보기
629
                if (e.AddedItems.Count() > 0 && this.pageNavigator.CurrentPage != null)
630
                {
631
                    foreach (var item in gridSelectionItem)
632
                    {
633
                        if (item.UserID == App.ViewInfo.UserID)
634
                        {
635
                            var controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
636
                            if (controls.Count == 0)
637
                            {
638
                                var instance = ViewerDataModel.Instance.MyMarkupList.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
639

    
640
                                foreach (var markup in instance)
641
                                {
642
                                    await MarkupParser.ParseExAsync(App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, item.DisplayColor, "", 
643
                                        item.MarkupInfoID, markup.ID);
644
                                }
645
                            }
646

    
647
                            controls = Common.ViewerDataModel.Instance.MarkupControls_USER.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
648
                            foreach (var control in controls)
649
                            {
650
                                Logger.sendCheckLog(String.Format("=={0}", control), 1);
651
                                control.Visibility = Visibility.Visible;
652
                            }
653
                        }
654
                        else
655
                        {
656
                            var controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
657
                            if (controls.Count == 0)
658
                            {
659
                                var instance = ViewerDataModel.Instance.MarkupList_Pre.Where(d => d.PageNumber == this.pageNavigator.CurrentPage.PageNumber && d.MarkupInfoID == item.MarkupInfoID).ToList();
660
                                foreach (var markup in instance)
661
                                {
662
                                    await MarkupParser.ParseExAsync(App.ViewInfo.ProjectNO, markup.Data, Common.ViewerDataModel.Instance.MarkupControls, item.DisplayColor, "",
663
                                        item.MarkupInfoID, markup.ID);
664
                                }
665
                            }
666

    
667
                            controls = Common.ViewerDataModel.Instance.MarkupControls.Where(d => d.MarkupInfoID == item.MarkupInfoID).ToList();
668
                            foreach (var control in controls)
669
                            {
670
                                control.Visibility = Visibility.Visible;
671
                            }
672
                        }
673
                    }
674
                }
675
                #endregion
676
                #region 코멘트 숨기기
677
                else if (e.RemovedItems.Count > 0)
678
                {
679
                    var _infoItem = e.RemovedItems.Cast<MarkupInfoItem>().ToList();
680

    
681
                    (from A in _infoItem
682
                     from B in Common.ViewerDataModel.Instance.MarkupControls
683
                     where A.MarkupInfoID == B.MarkupInfoID
684
                     select B).ToList().ForEach(data =>
685
                     {
686
                         data.Visibility = Visibility.Hidden;                         
687
                     });
688

    
689

    
690
                    var myComment = _infoItem.Where(d => d.UserID == App.ViewInfo.UserID).FirstOrDefault();
691
                    if (myComment != null)
692
                    {
693
                        Common.ViewerDataModel.Instance.MarkupControls_USER.ToList().ForEach(delegate (MarkupToPDF.Common.CommentUserInfo markupitem)
694
                        {
695
                            markupitem.Visibility = Visibility.Hidden;
696
                        });
697
                    }
698
                }
699
                #endregion
700
            }
701
        }
702

    
703
        private void BaseClient_GetDocumentItemInfoCompleted(object sender, GetDocumentItemInfoCompletedEventArgs e)
704
        {
705
            Logger.sendResLog("GetDocumentItemInfoCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
706

    
707
            if (e.Result != null)
708
            {
709
                _DocItem = e.Result;
710

    
711
                if (e.Result.DOCUMENT_NO == "" && e.Result.DOCUMENT_NAME == "" && e.Result.GROUP_NO == "0")
712
                {
713
                    //장원
714
                    _ViewInfo.UserID = _ViewInfo.UserID.Replace(@"DAELIM\", "");
715
                }
716
                Logger.sendReqLog("GetDocInfoAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
717
                BaseClient.GetDocInfoAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
718
            }
719
            else
720
            {
721
                DialogMessage_Alert("Document Information Not Found.", "Error");
722

    
723
                BaseClient.GetCheckSystemAdminCompleted += (sen, ea) =>
724
                {
725
                    Logger.sendResLog("GetCheckSystemAdminCompleted", "UserState : " + ea.UserState + "\r Result :" + ea.Result + "\r Cancelled :" + ea.Cancelled + "\r Error :" + ea.Error, 1);
726

    
727
                    if (ea.Error == null)
728
                    {
729
                        if (ea.Result)
730
                        {
731
                            this._ViewInfo.isAdmin = true;
732
                            Logger.sendReqLog("GetDocInfoAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
733
                            BaseClient.GetDocInfoAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
734
                        }
735
                        else
736
                        {
737
                            //System.Windows.Forms.MessageBox.Show("해당 프로젝트에 가입되지 않은 유저입니다. 관리자에게 등록신청을 해주세요", "안내");
738
                            DialogMessage_Alert("You are not belong to this project. Please ask admin for an authority.", "Info");
739
                            //this.ParentOfType<MainPage>().DialogMessage_Alert("해당 프로젝트에 가입되지 않은 유저입니다. 관리자에게 등록신청을 해주세요", "안내");
740
                        }
741

    
742
                    }
743
                    else
744
                    {
745
                        //System.Windows.Browser.HtmlPage.Window.Invoke("close");
746
                    }
747
                };
748
                Logger.sendReqLog("GetCheckSystemAdminAsync", _ViewInfo.UserID, 1);
749
                BaseClient.GetCheckSystemAdminAsync(this._ViewInfo.UserID);
750
            }
751
        }
752

    
753
        private void BaseClient_GetSystemDataCompleted(object sender, GetSystemDataCompletedEventArgs e)
754
        {
755
            Logger.sendResLog("GetSystemDataCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
756

    
757
            if (e.Error == null && e.Result != null)
758
            {
759
                App.SystemInfo = e.Result;
760

    
761
                //App.urlPort_DB = App.SystemInfo.HostPort;
762
                //App.urlHost_DB = App.SystemInfo.HostName;
763
                Logger.sendReqLog("GetConversionStateAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID, 1);
764
                BaseClient.GetConversionStateAsync(new KCOM_BasicParam { projectNo = _ViewInfo.ProjectNO, documentID = _ViewInfo.DocumentItemID });
765

    
766
                //if (App.urlHost.Contains("localhost"))
767
                //{
768
                //    App.urlHost = App.urlHost_DB;
769
                //}
770
            }
771
        }
772

    
773
        private void BaseClient_GetConversionStateCompleted(object sender, GetConversionStateCompletedEventArgs e)
774
        {
775
            
776
            Logger.sendResLog("GetConversionStateCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
777
            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잠시만 기다려 주신 후 다시 열람하여 주시기 바랍니다");
778
            if (e.Error == null && e.Result == true)
779
            {
780
                Logger.sendReqLog("GetDocumentItemInfoAsync", _ViewInfo.ProjectNO + "," + _ViewInfo.DocumentItemID + "," + _ViewInfo.UserID, 1);
781

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

    
784
                if (App.ViewInfo != null && App.ViewInfo.ProjectNO != "")
785
                {
786
                    Logger.sendReqLog("GetMember", _ViewInfo.ProjectNO + "," + _ViewInfo.UserID, 1);
787
                    userData = BaseClient.GetMember(App.ViewInfo.ProjectNO, App.ViewInfo.UserID);
788
                    if (userData != null)
789
                    {
790
                        Logger.sendReqLog("GetDeptDataAsync", userData.DEPARTMENT, 1);
791
                        BaseClient.GetDeptDataAsync(userData.DEPARTMENT);
792
                    }
793
                    else
794
                    {
795
                        userData = new MEMBER();
796
                        userData.DEPARTMENT = "ALL";
797
                        Logger.sendReqLog("GetDeptDataAsync", userData.DEPARTMENT, 1);
798
                        BaseClient.GetDeptDataAsync(userData.DEPARTMENT);
799
                    }
800
                }
801
            }
802
            else
803
            {
804
                
805
                DialogMessage_Alert(failedmsg, "Warning");
806
            }
807
        }
808

    
809
        public void SetView(ViewInfo info)
810
        { 
811
            this._ViewInfo = info;
812
            try
813
            {
814
                /// 대림의 경우 EnsembleID를 가지고 DocumentItemID를 구함
815
                /// 다른 Site를 대비하여 에러 처리함
816
                string docid = BaseClient.GetDocItemID(info.EnsembleID);
817
                if (!string.IsNullOrEmpty(docid))
818
                {
819
                    this._ViewInfo.DocumentItemID = docid;
820
                }
821
            }
822
            catch(Exception ex)
823
            {
824
                App.FileLogger.Fatal(ex);
825
            }
826

    
827
            Logger.sendReqLog("GetSystemDataAsync", "", 1);
828
            BaseClient.GetSystemDataAsync();
829
        }
830

    
831
        public void HubSet()
832
        {
833
            // 허브 연결 구성
834
            var hubConnection = new HubConnection(CommonLib.Common.GetConfigString("HubAddress", "URL", "", App.isExternal));
835
            IHubProxy MarkusLicenseProxy = hubConnection.CreateHubProxy("MarkusLicenseHub");
836

    
837

    
838
            // 허브 연결 
839
            hubConnection.Start().ContinueWith(task =>
840
            {
841
                if (task.IsFaulted)
842
                {
843
                    Console.WriteLine("There was an error opening the connection:{0}",
844
                                      task.Exception.GetBaseException());
845
                    //throw task.Exception.GetBaseException();
846
                }
847
                else
848
                {
849
                    Console.WriteLine("Connected :: " + task.Id);
850
                }
851

    
852
            }).Wait();
853

    
854

    
855
            // [ 프로그램 시작 ]
856
            // 클라이언트에서 서버를 호출 ( 접속 시 )  : 라이센스 체크
857
            //( "method name", arg1, arg2 )
858
            //MarkusLicenseProxy.Invoke<string>("ConnectionMarkus", "H2009115", "고동균").ContinueWith(task =>
859
            //{
860
            //    if (task.IsFaulted)
861
            //    {
862
            //        Console.WriteLine("ConnectionMarkus :: There was an error calling send: {0}", task.Exception.GetBaseException());
863
            //    }
864
            //    else
865
            //    {
866
            //        Console.WriteLine(task.Result);
867
            //    }
868
            //});
869
            MarkusLicenseProxy.Invoke<string>("ConnectionMarkus", App.ViewInfo.UserID,App.ViewInfo.ProjectNO).ContinueWith(task =>
870
            {
871
                if (task.IsFaulted)
872
                {
873
                    Console.WriteLine("ConnectionMarkus :: There was an error calling send: {0}", task.Exception.GetBaseException());
874
                    //throw task.Exception.GetBaseException();
875
                }
876
                else
877
                {
878
                    switch (task.Result)
879
                    {
880
                        case "2":
881
                            {
882
                                var result = MessageBox.Show("권한이 없습니다.");
883
                                if (result == MessageBoxResult.OK)
884
                                    System.Diagnostics.Process.GetCurrentProcess().Kill();
885
                            }
886
                            break;
887
                        case "404":
888
                            {
889
                                var result = MessageBox.Show("등록된 사용자가 아닙니다.");
890
                                if(result == MessageBoxResult.OK)
891
                                    System.Diagnostics.Process.GetCurrentProcess().Kill();
892
                            }
893
                            break;
894
                    }
895
                }
896
            });
897

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

    
902
            //    if (status)
903
            //    {
904
            //        // 프로그램 시작 
905
            //        Console.WriteLine("connection status : " + status);
906
            //    }
907
            //    else
908
            //    {
909
            //        // 프로그램 종료 ( signalr 접속 끊기 )  
910
            //        hubConnection.Stop();
911
            //    }
912
            //});
913

    
914
            // 공지 메세지 ( 서버에서 클라이언트 호출 ) 
915
            MarkusLicenseProxy.On<string>("MarkusNotification", msg =>
916
                Console.WriteLine("Noficiation Message : " + msg)
917
            );
918

    
919

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

    
923
            //Console.ReadKey();
924

    
925
            //hubConnection.Stop();
926
        }
927

    
928
        public async void MarkupUserListDisplay()
929
        {
930
            List<MarkupInfoItem> gridItem = gridViewMarkup.Items.Cast<MarkupInfoItem>().ToList(); //전체 마크업
931
            List<MarkupInfoItem> gridSelectionItem = gridViewMarkup.SelectedItems.Cast<MarkupInfoItem>().ToList(); //선택 된 마크업
932
            List<MarkupInfoItem> gridNonSelectionItem = gridItem.Except(gridSelectionItem).ToList(); //선택 되지 않은 마크업
933
                                                                                                     //MarkupToPDF.Controls.Parsing.LayerControl layerControl = new MarkupToPDF.Controls.Parsing.LayerControl();
934
            Common.ViewerDataModel.Instance.MarkupControls_USER.Clear();  //전체 제거
935
            Common.ViewerDataModel.Instance.MarkupControls.Clear();  //전체 제거
936
            //foreach (var item in gridSelectionItem)
937
            //{
938
            //    if (item.UserID == App.ViewInfo.UserID)
939
            //    {
940
            //        ViewerDataModel.Instance.MyMarkupList.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList().ForEach(delegate (MarkupItemEx markupitem)
941
            //        {
942
            //            layerControl.markupParseEx(markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, item.DisplayColor, "", item.MarkupInfoID, markupitem.ID);
943
            //        });
944
            //    }
945
            //    else
946
            //    {
947
            //        ViewerDataModel.Instance.MarkupList_Pre.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList().ForEach(delegate (MarkupItemEx markupitem)
948
            //        {
949
            //            layerControl.markupParse(markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls, item.DisplayColor, "", item.MarkupInfoID);
950
            //        });
951
            //    }
952
            //}
953
                (from A in gridSelectionItem
954
                 from B in Common.ViewerDataModel.Instance.MarkupControls_USER
955
                 where A.MarkupInfoID == B.MarkupInfoID
956
                 select B).ToList().ForEach(data =>
957
                 {
958
                     Common.ViewerDataModel.Instance.MarkupControls_USER.Remove(data);
959
                 });
960
            (from A in gridSelectionItem
961
             from B in Common.ViewerDataModel.Instance.MarkupControls
962
             where A.MarkupInfoID == B.MarkupInfoID
963
             select B).ToList().ForEach(data =>
964
             {
965
                 Common.ViewerDataModel.Instance.MarkupControls.Remove(data);
966
             });
967

    
968
            foreach (var item in gridSelectionItem)
969
            {
970

    
971
                if (item.UserID == App.ViewInfo.UserID)
972
                {
973
                    var markupItems = ViewerDataModel.Instance.MyMarkupList.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList();
974

    
975
                    foreach (var markupitem in markupItems)
976
                    {
977
                        await MarkupParser.ParseExAsync(App.ViewInfo.ProjectNO, markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls_USER, item.DisplayColor, "", 
978
                                item.MarkupInfoID, markupitem.ID);
979
                    }
980
                }
981
                else
982
                {
983
                    var markupItems = ViewerDataModel.Instance.MarkupList_Pre.Where(data => data.PageNumber == pageNavigator.CurrentPage.PageNumber && data.MarkupInfoID == item.MarkupInfoID).ToList();
984

    
985
                    foreach (var markupitem in markupItems)
986
                    {
987
                        await MarkupParser.ParseExAsync(App.ViewInfo.ProjectNO, markupitem.Data, Common.ViewerDataModel.Instance.MarkupControls, item.DisplayColor, "", item.MarkupInfoID);
988
                    }
989
                }
990
            }
991
        }
992
    }
993
}
클립보드 이미지 추가 (최대 크기: 500 MB)