프로젝트

일반

사용자정보

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

markus / KCOM / Common / DataSaveTask.cs @ 5c5e04cc

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

1 6b6e937c taeseongkim
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4 3b938959 taeseongkim
using System.ServiceModel.Security;
5 6b6e937c taeseongkim
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 3b938959 taeseongkim
                //DeepViewTaskClient.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication();
49
                //DeepViewTaskClient.ClientCredentials.ServiceCertificate.SslCertificateAuthentication.CertificateValidationMode = X509CertificateValidationMode.None;
50 6b6e937c taeseongkim
            }
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 752b18ef taeseongkim
                int currentPageNo = ViewerDataModel.Instance.SyncPageNumber;
145 6b6e937c taeseongkim
146
                foreach (var UserState in UserStates)
147
                {
148
                    bool IsSuccess = false;
149
                    List <MARKUP_DATA> markupdata = new List<MARKUP_DATA>();
150
151
                    var updateItems = ViewerDataModel.Instance.MyMarkupList
152
                                    .Where(d => d.MarkupInfoID == UserState.MarkupInfoID && d.PageNumber == currentPageNo)
153 b2d0f316 humkyung
                                    .GroupBy(p => p.ID).Select(g => g.First())
154
                                    .OrderBy(x => x.ZIndex).ToList();
155
                    if (updateItems.Any())
156 6b6e937c taeseongkim
                    {
157
                        updateItems.ForEach(value =>
158
                        {
159
                            markupdata.Add(new MARKUP_DATA()
160
                            {
161
                                ID = value.ID,
162
                                PAGENUMBER = value.PageNumber,
163
                                DATA = value.Data,
164
                                MARKUPINFO_VERSION_ID = UserState.MarkupVersionID,
165
                                DATA_TYPE = value.Data_Type
166
                            });
167
                        });
168
169
                        IsSuccess = await DeepViewTaskClient.SavePageMarkupDataAsync(UserState,currentPageNo, project_no, doc_id, user_id, markupdata);
170
171
                        System.Diagnostics.Debug.WriteLine($"SaveProcessTaskAsync Project : {project_no} DocID :{doc_id} User ID {user_id} result {IsSuccess}");
172 664ea2e1 taeseongkim
                        //Logger.sendResLog("SaveProcessTaskAsync", $" Project : {project_no} DocID :{doc_id} User ID {user_id} result {IsSuccess}", 1);
173 6b6e937c taeseongkim
                    }
174
                    else
175
                    {
176
                        IsSuccess = true;
177
                        System.Diagnostics.Debug.WriteLine($"SaveProcessTaskAsync Project : {project_no} DocID :{doc_id} User ID {user_id} Item = 0");
178
                    }
179
180
181
                    if (!IsSuccess)
182
                    {
183
                        result = false;
184
                        break;
185
                    }
186
                    else
187
                    {
188
                        result = true;
189
                        //Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.MarkupitemViewUpdate(UserState.MarkupInfoID);
190
                    }
191
                }
192
193
            }
194
            catch (Exception ex)
195
            {
196
                System.Diagnostics.Debug.WriteLine($"SaveProcessTaskAsync Error {ex.ToString()}");
197
198 664ea2e1 taeseongkim
                //Logger.sendResLog("SaveProcessTaskAsync", ex.Message, 1);
199 6b6e937c taeseongkim
            }
200
201
            return result;
202
        }
203
204
        public void Dispose()
205
        {
206
            DeepViewTaskClient = null;
207
        }
208
    }
209
}
클립보드 이미지 추가 (최대 크기: 500 MB)