Vars

static class · namespace z3n7 · source Essentials/Vars.cs

public static class Vars

Short accessors for project variables: read, write, parse, count.

Methods

Bool

public static bool Bool(this IZennoPosterProjectModel project, string var)

Extension method for IZennoPosterProjectModel. source

Returns true when the project variable equals True exactly.

Decimal

public static decimal Decimal(this IZennoPosterProjectModel project, string var)

Extension method for IZennoPosterProjectModel. source

Returns a project variable parsed as decimal (current culture), or 0 when it cannot be parsed.

Int

public static int Int(this IZennoPosterProjectModel project, string var)

Extension method for IZennoPosterProjectModel. source

Returns a project variable parsed as int, or 0 when it is empty or not a number.

public static int Int(this IZennoPosterProjectModel project, string varName, int input)

Extension method for IZennoPosterProjectModel. source

Adds input to an integer project variable and stores the result.

Returns: The new value.

MaxErr

public static void MaxErr(this IZennoPosterProjectModel project, int maxAttempts, Exception ex = null)

Extension method for IZennoPosterProjectModel. source

Error counter for retry loops. Stores the error text in err and increments maxErr; once maxErr exceeds maxAttempts, writes a warning and throws.

Parameter Description
maxAttempts Number of errors tolerated.
ex The error; when null, project.LastErrorComment is used.

Range

public static List<string> Range(this IZennoPosterProjectModel project, string accRange = null, string output = null, bool log = false)

Extension method for IZennoPosterProjectModel. source

Parses an account range and stores it in rangeStart, rangeEnd and range (comma-separated list). Accepted forms: 5, 1-10, 1,4,7. Anything after : is ignored.

Parameter Description
accRange Range text; when empty, the cfgAccRange variable is used.
output Not used.
log Not used.

Returns: Account numbers as strings, or null (with a warning) when no range is given.

Var

public static string Var(this IZennoPosterProjectModel project, string var)

Extension method for IZennoPosterProjectModel. source

Returns the value of a project variable. A missing variable is reported to the log and an empty string is returned.

Parameter Description
var Variable name.
public static string Var(this IZennoPosterProjectModel project, string var, object value)

Extension method for IZennoPosterProjectModel. source

Sets a project variable to value.ToString(). null is ignored. A missing variable is reported to the log, nothing is thrown.

Parameter Description
var Variable name.
value New value.

Returns: Always an empty string.

VarAdd

public static bool VarAdd(this IZennoPosterProjectModel project, string name, string defaultValue = "", string comment = "")

Extension method for IZennoPosterProjectModel. source

Adds a variable to the project open in ProjectMaker through the local ZennoPoster API (http://localhost:5299). Development-time only: it edits ProjectMaker's in-memory copy of the project, so a task running in the runner is not affected. Save the project to keep the change. The API key is read from ZENNO_API_KEY in the .env next to z3n7.dll; the key tier must be T1 or higher.

Parameter Description
name Variable name.
defaultValue Initial value.
comment Variable comment.

Returns: true when the API answered RESULT_OK; otherwise the answer is written to the log as a warning.

VarCounter

public static int VarCounter(this IZennoPosterProjectModel project, string varName, int input)

Extension method for IZennoPosterProjectModel. source

Adds input to an integer project variable and stores the result. Same as Int(varName, input).

Returns: The new value.

VarRnd

public static string VarRnd(this IZennoPosterProjectModel project, string var)

Extension method for IZennoPosterProjectModel. source

Reads a project variable. A value like 10-20 returns a random integer from 10 (inclusive) to 20 (exclusive); any other value is returned trimmed.

Parameter Description
var Variable name.

VarsFromDict

public static void VarsFromDict(this IZennoPosterProjectModel project, Dictionary<string, string> dict)

Extension method for IZennoPosterProjectModel. source

Sets a project variable for every key of the dictionary.

VarsFromJson

public static void VarsFromJson(this IZennoPosterProjectModel project, string json = "jVars")

Extension method for IZennoPosterProjectModel. source

Sets project variables from a flat JSON object of string values.

Parameter Description
json JSON text, or the default jVars to read the JSON from the jVars variable.

VarsMath

public static decimal VarsMath(this IZennoPosterProjectModel project, string varA, string operation, string varB, string resultVar = null)

Extension method for IZennoPosterProjectModel. source

Applies +, -, * or / to two project variables parsed as decimal (invariant culture). Other operations throw.

Parameter Description
varA Left operand variable.
operation One of + - * /.
varB Right operand variable.
resultVar Variable that receives the result; empty to skip.

Returns: The result.