Forum Discussion

ssmith-nova's avatar
ssmith-nova
New Contributor III
9 months ago

Import XML to create objects

Hi All, 

I have a process that exports a dashboard and all of its components to XML.  It then reads through the XML and creates new objects.  The process works when I import the XML by hand.  I was wondering if there is a way to have the code:

1) delete objects if they exist

2) import the XML to create the new objects. 

 

Thank you,
Scott

  • MarcusH's avatar
    MarcusH
    Contributor III

    The only method I know that will effectively replace Dashboards is XFProject. Have a look in the Design and Reference Guide and search this forum for more info. This screenshot gives you an idea:

     

    • ssmith-nova's avatar
      ssmith-nova
      New Contributor III

      I had looked at that.  Do you know if there a method to import and export the xfProj via code?  

       

      • RobbSalzmann's avatar
        RobbSalzmann
        Valued Contributor II

        XFProj has its own XML library: XFProjectWcf

        Use XFProjectWcf.ExtractXFProjectFileHierarchy to extract,  and XFProjectWcf.StartLoadXFProjectFileHierarchy using similar structure to the code posted for application zip and dashboards.

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    You would use the XmlLoadWcf library for this.  It can load either xml as a string or as a zip file.  It runs similar to running a Data Management sequence, returning a TaskActivity object:

    						
    Dim task As TaskActivityItem = Nothing
    'Execute the XML load and assign the TaskActivityItem
    task = XmlLoadWcf.StartLoadXml(si, xmlString, Nothing,  String.Empty, SystemXmlFileType.Unknown, ApplicationXmlFileType.ApplicationDashboards, Nothing)
    


    Here it is an example round trip using some of PeterFu's code:

    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 & "\" & 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
    
    'Load the file back in
    Dim task As TaskActivityItem = Nothing
    
    'load the application zip file
    task = XmlLoadWcf.StartLoadXml(si, "",  Nothing, filePath, SystemXmlFileType.Unknown, ApplicationXmlFileType.ApplicationZipFile, Nothing)