IVirtualCubeInstance.ExecuteCallback

Syntax

ExecuteCallback: IVirtualCubeExecuteCallback;

Description

The ExecuteCallback property determines a handler for events that occur on calculating virtual cube.

Comments

As the property value, determine class instance that implements methods of the IVirtualCubeExecuteCallback interface.

The cube is calculated according to the selection that is sent to the ICubeInstanceDestinationExecutor.PrepareExecute method. It is also available to set additional selection by each source and get matrix calculated for sources.

Example

Executing the example requires that the repository contains a virtual cube with the VIRT_CUBE identifier. The cube is based on several data sources.

Add links to the Cubes, Dimensions, Matrix, Metabase system assemblies.

Sub UserProc;
Var
    Mb: IMetabase;
    Cube: ICubeInstance;
    CubeDest: ICubeInstanceDestination;
    Sels: IDimSelectionSet;
    Sel: IDimSelection;
    CubeExec: ICubeInstanceDestinationExecutor;
    MatrixVirtual : IMatrix;
Begin
    Mb := MetabaseClass.Active;
    
// Open cube
    Cube := Mb.ItemById("VIRT_CUBE").Open(NullAs ICubeInstance;
    CubeDest := Cube.Destinations.DefaultDestination;
    
// Event handler
    (Cube As IVirtualCubeInstance).ExecuteCallback := New VirtualCubeExecCallback.Create;
    
// Selection for execution
    Sels := CubeDest.CreateDimSelectionSet;
    
For Each Sel In Sels Do
        Sel.SelectElement(
0False);
    End For;
    
// Create object to calculate cube with access flag to source matrix
    CubeExec := CubeDest.CreateExecutorO(CubeInstanceDestinationExecutorOptions.KeepSourceMatrices);
    
// Execute cube
    CubeExec.PrepareExecute(Sels);
    CubeExec.PerformExecute;
    
// Get calculated matrix with data
    MatrixVirtual := CubeExec.Matrix;
    ShowMatrix(
"Virtual cube matrix", MatrixVirtual);
End Sub UserProc;

Public Class VirtualCubeExecCallback: Object, IVirtualCubeExecuteCallback
    
Public Sub OnBeforeExecuteSources(Value: IVirtualCubeSourceSelections);
    
Var
        i: Integer;
        Sels: IDimSelectionSet;
        Sel: IDimSelection;
    
Begin
        
For i := 0 To Value.Count - 1 Do
            Sels := Value.Item(i).Selection;
            
// Change selection to calculate sources
            For Each Sel In Sels Do
                Sel.SelectAll;
            
End For;
        
End For;
    
End Sub OnBeforeExecuteSources;

    
Public Sub OnAfterExecuteSources(Value: IVirtualCubeSourceMatricesList);
    
Var
        i, j: Integer;
        SourceMatrix: IVirtualCubeSourceMatrix;
    
Begin
        j := Value.Count;
        Debug.WriteLine(
"Number of sources: " + j.ToString);
        
// View matrix obtained on calculating sources
        For i := 0 To j - 1 Do
            SourceMatrix := Value.Item(i);
            ShowMatrix(SourceMatrix.SourceKey.ToString, SourceMatrix.Matrix);
        
End For;
    
End Sub OnAfterExecuteSources;
End Class VirtualCubeExecCallback;

Sub ShowMatrix(Title: String; Matr: IMatrix);
Var
    Iter: IMatrixIterator;
Begin
    Debug.Write(Title + 
" : ");
    
If Matr.Count <> 0 Then
        Iter := Matr.CreateIterator;
        Iter.Move(IteratorDirection.First);
        
While Iter.Valid Do
            Debug.Write(Iter.Value + 
" ");
            Iter.Move(IteratorDirection.Next);
        
End While;
        Debug.WriteLine(
"");
    
Else
        Debug.WriteLine(
"Empty");
    
End If;
End Sub ShowMatrix;

Virtual cube will be calculated on executing the example. The virtual cube is calculated by single selection in dimensions and its sources will be calculated by maximum selections. The output matrix of sources and virtual cube will be displayed to the development environment console.

See also:

IVirtualCubeInstance