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