|
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.Collections.Generic; |
|
30
|
12 |
using System.Xml.Linq; |
|
|
13 |
using System.Threading; |
|
|
14 |
using Iri.Modernisation.Data.LDTClass; |
|
38
|
15 |
using System.IO; |
|
0
|
16 |
namespace Iri.Modernisation.Data.Models |
|
|
17 |
{ |
|
|
18 |
/// <summary> |
|
|
19 |
/// Classe VideoLivre |
|
|
20 |
/// </summary> |
|
|
21 |
public class VideoBook |
|
|
22 |
{ |
|
|
23 |
/// <summary> |
|
|
24 |
/// Titre du VideoLivre |
|
|
25 |
/// </summary> |
|
|
26 |
public String Title { get; set; } |
|
|
27 |
|
|
|
28 |
/// <summary> |
|
|
29 |
/// Auteur du VideoLivre |
|
|
30 |
/// </summary> |
|
|
31 |
public User Author { get; set; } |
|
|
32 |
|
|
|
33 |
/// <summary> |
|
|
34 |
/// Chapitre du VideoLivre |
|
|
35 |
/// </summary> |
|
|
36 |
public VideoChapter[] Chapters { get; set; } |
|
|
37 |
|
|
|
38 |
/// <summary> |
|
|
39 |
/// Durée du VideoLivre |
|
|
40 |
/// </summary> |
|
|
41 |
public TimeSpan Duration { get; set; } |
|
|
42 |
|
|
|
43 |
/// <summary> |
|
|
44 |
/// Chemin de la vidéo fini |
|
|
45 |
/// </summary> |
|
|
46 |
public String MediaPath { get; set; } |
|
|
47 |
|
|
|
48 |
/// <summary> |
|
34
|
49 |
/// Chemin du projet .ldt |
|
|
50 |
/// </summary> |
|
|
51 |
public String LdtPath { get; set; } |
|
|
52 |
|
|
|
53 |
/// <summary> |
|
|
54 |
/// Chemin du .iri |
|
|
55 |
/// </summary> |
|
|
56 |
public String IriPath { get; set; } |
|
|
57 |
|
|
35
|
58 |
|
|
39
|
59 |
public List<PolemicLink> BasicLinks { get; set; } |
|
|
60 |
|
|
|
61 |
public List<PolemicLink> PolemicLinks { get; set; } |
|
34
|
62 |
/// <summary> |
|
0
|
63 |
/// Constructeur par défaut |
|
|
64 |
/// </summary> |
|
|
65 |
public VideoBook() |
|
|
66 |
{ |
|
39
|
67 |
BasicLinks = new List<PolemicLink>(); |
|
|
68 |
PolemicLinks = new List<PolemicLink>(); |
|
27
|
69 |
Chapters = new VideoChapter[FactoryVideoLivre.VideoChapterDescriptions.Length]; |
|
|
70 |
for (int nbChapitre = 0; nbChapitre < FactoryVideoLivre.VideoChapterDescriptions.Length; nbChapitre++) |
|
|
71 |
{ |
|
|
72 |
Chapters[nbChapitre] = new VideoChapter(this, |
|
|
73 |
FactoryVideoLivre.VideoChapterDescriptions[nbChapitre].Id, |
|
|
74 |
FactoryVideoLivre.VideoChapterDescriptions[nbChapitre].Title, |
|
|
75 |
FactoryVideoLivre.VideoChapterDescriptions[nbChapitre].Color); |
|
|
76 |
|
|
|
77 |
} |
|
0
|
78 |
|
|
|
79 |
} |
|
|
80 |
|
|
39
|
81 |
public LDTFile GetLDTFile() |
|
|
82 |
{ |
|
|
83 |
LDTFile ldt = new LDTFile(); |
|
|
84 |
ldt.Project = new LDTProject() |
|
|
85 |
{ |
|
42
|
86 |
Title = this.Title, |
|
|
87 |
User = this.Author.UserName |
|
39
|
88 |
}; |
|
|
89 |
ldt.Medias = new List<LDTMedia>() |
|
|
90 |
{ |
|
|
91 |
new LDTMedia() |
|
|
92 |
{ |
|
40
|
93 |
Src = IriPath, |
|
|
94 |
|
|
39
|
95 |
} |
|
|
96 |
}; |
|
|
97 |
foreach (VideoChapter Vc in Chapters) |
|
|
98 |
{ |
|
|
99 |
ldt.Annotations.Add( |
|
|
100 |
new LDTAnnotationsContent() |
|
|
101 |
{ |
|
|
102 |
|
|
|
103 |
}); |
|
|
104 |
foreach (Annotation An in Vc.Annotations) |
|
|
105 |
{ |
|
|
106 |
LDTAnnotationsDecoupage decoupage = new LDTAnnotationsDecoupage() |
|
|
107 |
{ |
|
|
108 |
Title = Vc.Title, |
|
|
109 |
Author = SettingsProject.ActualUser.UserName |
|
|
110 |
}; |
|
|
111 |
decoupage.Elements.Add( |
|
|
112 |
new LDTElement() |
|
|
113 |
{ |
|
|
114 |
Id = An.Id, |
|
|
115 |
Title = An.Title, |
|
|
116 |
Abstract = An.Description, |
|
|
117 |
Date = DateTime.Now, |
|
|
118 |
Begin = An.TimerIn.TotalMilliseconds, |
|
|
119 |
Dur = An.Duration.TotalMilliseconds, |
|
|
120 |
Tags = An.Tags, |
|
|
121 |
Author = SettingsProject.ActualUser.UserName, |
|
|
122 |
} |
|
|
123 |
); |
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
ldt.Annotations[ldt.Annotations.Count - 1].Content.Add(decoupage); |
|
|
128 |
} |
|
|
129 |
foreach (PolemicLink Pl in BasicLinks) |
|
|
130 |
{ |
|
|
131 |
ldt.BasicRelations.Add(new LDTRelation() |
|
|
132 |
{ |
|
|
133 |
Type = Pl.Type.Title, |
|
|
134 |
IdElementFrom = Pl.FromElement.Id, |
|
|
135 |
IdElementTo = Pl.ToElement.Id, |
|
|
136 |
Title = Pl.ToElement.Title |
|
|
137 |
}); |
|
|
138 |
} |
|
|
139 |
foreach (PolemicLink Pl in PolemicLinks) |
|
|
140 |
{ |
|
|
141 |
ldt.PolemicRelations.Add(new LDTRelation() |
|
|
142 |
{ |
|
|
143 |
Type = Pl.Type.Title, |
|
|
144 |
IdElementFrom = Pl.FromElement.Id, |
|
|
145 |
IdElementTo = Pl.ToElement.Id, |
|
|
146 |
Title = Pl.ToElement.Title |
|
|
147 |
}); |
|
|
148 |
|
|
|
149 |
} |
|
|
150 |
|
|
|
151 |
} |
|
|
152 |
return ldt; |
|
|
153 |
} |
|
|
154 |
|
|
38
|
155 |
|
|
|
156 |
|
|
35
|
157 |
/// <summary> |
|
|
158 |
/// Méthode static pour le Loader de la list de videoBook |
|
|
159 |
/// </summary> |
|
|
160 |
/// <param name="XDoc">XDoc du fichier pointant tous les chemin .ldt des videoLivre disponible</param> |
|
|
161 |
/// <returns>List des VideoLivre (non chargé)</returns> |
|
|
162 |
public static List<VideoBook> GetListVideoBook(XDocument XDoc) |
|
|
163 |
{ |
|
|
164 |
|
|
|
165 |
List<VideoBook> ListReturn = new List<VideoBook>(); |
|
|
166 |
|
|
|
167 |
foreach (XElement XVideoBook in XDoc.Root.Elements()) |
|
|
168 |
{ |
|
|
169 |
|
|
|
170 |
VideoBook temp = new VideoBook(); |
|
|
171 |
temp.LdtPath = XVideoBook.Attribute("metafile").Value; ; |
|
|
172 |
temp.Title = XVideoBook.Attribute("title").Value; |
|
|
173 |
ListReturn.Add(temp); |
|
|
174 |
|
|
|
175 |
|
|
|
176 |
} |
|
|
177 |
return ListReturn; |
|
|
178 |
} |
|
30
|
179 |
|
|
|
180 |
|
|
0
|
181 |
|
|
|
182 |
} |
|
38
|
183 |
public class VideoBookUploader |
|
|
184 |
{ |
|
|
185 |
private static Loader<LDTFile> loaderLdt = new Loader<LDTFile>(LDTFile.FromXML); |
|
|
186 |
private static LDTFile ldt = new LDTFile(); |
|
|
187 |
private static VideoBook videoBookToUpdate; |
|
|
188 |
private static StreamWriter Sw; |
|
|
189 |
public static void UpdateAnnotation(VideoBook update,StreamWriter sw) |
|
|
190 |
{ |
|
|
191 |
Sw = sw; |
|
|
192 |
videoBookToUpdate = update; |
|
|
193 |
loaderLdt.LoaderFinished += new EventHandler<EventArgs>(loaderLdt_LoaderFinished); |
|
|
194 |
loaderLdt.Load(videoBookToUpdate.LdtPath); |
|
35
|
195 |
|
|
38
|
196 |
} |
|
|
197 |
public static void UpdateAnnotation(VideoBook update) |
|
|
198 |
{ |
|
|
199 |
videoBookToUpdate = update; |
|
|
200 |
loaderLdt.LoaderFinished += new EventHandler<EventArgs>(loaderLdt_LoaderFinished); |
|
|
201 |
loaderLdt.Load(videoBookToUpdate.LdtPath); |
|
|
202 |
|
|
|
203 |
} |
|
|
204 |
|
|
|
205 |
static void loaderLdt_LoaderFinished(object sender, EventArgs e) |
|
|
206 |
{ |
|
|
207 |
ldt = ((LoaderEventArgs<LDTFile>)e).CreatedObject; |
|
|
208 |
ldt.Annotations.Clear(); |
|
39
|
209 |
|
|
38
|
210 |
foreach (VideoChapter Vc in videoBookToUpdate.Chapters) |
|
|
211 |
{ |
|
39
|
212 |
ldt.Annotations.Add( |
|
|
213 |
new LDTAnnotationsContent() |
|
|
214 |
{ |
|
|
215 |
|
|
|
216 |
}); |
|
|
217 |
foreach(Annotation An in Vc.Annotations) |
|
|
218 |
{ |
|
|
219 |
LDTAnnotationsDecoupage decoupage = new LDTAnnotationsDecoupage() |
|
38
|
220 |
{ |
|
|
221 |
Title = Vc.Title, |
|
39
|
222 |
Author = SettingsProject.ActualUser.UserName |
|
38
|
223 |
}; |
|
|
224 |
decoupage.Elements.Add( |
|
|
225 |
new LDTElement() |
|
|
226 |
{ |
|
39
|
227 |
Id = An.Id, |
|
38
|
228 |
Title = An.Title, |
|
|
229 |
Abstract = An.Description, |
|
|
230 |
Date = DateTime.Now, |
|
|
231 |
Begin = An.TimerIn.TotalMilliseconds, |
|
|
232 |
Dur = An.Duration.TotalMilliseconds, |
|
|
233 |
Tags = An.Tags, |
|
39
|
234 |
Author = SettingsProject.ActualUser.UserName, |
|
38
|
235 |
} |
|
39
|
236 |
); |
|
|
237 |
|
|
|
238 |
|
|
38
|
239 |
|
|
39
|
240 |
ldt.Annotations[ldt.Annotations.Count - 1].Content.Add(decoupage); |
|
|
241 |
} |
|
|
242 |
foreach (PolemicLink Pl in videoBookToUpdate.BasicLinks) |
|
|
243 |
{ |
|
|
244 |
ldt.BasicRelations.Add(new LDTRelation() |
|
38
|
245 |
{ |
|
39
|
246 |
Type = Pl.Type.Title, |
|
|
247 |
IdElementFrom = Pl.FromElement.Id, |
|
|
248 |
IdElementTo = Pl.ToElement.Id, |
|
|
249 |
Title = Pl.ToElement.Title |
|
38
|
250 |
}); |
|
39
|
251 |
} |
|
|
252 |
foreach (PolemicLink Pl in videoBookToUpdate.PolemicLinks) |
|
|
253 |
{ |
|
|
254 |
ldt.PolemicRelations.Add(new LDTRelation() |
|
|
255 |
{ |
|
|
256 |
Type = Pl.Type.Title, |
|
|
257 |
IdElementFrom = Pl.FromElement.Id, |
|
|
258 |
IdElementTo = Pl.ToElement.Id, |
|
|
259 |
Title = Pl.ToElement.Title |
|
|
260 |
}); |
|
|
261 |
} |
|
38
|
262 |
} |
|
39
|
263 |
|
|
38
|
264 |
WebClient WebWriter = new WebClient(); |
|
|
265 |
|
|
|
266 |
|
|
|
267 |
WebWriter.OpenWriteCompleted +=new OpenWriteCompletedEventHandler(WebWriter_OpenWriteCompleted); |
|
|
268 |
WebWriter.OpenWriteAsync(new Uri(videoBookToUpdate.LdtPath, UriKind.RelativeOrAbsolute)); |
|
|
269 |
// WebWriter.UploadStringCompleted += new UploadStringCompletedEventHandler(WebWriter_UploadStringCompleted); |
|
|
270 |
// WebWriter.UploadStringAsync(new Uri(videoBookToUpdate.LdtPath, UriKind.RelativeOrAbsolute),"azerty"); |
|
|
271 |
|
|
|
272 |
} |
|
|
273 |
|
|
|
274 |
|
|
|
275 |
static void WebWriter_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e) |
|
|
276 |
{ |
|
|
277 |
|
|
|
278 |
} |
|
|
279 |
|
|
|
280 |
|
|
|
281 |
static void WebWriter_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) |
|
|
282 |
{ |
|
|
283 |
|
|
|
284 |
|
|
|
285 |
/*using (Stream fs = e.Result) |
|
|
286 |
{ |
|
|
287 |
|
|
|
288 |
// Add some information to the file. |
|
|
289 |
byte[] info = new System.Text.UTF8Encoding(true).GetBytes("This is some text in the file."); |
|
|
290 |
|
|
|
291 |
fs.Write(info, 0, info.Length); |
|
|
292 |
|
|
|
293 |
fs.Close(); |
|
|
294 |
|
|
|
295 |
}*/ |
|
39
|
296 |
|
|
|
297 |
StreamWriter fs = Sw; |
|
|
298 |
|
|
38
|
299 |
|
|
|
300 |
fs.Write(ldt.ToString()); |
|
|
301 |
fs.Close(); |
|
39
|
302 |
|
|
38
|
303 |
|
|
|
304 |
/*StreamWriter fs = new StreamWriter(e.Result); |
|
|
305 |
//MessageBox.Show(ldt.ToString()); |
|
|
306 |
fs.Write(ldt.ToString()); |
|
|
307 |
fs.Flush(); |
|
|
308 |
fs.Close();*/ |
|
|
309 |
} |
|
|
310 |
} |
|
35
|
311 |
public class VideoBookLoader |
|
30
|
312 |
{ |
|
35
|
313 |
private Loader<IRIFile> _iriFile; |
|
|
314 |
private Loader<LDTFile> _ldtFile; |
|
|
315 |
private IRIFile _loadedIriFile; |
|
|
316 |
private LDTFile _loadedLdtFile; |
|
|
317 |
public VideoBookLoader() |
|
30
|
318 |
{ |
|
35
|
319 |
_iriFile = new Loader<IRIFile>(IRIFile.FromXML); |
|
|
320 |
_ldtFile = new Loader<LDTFile>(LDTFile.FromXML); |
|
36
|
321 |
_ldtFile.LoaderFinished += new EventHandler<EventArgs>(_ldtFile_LoaderFinished); |
|
|
322 |
_iriFile.LoaderFinished += new EventHandler<EventArgs>(_iriFile_LoaderFinished); |
|
30
|
323 |
} |
|
0
|
324 |
|
|
36
|
325 |
void _iriFile_LoaderFinished(object sender, EventArgs e) |
|
30
|
326 |
{ |
|
36
|
327 |
_loadedIriFile = ((LoaderEventArgs<IRIFile>)e).CreatedObject; |
|
38
|
328 |
|
|
35
|
329 |
LoaderFinished(this,new LoaderEventArgs<VideoBook>(LDTFileReader.ConvertToVideoBook(_loadedLdtFile,_loadedIriFile))); |
|
|
330 |
} |
|
30
|
331 |
|
|
36
|
332 |
void _ldtFile_LoaderFinished(object sender, EventArgs e) |
|
35
|
333 |
{ |
|
36
|
334 |
_loadedLdtFile = ((LoaderEventArgs<LDTFile>)e).CreatedObject; |
|
38
|
335 |
_loadedLdtFile.Path = _ldtFile.Path; |
|
35
|
336 |
_iriFile.Load(_loadedLdtFile.Medias[0].Src); |
|
|
337 |
|
|
|
338 |
} |
|
38
|
339 |
public void Load(String ldtPath) |
|
|
340 |
{ |
|
|
341 |
_ldtFile.Load(ldtPath); |
|
|
342 |
} |
|
35
|
343 |
public event EventHandler<LoaderEventArgs<VideoBook>> LoaderFinished; |
|
30
|
344 |
|
|
|
345 |
|
|
35
|
346 |
} |
|
30
|
347 |
|
|
35
|
348 |
|
|
0
|
349 |
/// <summary> |
|
|
350 |
/// Comparateur pour Trier les livres |
|
|
351 |
/// </summary> |
|
|
352 |
public class VideoBookComparer : IComparer<VideoBook> |
|
|
353 |
{ |
|
|
354 |
public int Compare(VideoBook x, VideoBook y) |
|
|
355 |
{ |
|
|
356 |
return x.Title.CompareTo(y.Title); |
|
|
357 |
} |
|
|
358 |
} |
|
30
|
359 |
|
|
0
|
360 |
} |