OnBeforeSaveDataEx(Args: IMsProblemCalculationCallbackOnBeforeSaveDataArgs);
Args. Event arguments.
The OnBeforeSaveDataEx method implements the event that occurs before saving data with the ability to set additional saving parameters.
The OnBeforeSaveDataEx event occurs after OnBeforeSaveData.
Executing the example requires that the repository contains a calculation algorithm with the ALGORITHM identifier. The calculation algorithm should contain configured objects, caching is enabled for data sources.
Add links to the Algo, Metabase, Ms system assemblies. Add a link to the assembly that is required to work with calculation algorithm.
Sub UserProc;
Var
MB: IMetabase;
MObj: IMetabaseObjectDescriptor;
Algo: ICalcObject;
CalcAlgo: ICalcAlgorithm;
BaseExecutor: IAlgorithmBaseExecutor;
ParamValues: IAlgorithmParameterValues;
MsProblem: IMsProblem;
ProblemCalculation: IMsProblemCalculation;
CalcSettings: IMsProblemCalculationSettings;
Begin
MB := MetabaseClass.Active;
// Calculation algorithm
MObj := MB.ItemById("ALGORITHM");
Algo := CalcObjectFactory.CreateCalcObject(MObj, True);
CalcAlgo := Algo As ICalcAlgorithm;
// Object for modeling problem calculation
BaseExecutor := CalcAlgo As IAlgorithmBaseExecutor;
// Calculation algorithm parameters
ParamValues := BaseExecutor.ParamValues;
ParamValues.StartDate := DateTime.ComposeDay(2000, 1, 1);
ParamValues.EndDate := DateTime.ComposeDay(2020, 1, 1);
// Method for handling errors that may occur on calculation
BaseExecutor.ErrorState := SkipErrorState.Abort;
// Get modeling problem, based on which algorithm is created.
// Calculate modeling problem with default settings.
MsProblem := BaseExecutor.MsProblem;
Debug.WriteLine("Start algorithm modeling problem: '" + MObj.Name + "'");
CalcSettings := MsProblem.CreateCalculationSettings;
// Event handler
CalcSettings.Callback := New MCallback.Create;
// Object that executes calculation
ProblemCalculation := MsProblem.Calculate(CalcSettings);
// Start calculation
ProblemCalculation.Run;
Debug.WriteLine("Calculation complete.");
End Sub UserProc;
Public Class MCallback: ProblemCalculationCallback
Public Sub OnBeforeSaveDataEx(Args: IMsProblemCalculationCallbackOnBeforeSaveDataArgs);
Begin
Args.NeedSaveChangeHistory := False;
Args.SaveDataMode := CubeStorageSaveDataMode.Db;
End Sub OnBeforeSaveDataEx;
Public Sub OnSaveData(Stub: IVariableStub; Matrix: IMatrix; ValueFlag: Integer; AuditRecordKey: Variant);
Var
Iter: IMatrixIterator;
RecordCount: Integer;
Begin
Iter := Matrix.CreateIterator;
Iter.Move(IteratorDirection.First);
While Iter.Valid Do
If Iter.ValueFlag = ValueFlag Then
RecordCount := RecordCount + 1;
End If;
Iter.Move(IteratorDirection.Next);
End While;
Debug.WriteLine("Data is saved to ValueFlag: " + ValueFlag.ToString + #13 + #10 +
"Number of saved values: " + RecordCount.ToString + #13 + #10 +
"Record key in access protocol: " + AuditRecordKey);
End Sub OnSaveData;
End Class MCallback;
After executing the example, calculation period start and end will be set for the calculation algorithm. The problem used by the algorithm will be obtained and started. If any error occurs, the calculation will be stopped. Calculation results are saved only in the specified database without updating data consumer cache. If version history is enabled in destination cubes, a new revision in history will not be created.
See also: