ICalcAlgorithm.DebugAsync

Syntax

DebugAsync(Objs: ICalcObjectsList): IAlgorithmCalculationAsyncDebug;

Parameters

Objs. List of calculation algorithm objects.

NOTE. The list of calculation algorithm objects should be copied. To copy objects, use the ICalcObjectsList.Clone method.

Description

The DebugAsync method asynchronously debugs algorithm calculation.

Comments

During asynchronous algorithm calculation debugging, one should use the standby mode to execute consecutive calculation steps: initialization, first object calculation, second object calculation, and so on. The standby mode is used to detect calculation errors and to check if calculation is complete.

The standby mode is implemented by the GetState function:

Function GetState(CalcDebug: IAlgorithmCalculationAsyncDebug): CalculateState;
Var
    
State: CalculateState;
    i: Integer = 
1000;
Begin
    
// Check calculation state
    If CalcDebug <> Null Then
        State := CalcDebug.State;
        
While 
            (State <> CalculateState.PausedOnDebug) 
And
            (State <> CalculateState.PausedOnError) 
And 
            (State <> CalculateState.Aborted) 
And 
            (State <> CalculateState.Stoped) 
Do
            State := CalcDebug.State;
        
End While;
    
End If;
    
While i > 0 Do
        i := i - 
1;
    
End While;
    
Return State;
End Function GetState;

Example

Executing the example requires that the repository contains a calculation algorithm with the ALGORITHM identifier and a regular report with the REGULAR_REPORT identifier. A calculation algorithm should contain at least two calculation objects.

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

Sub UserProc;
Var
    MB: IMetabase;
    MObj: IMetabaseObjectDescriptor;
    Algo: ICalcObject;
    ObjList, CloneList: ICalcObjectsList;
    CalcAlgo: ICalcAlgorithm;
    CalcDebug:  IAlgorithmCalculationAsyncDebug;
    i: Integer;
    Report, ReportCalc: IPrxReport;
Begin
    MB := MetabaseClass.Active;
    // Get calculation algorithm
    MObj := MB.ItemById("ALGORITHM");
    Algo := CalcObjectFactory.CreateCalcObject(MObj, True);
    CalcAlgo := Algo As ICalcAlgorithm;
    // Set regular report to build intermediate calculation results
    Report := MB.ItemByID("REGULAR_REPORT").Edit As IPrxReport;
    // Get list of calculation algorithm objects
    ObjList := CalcAlgo.Items;
    // Copy list of calculation algorithm objects
    CloneList := ObjList.Clone;
    // Remove objects excluded calculation before debugging
    For i := CloneList.Count - 1 To 0 Step - 1 Do
        If Not CalcAlgo.Included(CloneList.Item(i)) Then
            CloneList.Remove(CloneList.Item(i));
        End If;
    End For;
    // Display the number of objects included in algorithm calculation in the console
    Debug.WriteLine("Number of objects: " + CloneList.Count.ToString);
    // Asynchronously debug algorithm calculation
    CalcDebug := CalcAlgo.DebugAsync(CloneList);
    // Start standby mode to execute initialization
    If GetState(CalcDebug) <> CalculateState.PausedOnDebug Then
        ErrorCheck(CalcDebug);
        Return;
    End If;
    For i := 0 To CloneList.Count - 1 Do
        // Calculate the next object
        CalcDebug.NextStep;
        // Start standby mode to calculate object
        If GetState(CalcDebug) <> CalculateState.PausedOnDebug Then
            ErrorCheck(CalcDebug);
            Return;
        End If;
        // Display key of the last calculated object in the console
        Debug.WriteLine("Object key: " + CalcDebug.LastObjectKey.ToString);
        // Check that the first object is included in calculation and save to regular report
        // intermediate result of calculation algorithm after first object calculation
        If CalcAlgo.Included(ObjList.Item(0)) Then
            ReportCalc := CalcDebug.PrxReport(CalcAlgo, ObjList.Item(0));
            Report.CopyFrom(ReportCalc);
            (Report As IMetabaseObject).Save;
        End If;
    End For;
    CalcDebug.Stop;
    CalcDebug.Dispose_;
End Sub UserProc;

Sub ErrorCheck(Var CalcDebug: IAlgorithmCalculationAsyncDebug);
Var
    Error: IAlgorithmCalculateErrorEvent;
Begin
    // Get calculation errors
    Error := CalcDebug.ErrorEvent;
    // If an error occurs, display error information in the console
    Debug.WriteLine(Error.Message);
    // Skip occurred error and continue calculation
    Error.ErrorState := SkipErrorState.IgnoreAll;
End Sub ErrorCheck;

Function GetState(CalcDebug:  IAlgorithmCalculationAsyncDebug): CalculateState;
Var
    State: CalculateState;
    i: Integer = 1000;
Begin
    // Check calculation state
    If CalcDebug <> Null Then
        State := CalcDebug.State;
        While
            (State <> CalculateState.PausedOnDebug) And
            (State <> CalculateState.PausedOnError) And
            (State <> CalculateState.Aborted) And
            (State <> CalculateState.Stoped) Do
            State := CalcDebug.State;
        End While;
    End If;
    While i > 0 Do
        i := i - 1;
    End While;
    Return State;
End Function GetState;

After executing the example, the algorithm calculation is asynchronously debugged. After the first object calculation the intermediate calculation result will be loaded to regular report. The console displays the number of calculated objects and their keys, for example:

Number of blocks: 2

Object key: 117966

Object key: 117970

See also:

ICalcAlgorithm