Below is the example of using the GetMs operation for step-by-step model calculation. The request contains an instance of opened modeling container, pattern and parameters of model calculation. The response contains information about calculation.
{
"GetMs" :
{
"tMs" :
{
"id" : "S30!M!S!C1"
},
"tArg" :
{
"pattern" :
{
"obInst" : "true",
"item" :
{
"key" : "2803",
"problem" :
{
"calculation" :
{
"calculationState" :
{
"model" :
{
"generatedName" : "true"
}
}
}
}
}
},
"execParams" :
{
"level" : "Year",
"problemCalculationKey" : "0",
"slices" :
{
"its" : ""
},
"execStepInto" : "false",
"execStepOver" : "true"
}
}
}
}
}
}
{
"GetMsResult" :
{
"id" :
{
"id" : "S30!M!S!C1"
},
"meta" :
{
"obInst" :
{
"obDesc" :
{
"@isShortcut" : "0",
"i" : "MODELSPACE",
"n" : "Modeling container",
"k" : "1581",
"c" : "5121",
"p" : "1580",
"h" : "0"
}
},
"dirty" : "0",
"item" :
{
"k" : "2803",
"id" : "TEMP_MODEL",
"n" : "TEMP_MODEL",
"vis" : "1",
"type" : "Problem",
"problemMd" :
{
"calculation" :
{
"pointCount" : "0",
"pointPassed" : "0",
"saveData" : "1",
"copyFact" : "0",
"treatNullsAsZeros" : "0",
"isRunning" : "0",
"calculationState" :
{
"model" : "",
"scenarioKey" : "4294967295",
"currentPoint" : "1899-12-30",
"message" : "Task calculation completed. Calculation time is 00:00:01" }, "isSuspend" : "0" } } } }
public static bool GetMsStepIntoCalc(MsId ms, ulong modelKey, ulong? prCalcKey, MsFormulaTransformSlice outSlice)
{
var getMsOp = new GetMs();
//Set operation execution parameters
getMsOp.tMs = ms;
getMsOp.tArg = new GetMsArg()
{ //Set general data getting pattern
pattern = new MsMdPattern()
{
item = new MsItemPattern()
{ //Set calculated model key
key = modelKey,
//Set data calculation pattern
problem = new MsProblemPattern()
{
calculation = new MsProblemCalculationPattern()
{
calculationState = new MsCalculationStatePattern()
{
model = new MsModelPattern() { generatedName = true }
}
}
}
}
},//Set calculation parameters
execParams = new MsMdExecParams()
{
execStepInto = false,
execStepOver = true,
problemCalculationKey = prCalcKey,
slices = new MsFormulaTransformSlices()
{
its = new MsFormulaTransformSlice[] { outSlice }
},
level = DimCalendarLvl.Year
}
};
//Create a proxy object for operation execution
var somClient = new SomPortTypeClient();
//Execute calculation steps
GetMsResult getMsResult = somClient.GetMs(getMsOp);
MsProblemCalculation calc = getMsResult.meta.item.problemMd.calculation;
//Output calculation data into console window
if ((calc.pointPassed == 0) && (calc.pointCount !=0))
{
Console.WriteLine("Task calculation information:");
Console.WriteLine("".PadRight(3) + "- number of calculation steps: " + calc.pointCount);
Console.WriteLine("".PadRight(3) + "- data is loaded into output variables after calculation end: " + calc.saveData);
Console.WriteLine("".PadRight(3) + "- data for sample period is copied from the Fact scenario: " + calc.copyFact);
Console.WriteLine("".PadRight(3) + "- empty values in data are filled with zeros: " + calc.treatNullsAsZeros);
Console.WriteLine("".PadRight(3) + "- model in calculation process: " + calc.isRunning);
};
Console.WriteLine("Task calculation. Step '" + calc.pointPassed + "' from '" + calc.pointCount + "'");
MsCalculationState calcState = calc.calculationState;
Console.WriteLine("".PadRight(3) + "- operation: " + calcState.message);
Console.WriteLine("".PadRight(3) + "- equation: " + calcState.model.generatedName);
Console.WriteLine("".PadRight(3) + "- calculation scenario key: "+calcState.scenarioKey);
Console.WriteLine("".PadRight(3) + "- calculation point: " + calcState.currentPoint);
Console.WriteLine("".PadRight(3) + "- values: " + printArray(calcState.values));
bool continueCalc = calc.isSuspend.Value;
return continueCalc;
}
See also: