client/src/Iri.Modernisation.Data/Models/FactoryVideoLivre.cs
author totetm <>
Thu, 04 Feb 2010 16:38:04 +0100
changeset 38 bd33267300aa
parent 36 b6df6fce6e5d
child 39 0f2bde8fdfeb
permissions -rw-r--r--
- FranceCulture Project - Ldt and Iri Parse Method - Bug MenuableUserControl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
     1
using System;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
     2
using System.Net;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
     3
using System.Windows;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
     4
using System.Windows.Controls;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
     5
using System.Windows.Documents;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
     6
using System.Windows.Ink;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
     7
using System.Windows.Input;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
     8
using System.Windows.Media;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
     9
using System.Windows.Media.Animation;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    10
using System.Windows.Shapes;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    11
using System.Xml.Linq;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    12
using System.Collections.Generic;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    13
namespace Iri.Modernisation.Data.Models
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    14
{
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    15
    public static class FactoryVideoLivre
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    16
    {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    17
         public static WebClient xmlClient = new WebClient();
36
b6df6fce6e5d Sync init XML download.
totetm <>
parents: 32
diff changeset
    18
         private static XDocument _configDoc; 
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    19
         public static VideoChapterDescription[] VideoChapterDescriptions {get;private set;}
28
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
    20
         public static PolemicTypeDescription[] AnnotationDescriptions { get; private set; }
32
36302cc9688d Web InitParams
totetm <>
parents: 30
diff changeset
    21
         public static String VideoBookListPath;
36
b6df6fce6e5d Sync init XML download.
totetm <>
parents: 32
diff changeset
    22
         public static String ProductionVideoPath;
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    23
         public static int NumberOfChapters
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    24
         {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    25
             get
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    26
             {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    27
                 return VideoChapterDescriptions.Length;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    28
             }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    29
         }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    30
         static FactoryVideoLivre()
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    31
	    {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    32
 
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    33
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    34
	    }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    35
        static public void Initialize()
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    36
        {
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    37
          //  LoadXMLFile();
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    38
        }
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    39
        public static void LoadXMLFile(String path)
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    40
        {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    41
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    42
            
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    43
            
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    44
            xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(XMLFileLoaded);
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    45
            Uri uri = new Uri(path, UriKind.RelativeOrAbsolute);
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    46
            xmlClient.DownloadStringAsync(uri);
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    47
          
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    48
            
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    49
        }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    50
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    51
        static void XMLFileLoaded(object sender, DownloadStringCompletedEventArgs e)
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    52
        {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    53
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    54
            if (e.Error == null)
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    55
            {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    56
            
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    57
                _configDoc = XDocument.Parse(e.Result);
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    58
                List<VideoChapterDescription> temp = new List<VideoChapterDescription>();
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    59
                List<PolemicTypeDescription> temp_an = new List<PolemicTypeDescription>();
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    60
                int nb = 0;
32
36302cc9688d Web InitParams
totetm <>
parents: 30
diff changeset
    61
                VideoBookListPath = _configDoc.Root.Attribute("VideoBookList").Value;
36
b6df6fce6e5d Sync init XML download.
totetm <>
parents: 32
diff changeset
    62
                ProductionVideoPath = _configDoc.Root.Attribute("ProductionVideo").Value;
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    63
                foreach (XElement XChapter in _configDoc.Root.Element("VideoBook").Elements())
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    64
                {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    65
                    temp.Add(new VideoChapterDescription(nb, XChapter.Attribute("name").Value, XChapter.Attribute("color").Value));
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    66
                    nb++;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    67
                }
38
bd33267300aa - FranceCulture Project
totetm <>
parents: 36
diff changeset
    68
                int annotatinIndex=0;
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    69
                foreach (XElement XAnnotation in _configDoc.Root.Element("PolemicTypes").Elements())
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    70
                {
38
bd33267300aa - FranceCulture Project
totetm <>
parents: 36
diff changeset
    71
                    temp_an.Add(new PolemicTypeDescription(annotatinIndex, XAnnotation.Attribute("name").Value, XAnnotation.Attribute("color").Value));
bd33267300aa - FranceCulture Project
totetm <>
parents: 36
diff changeset
    72
                    annotatinIndex++;
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    73
                }
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    74
             
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    75
                VideoChapterDescriptions = temp.ToArray();
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    76
                AnnotationDescriptions = temp_an.ToArray();
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    77
                FactoryReady(null, new EventArgs());
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    78
            }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    79
            else
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    80
            {
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    81
                MessageBox.Show(e.Error.Message);
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    82
            }
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    83
            
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    84
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    85
        }
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    86
        public static event EventHandler FactoryReady;
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    87
       static public void Load(string path)
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    88
       {
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    89
         
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    90
           _configDoc = XDocument.Load(path);
28
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
    91
           List<VideoChapterDescription> temp_vl = new List<VideoChapterDescription>();
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
    92
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
    93
           List<PolemicTypeDescription> temp_an = new List<PolemicTypeDescription>();
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    94
           int nb = 0;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    95
           foreach (XElement XChapter in _configDoc.Root.Element("VideoBook").Elements())
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    96
           {
28
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
    97
               temp_vl .Add(new VideoChapterDescription(nb,XChapter.Attribute("name").Value, XChapter.Attribute("color").Value));
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    98
               nb++;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    99
           }
38
bd33267300aa - FranceCulture Project
totetm <>
parents: 36
diff changeset
   100
           int annotatinIndex = 0;
28
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   101
           foreach (XElement XAnnotation in _configDoc.Root.Element("PolemicTypes").Elements())
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   102
           {
38
bd33267300aa - FranceCulture Project
totetm <>
parents: 36
diff changeset
   103
               temp_an.Add(new PolemicTypeDescription(annotatinIndex, XAnnotation.Attribute("name").Value, XAnnotation.Attribute("color").Value));
bd33267300aa - FranceCulture Project
totetm <>
parents: 36
diff changeset
   104
               annotatinIndex++;
28
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   105
           }
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   106
           VideoChapterDescriptions = temp_vl .ToArray();
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   107
           AnnotationDescriptions = temp_an.ToArray();
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   108
       }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   109
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   110
     
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   111
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   112
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   113
       
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   114
    }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   115
}