[longomatch] Add a new export plugin for CSV



commit e2e60c3a8da39ae23fb7af1baf54d56923cc7776
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sat Jan 19 13:48:22 2013 +0100

    Add a new export plugin for CSV

 LongoMatch.Plugins/Assembly.cs            |   22 +++++
 LongoMatch.Plugins/CSVExporter.cs         |  148 +++++++++++++++++++++++++++++
 LongoMatch.Plugins/LongoMatch.Plugins.mdp |   27 +++++
 LongoMatch.Plugins/Makefile.am            |   14 +++
 LongoMatch.mds                            |    4 +
 Makefile.am                               |    1 +
 build/build.environment.mk                |    6 +
 configure.ac                              |    1 +
 8 files changed, 223 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch.Plugins/Assembly.cs b/LongoMatch.Plugins/Assembly.cs
new file mode 100644
index 0000000..ac8d02e
--- /dev/null
+++ b/LongoMatch.Plugins/Assembly.cs
@@ -0,0 +1,22 @@
+// 
+//  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 Mono.Addins;
+
+[assembly:Addin]
+[assembly:AddinDependency ("LongoMatch", "1.0")]
\ No newline at end of file
diff --git a/LongoMatch.Plugins/CSVExporter.cs b/LongoMatch.Plugins/CSVExporter.cs
new file mode 100644
index 0000000..ce76d65
--- /dev/null
+++ b/LongoMatch.Plugins/CSVExporter.cs
@@ -0,0 +1,148 @@
+// 
+//  Copyright (C) 2013 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.Collections.Generic;
+using System.Linq; 
+using Mono.Addins;
+using Mono.Unix;
+
+using LongoMatch.Addins.ExtensionPoints;
+using LongoMatch.Interfaces.GUI;
+using LongoMatch.Store;
+using System.IO;
+using LongoMatch.Interfaces;
+
+namespace LongoMatch.Plugins
+{
+
+	[Extension]
+	public class CSVExporter:IExportProject
+	{
+		public string GetMenuEntryName () {
+			Log.Information("Registering new export entry");
+			return Catalog.GetString("Export project to CSV file");
+		}
+		
+		public string GetMenuEntryShortName () {
+			return "CSVExport";
+		}
+		
+		public void ExportProject (Project project, IGUIToolkit guiToolkit) {
+			string filename = guiToolkit.SaveFile(Catalog.GetString("Output file"), null,
+			                                      Config.HomeDir(), "CSV", ".csv");
+			
+			if (filename == null)
+				return;
+			
+			filename = System.IO.Path.ChangeExtension(filename, ".csv");
+			
+			try {
+				ProjectToCSV exporter = new ProjectToCSV(project, filename);
+				exporter.Export();
+				guiToolkit.InfoMessage(Catalog.GetString("Project exported successfully"));
+			}catch (Exception ex) {
+				guiToolkit.ErrorMessage(Catalog.GetString("Error exporting project"));
+				Log.Exception(ex);
+			}
+		}
+	}
+	
+	class ProjectToCSV
+	{
+		Project project;
+		string filename;
+		List<string> output;
+		
+		public ProjectToCSV(Project project, string filename) {
+			this.project = project;
+			this.filename = filename;
+			output = new List<string>();
+		}
+		
+		public void Export() {
+			foreach (Category cat in project.Categories) {
+				ExportCategory (cat);
+			}
+			File.WriteAllLines(filename, output);
+		}
+		
+		void ExportCategory (Category cat) {
+			string headers;
+			List<Play> plays;
+			
+			output.Add("CATEGORY: " + cat.Name);
+			plays = project.PlaysInCategory (cat);
+			
+			/* Write Headers for this category */
+			headers = "Name;Start;Stop;Team";
+			foreach (ISubCategory subcat in cat.SubCategories) {
+				TagSubCategory ts = subcat as TagSubCategory;
+				if (ts == null)
+					continue;
+					
+				foreach (string desc in ts.ElementsDesc()) {
+					headers += String.Format (";{0}:{1}", ts.Name, desc);
+				}
+			}
+			
+			/* Players subcategories */
+			foreach (ISubCategory subcat in cat.SubCategories) {
+				PlayerSubCategory ps = subcat as PlayerSubCategory;
+				if (ps == null)
+					continue;
+				headers += ";" + ps.Name;
+			}
+			output.Add (headers);
+			
+			foreach (Play play in plays.OrderBy(p=>p.Start)) {
+				string line;
+				
+				line = String.Format("{0};{1};{2};{3}", play.Name,
+				                         play.Start.ToMSecondsString(),
+				                         play.Stop.ToMSecondsString(),
+				                         play.Team);
+				
+				/* Strings Tags */
+				foreach (ISubCategory subcat in cat.SubCategories) {
+					TagSubCategory ts = subcat as TagSubCategory;
+					if (ts == null)
+						continue;
+					
+					foreach (string desc in ts.ElementsDesc()) {
+						StringTag t = new StringTag{SubCategory=subcat, Value = desc};
+						line += ";" + (play.Tags.Contains(t) ? "1" : "0");
+					}
+				}
+				
+				/* Player Tags */
+				foreach (ISubCategory subcat in cat.SubCategories) {
+					PlayerSubCategory ps = subcat as PlayerSubCategory;
+					if (ps == null)
+						continue;
+					
+					line += ";";
+					foreach (PlayerTag p in play.Players.GetTags (ps)) {
+						line += p.Value.Name + " ";
+					}
+				}
+				output.Add (line);
+			}
+			output.Add("");
+		}
+	}
+}
diff --git a/LongoMatch.Plugins/LongoMatch.Plugins.mdp b/LongoMatch.Plugins/LongoMatch.Plugins.mdp
new file mode 100644
index 0000000..4708654
--- /dev/null
+++ b/LongoMatch.Plugins/LongoMatch.Plugins.mdp
@@ -0,0 +1,27 @@
+<Project name="LongoMatch.Plugins" fileversion="2.0" DefaultNamespace="LongoMatch.Plugins" language="C#" targetFramework="4.0" ctype="DotNetProject">
+  <Configurations active="Release">
+    <Configuration name="Debug" ctype="DotNetProjectConfiguration">
+      <Output directory="../bin/" assembly="LongoMatch.Plugins" />
+      <Build debugmode="True" target="Library" />
+      <Execution consolepause="False" runwithwarnings="True" runtime="MsNet" />
+      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" definesymbols="DEBUG;" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+    </Configuration>
+    <Configuration name="Release" ctype="DotNetProjectConfiguration">
+      <Output directory="../bin/" assembly="LongoMatch.Plugins" />
+      <Build debugmode="False" target="Library" />
+      <Execution consolepause="False" runwithwarnings="True" runtime="MsNet" />
+      <CodeGeneration compiler="Mcs" warninglevel="4" optimize="False" unsafecodeallowed="False" generateoverflowchecks="False" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+    </Configuration>
+  </Configurations>
+  <Contents>
+    <File subtype="Code" buildaction="Compile" name="Assembly.cs" />
+    <File subtype="Code" buildaction="Compile" name="CSVExporter.cs" />
+  </Contents>
+  <References>
+    <ProjectReference type="Gac" localcopy="True" refto="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+    <ProjectReference type="Project" localcopy="True" refto="LongoMatch.Addins" />
+    <ProjectReference type="Project" localcopy="True" refto="LongoMatch.Core" />
+    <ProjectReference type="Gac" localcopy="False" refto="Mono.Addins, Version=0.6.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
+    <ProjectReference specificVersion="False" type="Gac" localcopy="False" refto="Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
+  </References>
+</Project>
\ No newline at end of file
diff --git a/LongoMatch.Plugins/Makefile.am b/LongoMatch.Plugins/Makefile.am
new file mode 100644
index 0000000..6a4ed87
--- /dev/null
+++ b/LongoMatch.Plugins/Makefile.am
@@ -0,0 +1,14 @@
+ASSEMBLY = LongoMatch.Plugins
+TARGET = library
+INSTALL_DIR = $(pkglibdir)/plugins
+
+LINK = $(REF_DEP_LONGOMATCH_PLUGINS)
+
+SOURCES = \
+	Assembly.cs \
+	CSVExporter.cs
+
+RESOURCES =
+
+include $(top_srcdir)/build/build.mk
+
diff --git a/LongoMatch.mds b/LongoMatch.mds
index 26745c4..492e82e 100644
--- a/LongoMatch.mds
+++ b/LongoMatch.mds
@@ -27,6 +27,7 @@
       <Entry build="True" name="LongoMatch.GUI.Multimedia" configuration="Debug" />
       <Entry build="True" name="LongoMatch.Addins" configuration="Debug" />
       <Entry build="True" name="LongoMatch.Addins.COE" configuration="Debug" />
