[longomatch/json] JSON WIP



commit 07a6d40adf687d9aaedc58f718492b59ad4f0e5d
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Aug 24 02:26:15 2011 +0200

    JSON WIP

 LongoMatch/Common/JSONSerializer.cs                |   53 +++++++++
 LongoMatch/LongoMatch.mdp                          |    2 +
 LongoMatch/Makefile.am                             |    1 +
 LongoMatch/Store/Category.cs                       |   34 +------
 LongoMatch/Store/Templates/CategoriesTemplate.cs   |    8 +-
 LongoMatch/Store/Templates/SubCategoryTemplate.cs  |    4 +-
 LongoMatch/Store/Templates/TeamTemplate.cs         |    5 +-
 ...LongoMatch.Gui.Dialog.ProjectSelectionDialog.cs |    1 +
 LongoMatch/gtk-gui/gui.stetic                      |    2 +-
 LongoMatch/gtk-gui/objects.xml                     |  117 --------------------
 build/build.environment.mk                         |    2 +
 11 files changed, 69 insertions(+), 160 deletions(-)
---
diff --git a/LongoMatch/Common/JSONSerializer.cs b/LongoMatch/Common/JSONSerializer.cs
new file mode 100644
index 0000000..7cdb909
--- /dev/null
+++ b/LongoMatch/Common/JSONSerializer.cs
@@ -0,0 +1,53 @@
+// 
+//  Copyright (C) 2011 Andoni Morales Alastruey
+// 
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+// 
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//  
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+// 
+using System;
+using System.IO;
+using System.Runtime.Serialization.Json;
+
+namespace LongoMatch.Common
+{
+	public class JSONSerializer
+	{
+		public static void Save<T>(T obj, Stream stream) {
+			DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
+			serializer.WriteObject(stream, obj);
+		}
+		
+		public static void Save<T>(T obj, string filepath) {
+			Stream stream = new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.None);
+			using (stream) {
+				Save<T> (obj, stream);
+				stream.Close();
+			}
+		}
+
+		public static T Load<T>(Stream stream) {
+			DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(T));
+			var obj = deserializer.ReadObject(stream);
+			return (T)obj;
+		}
+		
+		public static T Load<T>(string filepath) {
+			Stream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
+			using (stream) {
+				return Load<T> (stream);
+			}
+		}
+	}
+}
+
diff --git a/LongoMatch/LongoMatch.mdp b/LongoMatch/LongoMatch.mdp
index b1ee43e..58709b3 100644
--- a/LongoMatch/LongoMatch.mdp
+++ b/LongoMatch/LongoMatch.mdp
@@ -190,6 +190,7 @@
     <File subtype="Code" buildaction="Compile" name="gtk-gui/LongoMatch.Gui.Component.TeamTaggerWidget.cs" />
     <File subtype="Code" buildaction="Compile" name="Gui/Component/TeamTaggerWidget.cs" />
     <File subtype="Code" buildaction="Compile" name="Interfaces/ITag.cs" />
+    <File subtype="Code" buildaction="Compile" name="Common/JSONSerializer.cs" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
@@ -204,6 +205,7 @@
     <ProjectReference type="Gac" localcopy="True" refto="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
     <ProjectReference type="Gac" localcopy="True" refto="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
     <ProjectReference type="Gac" localcopy="True" refto="Db4objects.Db4o, Version=7.4.121.14026, Culture=neutral, PublicKeyToken=6199cd4f203aa8eb" />
+    <ProjectReference type="Gac" localcopy="True" refto="System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   </References>
   <LanguageParameters StartupObject="LongoMatch.MainClass" ApplicationIcon="." CodePage="65001" ctype="CSharpProjectParameters" />
 </Project>
\ No newline at end of file
diff --git a/LongoMatch/Makefile.am b/LongoMatch/Makefile.am
index e38b961..5766afb 100644
--- a/LongoMatch/Makefile.am
+++ b/LongoMatch/Makefile.am
@@ -9,6 +9,7 @@ SOURCES = \
 	Common/ConsoleCrayon.cs \
 	Common/Constants.cs \
 	Common/Enums.cs \
+	Common/JSONSerializer.cs \
 	Common/GStreamer.cs \
 	Common/Log.cs \
 	Common/ProjectUtils.cs \
diff --git a/LongoMatch/Store/Category.cs b/LongoMatch/Store/Category.cs
index f1b745d..6f3a8be 100644
--- a/LongoMatch/Store/Category.cs
+++ b/LongoMatch/Store/Category.cs
@@ -35,7 +35,7 @@ namespace LongoMatch.Store
 	/// tagged in this category
 	/// </summary>
 	[Serializable]
-	public class Category:TimeNode, ISerializable
+	public class Category:TimeNode
 	{
 
 		private Guid _UUID;
@@ -125,38 +125,6 @@ namespace LongoMatch.Store
 			}
 		}
 
