EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 10942|回复: 235
打印 上一主题 下一主题

Migrating Folder Property sample app to Vault 2012

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12404

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-14 10:32:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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.MasterId, "Setting folder property",

            false, files.ModDate,

            associations.DependFileIds.ToArray(), associations.DependSources.ToArray(),

            associations.AttachFileIds.ToArray(), associations.AttachSources.ToArray(),

            null, true, null, files.FileClass, files.Hidden, null);

    }

With these lines:

   try

    {

        // Get bom                  

        BOM tbom = docSvc.GetBOMByFileId(files.Id);

        FileAssocParam[] paramArray = null;

        if (associations.fileAssocParams!=null)

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

        docSvc.CheckinFile(files.MasterId, "Setting folder property",

            false, files.ModDate,

            paramArray,

            tbom, true,null, files.FileClass, files.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.


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对
工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言

14

主题

2892

帖子

2085

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
2085
推荐
发表于 2016-3-25 10:53:57 | 只看该作者
    <( ̄︶ ̄)>  不错o!~

14

主题

2892

帖子

2085

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
2085
推荐
发表于 2016-2-25 10:08:25 | 只看该作者
支持一下    (● ̄(エ) ̄●)
推荐
发表于 2017-6-2 09:46:09 | 只看该作者
就是来点赞的哦

1

主题

827

帖子

1316

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1316
12F
发表于 2014-2-25 11:08:44 | 只看该作者
顶......
楼下跟上.....

26

主题

722

帖子

-2205

积分

乞丐

积分
-2205
13F
发表于 2014-2-25 11:11:54 | 只看该作者
路过!!!
不发表意见……

1

主题

716

帖子

1133

积分

BIM项目负责人

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

积分
1133
14F
发表于 2014-2-25 11:12:36 | 只看该作者
路过!!!
不发表意见……

3

主题

839

帖子

1326

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1326
18F
发表于 2014-2-25 11:20:41 | 只看该作者
路过!!!
不发表意见……
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-16 12:21

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表