client/src/Iri.Modernisation.Data/Models/FactoryVideoLivre.cs
author totetm <>
Tue, 09 Feb 2010 15:30:46 +0100
changeset 39 0f2bde8fdfeb
parent 38 bd33267300aa
permissions -rw-r--r--
WebService-like
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
    {
39
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    17
       
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    18
         public static WebClient xmlClient = new WebClient();
36
b6df6fce6e5d Sync init XML download.
totetm <>
parents: 32
diff changeset
    19
         private static XDocument _configDoc; 
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    20
         public static VideoChapterDescription[] VideoChapterDescriptions {get;private set;}
39
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    21
         public static Dictionary<String, PolemicTypeDescription> DictionaryAnnotationDescriptions
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    22
         {
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    23
             get
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    24
             {
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    25
                 Dictionary<String, PolemicTypeDescription> returnDic = new Dictionary<string, PolemicTypeDescription>();
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    26
                 foreach(PolemicTypeDescription Ptd in AnnotationDescriptions)
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    27
                 {
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    28
                     returnDic.Add(Ptd.Title, Ptd);
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    29
                 }
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    30
                 return returnDic;
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    31
             }
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    32
         }
28
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
    33
         public static PolemicTypeDescription[] AnnotationDescriptions { get; private set; }
32
36302cc9688d Web InitParams
totetm <>
parents: 30
diff changeset
    34
         public static String VideoBookListPath;
36
b6df6fce6e5d Sync init XML download.
totetm <>
parents: 32
diff changeset
    35
         public static String ProductionVideoPath;
39
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    36
         public static String UpdateBookService;
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    37
         public static int NumberOfChapters
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    38
         {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    39
             get
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    40
             {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    41
                 return VideoChapterDescriptions.Length;
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
         static FactoryVideoLivre()
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    45
	    {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    46
 
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
        static public void Initialize()
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    50
        {
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    51
          //  LoadXMLFile();
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    52
        }
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    53
        public static void LoadXMLFile(String path)
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    54
        {
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
            
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    58
            xmlClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(XMLFileLoaded);
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    59
            Uri uri = new Uri(path, UriKind.RelativeOrAbsolute);
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    60
            xmlClient.DownloadStringAsync(uri);
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    61
          
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    62
            
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    63
        }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    64
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    65
        static void XMLFileLoaded(object sender, DownloadStringCompletedEventArgs e)
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    66
        {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    67
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    68
            if (e.Error == null)
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    69
            {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    70
            
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    71
                _configDoc = XDocument.Parse(e.Result);
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    72
                List<VideoChapterDescription> temp = new List<VideoChapterDescription>();
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    73
                List<PolemicTypeDescription> temp_an = new List<PolemicTypeDescription>();
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    74
                int nb = 0;
32
36302cc9688d Web InitParams
totetm <>
parents: 30
diff changeset
    75
                VideoBookListPath = _configDoc.Root.Attribute("VideoBookList").Value;
36
b6df6fce6e5d Sync init XML download.
totetm <>
parents: 32
diff changeset
    76
                ProductionVideoPath = _configDoc.Root.Attribute("ProductionVideo").Value;
39
0f2bde8fdfeb WebService-like
totetm <>
parents: 38
diff changeset
    77
                UpdateBookService = _configDoc.Root.Attribute("UpdateBookService").Value;
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    78
                foreach (XElement XChapter in _configDoc.Root.Element("VideoBook").Elements())
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    79
                {
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    80
                    temp.Add(new VideoChapterDescription(nb, XChapter.Attribute("name").Value, XChapter.Attribute("color").Value));
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    81
                    nb++;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    82
                }
38
bd33267300aa - FranceCulture Project
totetm <>
parents: 36
diff changeset
    83
                int annotatinIndex=0;
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    84
                foreach (XElement XAnnotation in _configDoc.Root.Element("PolemicTypes").Elements())
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    85
                {
38
bd33267300aa - FranceCulture Project
totetm <>
parents: 36
diff changeset
    86
                    temp_an.Add(new PolemicTypeDescription(annotatinIndex, XAnnotation.Attribute("name").Value, XAnnotation.Attribute("color").Value));
bd33267300aa - FranceCulture Project
totetm <>
parents: 36
diff changeset
    87
                    annotatinIndex++;
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    88
                }
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    89
             
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    90
                VideoChapterDescriptions = temp.ToArray();
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    91
                AnnotationDescriptions = temp_an.ToArray();
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    92
                FactoryReady(null, new EventArgs());
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    93
            }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    94
            else
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    95
            {
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    96
                MessageBox.Show(e.Error.Message);
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    97
            }
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
    98
            
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
    99
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   100
        }
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
   101
        public static event EventHandler FactoryReady;
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   102
       static public void Load(string path)
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   103
       {
30
644e3cd48034 Introduce in Web context
totetm <>
parents: 28
diff changeset
   104
         
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   105
           _configDoc = XDocument.Load(path);
28
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   106
           List<VideoChapterDescription> temp_vl = new List<VideoChapterDescription>();
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   107
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   108
           List<PolemicTypeDescription> temp_an = new List<PolemicTypeDescription>();
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   109
           int nb = 0;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   110
           foreach (XElement XChapter in _configDoc.Root.Element("VideoBook").Elements())
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   111
           {
28
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   112
               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
   113
               nb++;
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   114
           }
38
bd33267300aa - FranceCulture Project
totetm <>
parents: 36
diff changeset
   115
           int annotatinIndex = 0;
28
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   116
           foreach (XElement XAnnotation in _configDoc.Root.Element("PolemicTypes").Elements())
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   117
           {
38
bd33267300aa - FranceCulture Project
totetm <>
parents: 36
diff changeset
   118
               temp_an.Add(new PolemicTypeDescription(annotatinIndex, XAnnotation.Attribute("name").Value, XAnnotation.Attribute("color").Value));
bd33267300aa - FranceCulture Project
totetm <>
parents: 36
diff changeset
   119
               annotatinIndex++;
28
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   120
           }
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   121
           VideoChapterDescriptions = temp_vl .ToArray();
2d4ec5ab2a40 Commit Before SL4
Matthieu Totet
parents: 27
diff changeset
   122
           AnnotationDescriptions = temp_an.ToArray();
27
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   123
       }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   124
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   125
     
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   126
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   127
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   128
       
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   129
    }
f292db96b050 Generalization of Book Structure
Matthieu Totet
parents:
diff changeset
   130
}