IVirtualCubeInstance.ExecuteCallback

Syntax

ExecuteCallback: IVirtualCubeExecuteCallback;

ExecuteCallback: Prognoz.Platform.Interop.Cubes.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 and Metabase system assemblies. In Fore.NET add a link to the ForeSystem assembly.

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;

Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Matrix;
Imports Prognoz.Platform.Interop.Metabase;

Public Shared Sub Main(Params: StartParams);
Var
    Mb: IMetabase;
    Cube: ICubeInstance;
    CubeDest: ICubeInstanceDestination;
    Sels: IDimSelectionSet;
    Sel: IDimSelection;
    CubeExec: ICubeInstanceDestinationExecutor;
    MatrixVirtual: IMatrix;
Begin
    Mb := Params.Metabase;
    
// Open cube
    Cube := Mb.ItemById["VIRT_CUBE"].Open(NullAs ICubeInstance;
    CubeDest := Cube.Destinations.DefaultDestination;
    
// Event handler
    (Cube As IVirtualCubeInstance).ExecuteCallback := New VirtualCubeExecCallback();
    
// 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.cideoKeepSourceMatrices As Integer);
    
// Execute cube
    CubeExec.PrepareExecute(Sels);
    CubeExec.PerformExecute(
False);
    
// Get calculated matrix with data
    MatrixVirtual := CubeExec.Matrix;
    ShowMatrix(
"Virtual cube matrix", MatrixVirtual);
End Sub;

Public Class VirtualCubeExecCallback: 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;

    
Public Sub OnAfterExecuteSources(Value: IVirtualCubeSourceMatricesList);
    
Var
        i, j: Integer;
        SourceMatrix: IVirtualCubeSourceMatrix;
    
Begin
        j := Value.Count;
        System.Diagnostics.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;
End Class;

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

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