Skip to content

Commit b78738a

Browse files
author
Steve Ives
committed
Alow structures and aliases to be specified at the TaskSet level.
1 parent f9e386b commit b78738a

File tree

2 files changed

+91
-10
lines changed

2 files changed

+91
-10
lines changed

CodeGenEngine/CodeGenTaskSet.dbl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ namespace CodeGen.Engine
8383

8484
.region "Configuration properties - serialized"
8585

86+
;;; <summary>
87+
;;; Strcutures to process. To process all structures add an * as the first structure name.
88+
;;; Adding structure names to this collection is equivalent to using the -s command line option.
89+
;;; </summary>
90+
public readwrite property Structures, @ObservableCollection<String>, new ObservableCollection<String>()
91+
92+
;;; <summary>
93+
;;; Structure aliases. The number of aliases should be less than or equal to the number of structures being processed.
94+
;;; Adding alias names to this collection is equivalent to using the -a command line option.
95+
;;; Note that structure aliasing may not be used in conjunction with using alternate structure names (-as).
96+
;;; </summary>
97+
public readwrite property Aliases, @ObservableCollection<String>, new ObservableCollection<String>()
98+
8699
;;; <summary>
87100
;;; Continue processing even after an error.
88101
;;; Setting this property to true is equivalent to using the -c command line option.

CodeGenEngine/CodeGenerator.dbl

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
import Microsoft.Win32
4444
import System
45+
import Newtonsoft.Json
46+
import Newtonsoft.Json.Serialization
4547
import System.Collections
4648
import System.Collections.Generic
4749
import System.Collections.ObjectModel
@@ -50,7 +52,6 @@ import System.Linq
5052
import System.Reflection
5153
import System.Text
5254
import CodeGen.Engine
53-
import CodeGen.Engine
5455
import CodeGen.RepositoryAPI
5556

5657
.array 0
@@ -546,6 +547,7 @@ namespace CodeGen.Engine
546547
try
547548
begin
548549
context.Repository = new Repository()
550+
549551
if (context.DeveloperDebugLoggingEnabled)
550552
begin
551553
context.CurrentTask.DevDebugLog("Repository opened")
@@ -1015,15 +1017,15 @@ namespace CodeGen.Engine
10151017
;;-------------------------------------------------------------------------
10161018
;;Do we have Repository structures specified in the task?
10171019

