markus / KCOM / Common / DataSaveTask.cs @ d7e20d2d
이력 | 보기 | 이력해설 | 다운로드 (7.15 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
using System.Windows.Input; |
7 |
using KCOM.KcomService; |
8 |
using KCOMDataModel.DataModel; |
9 |
|
10 |
namespace KCOM.Common |
11 |
{ |
12 |
public class DataSaveTask : IDisposable |
13 |
{ |
14 |
private KcomService.ServiceDeepViewClient DeepViewTaskClient; |
15 |
private Views.MainMenu mainMenu; |
16 |
|
17 |
private TimeSpan _Interval; |
18 |
|
19 |
public TimeSpan Interval { get => _Interval; set => _Interval = value; } |
20 |
|
21 |
private bool _IsEnabled; |
22 |
|
23 |
public bool IsEnabled |
24 |
{ |
25 |
get => _IsEnabled; |
26 |
|
27 |
set |
28 |
{ |
29 |
if(_IsEnabled != value) |
30 |
{ |
31 |
_IsEnabled = value; |
32 |
|
33 |
if (_IsEnabled) |
34 |
{ |
35 |
Start(); |
36 |
} |
37 |
} |
38 |
} |
39 |
} |
40 |
|
41 |
|
42 |
public DataSaveTask() |
43 |
{ |
44 |
if (DeepViewTaskClient == null) |
45 |
{ |
46 |
DeepViewTaskClient = new ServiceDeepViewClient(App._binding, App._EndPoint); |
47 |
} |
48 |
|
49 |
this.Interval = new TimeSpan(0,0,10); |
50 |
} |
51 |
|
52 |
public DataSaveTask(TimeSpan interval, bool enable) |
53 |
{ |
54 |
if (DeepViewTaskClient == null) |
55 |
{ |
56 |
DeepViewTaskClient = new ServiceDeepViewClient(App._binding, App._EndPoint); |
57 |
} |
58 |
|
59 |
this.Interval = interval; |
60 |
this.IsEnabled = enable; |
61 |
} |
62 |
|
63 |
/// <summary> |
64 |
/// 자동 저장 작업 |
65 |
/// </summary> |
66 |
public async void Start() |
67 |
{ |
68 |
while (IsEnabled) |
69 |
{ |
70 |
if (ViewerDataModel.Instance?.SystemMain?.dzMainMenu != null) |
71 |
{ |
72 |
mainMenu = ViewerDataModel.Instance.SystemMain.dzMainMenu; |
73 |
|
74 |
if (mainMenu.gridViewMarkup.SelectedItems.Count > 0) |
75 |
{ |
76 |
if (mainMenu.currentControl == null)// && mainMenu.SelectLayer.Children.Count == 0) |
77 |
{ |
78 |
var result = await AutoSaveTaskAsync(mainMenu); |
79 |
|
80 |
if (result) |
81 |
{ |
82 |
// log |
83 |
} |
84 |
else |
85 |
{ |
86 |
// log |
87 |
} |
88 |
} |
89 |
} |
90 |
} |
91 |
|
92 |
await Task.Delay(Interval); |
93 |
} |
94 |
} |
95 |
|
96 |
private async Task<bool> AutoSaveTaskAsync(Views.MainMenu mainMenu) |
97 |
{ |
98 |
bool result = false; |
99 |
|
100 |
mainMenu.ConvertInkControlToPolygon(); |
101 |
|
102 |
//SelectionSet.Instance.UnSelect(mainMenu); |
103 |
// update mylist and gridview |
104 |
|
105 |
mainMenu.UpdateMyMarkupList(); |
106 |
|
107 |
/// 현재 사용자의 선택된 마크업(현재 수정중인 마크업)만 저장하도록 한다. |
108 |
var saveItems = mainMenu.gridViewMarkup.SelectedItems.Cast<IKCOM.MarkupInfoItem>().Where(x => x.UserID == App.ViewInfo.UserID).ToList(); |
109 |
|
110 |
result = await SaveProcessTaskAsync(saveItems); |
111 |
|
112 |
if (result) |
113 |
{ |
114 |
//Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.gridViewMarkup.Rebind(); |
115 |
|
116 |
saveItems.ForEach(x => |
117 |
{ |
118 |
var item = ViewerDataModel.Instance._markupInfoList.Where(data => data.MarkupInfoID == x.MarkupInfoID); |
119 |
|
120 |
if (item.Count() > 0) |
121 |
{ |
122 |
item.First().UpdateTime = DateTime.Now; |
123 |
} |
124 |
}); |
125 |
} |
126 |
|
127 |
//ViewerDataModel.Instance.UndoDataList.Clear(); |
128 |
|
129 |
return result; |
130 |
} |
131 |
|
132 |
private async Task<bool> SaveProcessTaskAsync(ICollection<IKCOM.MarkupInfoItem> UserStates) |
133 |
{ |
134 |
bool result = false; |
135 |
|
136 |
try |
137 |
{ |
138 |
string project_no = App.ViewInfo.ProjectNO; |
139 |
string doc_id = App.ViewInfo.DocumentItemID; |
140 |
string user_id = App.ViewInfo.UserID; |
141 |
int currentPageNo = ViewerDataModel.Instance.PageNumber; |
142 |
|
143 |
foreach (var UserState in UserStates) |
144 |
{ |
145 |
bool IsSuccess = false; |
146 |
List <MARKUP_DATA> markupdata = new List<MARKUP_DATA>(); |
147 |
|
148 |
//markupdata = UserState.MarkupList.Select(x=> |
149 |
// new MARKUP_DATA() |
150 |
// { |
151 |
// ID = x.ID, |
152 |
// PAGENUMBER = x.PageNumber, |
153 |
// DATA = x.Data, |
154 |
// MARKUPINFO_VERSION_ID = UserState.MarkupVersionID, |
155 |
// DATA_TYPE = x.Data_Type |
156 |
// } |
157 |
//).ToList(); |
158 |
|
159 |
var updateItems = ViewerDataModel.Instance.MyMarkupList |
160 |
.Where(d => d.MarkupInfoID == UserState.MarkupInfoID && d.PageNumber == currentPageNo) |
161 |
.GroupBy(p => p.ID).Select(g => g.First()).ToList(); |
162 |
|
163 |
if (updateItems.Count() > 0) |
164 |
{ |
165 |
updateItems.ForEach(value => |
166 |
{ |
167 |
markupdata.Add(new MARKUP_DATA() |
168 |
{ |
169 |
ID = value.ID, |
170 |
PAGENUMBER = value.PageNumber, |
171 |
DATA = value.Data, |
172 |
MARKUPINFO_VERSION_ID = UserState.MarkupVersionID, |
173 |
DATA_TYPE = value.Data_Type |
174 |
}); |
175 |
}); |
176 |
|
177 |
IsSuccess = await DeepViewTaskClient.SavePageMarkupDataAsync(UserState,currentPageNo, project_no, doc_id, user_id, markupdata); |
178 |
|
179 |
System.Diagnostics.Debug.WriteLine($"SaveProcessTaskAsync Project : {project_no} DocID :{doc_id} User ID {user_id} result {IsSuccess}"); |
180 |
Logger.sendResLog("SaveProcessTaskAsync", $" Project : {project_no} DocID :{doc_id} User ID {user_id} result {IsSuccess}", 1); |
181 |
} |
182 |
else |
183 |
{ |
184 |
IsSuccess = true; |
185 |
System.Diagnostics.Debug.WriteLine($"SaveProcessTaskAsync Project : {project_no} DocID :{doc_id} User ID {user_id} Item = 0"); |
186 |
} |
187 |
|
188 |
|
189 |
if (!IsSuccess) |
190 |
{ |
191 |
result = false; |
192 |
break; |
193 |
} |
194 |
else |
195 |
{ |
196 |
result = true; |
197 |
//Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.MarkupitemViewUpdate(UserState.MarkupInfoID); |
198 |
} |
199 |
} |
200 |
|
201 |
} |
202 |
catch (Exception ex) |
203 |
{ |
204 |
System.Diagnostics.Debug.WriteLine($"SaveProcessTaskAsync Error {ex.ToString()}"); |
205 |
|
206 |
Logger.sendResLog("SaveProcessTaskAsync", ex.Message, 1); |
207 |
} |
208 |
|
209 |
return result; |
210 |
} |
211 |
|
212 |
public void Dispose() |
213 |
{ |
214 |
DeepViewTaskClient = null; |
215 |
} |
216 |
} |
217 |
} |