Migrating Folder Property sample app to Vault 2012
来源:互联网 发布:redis和数据库同步 编辑:程序博客网 时间:2024/06/11 03:28
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.
- Migrating Folder Property sample app to Vault 2012
- Migrating Your Android App from Eclipse to Android Studio
- Migrating to .NET
- Migrating from VC6 to VC9
- iPhone - UIImagePickerController -> save the image to app folder
- Migrating Struts Apps to Struts 2
- .NET for Java Developers: Migrating to C#
- Migrating from 1.0.x to 1.5 Stable
- Migrating from HttpClient 3.1 to HttpClient 4.0
- Migrating Databases To and From ASM with
- Migrating the Flash Recovery Area to ASM
- Migrating Queries from One User To Another
- Migrating applications to JBoss EAP and EWP
- Migrating your code to Objective-C ARC
- Migrating to Spring 3.1 and Hibernate 4.1
- Migrating to WebView in Android 4.4
- 【书籍推荐】Migrating to Swift from Android
- migrating from ia32 to arm digest
- 系统调用与函数调用的区别
- SAP R/3 4.71 IDES安装参考
- Vsftpd虚拟用户设置(转自ubuntu中文)
- mina socket
- go 语句
- Migrating Folder Property sample app to Vault 2012
- cairngorm console
- 编程VS做菜
- u盘无法删除文件,文件或目录损坏
- 代码高亮syntaxhighlighter
- javascript var_dump
- 正则表达式判断字符串是不是数字
- 读书笔记
- PHP的ASCII码转换类