|
0
|
1 |
using System; |
|
|
2 |
using System.Net; |
|
|
3 |
using System.Windows; |
|
|
4 |
using System.Windows.Controls; |
|
|
5 |
using System.Windows.Documents; |
|
|
6 |
using System.Windows.Ink; |
|
|
7 |
using System.Windows.Input; |
|
|
8 |
using System.Windows.Media; |
|
|
9 |
using System.Windows.Media.Animation; |
|
|
10 |
using System.Windows.Shapes; |
|
|
11 |
using System.Windows.Data; |
|
|
12 |
using SLExtensions.Input; |
|
|
13 |
using Iri.Modernisation.BaseMVVM.Commands; |
|
|
14 |
using Iri.Modernisation.Data.Models; |
|
|
15 |
using System.Collections.Generic; |
|
|
16 |
using System.Linq; |
|
|
17 |
using Iri.Modernisation.Controls.View; |
|
39
|
18 |
using System.IO; |
|
34
|
19 |
using Iri.Modernisation.Data.LDTClass; |
|
0
|
20 |
namespace Iri.Modernisation.Controls.ViewModel |
|
|
21 |
{ |
|
|
22 |
|
|
|
23 |
/// <summary> |
|
|
24 |
/// ViewModel du module d'annotation |
|
|
25 |
/// </summary> |
|
|
26 |
public class AnnotationMakerVM : BaseMVVM.ViewModel.ViewModel |
|
|
27 |
{ |
|
25
|
28 |
|
|
|
29 |
private PolemicElement _refElement; |
|
0
|
30 |
/// <summary> |
|
|
31 |
/// Element référent |
|
|
32 |
/// </summary> |
|
|
33 |
public PolemicElement RefElement |
|
|
34 |
{ |
|
|
35 |
get |
|
|
36 |
{ |
|
|
37 |
return _refElement; |
|
|
38 |
} |
|
|
39 |
set |
|
|
40 |
{ |
|
|
41 |
_refElement = value; |
|
34
|
42 |
if(value!=null) |
|
|
43 |
{ |
|
0
|
44 |
_newAnnotation = new Annotation(((PolemicElement)value).Chapter); |
|
34
|
45 |
Title = String.Empty; |
|
|
46 |
Description = String.Empty; |
|
|
47 |
Tags = String.Empty; |
|
|
48 |
SelectedType = FactoryVideoLivre.AnnotationDescriptions[0]; |
|
28
|
49 |
BasicRelation = new PolemicLink() { FromElement = ((PolemicElement)value), ToElement = _newAnnotation, Type = null}; |
|
0
|
50 |
PolemicRelation = new PolemicLink(); |
|
|
51 |
PolemicRelation.FromElement = _newAnnotation; |
|
30
|
52 |
Begin = ((PolemicElement)value).TimerIn.TotalMilliseconds; |
|
|
53 |
End = ((PolemicElement)value).TimerOut.TotalMilliseconds; |
|
34
|
54 |
} |
|
0
|
55 |
OnPropertyChanged(String.Empty); |
|
|
56 |
//OnPropertyChanged("RefElement"); |
|
|
57 |
//OnPropertyChanged("IsControlEnable"); |
|
|
58 |
|
|
|
59 |
} |
|
|
60 |
} |
|
|
61 |
|
|
|
62 |
/// <summary> |
|
|
63 |
/// Savoir si le module de liens est activé |
|
|
64 |
/// </summary> |
|
|
65 |
public bool IsBinderActive { get; set; } |
|
25
|
66 |
/// <summary> |
|
|
67 |
/// Liste des Tags Référants |
|
|
68 |
/// </summary> |
|
0
|
69 |
public List<String> RefTags |
|
|
70 |
{ |
|
|
71 |
get |
|
|
72 |
{ |
|
|
73 |
if (_refElement != null) |
|
|
74 |
{ |
|
|
75 |
return _refElement.Tags; |
|
|
76 |
} |
|
|
77 |
else |
|
|
78 |
{ |
|
|
79 |
return new List<String>(); |
|
|
80 |
} |
|
|
81 |
} |
|
|
82 |
} |
|
|
83 |
|
|
|
84 |
/// <summary> |
|
|
85 |
/// Annotation créé |
|
|
86 |
/// </summary> |
|
|
87 |
private Annotation _newAnnotation; |
|
|
88 |
|
|
25
|
89 |
|
|
|
90 |
private TimeSpan _begin; |
|
0
|
91 |
/// <summary> |
|
|
92 |
/// Temps de début de l'annotation |
|
|
93 |
/// </summary> |
|
|
94 |
public double Begin |
|
|
95 |
{ |
|
|
96 |
get |
|
|
97 |
{ |
|
|
98 |
return _begin.TotalMilliseconds; |
|
|
99 |
} |
|
|
100 |
set |
|
|
101 |
{ |
|
|
102 |
_begin = TimeSpan.FromMilliseconds(value); |
|
|
103 |
_newAnnotation.TimerIn = TimeSpan.FromMilliseconds(value); |
|
|
104 |
OnPropertyChanged("Begin"); |
|
|
105 |
} |
|
|
106 |
} |
|
|
107 |
|
|
25
|
108 |
|
|
|
109 |
private TimeSpan _end; |
|
0
|
110 |
/// <summary> |
|
|
111 |
/// Temps de fin de l'annotation |
|
|
112 |
/// </summary> |
|
|
113 |
public double End |
|
|
114 |
{ |
|
|
115 |
get |
|
|
116 |
{ |
|
|
117 |
return _end.TotalMilliseconds; |
|
|
118 |
} |
|
|
119 |
set |
|
|
120 |
{ |
|
|
121 |
_end = TimeSpan.FromMilliseconds(value); |
|
|
122 |
_newAnnotation.TimerOut = TimeSpan.FromMilliseconds(value); |
|
|
123 |
OnPropertyChanged("End"); |
|
|
124 |
} |
|
|
125 |
} |
|
|
126 |
|
|
28
|
127 |
private PolemicTypeDescription _selectedType; |
|
0
|
128 |
/// <summary> |
|
|
129 |
/// Convertion Rectange |
|
|
130 |
/// </summary> |
|
28
|
131 |
public PolemicTypeDescription SelectedType |
|
0
|
132 |
{ |
|
|
133 |
get |
|
|
134 |
{ |
|
|
135 |
return _selectedType; |
|
|
136 |
} |
|
|
137 |
set |
|
|
138 |
{ |
|
|
139 |
_selectedType = value; |
|
28
|
140 |
OnPropertyChanged("SelectedType"); |
|
|
141 |
// Type = (PolemicElementType)((Rectangle)_selectedType).Resources["PolemicType"]; |
|
0
|
142 |
} |
|
|
143 |
} |
|
|
144 |
|
|
25
|
145 |
private String _title; |
|
0
|
146 |
/// <summary> |
|
|
147 |
/// Titre de l'annotation |
|
|
148 |
/// </summary> |
|
|
149 |
public String Title |
|
|
150 |
{ |
|
|
151 |
get |
|
42
|
152 |
{ |
|
|
153 |
if (_title != String.Empty) |
|
|
154 |
{ |
|
|
155 |
return _title; |
|
|
156 |
} |
|
|
157 |
else |
|
|
158 |
{ |
|
|
159 |
return "+Ajouter un titre"; |
|
|
160 |
|
|
|
161 |
} |
|
|
162 |
} |
|
0
|
163 |
set |
|
|
164 |
{ |
|
|
165 |
_title = value; |
|
|
166 |
_newAnnotation.Title = value; |
|
|
167 |
OnPropertyChanged("Title"); |
|
|
168 |
} |
|
|
169 |
} |
|
|
170 |
|
|
25
|
171 |
private String _description; |
|
|
172 |
|
|
0
|
173 |
/// <summary> |
|
|
174 |
/// Description de l'annotation |
|
|
175 |
/// </summary> |
|
|
176 |
public String Description |
|
|
177 |
{ |
|
|
178 |
get |
|
|
179 |
{ |
|
42
|
180 |
if(_description != String.Empty) |
|
|
181 |
{ |
|
|
182 |
return _description; |
|
|
183 |
} |
|
|
184 |
else |
|
|
185 |
{ |
|
|
186 |
return "+Ajouter Description"; |
|
|
187 |
} |
|
0
|
188 |
} |
|
|
189 |
set |
|
|
190 |
{ |
|
|
191 |
_description = value; |
|
|
192 |
_newAnnotation.Description = value; |
|
|
193 |
OnPropertyChanged("Description"); |
|
|
194 |
} |
|
|
195 |
|
|
|
196 |
} |
|
|
197 |
|
|
|
198 |
/// <summary> |
|
|
199 |
/// Tags de l'annotation |
|
|
200 |
/// </summary> |
|
|
201 |
public List<String> _tags =new List<String>(); |
|
25
|
202 |
/// <summary> |
|
|
203 |
/// Tags de l'annotation |
|
|
204 |
/// </summary> |
|
0
|
205 |
public String Tags |
|
|
206 |
{ |
|
|
207 |
get |
|
|
208 |
{ |
|
42
|
209 |
if(_tags.Count !=0 || _tags!=null) |
|
0
|
210 |
{ |
|
|
211 |
return String.Join(",", _tags.ToArray()); |
|
|
212 |
} |
|
42
|
213 |
else |
|
0
|
214 |
{ |
|
42
|
215 |
return "+Ajouter Tag"; |
|
0
|
216 |
} |
|
42
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
0
|
220 |
} |
|
|
221 |
set |
|
|
222 |
{ |
|
|
223 |
String val = (String)value; |
|
|
224 |
_tags = val.Split(',').ToList(); |
|
|
225 |
_newAnnotation.Tags = val.Split(',').ToList(); |
|
|
226 |
OnPropertyChanged("Tags"); |
|
|
227 |
|
|
|
228 |
|
|
|
229 |
} |
|
|
230 |
} |
|
|
231 |
|
|
25
|
232 |
|
|
|
233 |
private PolemicLink _basicRelation; |
|
0
|
234 |
/// <summary> |
|
|
235 |
/// Relation basique |
|
|
236 |
/// </summary> |
|
|
237 |
public PolemicLink BasicRelation |
|
|
238 |
{ |
|
|
239 |
get |
|
|
240 |
{ |
|
|
241 |
return _basicRelation; |
|
|
242 |
} |
|
|
243 |
set |
|
|
244 |
{ |
|
|
245 |
_basicRelation = value; |
|
|
246 |
OnPropertyChanged("BasicRelation"); |
|
|
247 |
} |
|
|
248 |
|
|
|
249 |
|
|
|
250 |
} |
|
|
251 |
|
|
25
|
252 |
|
|
|
253 |
private PolemicLink _polemicRelation; |
|
0
|
254 |
/// <summary> |
|
|
255 |
/// Relation polémique |
|
|
256 |
/// </summary> |
|
|
257 |
public PolemicLink PolemicRelation |
|
|
258 |
{ |
|
|
259 |
get |
|
|
260 |
{ |
|
|
261 |
|
|
|
262 |
return _polemicRelation; |
|
|
263 |
} |
|
|
264 |
set |
|
|
265 |
{ |
|
|
266 |
_polemicRelation = value; |
|
|
267 |
OnPropertyChanged("PolemicRelation"); |
|
|
268 |
} |
|
|
269 |
|
|
|
270 |
|
|
|
271 |
} |
|
|
272 |
|
|
|
273 |
/// <summary> |
|
|
274 |
/// Détermine si le control est activé ou non |
|
|
275 |
/// </summary> |
|
|
276 |
public bool IsControlEnable |
|
|
277 |
{ |
|
|
278 |
get |
|
|
279 |
{ |
|
|
280 |
return _refElement != null; |
|
|
281 |
} |
|
|
282 |
} |
|
|
283 |
|
|
|
284 |
/// <summary> |
|
|
285 |
/// Permet d'initialiser les commands; |
|
|
286 |
/// </summary> |
|
|
287 |
private void InitializeCommands() |
|
|
288 |
{ |
|
|
289 |
Commands.ContextualBinderLayer.BeginBind.Executed += new EventHandler<ExecutedEventArgs>(BeginBind_Executed); |
|
|
290 |
Commands.ContextualBinderLayer.SelectBind.Executed += new EventHandler<ExecutedEventArgs>(SelectBind_Executed); |
|
|
291 |
Commands.ContextualBinderLayer.ActiveBind.Executed += new EventHandler<ExecutedEventArgs>(ActiveBind_Executed); |
|
|
292 |
Commands.ContextualBinderLayer.DesactiveBind.Executed += new EventHandler<ExecutedEventArgs>(DesactiveBind_Executed); |
|
|
293 |
Commands.AnnotationMaker.OkClick.Executed += new EventHandler<ExecutedEventArgs>(OkClickAnnotationMaker_Executed); |
|
35
|
294 |
Commands.EscapeKeyPressed.Executed += new EventHandler<ExecutedEventArgs>(EscapeKeyPressed_Executed); |
|
|
295 |
} |
|
|
296 |
|
|
|
297 |
void EscapeKeyPressed_Executed(object sender, ExecutedEventArgs e) |
|
|
298 |
{ |
|
|
299 |
|
|
|
300 |
PolemicRelation = new PolemicLink(); |
|
|
301 |
PolemicRelation.FromElement = _newAnnotation; |
|
|
302 |
|
|
|
303 |
|
|
0
|
304 |
} |
|
|
305 |
|
|
25
|
306 |
private void DesactiveBind_Executed(object sender, ExecutedEventArgs e) |
|
0
|
307 |
{ |
|
|
308 |
IsBinderActive = false; |
|
|
309 |
} |
|
|
310 |
|
|
25
|
311 |
private void ActiveBind_Executed(object sender, ExecutedEventArgs e) |
|
0
|
312 |
{ |
|
|
313 |
IsBinderActive = true; |
|
|
314 |
} |
|
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
25
|
318 |
private void SelectBind_Executed(object sender, ExecutedEventArgs e) |
|
0
|
319 |
{ |
|
|
320 |
if (IsControlEnable && IsBinderActive ) |
|
|
321 |
{ |
|
|
322 |
PolemicRelation.ToElement = (PolemicElement)e.Source; |
|
|
323 |
OnPropertyChanged("PolemicRelation"); |
|
|
324 |
} |
|
|
325 |
|
|
|
326 |
} |
|
|
327 |
|
|
25
|
328 |
private void BeginBind_Executed(object sender, ExecutedEventArgs e) |
|
0
|
329 |
{ |
|
|
330 |
if (IsControlEnable) |
|
|
331 |
{ |
|
|
332 |
PolemicRelation.Type = ((ContextualLinkBinder)e.Parameter).PolemicType; |
|
|
333 |
PolemicRelation.ToElement = null; |
|
38
|
334 |
OnPropertyChanged("PolemicRelation"); |
|
0
|
335 |
} |
|
|
336 |
|
|
|
337 |
} |
|
|
338 |
|
|
|
339 |
|
|
|
340 |
|
|
25
|
341 |
private void OkClickAnnotationMaker_Executed(object sender, ExecutedEventArgs e) |
|
0
|
342 |
{ |
|
38
|
343 |
_newAnnotation.Type = _selectedType ; |
|
|
344 |
_basicRelation.ToElement = _newAnnotation; |
|
39
|
345 |
_basicRelation.Type = _newAnnotation.Type; |
|
|
346 |
_refElement.Chapter.Annotations.Add(_newAnnotation); |
|
|
347 |
_refElement.Chapter.Book.BasicLinks.Add(_basicRelation); |
|
|
348 |
if(_polemicRelation.ToElement != null) |
|
|
349 |
{ |
|
|
350 |
_refElement.Chapter.Book.PolemicLinks.Add(_polemicRelation); |
|
|
351 |
} |
|
|
352 |
|
|
38
|
353 |
LDTElement newAnnotation = new LDTElement(_newAnnotation); |
|
|
354 |
|
|
|
355 |
/* |
|
34
|
356 |
newAnnotation.Title = Title; |
|
|
357 |
newAnnotation.Abstract = Description; |
|
|
358 |
newAnnotation.Begin = Begin; |
|
|
359 |
newAnnotation.Dur = End - Begin; |
|
38
|
360 |
newAnnotation.Tags = _tags; |
|
34
|
361 |
newAnnotation.Color = int.Parse(_selectedType.Color.A.ToString() + _selectedType.Color.R.ToString() + _selectedType.Color.G.ToString() + _selectedType.Color.B.ToString()); |
|
38
|
362 |
*/ |
|
0
|
363 |
|
|
34
|
364 |
LDTFile newfile = new LDTFile() |
|
|
365 |
{ |
|
39
|
366 |
|
|
34
|
367 |
Medias = new List<LDTMedia>() |
|
|
368 |
{ |
|
|
369 |
new LDTMedia() |
|
|
370 |
{ |
|
|
371 |
Src = _refElement.Chapter.Book.IriPath |
|
|
372 |
} |
|
|
373 |
}, |
|
39
|
374 |
BasicRelations = new List<LDTRelation>() |
|
0
|
375 |
{ |
|
34
|
376 |
new LDTRelation() |
|
|
377 |
{ |
|
|
378 |
IdElementFrom = _basicRelation.FromElement.Id, |
|
|
379 |
IdElementTo = _basicRelation.ToElement.Id, |
|
|
380 |
//Title = _basicRelation.Title |
|
|
381 |
} |
|
|
382 |
}, |
|
39
|
383 |
|
|
34
|
384 |
Annotations = new List<LDTAnnotationsContent>() |
|
|
385 |
{ |
|
|
386 |
new LDTAnnotationsContent() |
|
|
387 |
{ |
|
|
388 |
Content = new List<LDTAnnotationsDecoupage>() |
|
|
389 |
{ |
|
|
390 |
new LDTAnnotationsDecoupage() |
|
|
391 |
{ |
|
|
392 |
Elements = new List<LDTElement>() |
|
|
393 |
{ |
|
|
394 |
newAnnotation |
|
|
395 |
} |
|
|
396 |
} |
|
|
397 |
} |
|
|
398 |
} |
|
0
|
399 |
} |
|
|
400 |
|
|
34
|
401 |
}; |
|
|
402 |
if (this._polemicRelation.ToElement != null) |
|
|
403 |
{ |
|
|
404 |
LDTRelation polemicRelation = new LDTRelation() |
|
|
405 |
{ |
|
|
406 |
IdElementFrom = _polemicRelation.FromElement.Id, |
|
|
407 |
IdElementTo = _polemicRelation.ToElement.Id, |
|
|
408 |
Title = _polemicRelation.Title |
|
|
409 |
}; |
|
39
|
410 |
newfile.BasicRelations.Add(polemicRelation); |
|
34
|
411 |
} |
|
39
|
412 |
|
|
|
413 |
|
|
35
|
414 |
//MessageBox.Show(newfile.ToString()); |
|
39
|
415 |
|
|
|
416 |
/* HttpSend For Web Mode */ |
|
|
417 |
Application app = Application.Current as Application; |
|
|
418 |
HttpSender helper = new HttpSender(new Uri(FactoryVideoLivre.UpdateBookService, UriKind.RelativeOrAbsolute), "POST", |
|
|
419 |
new KeyValuePair<string, string>("newAnnotation",System.Windows.Browser.HttpUtility.UrlEncode( |
|
|
420 |
System.Windows.Browser.HttpUtility.HtmlEncode( |
|
|
421 |
_refElement.Chapter.Book.GetLDTFile().ToString()) |
|
|
422 |
)), |
|
|
423 |
new KeyValuePair<String,String>("ldtFileURI",_refElement.Chapter.Book.LdtPath)); |
|
35
|
424 |
helper.ResponseComplete += new HttpResponseCompleteEventHandler(helper_ResponseComplete); |
|
39
|
425 |
helper.Execute(); |
|
|
426 |
|
|
42
|
427 |
|
|
39
|
428 |
|
|
38
|
429 |
|
|
42
|
430 |
|
|
38
|
431 |
Commands.AnnotationMaker.NewAnnotationFinished.Execute(_newAnnotation,_refElement); |
|
|
432 |
|
|
|
433 |
/********/ |
|
|
434 |
|
|
|
435 |
|
|
34
|
436 |
_refElement = null; |
|
42
|
437 |
Title = String.Empty; |
|
|
438 |
Description = String.Empty; |
|
|
439 |
Tags = String.Empty; |
|
|
440 |
BasicRelation = null; |
|
|
441 |
PolemicRelation = null; |
|
|
442 |
|
|
34
|
443 |
OnPropertyChanged("IsControlEnable"); |
|
42
|
444 |
|
|
38
|
445 |
|
|
35
|
446 |
} |
|
39
|
447 |
|
|
38
|
448 |
private String _sendAnnotationResponse; |
|
|
449 |
public String SendAnnotationResponse |
|
|
450 |
{ |
|
|
451 |
get |
|
|
452 |
{ |
|
|
453 |
return _sendAnnotationResponse; |
|
|
454 |
} |
|
|
455 |
set |
|
|
456 |
{ |
|
|
457 |
_sendAnnotationResponse = value; |
|
|
458 |
OnPropertyChanged("SendAnnotationResponse"); |
|
|
459 |
} |
|
|
460 |
} |
|
35
|
461 |
void helper_ResponseComplete(HttpResponseCompleteEventArgs e) |
|
|
462 |
{ |
|
38
|
463 |
SendAnnotationResponse = e.Response; |
|
|
464 |
Commands.HttpSenderResponse.Execute(e.Response); |
|
35
|
465 |
|
|
0
|
466 |
} |
|
|
467 |
|
|
|
468 |
/// <summary> |
|
|
469 |
/// Constructeur par défaut |
|
|
470 |
/// </summary> |
|
|
471 |
public AnnotationMakerVM() |
|
|
472 |
{ |
|
|
473 |
|
|
|
474 |
InitializeCommands(); |
|
|
475 |
|
|
|
476 |
} |
|
|
477 |
|
|
|
478 |
/// <summary> |
|
|
479 |
/// Constructeur par référence |
|
|
480 |
/// </summary> |
|
|
481 |
/// <param name="refAParam">Element référant</param> |
|
|
482 |
public AnnotationMakerVM(PolemicElement refAParam) |
|
|
483 |
{ |
|
|
484 |
RefElement = refAParam; |
|
|
485 |
_newAnnotation = new Annotation(RefElement.Chapter); |
|
30
|
486 |
|
|
28
|
487 |
_basicRelation = new PolemicLink() { FromElement = RefElement, ToElement = _newAnnotation, Type = null}; |
|
0
|
488 |
_polemicRelation = new PolemicLink(); |
|
|
489 |
PolemicRelation.FromElement = _newAnnotation; |
|
|
490 |
InitializeCommands(); |
|
30
|
491 |
Begin = RefElement.TimerIn.TotalMilliseconds; |
|
|
492 |
End = RefElement.TimerOut.TotalMilliseconds; |
|
42
|
493 |
|
|
|
494 |
|
|
0
|
495 |
} |
|
|
496 |
|
|
|
497 |
|
|
28
|
498 |
public PolemicTypeDescription[] ListAnnotationDescription |
|
|
499 |
{ |
|
|
500 |
get |
|
|
501 |
{ |
|
|
502 |
return FactoryVideoLivre.AnnotationDescriptions; |
|
|
503 |
} |
|
|
504 |
|
|
|
505 |
} |
|
|
506 |
|
|
|
507 |
|
|
34
|
508 |
|
|
0
|
509 |
} |
|
|
510 |
|
|
|
511 |
} |