IMsBranchConditionExpression.Expression

Fore Syntax

Expression: IExpression;

Fore.NET Syntax

Expression: Prognoz.Platform.Interop.ForeSystem.IExpression;

Description

The Expression property returns expression for calculating condition.

Comments

For correct working of the condition the expression after calculation must give the result of logical type.

Fore Example

Executing the example requires that the repository contains a modeling container with the MS identifier, which includes models with the MODEL_BRANCH_EXPR_F, MODEL_BRANCH_EXPR_S, DEFAULT_MODEL identifiers and a metamodel with the METAMODEL_BRANCH_EXPR identifier.

Add links to the Dal, Dimensions, Metabase, Ms, Xml system assemblies.

Sub UserProc;
Var
    pMetabase: IMetabase;
    pMSKey: Integer;
    pMeta: IMsMetaModel;
    Params: IMsModelParams;
    Param: IMsModelParam;
    pBranch, pBranchCopy: IMsCalculationChainBranch;
    pModel_a, pModel_b: IMsModel;
    pCase, pCaseCopy: IMsBranchCase;
    pCond, pCondCopy: IMsBranchConditionExpression;
    XmlDoc: IXmlDomDocument3;
    el: IXmlDomElement;
Begin
    pMetabase := MetabaseClass.Active;
    
//Get modeling container key
    pMSKey := pMetabase.GetObjectKeyById("MS");
    
// Get metamodel
    pMeta := pMetabase.ItemByIdNamespace("METAMODEL_BRANCH_EXPR", pMSKey).Edit As IMsMetaModel;
    
// Get metamodel parameters collection
    Params := pMeta.Params;
    
// Clear parameters collection
    Params.Clear;
    
// Add a new integer parameter
    Param := Params.Add;
    Param.Id := 
"INDICATOR_PARAM";
    Param.Name := 
"INDICATOR_PARAM";
    Param.DataType := DbDataType.Integer;
    
// Clear metamodel calculation chain
    pMeta.CalculationChain.Clear;
    
// Create a metamodel calculation condition
    pBranch := pMeta.CalculationChain.AddBranch("Calculation condition");
    
// Set calendar frequency of condition
    pBranch.Level := DimCalendarLevel.Year;
    
// Get the DEFAULT_MODEL metamodel
    pModel_a := pMetabase.ItemByIdNamespace("DEFAULT_MODEL", pMSKey).Bind As IMsModel;
    
// Add model to condition
    pBranch.DefaultContents.AddModel(pModel_a);
    
// Get the MODEL_BRANCH_EXPR_F model
    pModel_b := pMetabase.ItemByIdNamespace("MODEL_BRANCH_EXPR_F", pMSKey).Bind As IMsModel;
    
// Create a new branch of condition
    pCase := pBranch.CaseList.Add;
    
// Add the USER_MODEL model to new branch
    pCase.Contents.AddModel(pModel_b);
    
// Create a branch calculation condition
    pCond := pCase.Conditions.Add(MsBranchConditionType.Expression) As IMsBranchConditionExpression;
    pCond.Expression.AsString := 
"{INDICATOR_PARAM[t]} = 3";
    
// Save condition branch parameters to XML file
    XmlDoc := New FreeThreadedDOMDocument60.Create;
    el := XmlDoc.createElement(
"Root");
    XmlDoc.appendChild(el);
    pCond.SaveToXml(el);
    XmlDoc.save(
"C:\ConditionExpr.xml");
    
// Create a new condition of metamodel calculation 
    pBranchCopy := pMeta.CalculationChain.AddBranch("Calculation condition copy");
    
// Create a new branch of condition
    pCaseCopy := pBranchCopy.CaseList.Add;
    
// Create a branch calculation condition
    pCondCopy := pCaseCopy.Conditions.Add(MsBranchConditionType.Expression) As IMsBranchConditionExpression;
    
