++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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_ExportAppMetadata
Public Class MainClass
'------------------------------------------------------------------------------------------------------------
'Reference Code: XFR_ExportAppMetadata
'
'Description: Extender business rule that all application metadata to a zip file for the current application.
' The files are 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: <Your name>
'Date Created: <xx-xx-xxxx>
'------------------------------------------------------------------------------------------------------------
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.Unknown, ExtenderFunctionType.ExecuteDataMgmtBusinessRuleStep
'Prepare the Stage Data Extract File path
Dim configSettings as AppServerConfigSettings = AppServerConfig.GetSettings(si)
Dim folderPath as String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, True, configSettings.FileShareRootFolder, si.AppToken.AppName) & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\MetadataExtracts"
if Not Directory.Exists(folderPath) then Directory.CreateDirectory(folderPath)
Dim filePath as String = folderPath & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & " " & si.AppToken.AppName & ".zip"
If File.Exists(filePath) Then File.Delete(filePath)
'Set the extract options
Dim xmlOptions as New XmlExtractOptions
xmlOptions.ExtractAllItems = True
'Execute the Metadata Extract
Using dbConnFW as DBConnInfo = BRAPi.Database.CreateFrameworkDbConnInfo(si)
Using dbConnApp as DBConnInfo = BRAPi.Database.CreateApplicationDbConnInfo(si)
Dim zipBytes as Byte() = ApplicationZipFileHelper.Extract(dbConnFW, dbConnApp, Nothing, xmlOptions)
'Append the contents of this workflow profile to the extract file
Using FS As New FileStream(filePath, FileMode.Append, FileAccess.Write)
'Create a binary writer, and write all bytes to the FileStream at once
Using BW As New BinaryWriter(FS)
BW.Write(zipBytes)
End Using
End Using
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
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Reference link:
https://community.onestreamsoftware.com/t5/Rules/Automating-Application-Back-up/td-p/7980
Thanks,
Madhusudhan
No comments:
Post a Comment