Example - Report Add-In

Analysis Services Programming

Analysis Services Programming

Example - Report Add-in

The following example shows how to create an add-in that incorporates Decision Support Objects (DSO) functionality. A pop-up menu item named List is added to the server tree node with options to list Database, Cube, Dimension, and Level objects. Before you can use this example code, perform the following steps:

  1. In Microsoft® Visual Basic®, create a Microsoft ActiveX® DLL project. Name the project ReportAddIn and the publicly exposed class ReportClass. Ensure that references have been added for Microsoft OLAP Services Add-Ins Manager and Microsoft Decision Support Objects.

  2. Register the add-in.

  3. Add a form to the project and name it ReportForm. Include a ListBox control named ObjectList.

For more information, see Tutorial - Creating a Sample Add-in.

Place the following code into the ReportClass class:

Option Explicit
Implements IOlapAddIn

Private dsoServer As DSO.Server    'DSO Server object
Private frmReport As ReportForm
Const OLAPManagerName = "OLAP Manager"
Const ThisAddInName = "ReportAddIn"

Private Enum MenuItems
  mnuParentMenuItem = 1
  mnuListDatabase
  mnuListCube
  mnuListDimension
  mnuListLevel
  mnuObjList
End Enum

Private Sub Class_Initialize()
  Set frmReport = New ReportForm
End Sub

Private Function IOlapAddIn_ExecuteMenuItem( _
    CurrentNode As DSSAddInsManager.OlapTreeNode, _
    MenuItem As DSSAddInsManager.OlapMenuItem) _
    As DSSAddInsManager.RefreshTreeTypes
  Dim dsoDB As DSO.MDStore     'Database
  Dim dsoCube As MDStore       'Cube
  Dim dsoDim As DSO.Dimension  'Dimension
  Dim dsoLev As DSO.Level      'Level
  Dim DBCounter As Integer
  Dim CubeCounter As Integer
  Dim DimCounter As Integer
  Dim LevCounter As Integer
  
  Select Case MenuItem.Key
    Case mnuListDatabase    'List database objects
      frmReport.Caption = "Database Objects"
      For DBCounter = 1 To dsoServer.MDStores.Count
        Set dsoDB = dsoServer.MDStores(DBCounter)
        frmReport.ObjectList.AddItem dsoDB.Name
      Next DBCounter
      
    Case mnuListCube        'List cube objects
      frmReport.Caption = "Cube Objects"
      For DBCounter = 1 To dsoServer.MDStores.Count
        Set dsoDB = dsoServer.MDStores(DBCounter)
        frmReport.ObjectList.AddItem dsoDB.Name
        For CubeCounter = 1 To dsoDB.MDStores.Count
          Set dsoCube = dsoDB.MDStores(CubeCounter)
          frmReport.ObjectList.AddItem "  " & dsoCube.Name
        Next CubeCounter
      Next DBCounter
      
    Case mnuListDimension    'List dimension objects
      frmReport.Caption = "Dimension Objects"
      For DBCounter = 1 To dsoServer.MDStores.Count
        Set dsoDB = dsoServer.MDStores(DBCounter)
        frmReport.ObjectList.AddItem dsoDB.Name
        For CubeCounter = 1 To dsoDB.MDStores.Count
          Set dsoCube = dsoDB.MDStores(CubeCounter)
          frmReport.ObjectList.AddItem "  " & dsoCube.Name
          For DimCounter = 1 To dsoCube.Dimensions.Count
            Set dsoDim = dsoCube.Dimensions(DimCounter)
            frmReport.ObjectList.AddItem "      " & _
                dsoDim.Name
          Next DimCounter
        Next CubeCounter
      Next DBCounter
      
    Case mnuListLevel        'List level objects
      frmReport.Caption = "Level Objects"
      For DBCounter = 1 To dsoServer.MDStores.Count
        Set dsoDB = dsoServer.MDStores(DBCounter)
        frmReport.ObjectList.AddItem dsoDB.Name
        For CubeCounter = 1 To dsoDB.MDStores.Count
          Set dsoCube = dsoDB.MDStores(CubeCounter)
          frmReport.ObjectList.AddItem "  " & dsoCube.Name
          For DimCounter = 1 To dsoCube.Dimensions.Count
            Set dsoDim = dsoCube.Dimensions(DimCounter)
            frmReport.ObjectList.AddItem "      " & _
                dsoDim.Name
            For LevCounter = 1 To dsoDim.Levels.Count
              Set dsoLev = dsoDim.Levels(LevCounter)
              frmReport.ObjectList.AddItem _
                  "          " &  dsoLev.Name
            Next LevCounter
          Next DimCounter
        Next CubeCounter
      Next DBCounter
      
  End Select
  
  'Display the form
  frmReport.Show

End Function

Private Function IOlapAddIn_GetObject( _
    LinkedNode As DSSAddInsManager.OlapTreeNode) As Object

End Function

Private Property Get IOlapAddIn_Name() As String
  IOlapAddIn_Name = ThisAddInName
End Property

Private Sub IOlapAddIn_ProvideChildNodes( _
    ParentNode As DSSAddInsManager.OlapTreeNode, _
    OlapTreeNodes As DSSAddInsManager.OlapTreeNodes)
  'No child nodes needed
End Sub

Private Sub IOlapAddIn_ProvideHTML( _
    CurrentNode As DSSAddInsManager.OlapTreeNode, _
    CurrentURL As String)
  ' If custom HTML pages are needed -
  ' CurrentURL = "{custom.htm}"
End Sub

Private Function IOlapAddIn_ProvideIcon(Index As Integer) _
    As stdole.OLE_HANDLE
  'No icons needed
End Function

Private Sub IOlapAddIn_ProvideMenuItems( _
    CurrentNode As DSSAddInsManager.OlapTreeNode, _
    MenuItems As DSSAddInsManager.OlapMenuItems)
  Dim iFlags As OlapMenuFlags
  
  If CurrentNode.OwnerAddInName = OLAPManagerName Then
    'Do we have as server?
    If CurrentNode.LinkedObject.ClassType = clsServer Then
      Set dsoServer = CurrentNode.LinkedObject
      
      'If not connected to server, disable menu item
      If dsoServer.State = stateConnected Then
        iFlags = mnuflagRegular + mnuflagPopup
      Else
        iFlags = mnuflagGrayed + mnuflagPopup
      End If
      
      'Add popup menu item
      MenuItems.Add mnuSeparator
      MenuItems.Add mnuStandard, "&List", _
          mnuParentMenuItem, , iFlags
      
      'Add popup menu child menu items
      MenuItems.Add mnuStandard, "&Database", _
          mnuListDatabase, mnuParentMenuItem, mnuflagSubmenu
      MenuItems.Add mnuStandard, "&Cube", _
          mnuListCube, mnuParentMenuItem, mnuflagSubmenu
      MenuItems.Add mnuStandard, "&Dimension", _
          mnuListDimension, mnuParentMenuItem, mnuflagSubmenu
      MenuItems.Add mnuStandard, "&Level", _
          mnuListLevel, mnuParentMenuItem, mnuflagSubmenu
    End If
  End If
End Sub