Friday, 6 September 2013

Export all shared projects

Following code exports all projects in the Shared node. For each run it creates a new folder and then the projects are individually exported to xpo.

static void ExportAllProjects(Args _args)  
{  
 ProjectNode      sharedProject = Infolog.projectRootNode().AOTfindChild("Shared");  
 TreeNodeIterator   treeIterator;  
 TreeNode        childNode;  
 str           folderPath = @"C:\\AXProjects\\";  
 str           folderName;  
 System.DateTime    dateTime = DateTimeUtil::newDateTime(systemDateGet(), timeNow());  

 void exportProject(TreeNode _projectNode)  
 {  
  FileIoPermission   perm;  
  str           exportFileName;  

  if(_projectNode != null)  
  {  
   exportFileName = folderPath + folderName + "\\" + _projectNode.AOTname() + ".xpo";  
   perm = new FileIoPermission(exportFileName, "W");  
   perm.assert();  
   _projectNode.treeNodeExport(exportFileName);  
   CodeAccessPermission::revertAssert();  
  }  
 }  

 folderName = dateTime.ToString("yyyyMMdd_HHmmss");  

 if(sharedProject)  
 {  
  treeIterator = sharedProject.AOTiterator();  

  if(treeIterator)  
  {  
   if(!WinAPI::pathExists(folderPath + folderName))  
   {  
    info(strFmt('Creating the folder %1', folderPath + folderName));  
    WinAPI::createDirectoryPath(folderPath + folderName);  
   }  

   childNode = treeIterator.next();  
   while (childNode)  
   {  
    info(strFmt('Exporting %1', childNode.AOTname()));  
    exportProject(childNode);  

    childNode = treeIterator.next();  
   }  
  }  

  sharedProject.treeNodeRelease();  
 }  
}  

This posting is provided "AS IS" with no warranties. Use code at your own risk.

No comments:

Post a Comment