您的位置:首页 > 产品设计 > 产品经理

在Autodesk Vault 2014中使用VDF(Vault Development Framework) API获取所有文件的属性信息

2013-12-12 14:33 639 查看
这几天在玩儿VaultAPI,从AutodeskVault2014开始提供了VaultDevelopmentFramework(VDF)API,让开发工作更简单了。在Vault2013里面可以使用PropertyService来获取属性(包括属性定义和属性至),在Vault2014中的VDFAPI里,我们可以通过PropertyManager来获取。下面代码演示了如何登录到Vault并取得PropertyManager:
前面的文章提到了使用VDF内置的登录对话框登录非常简单,如果你不用使用那个登录框,也可以自己做界面,使用下面的无界面的登录方式:
////loginwithUI
//VDF.Vault.Currency.Connections.Connectionconnection=VDF.Vault.Forms.Library.Login(newVDF.Vault.Forms.Settings.LoginSettings());

//AnotherwaytologintoVaultwithoutUI
VDF.Vault.Results.LogInResultresults=
VDF.Vault.Library.ConnectionManager.LogIn(
"localhost","Vault","Administrator","",
VDF.Vault.Currency.Connections.AuthenticationFlags.Standard,null);
if(!results.Success)
{
Console.WriteLine("Loginfailed.exit...");
Console.ReadLine();
return;
}

VDF.Vault.Currency.Connections.Connectionconnection=results.Connection;

VDF.Vault.Services.Connection.IPropertyManagerpropMgr=connection.PropertyManager;


这个例子中,我要递归的获取Vault中所有的目录和文件,看到这几个字,我首先想到的就是用FileManager和FolderManager,不过这两个家伙对于获取文件本身,比如checkout并下载等工作来说很好用,我其实只要获取FileInteration进而获取他们的属性,所有FileManager和FolderManager并不是好办法。同事提醒我可以用IEntityOperationManager。Folder和File等都是Entity,对于这些Entity的操作还有一个更底层的IEntityOperationManager,其实FileManger和FolderManager也是调用的IEntityOperationManager。通过IEntityOperationManager的GetBrowseChildren方法就可以获取指定entity的所有子实体,就可以实现递归获取所有文件了。

好了,下面是代码:

usingAutodesk.Connectivity.WebServices;
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingVDF=Autodesk.DataManagement.Client.Framework;

namespaceVaultLabs
{
classLab03
{
//WewillcollectPropertyDefinitionshere
staticVDF.Vault.Currency.Properties.PropertyDefinitionDictionarypropDefs;

//Theentrypointoftheprogram
//==========================================================================
staticvoidMain(string[]args)
{
try
{

////loginwithUI
//VDF.Vault.Currency.Connections.Connectionconnection
=VDF.Vault.Forms.Library.Login(newVDF.Vault.Forms.Settings.LoginSettings());

//AnotherwaytologintoVaultwithoutUI
VDF.Vault.Results.LogInResultresults=
VDF.Vault.Library.ConnectionManager.LogIn(
"localhost","Vault","Administrator","",
VDF.Vault.Currency.Connections.AuthenticationFlags.Standard,null);
if(!results.Success)
{
Console.WriteLine("Loginfailed.exit...");
Console.ReadLine();
return;
}

VDF.Vault.Currency.Connections.Connectionconnection=results.Connection;

if(connection.IsConnected)
{
ReadProperties(connection);

VDF.Vault.Currency.Entities.Folderfolder=connection.FolderManager.RootFolder;

PrintChildren(connection,folder);

Console.ResetColor();
Console.WriteLine("");
Console.WriteLine("Pressanykeytoexit...");
Console.ReadKey();
}

}
catch(Exceptionex)
{
Console.WriteLine("ERROR:{0}",ex.Message);
}
}//Main()

//ReadallthePropertyDefinitionsforthe"FILE"EntityClass
//===============================================================================
staticvoidReadProperties(VDF.Vault.Currency.Connections.Connectionconnection)
{
propDefs=
connection.PropertyManager.GetPropertyDefinitions(
VDF.Vault.Currency.Entities.EntityClassIds.Files,
null,
VDF.Vault.Currency.Properties.PropertyDefinitionFilter.IncludeUserDefined
);

}

//Outputinformationabouteachfileinafolderalongwithitsproperties
//===========================================================================
staticvoidPrintChildren(VDF.Vault.Currency.Connections.Connectionconnection,
VDF.Vault.Currency.Entities.FolderparentFolder)
{
Console.ForegroundColor=ConsoleColor.Cyan;
Console.WriteLine("{0}",parentFolder.FullName);

IEnumerable<VDF.Vault.Currency.Entities.IEntity>entities=connection
.EntityOperations.GetBrowseChildren(parentFolder);
if(entities!=null&&entities.Count<VDF.Vault.Currency.Entities.IEntity>()>0)
{
foreach(varentinentities)
{
if(entisVDF.Vault.Currency.Entities.FileIteration)
{
VDF.Vault.Currency.Entities.FileIterationfileIteration
=entasVDF.Vault.Currency.Entities.FileIteration;

Console.ForegroundColor=ConsoleColor.Green;
Console.WriteLine("{0}",fileIteration.EntityName);
Console.ForegroundColor=ConsoleColor.Yellow;

//Nowprintthepropertiesofthefile
PrintProperties(connection,fileIteration);

}
elseif(entisVDF.Vault.Currency.Entities.Folder)
{
//Recursivelyprintinfoaboutsubfoldersandfilesinthem
//-------------------------------------------------------------------------

VDF.Vault.Currency.Entities.Folderfolder
=entasVDF.Vault.Currency.Entities.Folder;
PrintChildren(connection,folder);

}
}
}

}

staticvoidPrintProperties(VDF.Vault.Currency.Connections.Connectionconnection,
VDF.Vault.Currency.Entities.FileIterationfileInteration)
{
foreach(varkeyinpropDefs.Keys)
{
//PrinttheNamefromtheDefinitionandtheValuefromtheProperty
objectpropValue=connection.PropertyManager.GetPropertyValue(
fileInteration,propDefs[key],null);
Console.WriteLine("'{0}'='{1}'",
key.ToString(),
propValue==null?"":propValue.ToString());
}
}

}//classLab03

}//namespaceVaultLabs
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