Manual for library “Tools”

In this article:

SIM.Tools CheckCondition

You can evaluate a string describing a condition into a boolean using an SIM.Tools.ICondition. SIM.Tools.Condition class is its main implementation. It takes a string with the condition as an input parameter in the constructor. You can check the result of the condition using the property Result.

Check the next example:

Add-Type -Path ("$PSScriptRoot\bin\debug\CheckCondition.dll")

#Here are 2 examples of use of the class SIM.Tools.Condition, with different inputs.

#Given some inputs (be sure to use simple qutations for string literals: 'text'):
$numInput = "3 * (2 + 1) = 9"
$stringInput = "'M' ! 'R'"

#We create the Condition:
$numCondition = New-Object SIM.Tools.Condition($numInput)
$stringCondition = New-Object SIM.Tools.Condition($stringInput)

#And so we can access the condition result:

#We could also check the original condition from input:

This are the accepted operators:

  1. < -> less than
  2. > -> greater than
  3. = -> equals
  4. ! -> not equals
  5. AND -> ‘and’ logical operator
  6. OR -> ‘or’ logical operator
  7. NOT -> ‘not’ logical operator
  8. () -> Parentheses to modify operators preference

IMPORTANT: String literals must be enclosed by simple quotation marks: ‘literal’

SIM.Tools ResolveName

You can replace “keys” in a string for its corresponding “values” using a SIM.Tools.IResolvedText and a SIM.Tools.IResolver. SIM.Tools.ResolvedText class is the main implementation for IResolvedText. It takes the string with the keys and a IResolver as input parameters in the constructor. You can check the result using the property Text. For IResolver there is an implementation for v6 and v61 taking 2 parameter:

  1. An open connection with a SQL DB.
  2. An SQL Query containing the columns that will be used as keys. The column name must match the key name. The column value will be the value we will use.

You can check the result of the replacement using the property Text.

Check the next example:

Add-Type -Path ("$PSScriptRoot\bin\debug\ResolveName.dll")
Add-Type -Path ("$PSScriptRoot\..\SIMv61Database\bin\Debug\SIMv61Database.dll")

#Given a sample input
$input = '"<br>The software package: "{PackagingPackageName}" has been hand over to packaging factory. 
<br>Manufacturer: <b>{RequestManufacturerName}</b>
<br>Version: <b>{RequestProductVersion}</b>
<br>Architecture: <b>{HC_Architecture}</b>"'

#We obtain a connection with the corresponding table:
$connV61 = (New-Object SIMv61Database.SIMv61Database).Database.Connection

#We create the Resolved Text, using either connection.
#We can use different Resolvers. Here we use v6 resolver:
$inputResolvedText = New-Object SIM.Tools.ResolvedText(
    (New-Object SIM.Tools.V6SqlDbResolver(
        "SELECT * FROM PackagingJob WHERE Id=101"

#And so we can access its resolved text (use of property accessor method to expose exceptions in PS):

#We could also check the original text before resolving:

Error handling:

  1. If braces do not match on the input text, a FormatException will be thrown.
  2. If a key value is not found among the columns returned by the query, or no entries are returned, an ApplicationException will be thrown. You can opt out of this error by adding a 3rd parameter to the ResolvedText constructor with the value false, like this:
$resolvedText = New-Object SIM.Tools.ResolvedText($input, $resolver, false)