[commit] r2185 - trunk/SDK/DotNet/DsmlGenerator/CSharpDsmlGenerator
GMESRC Repository Notifications
gme-commit at list.isis.vanderbilt.edu
Wed Apr 24 15:37:08 CDT 2013
Author: ksmyth
Date: Wed Apr 24 15:37:08 2013
New Revision: 2185
Log:
Define MSBuild task GenerateCSharpDSML
Added:
trunk/SDK/DotNet/DsmlGenerator/CSharpDsmlGenerator/CSharpDSMLTask.cs
Added: trunk/SDK/DotNet/DsmlGenerator/CSharpDsmlGenerator/CSharpDSMLTask.cs
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/SDK/DotNet/DsmlGenerator/CSharpDsmlGenerator/CSharpDSMLTask.cs Wed Apr 24 15:37:08 2013 (r2185)
@@ -0,0 +1,139 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Build.Framework;
+using GME.MGA;
+using System.IO;
+using GME.CSharp;
+using System.Threading;
+
+namespace CSharpDSMLGenerator
+{
+ public class GenerateCSharpDSML : ITask
+ {
+ public GenerateCSharpDSML()
+ {
+ CompileDll = true;
+ }
+
+ public IBuildEngine BuildEngine
+ {
+ get;
+ set;
+ }
+
+ [Required]
+ public string InputFile
+ {
+ get;
+ set;
+ }
+
+ [Required]
+ public string OutputDir
+ {
+ get;
+ set;
+ }
+
+ public bool CompileDll
+ {
+ get;
+ set;
+ }
+
+ public string ParadigmXmpFile
+ {
+ get;
+ set;
+ }
+
+ public string GeneratorMode
+ {
+ get;
+ set;
+ }
+
+ public bool Execute()
+ {
+ Directory.CreateDirectory(OutputDir);
+ CSharpDSMLGeneratorInterpreter.GeneratorMode mode;
+ if (GeneratorMode == null)
+ {
+ mode = CSharpDSMLGeneratorInterpreter.GeneratorMode.Namespaces;
+ }
+ else
+ {
+ mode = (CSharpDSMLGeneratorInterpreter.GeneratorMode)Enum.Parse(typeof(CSharpDSMLGeneratorInterpreter.GeneratorMode), GeneratorMode);
+ }
+
+ Exception excep = null;
+ bool success = false;
+ Thread t = new Thread(() =>
+ {
+ try
+ {
+ MgaProject project = new MgaProject();
+ bool ro;
+ project.Open("MGA=" + InputFile, out ro);
+ try
+ {
+ project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_NON_NESTED);
+ try
+ {
+ if (ParadigmXmpFile == null)
+ {
+ string projectDir = Path.GetDirectoryName(InputFile);
+ ParadigmXmpFile = Path.Combine(projectDir, project.RootFolder.Name);
+ ParadigmXmpFile = Path.ChangeExtension(ParadigmXmpFile, "xmp");
+ }
+ var generator = new CSharpDSMLGeneratorInterpreter();
+ generator.GMEConsole = GMEConsole.CreateFromProject(project);
+ generator.MgaGateway = new MgaGateway(project);
+
+ var compileUnit = generator.GenerateDotNetCode(project, ParadigmXmpFile, OutputDir, mode);
+ if (CompileDll)
+ {
+ success = generator.CompileDll(OutputDir, compileUnit);
+ }
+ else
+ {
+ success = true;
+ }
+ }
+ finally
+ {
+ project.AbortTransaction();
+ }
+ }
+ finally
+ {
+ project.Close();
+ }
+
+ }
+ catch (Exception e)
+ {
+ excep = e;
+ }
+ }
+ );
+ t.SetApartmentState(ApartmentState.STA);
+ t.Start();
+ t.Join();
+
+ if (excep != null)
+ {
+ throw new Exception("Error generating DSML", excep);
+ }
+ return success;
+ }
+
+ public ITaskHost HostObject
+ {
+ get;
+ set;
+ }
+ }
+}
More information about the gme-commit
mailing list