[longomatch] Start removing file references on the templates



commit 1793d18444ee49e24f56fe2d1e61fa16c4a3d985
Author: Jorge Zapata <jorgeluis zapata gmail com>
Date:   Tue Mar 10 19:27:50 2015 +0100

    Start removing file references on the templates
    
    For that we need to put the custom deserialization on the correct place

 LongoMatch.Core/Store/Templates/Dashboard.cs    |   24 ++++++++++++++++------
 LongoMatch.Core/Store/Templates/TeamTemplate.cs |   18 +++++++++++++---
 2 files changed, 31 insertions(+), 11 deletions(-)
---
diff --git a/LongoMatch.Core/Store/Templates/Dashboard.cs b/LongoMatch.Core/Store/Templates/Dashboard.cs
index f48bf2b..8e75b1b 100644
--- a/LongoMatch.Core/Store/Templates/Dashboard.cs
+++ b/LongoMatch.Core/Store/Templates/Dashboard.cs
@@ -20,6 +20,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Runtime.Serialization;
 using Newtonsoft.Json;
 
 using Mono.Unix;
@@ -41,7 +42,7 @@ namespace LongoMatch.Core.Store.Templates
        /// The <see cref="LongoMatch.DB.Project"/> must handle all the changes
        /// </summary>
        [Serializable]
-       public class Dashboard: ITemplate
+       public class Dashboard: ITemplate, IDeserializationCallback
        {
 
                const int CAT_WIDTH = 120;
@@ -89,7 +90,7 @@ namespace LongoMatch.Core.Store.Templates
                        get;
                        set;
                }
-               
+
                public Image Image {
                        get;
                        set;
@@ -150,6 +151,20 @@ namespace LongoMatch.Core.Store.Templates
                        }
                }
 
+               #region IDeserializationCallback implementation
+
+               void IDeserializationCallback.OnDeserialization (object sender)
+               {
+                       // After being deserialized, make sure to create a default GamePeriod
+                       if (GamePeriods == null) {
+                               GamePeriods = new List<string>();
+                               GamePeriods.Add ("1");
+                               GamePeriods.Add ("2");
+                       }
+               }
+
+               #endregion
+
                public void Save(string filePath) {
                        Serializer.Save(this, filePath);
                }
@@ -200,11 +215,6 @@ namespace LongoMatch.Core.Store.Templates
 
                public static Dashboard Load(string filePath) {
                        Dashboard cat = Serializer.LoadSafe<Dashboard>(filePath);
-                       if (cat.GamePeriods == null) {
-                               cat.GamePeriods = new List<string>();
-                               cat.GamePeriods.Add ("1");
-                               cat.GamePeriods.Add ("2");
-                       }
                        return cat;
                }
 
diff --git a/LongoMatch.Core/Store/Templates/TeamTemplate.cs b/LongoMatch.Core/Store/Templates/TeamTemplate.cs
index 4c37270..0f9909b 100644
--- a/LongoMatch.Core/Store/Templates/TeamTemplate.cs
+++ b/LongoMatch.Core/Store/Templates/TeamTemplate.cs
@@ -19,6 +19,8 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Runtime.Serialization;
+
 using Mono.Unix;
 using Newtonsoft.Json;
 
@@ -29,7 +31,7 @@ using System.IO;
 namespace LongoMatch.Core.Store.Templates
 {
        [Serializable]
-       public class TeamTemplate: ITemplate
+       public class TeamTemplate: ITemplate, IDeserializationCallback
        {
                private const int MAX_WIDTH=100;
                private const int MAX_HEIGHT=100;
@@ -173,6 +175,17 @@ namespace LongoMatch.Core.Store.Templates
                        }
                }
 
+               #region IDeserializationCallback implementation
+
+               void IDeserializationCallback.OnDeserialization (object sender)
+               {
+                       if (Formation == null) {
+                               FormationStr = "1-4-3-3";
+                       }
+               }
+
+               #endregion
+
                public void RemovePlayers (List<Player> players, bool delete)
                {
                        List<Player> bench, starters;
@@ -228,9 +241,6 @@ namespace LongoMatch.Core.Store.Templates
 
                public static TeamTemplate Load(string filePath) {
                        TeamTemplate template = Serializer.LoadSafe<TeamTemplate>(filePath);
-                       if (template.Formation == null) {
-                               template.FormationStr = "1-4-3-3";
-                       }
                        return template;
                }
 


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