Community
Vault Forum
Welcome to Autodesk’s Vault Forums. Share your knowledge, ask questions, and explore popular Vault topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

would like to modify the Vault Mirror source to only download .dwfx

0 REPLIES 0
Reply
Message 1 of 1
truscher
518 Views, 0 Replies

would like to modify the Vault Mirror source to only download .dwfx

My company is using the dwf publish option with the base vault to publish dwf's to a network location for ERP access. This works fine as far as it goes, but we are having a problem with "orphaned" files due to files being deleted or moved in the vault. This causes problems for us, the worst of witch is if user does not manually clean up the previously published dwf's, the erp system returns old drawings to the purchasing folks for their p.o.'s.  to solve this problem we would like to use the vault mirror application to "sync" the network location with the vault. Our file store is quite large and we only need to return dwf's, so I would like to limit the scope of returned files to those with the .dwfx extension. Can anyone suggest how to modify this code to exclude all files whose extension is not .DWFx?

 

The code in the SDK (FullMirrorCommand.cs) Is as follows:

 

/*=====================================================================

 

  This file is part of the Autodesk Vault API Code Samples.

  Copyright (C) Autodesk Inc.  All rights reserved.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY

KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE

IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A

PARTICULAR PURPOSE.

=====================================================================*/

using

System;

using

System.IO;

 

using

Autodesk.Connectivity.WebServices;

using

ADSK = Autodesk.Connectivity.WebServices;

 

namespace

VaultMirror

{

///<summary>

/// Summary description for FullMirrorCommand.

///</summary>

publicclassFullMirrorCommand : Command

{

       

privatestring m_outputFolder;

       

public FullMirrorCommand(string username, string password,

           

string server, string vault, string outputFolder)

            :

base (username, password, server, vault)

{

m_outputFolder = outputFolder;

}

       

publicoverridevoid Execute_Impl()

        {

           

// cycle through all of the files in the Vault and place them on disk if needed

           

Folder root = m_serviceManager.DocumentService.GetFolderRoot();

           

// add the vault name to the local path.  This prevents users from accedently

           

// wiping out their C drive or something like that.

           

string localPath = Path.Combine(m_outputFolder, m_vault);

            FullMirrorVaultFolder(root, localPath);

           

// cycle through all of the files on disk and make sure that they are in the Vault

            FullMirrorLocalFolder(root, localPath);

        }

       

privatevoid FullMirrorVaultFolder(Folder folder, string localFolder)

        {

           

if (folder.Cloaked)

               

return;

           

if (!Directory.Exists(localFolder))

               

Directory.CreateDirectory(localFolder);

            ADSK.

File[] files = m_serviceManager.DocumentService.GetLatestFilesByFolderId(

                folder.Id,

true);

           

if (files != null)

            {

               

foreach (ADSK.File file in files)

                {

                   

if (file.Cloaked)

                       

continue;

                   

string filePath = Path.Combine(localFolder, file.Name);

                   

if (System.IO.File.Exists(filePath))

                    {

                       

if (file.CreateDate != System.IO.File.GetCreationTime(filePath))

                            DownloadFile(file, filePath);

                    }

                   

else

                        DownloadFile(file, filePath);

                }

            }

           

Folder[] subFolders = m_serviceManager.DocumentService.GetFoldersByParentId(folder.Id, false);

           

if (subFolders != null)

            {

               

foreach (Folder subFolder in subFolders)

                {

                    FullMirrorVaultFolder(subFolder,

Path.Combine(localFolder, subFolder.Name));

                }

            }

        }

       

privatevoid FullMirrorLocalFolder(Folder folder, string localFolder)

        {

           

if (folder.Cloaked)

               

return;

           

// delete any files on disk that are not in the vault

           

string [] localFiles = Directory.GetFiles(localFolder);

            ADSK.

File[] vaultFiles = m_serviceManager.DocumentService.GetLatestFilesByFolderId(folder.Id, true);

           

if (vaultFiles == null && localFiles != null)

            {

               

foreach (string localFile in localFiles)

                {

                    DeleteFile(localFile);

                }

            }

           

else

            {

               

foreach (string localFile in localFiles)

                {

                   

bool fileFound = false;

                   

string filename = Path.GetFileName(localFile);

                   

foreach (ADSK.File vaultFile in vaultFiles)

                    {

                       

if (!vaultFile.Cloaked && vaultFile.Name == filename)

                        {

                            fileFound =

true;

                           

break;

                        }

                    }

                   

if (!fileFound)

                        DeleteFile(localFile);

                }

            }

           

           

// recurse the subdirectories and delete any folders not in the Vault

           

string [] localFullPaths = Directory.GetDirectories(localFolder);

           

if (localFullPaths != null)

            {

               

foreach (string localFullPath in localFullPaths)

                {

                   

string vaultPath = folder.FullName + "/" + Path.GetFileName(localFullPath);

                   

Folder[] vaultSubFolder = m_serviceManager.DocumentService.FindFoldersByPaths(

                       

newstring [] { vaultPath });

                   

                   

if (vaultSubFolder[0].Id < 0)

                        DeleteFolder(localFullPath);

                   

else

                        FullMirrorLocalFolder(vaultSubFolder[0], localFullPath);

                }

            }

        }

}

}

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report