Looping through variables

Comments

1 comment

  • Avatar
    Dirk Stegemann

    I'd probably create a custom <actiondefinition> which takes minutes, hours, days, months etc. as input parameters. That custom action would perform several <while> loops to write text strings to a file using the <addtexttofile> action; the loop should have a counter variable that increases with each loop (possible through <mathexpression> actions) to be able to write the correct amount of strings to the file (e.g. 60 times "f" for minutes, 24 times "f" for hours etc.); then I'd use <comparevalues> actions to ensure that the loop is run correctly, and to check whether the default string "f" or the special string "t" should be written to the text file.

    Something like this (pseudo code which doesn't take care of the opening and closing brackets, commas etc. which would need to be positioned within your text file as well):

    <actionDefinition>
      <name="writeScheduleString" />
    
      <parameterList>
        // Define parameters named "minute_to_run", "hour_to_run", "day_to_run", "month_to_run"
      </parameterList>
    
      <actionList>
        // Use <setInstallerVariable> to create loop counter variables named 
        // "loop_counter_minutes", "loop_counter_hours", "loop_counter_days" 
        // and "loop_counter_months" with values "0"
    
        <while>
          // Run while loop for minutes
    
          <conditionRuleList>
            // Run the loop while counter variable is less than input parameter
            <compareValues>
            <value1>${loop_counter_minutes}</value2>
            <logic>less</logic>
            <value2>${minute_to_run}</value1>
            </compareValues>
          </conditionRuleList>
    
          <actionList>
            // Increase loop counter
            <mathExpression text="${loop_counter_minutes}+1" variable="loop_counter_minutes" />
    
            // Either write "f" or "t" to file
            <if>
            <conditionRuleList>
              <compareValues>
                <value1>${loop_counter_minutes}</value2>
                <logic>equals</logic>
                <value2>${minute_to_run}</value1>
              </compareValues>
            </conditionRuleList>
            </if>
    
            <actionList>
            // Write "t" to file using <addTextToFile>
            </actionList>
    
            <elseActionList>
            // Write "f" to file using <addTextToFile>
            </elseActionList>
    
          </actionList>
        </while>
    
        // Create more loops for hours, days and months
    
      </actionList>
    
    </actionDefinition>
    

    Instead of writing to a text file, you could write your "f"s and "t"s to a string, then afterwards write the string to the text file (to save a lot of disk access).

    Hope that helps!

    0
    Comment actions Permalink

Please sign in to leave a comment.