-		// this constructor is automatically called during deserialization
-		public Category(SerializationInfo info, StreamingContext context) {
-			_UUID = (Guid)info.GetValue("uuid", typeof(Guid));
-			Name = info.GetString("name");
-			Start = (Time)info.GetValue("start", typeof(Time));
-			Stop = (Time)info.GetValue("stop", typeof(Time));
-			HotKey = (HotKey)info.GetValue("hotkey", typeof(HotKey));
-			SubCategories = (List<ISubCategory>)info.GetValue("subcategories", typeof(List<ISubCategory>));
-			Position = info.GetInt32("position");
-			SortMethod = (SortMethodType)info.GetValue("sort_method", typeof(SortMethodType));
-			// read 'red', 'blue' and 'green' values and convert it to Gdk.Color
-			Color c = new Color();
-			c.Red = (ushort)info.GetValue("red", typeof(ushort));
-			c.Green = (ushort)info.GetValue("green", typeof(ushort));
-			c.Blue = (ushort)info.GetValue("blue", typeof(ushort));
-			Color = c;
-		}
-
-		// this method is automatically called during serialization
-		public void GetObjectData(SerializationInfo info, StreamingContext context) {
-			info.AddValue("uuid", UUID);
-			info.AddValue("name", Name);
-			info.AddValue("start", Start);
-			info.AddValue("stop", Stop);
-			info.AddValue("hotkey", HotKey);
-			info.AddValue("position", Position);
-			info.AddValue("subcategories", SubCategories);
-			info.AddValue("red", Color.Red);
-			info.AddValue("green", Color.Green);
-			info.AddValue("blue", Color.Blue);
-			info.AddValue("sort_method", SortMethod);
-		}
 		#endregion
 	}
 }
