ICalcObject.RefreshMetaModel

Syntax

RefreshMetaModel;

Description

The RefreshMetaModel method refreshes metamodel.

Comments

During the update, a folder that is required for storing the models used by calculation block will be created in the metamodel structure.

Example

Executing the example requires that the repository contains a calculation algorithm with the ALGORITHM identifier. A calculation block with one parameter is created in the algorithm.

Add links to the Algo, Metabase, Ms, Transform system assemblies. Add links to the assemblies required for working with calculation algorithms.

Sub UserProc;
Var
    MB: IMetabase;
    MObj: IMetabaseObjectDescriptor;
    Algo, CalcBlock: ICalcObject;
    List: ICalcObjectsList;
    CalcAlgo: ICalcAlgorithm;
    Block: ICalcBlock;
    MModel: IMsMetaModel;
    backupMetamodel: IMetabaseObject;
Begin
    MB := MetabaseClass.Active;
    // Get calculation algorithm
    MObj := MB.ItemById("ALGORITHM");
    Algo := CalcObjectFactory.CreateCalcObject(MObj, True);
    CalcAlgo := Algo As ICalcAlgorithm;
    // Get calculation block
    Block := CalcAlgo.Items.Item(0As ICalcBlock;
    MModel := Block.MetaModel;
    //Save initial settings of metamodel
    backupMetamodel := CreateCloneMetamodel(Block);
    // Try changing specific settings of metamodel
    Try
        MModel.Id := "New_Metamodel_Id";
        MModel.Name := "Changed Metamodel";
        // The below string contains an error of assigning default value
        MModel.Params.Item(0).DefaultValue := "Error value";
        MModel.CalculationChain.Item(0).Name := "New Calculation Chain Entry Name"
    Except On E: Exception Do
        // If an error occurred on changing settings, clear entire metamodel
        // and return its initial state
        RecursiveCleanUpModels(Block.Folder.Contents);
        Block.MetaModel.MetabaseObject.Assign(backupMetamodel);
        // Refresh metamodel for correct work of calculation block
        Block.RefreshMetaModel;
    End Try;
    If Block.IsNeedConvert Then
        Block.Convert;
    End If;
    // Save changes
    Block.SaveObject;
End Sub UserProc;

Private Function CreateCloneMetaModel(calcObj: ICalcObject): IMetabaseObject;
Var
    crInfo : IMetabaseObjectCreateInfo;
    obj : IMetabaseObject;
Begin
    crInfo := MetabaseClass.Active.CreateCreateInfo;
    crInfo.Name := calcObj.Name;
    crInfo.ClassId := MetabaseObjectClass.KE_CLASS_MSMETAMODEL;
    crInfo.IsTemporary := True;
    crInfo.Parent := calcObj.MetaModel.MetabaseObject.Parent;
    crInfo.Permanent := False;
    obj := MetabaseClass.Active.CreateObject(crInfo).Edit;
    obj.Assign(calcObj.MetaModel.MetabaseObject);
    Return obj;
End Function CreateCloneMetaModel;

Private Sub RecursiveCleanUpModels(entries: IMsCalculationChainEntries);
Var
    Entry: IMsCalculationChainEntry;
    Model: IMsModel;
    Formula: IMsFormula;
    Determ: IMsDeterministicTransform;
    DetermExprList: IMsDeterministicExpressionList;
    DetermExpr: IMsDeterministicExpression;
    Transform: IMsFormulaTransform;
Begin
    For Each Entry In entries Do
        If Entry Is IMsCalculationChainFolder Then
            RecursiveCleanUpModels((Entry As IMsCalculationChainFolder).Contents);
        Elseif Entry Is IMsCalculationChainModel Then
            Model := (Entry As IMsCalculationChainModel).EditModel;
            Transform := Model.Transform;
            If Transform.FormulaCount = 0 Then
                Continue;
            End If;
            Formula := Transform.FormulaItem(0);
            Determ := Formula.Method As IMsDeterministicTransform;
            DetermExprList := Determ.ExpressionList;
            For Each DetermExpr In DetermExprList Do
                DetermExpr.Operands.Cleanup(True);
            End For;
        End If;
    End For;
End Sub RecursiveCleanUpModels;

After executing the example the system attempts to change settings of calculation block metamodel. If an error occurs, the metamodel will be restored from the previously created backup. The metamodel will be refreshed to provide correct work of the calculation block.

See also:

ICalcObject