diff -r 000000000000 -r 249d70e7b32d client/src/Iri.Modernisation.Controls/ViewModel/BookTimeLine/BookTimeLineVM.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/src/Iri.Modernisation.Controls/ViewModel/BookTimeLine/BookTimeLineVM.cs Wed Nov 18 15:30:31 2009 +0100 @@ -0,0 +1,301 @@ +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; +using Iri.Modernisation.Data.Models; +using Iri.Modernisation.BaseMVVM.Commands; +using Iri.Modernisation.BaseMVVM.ViewModel; +using System.Collections.Generic; +namespace Iri.Modernisation.Controls.ViewModel +{ + /// + /// ViewModel du module BookTimeLine + /// + public class BookTimeLineVM : BaseMVVM.ViewModel.ViewModel + { + /// + /// Livre sélectionné + /// + private VideoBook _selectedBook; + public VideoBook SelectedBook + { + get + { + return _selectedBook; + } + } + + /// + /// + /// + public String AuthorFullname + { + get + { + return Author.FirstName + " " + Author.Name; + } + } + + /// + /// Titre du Livre + /// + private String _title; + public String Title + { + get + { + return _title; + } + private set + { + _title = value; + _selectedBook.Title = value; + OnPropertyChanged("Title"); + } + } + + /// + /// Auteur du Livre + /// + private User _author; + public User Author + { + get + { + return _author; + } + private set + { + _author = value; + _selectedBook.Author = value; + OnPropertyChanged("Author"); + } + + } + + /// + /// Chapitre du Livre + /// + private VideoChapter[] _chapters; + public VideoChapter[] Chapters + { + get + { + return _chapters; + } + private set + { + _chapters = value; + _selectedBook.Chapters = value; + OnPropertyChanged("Chapters"); + } + } + + /// + /// Liste des Index des Chapitres + /// + private List[] _segmentIndex=new List[4]; + public List[] SegmentIndex + { + get + { + return _segmentIndex; + } + set + { + _segmentIndex = value; + OnPropertyChanged("SegmentIndex"); + } + } + + /// + /// Liste des Annotations + /// + private List[] _annotations=new List[4]; + public List[] Annotations + { + get + { + return _annotations; + } + set + { + _annotations = value; + OnPropertyChanged("Annotations"); + } + } + + /// + /// Durée totale du Livre + /// + private TimeSpan _totalDuration; + public double TotalDuration + { + get + { + return _totalDuration.TotalMilliseconds; + } + set + { + _totalDuration = new TimeSpan(0, 0, 0, 0, (int)value); + _selectedBook.Duration = new TimeSpan(0, 0, 0, 0, (int)value); ; + OnPropertyChanged("Duration"); + } + } + + private List _polemicSpectrumData = new List(); + public List PolemicSpectrumData + { + get + { + return _polemicSpectrumData; + } + } + + private List _adhesionSpectrumData = new List(); + public List AdhesionSpectrumData + { + get + { + return _adhesionSpectrumData; + } + } + + private List _referenceSpectrumData = new List(); + public List ReferenceSpectrumData + { + get + { + return _referenceSpectrumData; + } + } + + private List _questionSpectrumData = new List(); + public List QuestionSpectrumData + { + get + { + return _questionSpectrumData; + } + } + + private List _generalSpectrumData = new List(); + public List GeneralSpectrumData + { + get + { + return _generalSpectrumData; + } + } + + /// + /// Position du curseur de lecture + /// + private double _position; + public double Position + { + get + { + return _position; + } + set + { + _position = value; + OnPropertyChanged("Position"); + } + } + + /// + /// Chargement des données et annalyse + /// + private void LoadData() + { + if (_selectedBook.Duration != TimeSpan.Zero) + { + + for (double i = 0; i <= _selectedBook.Duration.TotalMilliseconds; i = (i + _selectedBook.Duration.TotalMilliseconds / 150)) + { + int[] Tem = new int[4]{0,0,0,0}; + foreach (VideoChapter Ch in _selectedBook.Chapters) + { + foreach (Annotation An in Ch.Annotations) + { + if (An.TimerIn.TotalMilliseconds <= i && An.TimerOut.TotalMilliseconds >= i) + { + switch (An.Type) + { + case PolemicElementType.Polemic: + Tem[0]++; + break; + case PolemicElementType.Adhesion: + Tem[1]++; + break; + case PolemicElementType.Reference: + Tem[2]++; + break; + case PolemicElementType.Question: + Tem[3]++; + break; + default: + break; + } + } + } + } + _polemicSpectrumData.Add(Tem[0]); + _adhesionSpectrumData.Add(Tem[1]); + _referenceSpectrumData.Add(Tem[2]); + _questionSpectrumData.Add(Tem[3]); + _generalSpectrumData.Add((Tem[0]+Tem[1]+Tem[2]+Tem[3])); + } + } + + + } + + /// + /// Constructeur + /// + /// VideoLivre à étudier + public BookTimeLineVM(VideoBook bookParam) + { + _selectedBook = bookParam; + _title = bookParam.Title; + _author = bookParam.Author; + _chapters = bookParam.Chapters; + _totalDuration = bookParam.Duration; + LoadData(); + LoadElements(); + Commands.TimeChange.Executed += new EventHandler(TimeChange_Executed); + + } + + void TimeChange_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) + { + // Position = ((Slider)e.Parameter).Value; + //Commands.VideoViewer.Pause.Execute(); + Commands.GoToTime.Execute(((Slider)e.Parameter).Value); + //Commands.VideoViewer.Play.Execute(); + } + + + /// + /// Chargement des éléments du livre (Index et Annotations) + /// + private void LoadElements() + { + for(int key=0;key< _selectedBook.Chapters.Length;key++) + { + _segmentIndex[key] = _selectedBook.Chapters[key].Index; + _annotations[key] = _selectedBook.Chapters[key].Annotations; + } + } + + } +}