1018-
if (!errStatus && (context.CurrentTask.Structures.Count>0))
1020+
if (!errStatus && ((context.CurrentTask.Structures != ^null && context.CurrentTask.Structures.Count > 0) || (context.TaskSet.Structures.Count > 0)))
10191021
begin
10201022
if (context.FileDefinition!=^null) then
10211023
errStatus = context.CurrentTask.Errorlog("You can't specify both a repository file and repository structures at the same time!")
10221024
else if (!String.IsNullOrWhiteSpace(context.CurrentTask.WindowScript)) then
10231025
errStatus = context.CurrentTask.Errorlog("You can't specify a window script and repository structures at the same time!")
10241026
else if (!String.IsNullOrEmpty(context.CurrentTask.ProformaFile)) then
10251027
errStatus = context.CurrentTask.Errorlog("You can't specify a proforma file and repository structures at the same time!")
1026-
else
1028+
else if (context.CurrentTask.Structures != ^null && context.CurrentTask.Structures.Count>0) then
10271029
begin
10281030
;;All or specific structures?
10291031
if (context.CurrentTask.Structures[0]=="*") then
@@ -1067,16 +1069,62 @@ namespace CodeGen.Engine
10671069
endtry
10681070
end
10691071
end
1070-
1071-
;;Default all structures to use the first file assigned
1072-
if (!errStatus)
1072+
end
1073+
else if (context.Taskset.Structures.Count > 0)
1074+
begin
1075+
;;All or specific structures?
1076+
if (context.Taskset.Structures[0]=="*") then
1077+
begin
1078+
;;Process all structures
1079+
try
1080+
begin
1081+
context.Structures = new RpsStructureCollection(RpsLoadMode.Load,context.CurrentTask.UseAlternateFieldNames)
1082+
if (context.Structures.Count == 0)
1083+
errStatus = context.CurrentTask.Errorlog("Your repository contains no structures!")
1084+
end
1085+
catch (ex, @RpsException)
1086+
begin
1087+
errStatus = context.CurrentTask.Errorlog(ex.Message)
1088+
end
1089+
endtry
1090+
end
1091+
else
10731092
begin
1093+
;;Process specified structures
10741094
data ix, int
1075-
context.StructureFileIndex = new int[context.Structures.Count]
1076-
for ix from 0 thru context.Structures.Count - 1
1077-
context.StructureFileIndex[ix] = 0
1095+
for ix from 0 thru context.Taskset.Structures.Count-1
1096+
begin
1097+
try
1098+
begin
1099+
data newStructure, @RpsStructure, new RpsStructure(context.Taskset.Structures[ix],context.CurrentTask.UseAlternateFieldNames)
1100+
if (!String.IsNullOrWhiteSpace(context.SelectionWindowScript))
1101+
begin
1102+
if (!ProcessSelectionWindows(context,newStructure))
1103+
begin
1104+
errStatus = context.CurrentTask.Errorlog(String.Format("Failed to resolve selection windows for structure {0}.",newStructure.Name))
1105+
exitloop
1106+
end
1107+
end
1108+
context.Structures.Add(newStructure)
1109+
end
1110+
catch (ex)
1111+
begin
1112+
errStatus = context.CurrentTask.Errorlog(ex.Message)
1113+
end
1114+
endtry
1115+
end
10781116
end
10791117
end
1118+
1119+
;;Default all structures to use the first file assigned
1120+
if (!errStatus)
1121+
begin
1122+
data ix, int
1123+
context.StructureFileIndex = new int[context.Structures.Count]
1124+
for ix from 0 thru context.Structures.Count - 1
1125+
context.StructureFileIndex[ix] = 0
1126+
end
1127+
10801128
end
10811129

10821130
;;-------------------------------------------------------------------------
@@ -1235,7 +1283,7 @@ namespace CodeGen.Engine
12351283
tmpStr.Alias = tmpStr.Name
12361284

12371285
;;Now apply specific aliases from the command line
1238-
if (context.CurrentTask.Aliases.Count>0)
1286+
if (context.CurrentTask.Aliases != ^null && context.CurrentTask.Aliases.Count>0) then
12391287
begin
12401288
if (!String.IsNullOrWhiteSpace(context.CurrentTask.WindowScript)) then
12411289
errStatus = context.CurrentTask.Errorlog("Can't use WindowScript and Aliases properties together!")
@@ -1255,6 +1303,26 @@ namespace CodeGen.Engine
12551303
end
12561304
end
12571305
end
1306+
else if (context.Taskset.Aliases.Count > 0)
1307+
begin
1308+
if (!String.IsNullOrWhiteSpace(context.CurrentTask.WindowScript)) then
1309+
errStatus = context.CurrentTask.Errorlog("Can't use WindowScript and Aliases properties together!")
1310+
else if (context.TaskSet.Aliases.Count > context.Structures.Count) then
1311+
errStatus = context.CurrentTask.Errorlog("More aliases than repository structures!")
1312+
else
1313+
begin
1314+
context.CurrentTask.DebugLog("Applying structure aliases",true,false)
1315+
data AliasIndex, int
1316+
for AliasIndex from 0 thru context.TaskSet.Aliases.Count - 1
1317+
begin
1318+
if (!String.IsNullOrWhiteSpace(context.TaskSet.Aliases[AliasIndex]))
1319+
begin
1320+
context.Structures[AliasIndex].Alias = context.TaskSet.Aliases[AliasIndex].ToUpper()
1321+
context.CurrentTask.DebugLog(" - Structure " + context.Structures[AliasIndex].Name + " aliased as " + context.Structures[AliasIndex].Alias)
1322+
end
1323+
end
1324+
end
1325+
end
12581326
end
12591327

12601328
;;-------------------------------------------------------------------------

0 commit comments

Comments
 (0)