// Load conditions from XML file
    XmlDoc := New FreeThreadedDOMDocument60.Create;
    XmlDoc.load(
"C:\ConditionExpr.xml");
    el := XmlDoc.selectSingleNode(
"Root"As IXmlDomElement;
    pCondCopy.LoadFromXml(el);
    
// Get the MODEL_BRANCH_EXPR_S model
    pModel_b := pMetabase.ItemByIdNamespace("MODEL_BRANCH_EXPR_S", pMSKey).Bind As IMsModel;
    pCaseCopy.Contents.AddModel(pModel_b);
    
// Change branch calculation condition
    pCondCopy.Expression.AsString := "{INDICATOR_PARAM[t]} = 4";
    
// Save metamodel
    (pMeta As IMetabaseObject).Save;
End Sub UserProc;

After executing the example the calculation condition will be added to the metamodel: if metamodel parameter value is equal to three, the MODEL_BRANCH_EXPR_F model is calculated, if not, the DEFAULT_MODEL model is calculated. Then a new calculation condition, which is a copy of the first one, is added. The copied condition will be changed: if metamodel parameter values is equal to four, the MODEL_BRANCH_EXPR_S model is calculated, if not, the DEFAULT_MODEL model is calculated.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.MsXml2;

Public Shared Sub Main(Params: StartParams);
Var
    pMetabase: IMetabase;
    pMSKey: uinteger;
    pMeta: IMsMetaModel;
    pParams: IMsModelParams;
    Param: IMsModelParam;
    pBranch, pBranchCopy: IMsCalculationChainBranch;
    pModel_a, pModel_b: IMsModel;
    pCase, pCaseCopy: IMsBranchCase;
    pCond, pCondCopy: IMsBranchConditionExpression;
    XmlDoc: IXmlDomDocument3;
    el: IXmlDomElement;
Begin
    pMetabase := Params.Metabase;
    //Get modeling container key
    pMSKey := pMetabase.GetObjectKeyById("MS");
    // Get metamodel
    pMeta := pMetabase.ItemByIdNamespace["METAMODEL_BRANCH_EXPR", pMSKey].Edit() As IMsMetaModel;
    // Get metamodel parameters collection
    pParams := pMeta.Params;
    // Clear parameters collection
    pParams.Clear();
    // Add a new integer parameter
    Param := pParams.Add();
    Param.Id := "INDICATOR_PARAM";
    Param.Name := "INDICATOR_PARAM";
    Param.DataType := DbDataType.ddtInteger;
    // Clear calculation chain of metamodel
    pMeta.CalculationChain.Clear();
    // Create a condition of metamodel calculation
    pBranch := pMeta.CalculationChain.AddBranch("Calculation condition");
    // Set calendar frequency of condition
    pBranch.Level := DimCalendarLevel.dclYear;
    // Get the DEFAULT_MODEL model
    pModel_a := pMetabase.ItemByIdNamespace["DEFAULT_MODEL", pMSKey].Bind() As IMsModel;
    // Add model to condition
    pBranch.DefaultContents.AddModel(pModel_a);
    // Get the MODEL_BRANCH_EXPR_F model
    pModel_b := pMetabase.ItemByIdNamespace["MODEL_BRANCH_EXPR_F", pMSKey].Bind() As IMsModel;
    // Create a new branch of condition
    pCase := pBranch.CaseList.Add();
    // Add the USER_MODEL model to new branch
    pCase.Contents.AddModel(pModel_b);
    // Create a condition of branch calculation
    pCond := pCase.Conditions.Add(MsBranchConditionType.mbctExpression) As IMsBranchConditionExpression;
    pCond.Expression.AsString := "{INDICATOR_PARAM[t]} = 3";
    // Save parameters of condition branch to XML file
    XmlDoc := New FreeThreadedDOMDocument60.Create();
    el := XmlDoc.createElement("Root");
    XmlDoc.appendChild(el);
    pCond.SaveToXml(el);
    XmlDoc.save("C:\ConditionExpr.xml");
    // Create a new metamodel calculation condition 
    pBranchCopy := pMeta.CalculationChain.AddBranch("Calculation condition copy");
    // Create a new branch of condition
    pCaseCopy := pBranchCopy.CaseList.Add();
    // Create a condition of branch calculation
    pCondCopy := pCaseCopy.Conditions.Add(MsBranchConditionType.mbctExpression) As IMsBranchConditionExpression;
    // Load conditions from XML file
    XmlDoc := New FreeThreadedDOMDocument60.Create();
    XmlDoc.load("C:\ConditionExpr.xml");
    el := XmlDoc.selectSingleNode("Root"As IXmlDomElement;
    pCondCopy.LoadFromXml(el);
    // Get the MODEL_BRANCH_EXPR_S model
    pModel_b := pMetabase.ItemByIdNamespace["MODEL_BRANCH_EXPR_S", pMSKey].Bind() As IMsModel;
    pCaseCopy.Contents.AddModel(pModel_b);
    // Change branch calculation condition
    pCondCopy.Expression.AsString := "{INDICATOR_PARAM[t]} = 4";
    // Save metamodel
    (pMeta As IMetabaseObject).Save();
End Sub;

See also:

IMsBranchConditionExpression