...
A sample upgrade program using the API is shown here. Notice that it use WPF Subsystem logic that is implemented in a C# assembly and available as C# source.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
using gmslLibrary; using wpfLibrary; using GM=gmslAPI; namespace gmUpgrade { public static class Program { [System.STAThread] // Much faster using STA, ~1.6 vs 8.6 seconds static void Main(string[] args) { // When started by gmStudio, TaskInfo is passed on command line. // For debugging or direct operation, load upgrade tasks here. if (args.Length == 0) { args = new string[] { @"TaskInfo=c:\Upgrades\proj\log\Upgrade-task1-exe-csh.xml", @"TaskInfo=c:\Upgrades\proj\log\Upgrade-task2-exe-csh.xmlxml", @"TaskInfo=c:\Upgrades\proj\log\Upgrade-task3-exe-csh.xml", @"TaskInfo=c:\Upgrades\proj\log\Upgrade-task4-exe-csh.xmll" }; } RunAllTranslations(args); System.Environment.Exit(0); } static void RunAllTranslations(string[] args) { GM.gmslAPI.LoadLicense(logInfo:true); // Must load gmStudio License string taskInfoPath = ""; foreach (string arg in args) { if (arg.StartsWith("TaskInfo=")) { taskInfoPath = arg.Split('=')[1]; if (!System.IO.File.Exists(taskInfoPath)) { System.Console.WriteLine("ERROR: TaskInfo File Not Found:" + taskInfoPath); System.Environment.Exit(999); } else { Run1Translation(taskInfoPath); } } } } private static void Run1Translation(string taskInfoPath) { GM.gmStudioTask task = GM.gmslAPI.Load(taskInfoPath); bool useWPF = task.UserDesc == "WPF"; // Go to Upgrade project working folder so relative file references are correct System.IO.Directory.SetCurrentDirectory(task.WorkFolder); // Detailed translation rules are stored in a ScriptRules.xml // This format can be used by both XML-based and API-based upgrade tasks // The ScriptRules class makes these rules available to API calls. GM.ScriptRules rules = new GM.ScriptRules(@"..\usr\ScriptRules.xml"); rules.AddRules(task, "SetOptions"); rules.AddRules(task, "PreEdits"); rules.AddRules(task, "msado15.dll"); rules.AddRules(task, "scrrun.dll"); rules.AddRules(task, "excel.exe"); rules.AddRules(task, "AssessmentRules"); rules.AddRules(task, "GenericCollections"); rules.logEnable = true; if (rules.logEnable) FileSystem.LogMessage(rules.AllRulesReport()); gmBasic.StartUp(@"..\usr\gmBasic.xml", null, null); Execute.Storage(action: "Create", identifier: task.JobId); Execute.gmPL(commands: rules.OptionRules); Execute.Compile(project: task.SrcPath, commands: rules.CompileRules); if (rules.PreAnalyseRules != 0) { Execute.gmPL(commands: rules.PreAnalyseRules); } Execute.Analyse(); if (rules.PostAnalyseRules!=0) { Execute.gmPL(commands: rules.PostAnalyseRules); } int projectRoot = (useWPF ? wpfSubsystem.WPFCodeScan() : 0); // WPF Execute.Output(status: "New", filename: task.BndPath); if (useWPF) wpfSubsystem.WPFAuthorProject(projectRoot, rules.AuthorRules); // WPF else Execute.Author(commands: rules.AuthorRules); Execute.Storage(action: "Close"); gmBasic.Terminate(); } } } |