Migrating Folder Property sample app to Vault 2012

Doug called up everyone to help migrating his Vault sample apps in his blog HELP - Too many sample apps, and I’m taking one of them - the Folder Property. This sample is to show you how to use Vault API to find all files in Vault, also find the specific property for each Vault file, change the value of the property. It also demonstrates how to find files through specifying search condition, e.g. the Date version created is bigger than specific time.

This sample also implements the function of detecting what file is editable. In some cases, the file is not editable because it’s released or checked out. I used this function last time when I wrote an article for our Newsletter about how to customize the report page of Vault. I copied that function below:

        /// <summary>

        /// Remove files that we know that we cannot edit.

        /// </summary>

        protected List<Document.File> PruneFileList(IEnumerable<Document.File> files)

        {

            List<Document.File> retVal = new List<FolderProperty.Document.File>();

 

            foreach (Document.File f in files)

            {

                if (f == null || f.Id <= 0 || f.Cloaked || f.CheckedOut)

                    continue;

 

                if (f.FileLfCyc != null && f.FileLfCyc.Consume)

                    continue;

 

                retVal.Add(f);

            }

            return retVal;

        }

Now you can download the migrated sample app from:

http://barbarahan.download.csdn.net/

If you want to know what to do for porting this sample to Vault 2012, here is some information that I am happy to share:

1.       Open the sample project in VS 2008;

2.       Remove the web reference folder from the solution explorer window, and add reference to Autodesk.Connectivity.WebServices.DLL located in Vault 2012 SDK/bin folder, and ensure the Copy Local to be True.

3.       Build project and fix the compiling error – most of errors are failing to find object in some namespace. Replacing the old namespace, such as Document, with Autodesk.Connectivity.WebServices would resolve this sort of error. Other errors are caused by some functions being changed in Vault 2012, for example CheckInFile function has a new parameter and 4 parameters are removed, so you need to re-write some codes to set up the new parameter. Here is a sample for adjusting the code to make CheckInFile work:

Replace FileAssociations class:

    public class FileAssociations

    {

        public List<long> DependFileIds;

        public List<string> DependSources;

        public List<long> AttachFileIds;

        public List<string> AttachSources;

 

        public FileAssociations(FileAssocArray fileAssocArray)

        {

            DependFileIds = new List<long>();

            DependSources = new List<string>();

            AttachFileIds = new List<long>();

            AttachSources = new List<string>();

 

            if (fileAssocArray == null || fileAssocArray.FileAssocs == null)

                return;

 

            foreach (FileAssoc assoc in fileAssocArray.FileAssocs)

            {

                if (assoc.Typ == AssociationType.Attachment)

                {

                    AttachFileIds.Add(assoc.CldFile.Id);

                    AttachSources.Add(assoc.Source);

                }

                else if (assoc.Typ == AssociationType.Dependency)

                {

                    DependFileIds.Add(assoc.CldFile.Id);

                    DependSources.Add(assoc.Source);

                }

            }

        }

 

}

With the new one:

        public FileAssociations(FileAssocArray fileAssocArray)

        {

 

            if (fileAssocArray != null)

            {

                if (fileAssocArray.FileAssocs != null)

                {

                    fileAssocParams = new ArrayList();

                    foreach (FileAssoc assoc in fileAssocArray.FileAssocs)

                    {

                        FileAssocParam param1 = new FileAssocParam();

                        param1.CldFileId = assoc.CldFile.Id;

                        param1.RefId = assoc.RefId;

                        param1.Source = assoc.Source;

                        param1.Typ = assoc.Typ;

                        param1.ExpectedVaultPath = assoc.ExpectedVaultPath;

                        fileAssocParams.Add(param1);

                    }

                }

            }

        }

}

 

Replace the following lines which calls CheckinFile function to check file in Vault:

    try

    {

        docSvc.CheckinFile(files[i].MasterId, "Setting folder property",

            false, files[i].ModDate,

            associations[i].DependFileIds.ToArray(), associations[i].DependSources.ToArray(),

            associations[i].AttachFileIds.ToArray(), associations[i].AttachSources.ToArray(),

            null, true, null, files[i].FileClass, files[i].Hidden, null);

    }

With these lines:

   try

    {

        // Get bom                   

        BOM tbom = docSvc.GetBOMByFileId(files[i].Id);

 

        FileAssocParam[] paramArray = null;

        if (associations[i].fileAssocParams!=null)

            paramArray = (FileAssocParam[])associations[i].fileAssocParams.ToArray(typeof(FileAssocParam));

 

        docSvc.CheckinFile(files[i].MasterId, "Setting folder property",

            false, files[i].ModDate,

            paramArray,

            tbom, true,null, files[i].FileClass, files[i].Hidden, null);

    }

 

4.       Debug the app and fix the run-time error – I got a couple of null exceptions, e.g. some files have no FileAssocs and the code doesn’t detect this situation, so I went forward to fix these. Another run-time error that I could’t forget is that the property Id for Date Version Created is changed. In old version of the sample app, the Id is set to -31, and when I ran this app, one error incured and said the property Id is not right. I opened a SDK sample named “VaultFileBrowser” because I recalled it could set the serach condition so I can step in to find the Date Version Created property information through debugging it. I got “5” for that property’s Id. That is it.

It is quite straightforward to update this sample app. If you see anything wrong with the new version, please feel free to let me know.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章