diff --git a/LongoMatch/Store/Templates/CategoriesTemplate.cs b/LongoMatch/Store/Templates/CategoriesTemplate.cs
index 5500a0c..d0f7980 100644
--- a/LongoMatch/Store/Templates/CategoriesTemplate.cs
+++ b/LongoMatch/Store/Templates/CategoriesTemplate.cs
@@ -50,11 +50,11 @@ namespace LongoMatch.Store.Templates
 			set;
 		}
 		public void Save(string filePath) {
-			SerializableObject.Save(this, filePath);
+			JSONSerializer.Save(this, filePath);
 		}
 
 		public static Categories Load(string filePath) {
-			return SerializableObject.Load<Categories>(filePath);
+			return JSONSerializer.Load<Categories>(filePath);
 		}
 
 		public static Categories DefaultTemplate(int count) {
@@ -81,13 +81,13 @@ namespace LongoMatch.Store.Templates
 				team.Add(Team.VISITOR);
 				
 				localplayers = new PlayerSubCategory {
-					Name = Catalog.GetString("Local Team Players"),
+					Name = Catalog.GetString("Local"),
 					AllowMultiple = true,
 					FastTag = true};
 			    localplayers.Add(Team.LOCAL);
 			    
 				visitorplayers = new PlayerSubCategory {
-					Name = Catalog.GetString("Visitor Team Players"),
+					Name = Catalog.GetString("Visitor"),
 					AllowMultiple = true,
 					FastTag = true};
 				visitorplayers.Add(Team.VISITOR);	
diff --git a/LongoMatch/Store/Templates/SubCategoryTemplate.cs b/LongoMatch/Store/Templates/SubCategoryTemplate.cs
index ac24a0d..d744877 100644
--- a/LongoMatch/Store/Templates/SubCategoryTemplate.cs
+++ b/LongoMatch/Store/Templates/SubCategoryTemplate.cs
@@ -34,11 +34,11 @@ namespace LongoMatch.Store.Templates
 		public SubCategoryTemplate(IEnumerable<string> tags): base (tags) {}
 
 		public void Save(string filePath) {
-			SerializableObject.Save(this, filePath);
+			JSONSerializer.Save(this, filePath);
 		}
 
 		public static SubCategoryTemplate Load(string filePath) {
-			return SerializableObject.Load<SubCategoryTemplate>(filePath);
+			return JSONSerializer.Load<SubCategoryTemplate>(filePath);
 		}
 		
 		public static SubCategoryTemplate DefaultTemplate (int not_used) {
diff --git a/LongoMatch/Store/Templates/TeamTemplate.cs b/LongoMatch/Store/Templates/TeamTemplate.cs
index a970a60..445a97e 100644
--- a/LongoMatch/Store/Templates/TeamTemplate.cs
+++ b/LongoMatch/Store/Templates/TeamTemplate.cs
@@ -27,7 +27,6 @@ using LongoMatch.Interfaces;
 namespace LongoMatch.Store.Templates
 {
 	[Serializable]
-
 	public class TeamTemplate: List<Player>, ITemplate<Player>
 	{
 		public TeamTemplate() {
@@ -51,11 +50,11 @@ namespace LongoMatch.Store.Templates
 		}
 
 		public void Save(string filePath) {
-			SerializableObject.Save(this, filePath);
+			JSONSerializer.Save(this, filePath);
 		}
 
 		public static TeamTemplate Load(string filePath) {
-			return SerializableObject.Load<TeamTemplate>(filePath);
+			return JSONSerializer.Load<TeamTemplate>(filePath);
 		}
 
 		public static TeamTemplate DefaultTemplate(int playersCount) {
diff --git a/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.ProjectSelectionDialog.cs b/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.ProjectSelectionDialog.cs
index 56ed755..72e5557 100644
--- a/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.ProjectSelectionDialog.cs
+++ b/LongoMatch/gtk-gui/LongoMatch.Gui.Dialog.ProjectSelectionDialog.cs
@@ -56,6 +56,7 @@ namespace LongoMatch.Gui.Dialog
 			this.fromfileradiobutton = new global::Gtk.RadioButton (global::Mono.Unix.Catalog.GetString ("New project using a video file"));
 			this.fromfileradiobutton.CanFocus = true;
 			this.fromfileradiobutton.Name = "fromfileradiobutton";
+			this.fromfileradiobutton.Active = true;
 			this.fromfileradiobutton.DrawIndicator = true;
 			this.fromfileradiobutton.UseUnderline = true;
 			this.fromfileradiobutton.FocusOnClick = false;
diff --git a/LongoMatch/gtk-gui/gui.stetic b/LongoMatch/gtk-gui/gui.stetic
index 3f89120..57d0fc6 100644
--- a/LongoMatch/gtk-gui/gui.stetic
+++ b/LongoMatch/gtk-gui/gui.stetic
@@ -5,7 +5,7 @@
     <target-gtk-version>2.12</target-gtk-version>
   </configuration>
   <import>
-    <widget-library name="../../bin/CesarPlayer.dll" />
+    <widget-library name="../../CesarPlayer/a.dll" />
     <widget-library name="../../bin/LongoMatch.exe" internal="true" />
   </import>
   <icon-factory>
diff --git a/LongoMatch/gtk-gui/objects.xml b/LongoMatch/gtk-gui/objects.xml
index 07b38c8..a84b975 100644
--- a/LongoMatch/gtk-gui/objects.xml
+++ b/LongoMatch/gtk-gui/objects.xml
@@ -15,59 +15,6 @@
       </itemgroup>
     </signals>
   </object>
-  <object type="LongoMatch.Gui.Component.PlayerPropertiesTreeView" palette-category="LongoMatch" allow-children="false" base-type="Gtk.TreeView">
-    <itemgroups />
-    <signals>
-      <itemgroup label="PlayerPropertiesTreeView Signals">
-        <signal name="PlayerClicked" />
-        <signal name="PlayerSelected" />
-      </itemgroup>
-    </signals>
-  </object>
-  <object type="LongoMatch.Gui.Component.PlayListTreeView" palette-category="LongoMatch" allow-children="false" base-type="Gtk.TreeView">
-    <itemgroups />
-    <signals>
-      <itemgroup label="PlayListTreeView Signals">
-        <signal name="ApplyCurrentRate" />
-      </itemgroup>
-    </signals>
-  </object>
-  <object type="LongoMatch.Gui.Component.CategoriesTreeView" palette-category="LongoMatch" allow-children="false" base-type="Gtk.TreeView">
-    <itemgroups />
-    <signals>
-      <itemgroup label="CategoriesTreeView Signals">
-        <signal name="CategoryClicked" />
-        <signal name="CategoriesSelected" />
-      </itemgroup>
-    </signals>
-  </object>
-  <object type="LongoMatch.Gui.Component.TimeScale" palette-category="LongoMatch" allow-children="false" base-type="Gtk.DrawingArea">
-    <itemgroups>
-      <itemgroup label="TimeScale Properties">
-        <property name="PixelRatio" />
-        <property name="CurrentFrame" />
-      </itemgroup>
-    </itemgroups>
-    <signals>
-      <itemgroup label="TimeScale Signals">
-        <signal name="NewMarkAtFrameEvent" />
-        <signal name="TimeNodeChanged" />
-        <signal name="TimeNodeSelected" />
-        <signal name="TimeNodeDeleted" />
-      </itemgroup>
-    </signals>
-  </object>
-  <object type="LongoMatch.Gui.Component.TimeReferenceWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.DrawingArea">
-    <itemgroups>
-      <itemgroup label="TimeReferenceWidget Properties">
-        <property name="CurrentFrame" />
-        <property name="PixelRatio" />
-        <property name="Scroll" />
-        <property name="FrameRate" />
-      </itemgroup>
-    </itemgroups>
-    <signals />
-  </object>
   <object type="LongoMatch.Gui.Component.PlayerProperties" palette-category="General" allow-children="false" base-type="Gtk.Bin">
     <itemgroups />
     <signals />
@@ -104,57 +51,6 @@
     <itemgroups />
     <signals />
   </object>
-  <object type="LongoMatch.Gui.Component.TagsTreeView" palette-category="LongoMatch" allow-children="false" base-type="Gtk.TreeView">
-    <itemgroups>
-      <itemgroup label="ListTreeViewBase Properties">
-        <property name="Colors" />
-      </itemgroup>
-    </itemgroups>
-    <signals>
-      <itemgroup label="ListTreeViewBase Signals">
-        <signal name="TimeNodeChanged" />
-        <signal name="TimeNodeSelected" />
-        <signal name="TimeNodeDeleted" />
-        <signal name="PlayListNodeAdded" />
-        <signal name="SnapshotSeriesEvent" />
-        <signal name="TagPlay" />
-      </itemgroup>
-    </signals>
-  </object>
-  <object type="LongoMatch.Gui.Component.PlayersTreeView" palette-category="LongoMatch" allow-children="false" base-type="Gtk.TreeView">
-    <itemgroups>
-      <itemgroup label="ListTreeViewBase Properties">
-        <property name="Colors" />
-      </itemgroup>
-    </itemgroups>
-    <signals>
-      <itemgroup label="ListTreeViewBase Signals">
-        <signal name="TimeNodeChanged" />
-        <signal name="TimeNodeSelected" />
-        <signal name="TimeNodeDeleted" />
-        <signal name="PlayListNodeAdded" />
-        <signal name="SnapshotSeriesEvent" />
-        <signal name="TagPlay" />
-      </itemgroup>
-    </signals>
-  </object>
-  <object type="LongoMatch.Gui.Component.PlaysTreeView" palette-category="LongoMatch" allow-children="false" base-type="Gtk.TreeView">
-    <itemgroups>
-      <itemgroup label="ListTreeViewBase Properties">
-        <property name="Colors" />
-      </itemgroup>
-    </itemgroups>
-    <signals>
-      <itemgroup label="ListTreeViewBase Signals">
-        <signal name="TimeNodeChanged" />
-        <signal name="TimeNodeSelected" />
-        <signal name="TimeNodeDeleted" />
-        <signal name="PlayListNodeAdded" />
-        <signal name="SnapshotSeriesEvent" />
-        <signal name="TagPlay" />
-      </itemgroup>
-    </signals>
-  </object>
   <object type="LongoMatch.Gui.Component.PlayListWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
     <itemgroups />
     <signals>
@@ -251,15 +147,6 @@
       </itemgroup>
     </signals>
   </object>
-  <object type="LongoMatch.Gui.SubCategoriesTreeView" palette-category="LongoMatch" allow-children="false" base-type="Gtk.TreeView">
-    <itemgroups />
-    <signals>
-      <itemgroup label="SubCategoriesTreeView Signals">
-        <signal name="SubCategoriesDeleted" />
-        <signal name="SubCategorySelected" />
-      </itemgroup>
-    </signals>
-  </object>
   <object type="LongoMatch.Gui.Component.TemplatesEditorBase" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
     <itemgroups>
       <itemgroup label="TemplatesEditorBase Properties">
@@ -278,8 +165,4 @@
     <itemgroups />
     <signals />
   </object>
-  <object type="LongoMatch.Gui.Component.TeamTaggerWidget" palette-category="General" allow-children="false" base-type="Gtk.Bin">
-    <itemgroups />
-    <signals />
-  </object>
 </objects>
\ No newline at end of file
diff --git a/build/build.environment.mk b/build/build.environment.mk
index 89a1386..f0af91d 100644
--- a/build/build.environment.mk
+++ b/build/build.environment.mk
@@ -7,6 +7,7 @@ DEFAULT_INSTALL_DIR = $(pkglibdir)
 
 # External libraries to link against, generated from configure
 LINK_SYSTEM = -r:System
+LINK_SYSTEM_SERVICEMODEL_WEB = -r:System.ServiceModel.Web
 LINK_CAIRO = -r:Mono.Cairo
 LINK_MONO_POSIX = -r:Mono.Posix
 LINK_MONO_ZEROCONF = $(MONO_ZEROCONF_LIBS)
@@ -22,6 +23,7 @@ REF_DEP_CESARPLAYER = $(LINK_GLIB) \
 
 REF_DEP_LONGOMATCH = \
                      $(LINK_MONO_POSIX) \
+                     $(LINK_SYSTEM_SERVICEMODEL_WEB) \
                      $(LINK_DB40) \
                      $(LINK_GLIB) \
                      $(LINK_GTK) \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]