프로젝트

일반

사용자정보

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

markus / KCOM / Common / DataSaveTask.cs @ 3b938959

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

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.ServiceModel.Security;
5
using System.Text;
6
using System.Threading.Tasks;
7
using System.Windows.Input;
8
using KCOM.KcomService;
9
using KCOMDataModel.DataModel;
10

    
11
namespace KCOM.Common
12
{
13
    public class DataSaveTask : IDisposable
14
    {
15
        private KcomService.ServiceDeepViewClient DeepViewTaskClient;
16
        private Views.MainMenu mainMenu;
17

    
18
        private TimeSpan _Interval;
19

    
20
        public TimeSpan Interval { get => _Interval; set => _Interval = value; }
21

    
22
        private bool _IsEnabled;
23

    
24
        public bool IsEnabled
25
        {
26
            get => _IsEnabled;
27

    
28
            set
29
            {
30
                if(_IsEnabled != value)
31
                {
32
                    _IsEnabled = value;
33

    
34
                    if (_IsEnabled)
35
                    {
36
                       Start();
37
                    }
38
                }
39
            }
40
        }
41

    
42

    
43
        public DataSaveTask()
44
        {
45
            if (DeepViewTaskClient == null)
46
            {
47
                DeepViewTaskClient = new ServiceDeepViewClient(App._binding, App._EndPoint);
48
                //DeepViewTaskClient.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication();
49
                //DeepViewTaskClient.ClientCredentials.ServiceCertificate.SslCertificateAuthentication.CertificateValidationMode = X509CertificateValidationMode.None;
50
            }
51

    
52
            this.Interval = new TimeSpan(0,0,10);
53
        }
54

    
55
        public DataSaveTask(TimeSpan interval, bool enable)
56
        {
57
            if (DeepViewTaskClient == null)
58
            {
59
                DeepViewTaskClient = new ServiceDeepViewClient(App._binding, App._EndPoint);
60
            }
61

    
62
            this.Interval = interval;
63
            this.IsEnabled = enable;
64
        }
65

    
66
        /// <summary>
67
        /// 자동 저장 작업
68
        /// </summary>
69
        public async void Start()
70
        {
71
            while (IsEnabled)
72
            {
73
                if (ViewerDataModel.Instance?.SystemMain?.dzMainMenu != null)
74
                {
75
                    mainMenu = ViewerDataModel.Instance.SystemMain.dzMainMenu;
76

    
77
                    if (mainMenu.gridViewMarkup.SelectedItems.Count > 0)
78
                    {
79
                        if (mainMenu.currentControl == null)// && mainMenu.SelectLayer.Children.Count == 0)
80
                        {
81
                            var result = await AutoSaveTaskAsync(mainMenu);
82

    
83
                            if (result)
84
                            {
85
                                // log
86
                            }
87
                            else
88
                            {
89
                                // log
90
                            }
91
                        }
92
                    }
93
                }
94

    
95
                await Task.Delay(Interval);
96
            }
97
        }
98

    
99
        private async Task<bool> AutoSaveTaskAsync(Views.MainMenu mainMenu)
100
        {
101
            bool result = false;
102

    
103
            mainMenu.ConvertInkControlToPolygon();
104

    
105
            //SelectionSet.Instance.UnSelect(mainMenu);
106
            // update mylist and gridview
107

    
108
            mainMenu.UpdateMyMarkupList();
109

    
110
            /// 현재 사용자의 선택된 마크업(현재 수정중인 마크업)만 저장하도록 한다.
111
            var saveItems = mainMenu.gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>().Where(x => x.UserID == App.ViewInfo.UserID).ToList();
112

    
113
            result = await SaveProcessTaskAsync(saveItems);
114

    
115
            if (result)
116
            {
117
                //Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.gridViewMarkup.Rebind();
118

    
119
                saveItems.ForEach(x =>
120
                {
121
                    var item = ViewerDataModel.Instance._markupInfoList.Where(data => data.MarkupInfoID == x.MarkupInfoID);
122

    
123
                    if (item.Count() > 0)
124
                    {
125
                        item.First().UpdateTime = DateTime.Now;
126
                    }
127
                });
128
            }
129

    
130
            //ViewerDataModel.Instance.UndoDataList.Clear();
131

    
132
            return result;
133
        }
134

    
135
        private async Task<bool> SaveProcessTaskAsync(ICollection<IKCOM.MarkupInfoItem> UserStates)
136
        {
137
            bool result = false;
138

    
139
            try
140
            {
141
                string project_no = App.ViewInfo.ProjectNO;
142
                string doc_id = App.ViewInfo.DocumentItemID;
143
                string user_id = App.ViewInfo.UserID;
144
                int currentPageNo = ViewerDataModel.Instance.SyncPageNumber;
145

    
146
                foreach (var UserState in UserStates)
147
                {
148
                    bool IsSuccess = false;
149
                    List <MARKUP_DATA> markupdata = new List<MARKUP_DATA>();
150

    
151
                    //markupdata = UserState.MarkupList.Select(x=>
152
                    //    new MARKUP_DATA()
153
                    //    {
154
                    //        ID = x.ID,
155
                    //        PAGENUMBER = x.PageNumber,
156
                    //        DATA = x.Data,
157
                    //        MARKUPINFO_VERSION_ID = UserState.MarkupVersionID,
158
                    //        DATA_TYPE = x.Data_Type
159
                    //    }
160
                    //).ToList();
161

    
162
                    var updateItems = ViewerDataModel.Instance.MyMarkupList
163
                                    .Where(d => d.MarkupInfoID == UserState.MarkupInfoID && d.PageNumber == currentPageNo)
164
                                    .GroupBy(p => p.ID).Select(g => g.First()).ToList();
165

    
166
                    if (updateItems.Count() > 0)
167
                    {
168
                        updateItems.ForEach(value =>
169
                        {
170
                            markupdata.Add(new MARKUP_DATA()
171
                            {
172
                                ID = value.ID,
173
                                PAGENUMBER = value.PageNumber,
174
                                DATA = value.Data,
175
                                MARKUPINFO_VERSION_ID = UserState.MarkupVersionID,
176
                                DATA_TYPE = value.Data_Type
177
                            });
178
                        });
179

    
180
                        IsSuccess = await DeepViewTaskClient.SavePageMarkupDataAsync(UserState,currentPageNo, project_no, doc_id, user_id, markupdata);
181

    
182
                        System.Diagnostics.Debug.WriteLine($"SaveProcessTaskAsync Project : {project_no} DocID :{doc_id} User ID {user_id} result {IsSuccess}");
183
                        //Logger.sendResLog("SaveProcessTaskAsync", $" Project : {project_no} DocID :{doc_id} User ID {user_id} result {IsSuccess}", 1);
184
                    }
185
                    else
186
                    {
187
                        IsSuccess = true;
188
                        System.Diagnostics.Debug.WriteLine($"SaveProcessTaskAsync Project : {project_no} DocID :{doc_id} User ID {user_id} Item = 0");
189
                    }
190

    
191

    
192
                    if (!IsSuccess)
193
                    {
194
                        result = false;
195
                        break;
196
                    }
197
                    else
198
                    {
199
                        result = true;
200
                        //Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.MarkupitemViewUpdate(UserState.MarkupInfoID);
201
                    }
202
                }
203

    
204
            }
205
            catch (Exception ex)
206
            {
207
                System.Diagnostics.Debug.WriteLine($"SaveProcessTaskAsync Error {ex.ToString()}");
208

    
209
                //Logger.sendResLog("SaveProcessTaskAsync", ex.Message, 1);
210
            }
211

    
212
            return result;
213
        }
214

    
215
        public void Dispose()
216
        {
217
            DeepViewTaskClient = null;
218
        }
219
    }
220
}
클립보드 이미지 추가 (최대 크기: 500 MB)