+      <Entry build="True" name="LongoMatch.Plugins" configuration="Debug" />
     </Configuration>
     <Configuration name="Release" ctype="CombineConfiguration">
       <Entry build="True" name="LongoMatch.GUI" configuration="Release" />
@@ -38,6 +39,7 @@
       <Entry build="True" name="LongoMatch.GUI.Multimedia" configuration="Release" />
       <Entry build="True" name="LongoMatch.Addins" configuration="Release" />
       <Entry build="True" name="LongoMatch.Addins.COE" configuration="Release" />
+      <Entry build="True" name="LongoMatch.Plugins" configuration="Release" />
     </Configuration>
   </Configurations>
   <StartMode startupentry="LongoMatchGtk" single="True">
@@ -50,6 +52,7 @@
     <Execute type="None" entry="LongoMatch.GUI.Multimedia" />
     <Execute type="None" entry="LongoMatch.Addins" />
     <Execute type="None" entry="LongoMatch.Addins.COE" />
+    <Execute type="None" entry="LongoMatch.Plugins" />
   </StartMode>
   <Entries>
     <Entry filename="LongoMatch.GUI/LongoMatch.GUI.mdp" />
@@ -61,5 +64,6 @@
     <Entry filename="LongoMatch.GUI.Multimedia/LongoMatch.GUI.Multimedia.mdp" />
     <Entry filename="LongoMatch.Addins/LongoMatch.Addins.mdp" />
     <Entry filename="LongoMatch.Addins.COE/LongoMatch.Addins.COE.mdp" />
