[longomatch/redesign: 34/47] Fix serialization of templates



commit 49404389e8cac44e787c3e50d8bc779858024bea
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Wed Dec 22 00:27:12 2010 +0100

    Fix serialization of templates

 LongoMatch/Store/Templates/CategoriesTemplate.cs |    4 ++++
 LongoMatch/Store/Templates/TagsTemplate.cs       |   13 +++++++++----
 LongoMatch/Store/Templates/TeamTemplate.cs       |   12 ++++++++----
 LongoMatch/Store/Templates/Template.cs           |    6 ++++--
 4 files changed, 25 insertions(+), 10 deletions(-)
---
diff --git a/LongoMatch/Store/Templates/CategoriesTemplate.cs b/LongoMatch/Store/Templates/CategoriesTemplate.cs
index dfbbf80..42e3af2 100644
--- a/LongoMatch/Store/Templates/CategoriesTemplate.cs
+++ b/LongoMatch/Store/Templates/CategoriesTemplate.cs
@@ -174,6 +174,10 @@ namespace LongoMatch.Store.Templates
 			        select c.Stop).ToList();
 		}
 		
+		public void Save(string filePath){
+			Save(this, filePath);
+		}
+		
 		public static Categories Load(string filePath) {
 			return Load<Categories>(filePath);
 		}
diff --git a/LongoMatch/Store/Templates/TagsTemplate.cs b/LongoMatch/Store/Templates/TagsTemplate.cs
index c11c4ca..583f016 100644
--- a/LongoMatch/Store/Templates/TagsTemplate.cs
+++ b/LongoMatch/Store/Templates/TagsTemplate.cs
@@ -54,16 +54,21 @@ namespace LongoMatch.Store.Templates
 		public IEnumerator<Tag> GetEnumerator(){
 			return tagsList.GetEnumerator();
 		}
-		public static TagsTemplate DefaultTemplate() {
-			TagsTemplate defaultTemplate = new TagsTemplate();
-			defaultTemplate.FillDefaultTemplate();
-			return defaultTemplate;
+		
+		public void Save(string filePath){
+			Save(this, filePath);
 		}
 		
 		public static TagsTemplate Load(string filePath) {
 			return Load<TagsTemplate>(filePath);
 		}
 		
+		public static TagsTemplate DefaultTemplate() {
+			TagsTemplate defaultTemplate = new TagsTemplate();
+			defaultTemplate.FillDefaultTemplate();
+			return defaultTemplate;
+		}
+		
 		private void FillDefaultTemplate() {
 			//FIXME: To implement
 		}
diff --git a/LongoMatch/Store/Templates/TeamTemplate.cs b/LongoMatch/Store/Templates/TeamTemplate.cs
index 270da3f..f3b41b7 100644
--- a/LongoMatch/Store/Templates/TeamTemplate.cs
+++ b/LongoMatch/Store/Templates/TeamTemplate.cs
@@ -67,16 +67,20 @@ namespace LongoMatch.Store.Templates
 			playersList.Add(player);
 		}
 
-		public static TeamTemplate DefaultTemplate(int playersCount) {
-			TeamTemplate defaultTemplate = new TeamTemplate();
-			defaultTemplate.FillDefaultTemplate(playersCount);
-			return defaultTemplate;
+		public void Save(string filePath){
+			Save(this, filePath);
 		}
 		
 		public static TeamTemplate Load(string filePath) {
 			return Load<TeamTemplate>(filePath);
 		}
 		
+		public static TeamTemplate DefaultTemplate(int playersCount) {
+			TeamTemplate defaultTemplate = new TeamTemplate();
+			defaultTemplate.FillDefaultTemplate(playersCount);
+			return defaultTemplate;
+		}
+		
 		private void FillDefaultTemplate(int playersCount) {
 			for (int i=1; i<=playersCount;i++) {
 				playersList.Add(new Player{
diff --git a/LongoMatch/Store/Templates/Template.cs b/LongoMatch/Store/Templates/Template.cs
index b1c7304..723a414 100644
--- a/LongoMatch/Store/Templates/Template.cs
+++ b/LongoMatch/Store/Templates/Template.cs
@@ -15,18 +15,20 @@
 //  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;
 using System.Runtime.Serialization.Formatters.Binary;
 
 namespace LongoMatch.Store.Templates
 {
+	[Serializable]
 	public abstract class Template
 	{
-		public void Save(string filepath) {
+		protected void Save<T>(T template, string filepath) {
 			IFormatter formatter = new  BinaryFormatter();
 			Stream stream = new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.None);
-			formatter.Serialize(stream, this);
+			formatter.Serialize(stream, template);
 			stream.Close();
 		}
 



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