@@ -45,6 +45,7 @@ import System.Collections.Generic
4545import System.Linq
4646import System.Text
4747import System.Threading.Tasks
48+ import CodeGen.RepositoryAPI
4849
4950.array 0
5051
@@ -342,6 +343,65 @@ namespace CodeGen.Engine
342343
343344 endmethod
344345
346+ private static method replicationExpandLoopUtilRemainingMax, string
347+ tkn, @Token
348+ template, @FileNode
349+ loops, @IEnumerable<LoopNode>
350+ endparams
351+ proc
352+ ;This method will be called to expand the following tokens:
353+ ;
354+ ;<REPLICATION_REMAINING_EXCLUSIVE_MAX_value>
355+ ;<REPLICATION_REMAINING_INCLUSIVE_MAX_value>
356+ ;
357+ ;Where value is a numeric literal
358+ ;
359+ ;The bahavior is identical to that of expandLoopUtilRemainingMax (above)
360+ ;except that the loops MaxIndex is reduced by the number of fields being
361+ ;excluded via the special token REPLICATOR_EXCLUDE in field user text or
362+ ;long descripotions.
363+
364+ lambda isLoopNode(node) (node .is. LoopNode)
365+ data loop, @LoopNode, loops.Last(isLoopNode)
366+
367+ data tokenText = tkn.Value
368+ data maxValue = 0
369+ data remainingValue = 0
370+
371+ ;;Figure out how many fields have been excluded
372+
373+ data fld, @RpsField
374+ data excludedFieldCount = 0
375+
376+ foreach fld in template.Context.CurrentStructure.Fields
377+ begin
378+ if (fld.UserText.Contains("REPLICATOR_EXCLUDE") || fld.LongDescription.Contains("REPLICATOR_EXCLUDE"))
379+ begin
380+ excludedFieldCount += 1
381+ end
382+ end
383+
384+ if (tokenText.StartsWith("REPLICATION_REMAINING_EXCLUSIVE_MAX_")) then
385+ begin
386+ tokenText = tokenText.Replace("REPLICATION_REMAINING_EXCLUSIVE_MAX_","")
387+ remainingValue = loop.MaxIndex - excludedFieldCount - loop.CurrentIndex
388+ end
389+ else if (tokenText.StartsWith("REPLICATION_REMAINING_INCLUSIVE_MAX_"))
390+ begin
391+ tokenText = tokenText.Replace("REPLICATION_REMAINING_INCLUSIVE_MAX_","")
392+ remainingValue = loop.MaxIndex - excludedFieldCount - loop.CurrentIndex + 1
393+ end
394+
395+ if (int.TryParse(tokenText,maxValue))
396+ begin
397+ lambda doExpand(loop) String.Format("{0}", (remainingValue < maxValue) ? remainingValue : maxValue )
398+ mreturn ExpandLoopUtilityToken(tkn, template, loops, doExpand)
399+ end
400+
401+ throw new ApplicationException("Invalid loop utility token " + tkn.Value)
402+
403+ endmethod
404+
345405 private static method expandLoopUtilTotalItems, string
346406 tkn, @Token
347407 template, @FileNode
0 commit comments