+    <Entry filename="LongoMatch.Plugins/LongoMatch.Plugins.mdp" />
   </Entries>
 </Combine>
\ No newline at end of file
diff --git a/Makefile.am b/Makefile.am
index fa91cad..6d53d58 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,6 +11,7 @@ SUBDIRS = \
 	LongoMatch.Multimedia \
 	LongoMatch.GUI.Multimedia \
 	LongoMatch.GUI \
+	LongoMatch.Plugins \
 	LongoMatch.Services \
 	LongoMatch \
 	po
diff --git a/build/build.environment.mk b/build/build.environment.mk
index c9b48bb..589e7f9 100644
--- a/build/build.environment.mk
+++ b/build/build.environment.mk
@@ -29,6 +29,12 @@ REF_DEP_LONGOMATCH_ADDINS = \
                      $(LINK_MONO_ADDINS) \
                      $(LINK_LONGOMATCH_CORE)
 
+REF_DEP_LONGOMATCH_PLUGINS = \
+                     $(LINK_MONO_ADDINS) \
+                     $(LINK_MONO_POSIX) \
+                     $(LINK_LONGOMATCH_CORE) \
+                     $(LINK_LONGOMATCH_ADDINS)
+
 REF_DEP_LONGOMATCH_CORE = \
                      $(LINK_SYSTEM_DRAWING) \
                      $(LINK_MONO_POSIX) \
diff --git a/configure.ac b/configure.ac
index 25dab3a..beaec33 100644
--- a/configure.ac
+++ b/configure.ac
@@ -131,6 +131,7 @@ LongoMatch.Multimedia/Makefile
 LongoMatch.Multimedia/LongoMatch.Multimedia.dll.config
 LongoMatch.GUI.Multimedia/Makefile
 LongoMatch.GUI/Makefile
+LongoMatch.Plugins/Makefile
 LongoMatch.Services/Makefile
 LongoMatch/Makefile
 LongoMatch/longomatch



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