Vault Mirror & Drawing Compare

Reply
Contributor
truscher
Posts: 22
Registered: ‎11-09-2010
Message 1 of 1 (225 Views)

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

225 Views, 0 Replies
11-27-2012 11:59 AM

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);

                }

            }

        }

}

}

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community