Singletton ListVideos
authorPAMPHILE Jonathan <pamphile@efrei.fr>
Fri, 25 Sep 2009 03:38:22 +0200
changeset 123 8af72b302e0a
parent 122 b489c2756a13
child 124 14b058fc64fc
Singletton ListVideos
src/FingersDance.Control.ListVideo/FingersDance.Control.ListVideo.csproj
src/FingersDance.Control.ListVideo/ListVideo.cs
src/FingersDance.Control.ListVideo/UserControlListVideo.xaml.cs
src/FingersDance/Resources/videos.xml
--- a/src/FingersDance.Control.ListVideo/FingersDance.Control.ListVideo.csproj	Fri Sep 25 02:57:58 2009 +0200
+++ b/src/FingersDance.Control.ListVideo/FingersDance.Control.ListVideo.csproj	Fri Sep 25 03:38:22 2009 +0200
@@ -70,6 +70,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="CustomListBoxItem.cs" />
+    <Compile Include="ListVideo.cs" />
     <Compile Include="ListVideoItem.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <EmbeddedResource Include="Properties\Resources.resx">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/FingersDance.Control.ListVideo/ListVideo.cs	Fri Sep 25 03:38:22 2009 +0200
@@ -0,0 +1,51 @@
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Xml.Serialization;
+using System.Reflection;
+
+namespace FingersDance.Control.ListVideo
+{
+    public class ListVideo
+    {
+        static Dictionary<string, ListVideoItem> _Videos;
+
+        public ListVideo()
+        { }
+
+        public Dictionary<string, ListVideoItem> GetVideos()
+        {
+            if (_Videos == null)
+            {
+                _Videos = new Dictionary<string, ListVideoItem>();
+                LoadList();
+            }
+            return _Videos;
+        }
+
+        void LoadList()
+        {
+            _Videos.Clear();
+            StreamReader reader = null;
+            FileInfo assemblyPath = new FileInfo(Assembly.GetExecutingAssembly().Location);
+            DirectoryInfo info = assemblyPath.Directory;
+            try
+            {
+                reader = new StreamReader(info.FullName.ToString() + "\\Resources\\videos.xml");
+                XmlSerializer serializer = new XmlSerializer(typeof(List<ListVideoItem>));
+                List<ListVideoItem> temp = (List<ListVideoItem>)serializer.Deserialize(reader);
+                foreach (ListVideoItem elt in temp)
+                    if (!elt.Preview.Equals("") && !_Videos.ContainsKey(elt.Path))
+                        _Videos.Add(elt.Path, elt);
+                reader.Close();
+            }
+            catch (Exception e)
+            {
+                if (reader != null)
+                    reader.Close();
+            }
+        }
+    }
+}
--- a/src/FingersDance.Control.ListVideo/UserControlListVideo.xaml.cs	Fri Sep 25 02:57:58 2009 +0200
+++ b/src/FingersDance.Control.ListVideo/UserControlListVideo.xaml.cs	Fri Sep 25 03:38:22 2009 +0200
@@ -13,7 +13,6 @@
 using System.Collections.Generic;
 using System.Windows.Media.Imaging;
 using System.Xml.Serialization;
-
 using System.Reflection;
 
 namespace FingersDance.Control.ListVideo
@@ -22,15 +21,12 @@
     {
         //Creation d'un Event pour Chaque Item Video
         public event EventHandler EH_ItemVideo1_ContactDown;
-        public event EventHandler EH_ItemVideo2_ContactDown;
 
         public string path = "";
-        static Dictionary<string, ListVideoItem> _Videos = new Dictionary<string, ListVideoItem>();
-
+        
         public UserControlListVideo()
         {
             this.InitializeComponent();
-            LoadList();
             UpdateList();
 
             // Insert code required on object creation below this point.
@@ -67,6 +63,7 @@
         {
             try
             {
+                Dictionary<string, ListVideoItem> _Videos = (new ListVideo()).GetVideos();
                 string[] Files = new string[1];
                 if (System.IO.Directory.Exists(PathImporter.Text))
                     Files = System.IO.Directory.GetFiles(PathImporter.Text);
@@ -122,41 +119,19 @@
 
         private void RefreshButton_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
         {
-            LoadList();
             UpdateList();
         }
 
         private void RefreshButton_Click(object sender, System.Windows.RoutedEventArgs e)
         {
-            LoadList();
             UpdateList();
         }
 
-        void LoadList()
-        {
-            _Videos.Clear();
-            StreamReader reader = null;
-            FileInfo assemblyPath = new FileInfo(Assembly.GetExecutingAssembly().Location);
-            DirectoryInfo info = assemblyPath.Directory;
-            try
-            {
-                reader = new StreamReader(info.FullName.ToString() + "\\Resources\\videos.xml");
-                XmlSerializer serializer = new XmlSerializer(typeof(List<ListVideoItem>));
-                List<ListVideoItem> temp = (List<ListVideoItem>)serializer.Deserialize(reader);
-                foreach (ListVideoItem elt in temp)
-                    if (!elt.Preview.Equals("") && !_Videos.ContainsKey(elt.Path))
-                        _Videos.Add(elt.Path, elt);
-                reader.Close();
-            }
-            catch (Exception e)
-            {
-                if (reader != null)
-                    reader.Close();
-            }
-        }
+        
 
         void SaveList()
         {
+            Dictionary<string, ListVideoItem> _Videos = (new ListVideo()).GetVideos();
             StreamWriter writter = null;
             FileInfo assemblyPath = new FileInfo(Assembly.GetExecutingAssembly().Location);
             DirectoryInfo info = assemblyPath.Directory;
@@ -179,6 +154,7 @@
 
         void UpdateList()
         {
+            Dictionary<string, ListVideoItem> _Videos = (new ListVideo()).GetVideos();
             stackPanel.Children.Clear();
             foreach (KeyValuePair<string, ListVideoItem> elt in _Videos)
             {
--- a/src/FingersDance/Resources/videos.xml	Fri Sep 25 02:57:58 2009 +0200
+++ b/src/FingersDance/Resources/videos.xml	Fri Sep 25 03:38:22 2009 +0200
@@ -2,12 +2,12 @@
 <ArrayOfListVideoItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <ListVideoItem>
     <Name>Butterfly</Name>
-    <Path>C:\Users\Jonathan.PIAF\Desktop\IRI\src\FingersDance\Resources\Butterfly.wmv</Path>
-    <Preview>C:\Users\Jonathan.PIAF\Desktop\IRI\src\FingersDance\Resources\Butterfly.jpg</Preview>
+    <Path>C:\Users\Piaf\Desktop\Développement\IRI\src\FingersDance\bin\Debug\Resources\Butterfly.wmv</Path>
+    <Preview>C:\Users\Piaf\Desktop\Développement\IRI\src\FingersDance\bin\Debug\Resources\Butterfly.jpg</Preview>
   </ListVideoItem>
   <ListVideoItem>
     <Name>Lake</Name>
-    <Path>C:\Users\Jonathan.PIAF\Desktop\IRI\src\FingersDance\Resources\Lake.wmv</Path>
-    <Preview>C:\Users\Jonathan.PIAF\Desktop\IRI\src\FingersDance\Resources\Lake.jpg</Preview>
+    <Path>C:\Users\Piaf\Desktop\Développement\IRI\src\FingersDance\bin\Debug\Resources\Lake.wmv</Path>
+    <Preview>C:\Users\Piaf\Desktop\Développement\IRI\src\FingersDance\bin\Debug\Resources\Lake.jpg</Preview>
   </ListVideoItem>
 </ArrayOfListVideoItem>
\ No newline at end of file