[longomatch] Remove every Load/Save method from the Template



commit 086ce8a4c3043a2014b2f4bf4319df5dec2a17bf
Author: Jorge Zapata <jorgeluis zapata gmail com>
Date:   Wed Mar 11 11:32:14 2015 +0100

    Remove every Load/Save method from the Template
    
    The templates should not load/save any file/template name, let the
    upper access layer (db or file, to do it).

 LongoMatch.Core/Interfaces/ITemplates.cs         |    2 +-
 LongoMatch.Core/Store/Templates/Dashboard.cs     |    9 ---------
 LongoMatch.Core/Store/Templates/TeamTemplate.cs  |    9 ---------
 LongoMatch.GUI/Gui/Panel/SportsTemplatesPanel.cs |    2 +-
 LongoMatch.Services/Services/TemplatesService.cs |   17 ++++++++++++-----
 5 files changed, 14 insertions(+), 25 deletions(-)
---
diff --git a/LongoMatch.Core/Interfaces/ITemplates.cs b/LongoMatch.Core/Interfaces/ITemplates.cs
index 197e6d3..b11b7c5 100644
--- a/LongoMatch.Core/Interfaces/ITemplates.cs
+++ b/LongoMatch.Core/Interfaces/ITemplates.cs
@@ -24,7 +24,6 @@ namespace LongoMatch.Core.Interfaces
 {
        public interface ITemplate: IIDObject
        {
-               void Save (string filename);
                string Name {get; set;}
        }
        
@@ -42,6 +41,7 @@ namespace LongoMatch.Core.Interfaces
        {
                List<T> Templates {get;}
                T Load (string name);
+               T LoadFile (string filename);
                void Save (ITemplate template);
                void Update (ITemplate template);
                void Register (T template);
diff --git a/LongoMatch.Core/Store/Templates/Dashboard.cs b/LongoMatch.Core/Store/Templates/Dashboard.cs
index 8e75b1b..8677e44 100644
--- a/LongoMatch.Core/Store/Templates/Dashboard.cs
+++ b/LongoMatch.Core/Store/Templates/Dashboard.cs
@@ -165,10 +165,6 @@ namespace LongoMatch.Core.Store.Templates
 
                #endregion
 
-               public void Save(string filePath) {
-                       Serializer.Save(this, filePath);
-               }
-
                public void ChangeHotkey (DashboardButton button, HotKey hotkey)
                {
                        if (List.Count (d => d.HotKey == hotkey) > 0) {
@@ -213,11 +209,6 @@ namespace LongoMatch.Core.Store.Templates
                        return button;
                }
 
-               public static Dashboard Load(string filePath) {
-                       Dashboard cat = Serializer.LoadSafe<Dashboard>(filePath);
-                       return cat;
-               }
-
                public static Dashboard DefaultTemplate(int count) {
                        TagButton tagbutton;
                        TimerButton timerButton;
diff --git a/LongoMatch.Core/Store/Templates/TeamTemplate.cs b/LongoMatch.Core/Store/Templates/TeamTemplate.cs
index 0f9909b..943346f 100644
--- a/LongoMatch.Core/Store/Templates/TeamTemplate.cs
+++ b/LongoMatch.Core/Store/Templates/TeamTemplate.cs
@@ -214,10 +214,6 @@ namespace LongoMatch.Core.Store.Templates
                        }
                }
 
-               public void Save(string filePath) {
-                       Serializer.Save(this, filePath);
-               }
-
                public void UpdateColors ()
                {
                        foreach (Player p in List) {
@@ -239,11 +235,6 @@ namespace LongoMatch.Core.Store.Templates
                        return p;
                }
 
-               public static TeamTemplate Load(string filePath) {
-                       TeamTemplate template = Serializer.LoadSafe<TeamTemplate>(filePath);
-                       return template;
-               }
-
                public static TeamTemplate DefaultTemplate(int playersCount) {
                        TeamTemplate defaultTemplate = new TeamTemplate();
                        defaultTemplate.FillDefaultTemplate(playersCount);
diff --git a/LongoMatch.GUI/Gui/Panel/SportsTemplatesPanel.cs 
b/LongoMatch.GUI/Gui/Panel/SportsTemplatesPanel.cs
index b382db2..f4f3aa4 100644
--- a/LongoMatch.GUI/Gui/Panel/SportsTemplatesPanel.cs
+++ b/LongoMatch.GUI/Gui/Panel/SportsTemplatesPanel.cs
@@ -318,7 +318,7 @@ namespace LongoMatch.Gui.Panel
                                return;
 
                        try {
-                               Dashboard new_dashboard = Dashboard.Load (fileName);
+                               Dashboard new_dashboard = provider.LoadFile (fileName);
 
                                if (new_dashboard != null) {
                                        bool abort = false;
diff --git a/LongoMatch.Services/Services/TemplatesService.cs 
b/LongoMatch.Services/Services/TemplatesService.cs
index afffdca..444c20e 100644
--- a/LongoMatch.Services/Services/TemplatesService.cs
+++ b/LongoMatch.Services/Services/TemplatesService.cs
@@ -71,7 +71,6 @@ namespace LongoMatch.Services
        {
                readonly string basePath;
                readonly string extension;
-               readonly MethodInfo methodLoad;
                readonly MethodInfo methodDefaultTemplate;
                List<T> systemTemplates;
 
@@ -79,7 +78,6 @@ namespace LongoMatch.Services
                {
                        this.basePath = basePath;
                        this.extension = extension;
-                       methodLoad = typeof(T).GetMethod ("Load");
                        methodDefaultTemplate = typeof(T).GetMethod ("DefaultTemplate");
                        systemTemplates = new List<T> ();
                }
@@ -137,12 +135,21 @@ namespace LongoMatch.Services
                                return Cloner.Clone (template);
                        } else {
                                Log.Information ("Loading template " + name);
-                               template = (T)methodLoad.Invoke (null, new object[] { GetPath(name) });
+                               template = (T)Serializer.LoadSafe<T>(GetPath(name));
                                template.Name = name;
                                return template;
                        }
                }
 
+               public T LoadFile (string filename)
+               {
+                       T template;
+
+                       Log.Information ("Loading template file " + filename);
+                       template = (T)Serializer.LoadSafe<T>(filename);
+                       return template;
+               }
+
                public void Save (ITemplate template)
                {
                        CheckInvalidChars (template.Name);
@@ -160,7 +167,7 @@ namespace LongoMatch.Services
                        }
                        
                        /* Don't cach the Exception here to chain it up */
-                       template.Save (filename);
+                       Serializer.Save<T>((T)template, filename);
                }
 
                public void Update (ITemplate template)
@@ -169,7 +176,7 @@ namespace LongoMatch.Services
                        string filename = GetPath (template.Name);
                        Log.Information ("Updating template " + filename);
                        /* Don't cach the Exception here to chain it up */
-                       template.Save (filename);
+                       Save(template);
                }
 
                public void Register (T template)


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