Expression: IExpression;
Expression: Prognoz.Platform.Interop.ForeSystem.IExpression;
The Expression property returns an expression for calculating condition.
For correct working of the condition the expression after calculation must give the result of logical type.
Executing the example requires that repository contains a modeling container with the MS identifier where there are models with the MODEL_BRANCH_EXPR_F, MODEL_BRANCH_EXPR_S, DEFAULT_MODEL identifier and 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 key of the modeling container
pMSKey := pMetabase.GetObjectKeyById("MS");
// Get metamodel
pMeta := pMetabase.ItemByIdNamespace("METAMODEL_BRANCH_EXPR", pMSKey).Edit As IMsMetaModel;
// Get collection of metamodel parameters
Params := pMeta.Params;
// Clear parameter 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 metamodel calculation condition
pBranch := pMeta.CalculationChain.AddBranch("Calculation condition");
// Set the calendar frequency of the condition
pBranch.Level := DimCalendarLevel.Year;
// Get DEFAULT_MODEL metamodel
pModel_a := pMetabase.ItemByIdNamespace("DEFAULT_MODEL", pMSKey).Bind As IMsModel;
// Add model to the 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 new branch of condition
pCase := pBranch.CaseList.Add;
// Add USER_MODEL model to the new branch
pCase.Contents.AddModel(pModel_b);
// Create 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 new condition of metamodel calculation
pBranchCopy := pMeta.CalculationChain.AddBranch("Calculation condition copy");
// Create new branch of condition
pCaseCopy := pBranchCopy.CaseList.Add;
// Create 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 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. Them new calculation condition which is a copy of the first one will be added. Copied condition will be modified: if metamodel parameter values is equal to four, the MODEL_BRANCH_EXPR_S model is calculated, if not, the DEFAULT_MODEL model is calculated.
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 the key of the modeling container
pMSKey := pMetabase.GetObjectKeyById("MS");
// Get metamodel
pMeta := pMetabase.ItemByIdNamespace["METAMODEL_BRANCH_EXPR", pMSKey].Edit() As IMsMetaModel;
// Get collection of metamodel parameters
pParams := pMeta.Params;
// Clear parameter collection
pParams.Clear();
// Add new integer parameter
Param := pParams.Add();
Param.Id := "INDICATOR_PARAM";
Param.Name := "INDICATOR_PARAM";
Param.DataType := DbDataType.ddtInteger;
// Clear the calculation chain of the metamodel
pMeta.CalculationChain.Clear();
// Create a condition of metamodel calculation
pBranch := pMeta.CalculationChain.AddBranch("Calculation condition");
// Set the calendar frequency of the condition
pBranch.Level := DimCalendarLevel.dclYear;
// Get the DEFAULT_MODEL model
pModel_a := pMetabase.ItemByIdNamespace["DEFAULT_MODEL", pMSKey].Bind() As IMsModel;
// Add model to the 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 new branch of the condition
pCase := pBranch.CaseList.Add();
// Add USER_MODEL model to a 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 new metamodel calculation condition
pBranchCopy := pMeta.CalculationChain.AddBranch("Calculation condition copy");
// Create new branch of the 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: