Skip to main content

Data Management Step Service

  1. In assembly DevUtilServices, create a Data Management Step Service called HelperDmSvc.
  2. In the sub ProcessDataManagementStep, below the comment Implement Data Management Step logic here, add the following code:
if (args.DataMgmtArgs.CurrentStep.Step.StepType == DataMgmtStepType.ExecuteBusinessRule & args.DataMgmtArgs.CurrentStep.Step.Name.XFEqualsIgnoreCase("Create XFProj"))
{
// create a xfProject object
XFProject xfPr = new XFProject();
// set basic properties
xfPr.DefaultZipFileName = workspace.Name;
xfPr.TopFolderPath = workspace.Name;
// create projectItem elements and add them
// Note: for easier maintenance, this is set
// in a parameter called XfProjectConfig.
NameValueFormatBuilder nvb = new NameValueFormatBuilder(BRApi.Dashboards.Parameters.GetLiteralParameterValue(si, false, workspace.UniqueID, "XfProjectConfig"));
// the list of Maintenance Units has to be parsed
List<string> maintUnits = StringHelper.SplitString(nvb.NameValuePairs.XFGetValue("MaintUnits", ""), ',');
// add each unit to the list, wrapped into a xfProjectItem object
foreach (string maintUnit in maintUnits)
{
XFProjectItem xfProjItem = new XFProjectItem(XFProjectItemType.DashboardMaintenanceUnit, "", workspace.Name, maintUnit, true);
xfPr.ProjectItems.Add(xfProjItem);
}
// Dashboard profiles are not kept in Workspaces,
// so Let's do it again for them.
// Note workspace name was set to Default for these items.
List<string> dbdProfiles = StringHelper.SplitString(nvb.NameValuePairs.XFGetValue("DbdProfiles", ""), ',');
foreach (string dbProfile in dbdProfiles)
{
XFProjectItem xfProjItem = new XFProjectItem(XFProjectItemType.DashboardProfile, "", "Default", dbProfile, true);
xfPr.ProjectItems.Add(xfProjItem);
}
// save xfproj to app filesystem in Documents/Users/YourUser/YourWsName.xfproj
string targetFileName = Path.Combine("Documents", "Users", StringHelper.RemoveSystemCharacters(si.UserName, false, false), $"{xfPr.DefaultZipFileName}.xfProj");
XFFileInfo targetXFProjInfo = new XFFileInfo(FileSystemLocation.ApplicationDatabase, targetFileName);
XFFile targetXFProjFile = new XFFile(targetXFProjInfo, string.Empty, xfPr.WriteXmlStringAsBytes(si));
BRApi.FileSystem.InsertOrUpdateFile(si, targetXFProjFile);
}