src/FingersDance/MainSurfaceWindow.xaml.cs
changeset 191 8a25a85f2656
parent 190 619ca3ae13c7
child 192 11083c390ce4
--- a/src/FingersDance/MainSurfaceWindow.xaml.cs	Mon Nov 09 12:11:42 2009 +0100
+++ b/src/FingersDance/MainSurfaceWindow.xaml.cs	Tue Nov 10 13:47:58 2009 +0100
@@ -1,6 +1,8 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Xml;
+using System.Xml.Linq;
 using System.Text;
 using System.Windows;
 using System.Windows.Controls;
@@ -401,8 +403,9 @@
         {
             try
             {
-                //1-Suppression du UC Screen
+                // We get UserControlScreen's instance and content
                 Grid root = (Grid)(((UserControlScreen)sender).Parent);
+                // We remove the UserControlScreen's instance
                 root.Children.Remove(((UserControlScreen)sender));
                 
                 if (((UserControlScreen)sender).Cutting != null)
@@ -426,7 +429,7 @@
 
                     // We add the new cutting to the _mainviewmodel's datas
                     _mainviewmodel.Project.Cuttings.Add(newCutting);
-                    _mainviewmodel.Project.CuttingsDict.Add("User " + ((UserControlScreen)sender).id, newCutting);
+                    _mainviewmodel.Project.CuttingsDict.Add(newCutting.Title, newCutting);
 
                     // And now we build the new UserPanel
                     Random c = new Random();
@@ -531,7 +534,100 @@
                 Panel3.UserControlSyncSource_DisplayAnnotation(idUser, brushAnnot);
             if (Panel4 != null)
                 Panel4.UserControlSyncSource_DisplayAnnotation(idUser, brushAnnot);
+
+            // We save datas
+            saveDatas();
+
         }
+
+        //
+        // Enable to save datas in a xml file with LDT format
+        //
+        private void saveDatas()
+        {
+            //XDocument d = new XDocument(
+            //    new XComment("This is a comment."),
+            //    new XProcessingInstruction("xml-stylesheet",
+            //        "href='mystyle.css' title='Compact' type='text/css'"),
+            //    new XElement("Pubs",
+            //        new XElement("Book",
+            //            new XElement("Title", "Artifacts of Roman Civilization"),
+            //            new XElement("Author", "Moreno, Jordao")
+            //        ),
+            //        new XElement("Book",
+            //            new XElement("Title", "Midieval Tools and Implements"),
+            //            new XElement("Author", "Gazit, Inbar")
+            //        )
+            //    ),
+            //    new XComment("This is another comment.")
+            //);
+            //d.Declaration = new XDeclaration("1.0", "utf-8", "true");
+            //Console.WriteLine(d);
+
+            XDocument d = new XDocument(
+                new XElement("iri",
+                    new XElement("project",
+                        new XAttribute("id", "1"),
+                        new XAttribute("user", "IRI-Strate-EFREI"),
+                        new XAttribute("title", _mainviewmodel.Project.Name),
+                        new XAttribute("abstract", _mainviewmodel.Project.Description)
+                    ),
+                    new XElement("medias",
+                        new XElement("media",
+                            new XAttribute("id","for_oneflat"),
+                            new XAttribute("src","srcIri"),
+                            new XAttribute("video",""),
+                            new XAttribute("extra",""),
+                            new XAttribute("pict","")
+                        )
+                    ),
+                    new XElement("annotations",
+                        new XElement("content",
+                            new XAttribute("id", "for_oneflat"),
+                            new XAttribute("title", "Déc. personnels"),
+                            new XAttribute("author", "perso"),
+                            new XAttribute("abstract", "Ensemble de découpages définis par un utilisateur")
+                        )
+                    ),
+                    new XElement("displays"),
+                    new XElement("edits")
+                )
+            );
+            // We add each cutting
+            XElement annotContent = (XElement)(d.Root.Elements().ToList()[2]).FirstNode;
+            foreach (Cutting cut in _mainviewmodel.Project.Cuttings)
+            {
+                XElement cutNode = new XElement("decoupage", new XAttribute("id", "c_" + System.Guid.NewGuid()), new XAttribute("author", "perso"),
+                                                new XElement("title",cut.Title),
+                                                new XElement("abstract",""));
+                XElement cutElmts = new XElement("elements");
+                cutNode.Add(cutElmts);
+                foreach (Annotation annot in cut.AnnotList)
+                {
+                    cutElmts.Add(new XElement("element", new XAttribute("id", "s_" + System.Guid.NewGuid()),
+                                                         new XAttribute("begin", annot.TcBegin),
+                                                         new XAttribute("dur", annot.Dur),
+                                                         new XAttribute("author", cut.Title),
+                                                         new XAttribute("date", DateTime.Now.Day.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Year.ToString()),
+                                                         new XAttribute("color", annot.Color),
+                                                         new XAttribute("src", ""),
+                                                         new XElement("title", annot.GestureType),
+                                                         new XElement("abstract"),
+                                                         new XElement("audio"),
+                                                         new XElement("tags"),
+                                                         new XElement("gestureType", annot.GestureType)));
+                }
+                annotContent.Add(cutNode);
+            }
+
+            d.Declaration = new XDeclaration("1.0", "utf-8", "true");
+            Console.WriteLine(d);
+
+            d.Save(_mainviewmodel.Project.Name + ".ldt");
+
+        }
+
+
         //On Tag Visualisation Mute all the other Players
         private void Panel_OnTagVisualisation(object sender, EventArgs e)
         {