Forum Discussion
PeterFu
Contributor II
Hi Adam,
Take a look at the BR below.
Imports System
Imports System.Data
Imports System.Data.Common
Imports System.IO
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Linq
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports OneStream.Shared.Common
Imports OneStream.Shared.Wcf
Imports OneStream.Shared.Engine
Imports OneStream.Shared.Database
Imports OneStream.Stage.Engine
Imports OneStream.Stage.Database
Imports OneStream.Finance.Engine
Imports OneStream.Finance.Database
Namespace OneStream.BusinessRule.Extender.XFR_ExportAppTypes
Public Class MainClass
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Reference Code: XFR_ExportAppTypes
'
'Description: Executes application extracts and produces XML file.
' This can be run for different extract types like Metadata or CubeViews
' The file is written to the application Data Mgmt Export folder in the file share directory.
'
'Usage: Can be executed from Business Rule editor or run as part of a Data Management sequence.
'
'Created By: Peter Fu
'
'Date Created: 06-05-2021
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As Object
Try
Select Case args.FunctionType
Case Is = ExtenderFunctionType.ExecuteDataMgmtBusinessRuleStep
'Get Configuration Settings
Dim configSettings As AppServerConfigSettings = AppServerConfig.GetSettings(si)
'Data Management extract location
Dim folderPath As String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, True, configSettings.FileShareRootFolder, _
si.AppToken.AppName) & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\Extracts"
'If the directory does not exist create
If Not Directory.Exists(folderPath) Then Directory.CreateDirectory(folderPath)
'Full path and file name for extract
Dim filePath As String = folderPath & "\MetadataEntity " & DateTime.UtcNow.ToString("yyyyMMdd") & ".xml"
'If file already exist
If File.Exists(filePath) Then File.Delete(filePath)
'-------------------------------------------------------------------------------------------------------------------------
'Extract Options
Dim xmlOptions As New XmlExtractOptions
xmlOptions.ExtractAllItems = False
'Extract dimensions
Dim extractDict As New Dictionary(Of XmlExtractItemPk, Boolean)
extractDict.Add(New XmlExtractItemPk(XmlExtractItemType.Dimensions), True)
'Extract Entities
Dim dimID As Integer = BRApi.Finance.Dim.GetDimPk(si, "CorpEntities").DimId
extractDict.Add(New XmlExtractItemPk(XmlExtractItemType.Dimension, dimID), True)
'Define dimension options for extract
Dim xmlDimOptions As New XmlExtractMetadataDimOptions
'Extract specified members
xmlDimOptions.ExtractAllMembers = False
'Member(s) to extract
Dim memExtract As New Dictionary(Of String, Object)
memExtract.Add("All Orgs", Nothing)
'memExtract.Add("Corporate", Nothing)
xmlDimOptions.MembersToExtract = memExtract
'Extract all member relationships
xmlDimOptions.ExtractAllRelationships = False
'Extract members for each relationship
xmlDimOptions.ExtractMembersForEachSelectedRelationship = False
'Define Metadata extract options
'Dim EntID As New Dictionary(Of DimPk, XmlExtractMetadataDimOptions)
'EntID = BRApi.Finance.Dim.GetDimPk(si, "Total Golfstream")
Dim xmlMetadataOptions As New XmlExtractMetadataOptions()
'Entity Dimension type
Dim dimT As Integer = DimType.Entity.Id
'Set the extract dimension options for specified dimension
xmlMetadataOptions.SetOptionsForDimension(dimT, dimID, xmlDimOptions)
'Add dimension member options to metadata options
xmlOptions.MetadataOptions = xmlMetadataOptions
'Execute the Metadata Extract
Using dbConnFW As DbConnInfo = BRApi.Database.CreateFrameworkDbConnInfo(si)
Using dbConnApp As DbConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
'Extract XML metadata to target location
File.WriteAllText(filePath, MetadataExtract.ExtractXml(dbConnFW, dbConnApp, xmlOptions, extractDict))
End Using
End Using
End Select
Return Nothing
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Function
End Class
End Namespace
#End Region "Export Dimension Metadata to XML File"
Regards,
Peter
jwagner
5 months agoNew Contributor III
Where is this MetadataExtract.ExtractXML function coming from? I'm trying to expand on this idea except with all Object Types including dashboards, cube views etc. Is there something similar for them?
Related Content
- 4 months ago
- 2 years ago
- 11 months ago
- 4 months ago
- 10 months ago