在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
相关文章推荐
- 使用ShellClass获取文件属性详细信息
- 使用ShellClass获取文件属性详细信息的实现方法
- Qt学习笔记,使用QDir获取当前目录下所有目录和文件信息
- 使用ShellClass获取文件属性详细信息
- Qt学习笔记,使用QDir获取当前目录下所有目录和文件信息
- PHP遍历指定目录,并存储目录内所有文件属性信息
- IOS开发——获取本地音频文件(属性/信息)
- Swift - 使用PhotoKit获取照片1(获取所有照片缩略图、原图及其信息)
- IOS开发——获取本地音频文件(属性/信息)
- C# 获取文件大小,创建时间,文件信息,FileInfo类的属性表
- 使用ISBN码通过豆瓣API获取图书信息(ThinkPHP)
- 编写一个JSP文件,使用pageContext内置对象来获取由session、request和application内置对象设置的属性。
- 请使用sun 内省api得到某一个bean的所有属性,并操作bean的其中一个属性(给属性赋值,以及得到属性的值
- jdbc数据库连接管理封装工具类,不同使用属性文件配置数据库连接信息(1)
- Spring配置文件中使用PropertyPlaceholderConfigurer配置获取jdbc的配置信息
- python_批量获取指定文件夹下的所有文件的厂商信息
- 文件属性获取及控件ListView使用常用方法
- SVN使用log,list,cat,diff查看所有及特定文件版本信息
- android出现注: 某些输入文件使用或覆盖了已过时的 API。 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。 注: 某些输入文件使用了未经检查或不安全的操作。 注
- 102-资源打包,内存分配,内存泄漏,私有API,硬件信息的获取,使用imageName加载图片和使用imageWithContentsOfFile加载图片的场合优缺点及内存分析