在Autodesk Vault 2014中使用VDF(Vault Development Framework) API获取所有文件的属性信息
2023-09-27 14:25:07 时间
这几天在玩儿Vault API, 从Autodesk Vault 2014开始提供了Vault Development Framework(VDF) API,让开发工作更简单了。在Vault 2013里面可以使用PropertyService 来获取属性(包括属性定义和属性至),在Vault 2014中的VDF API里,我们可以通过PropertyManager来获取。下面代码演示了如何登录到Vault并取得PropertyManager:
前面的文章提到了使用VDF内置的登录对话框登录非常简单,如果你不用使用那个登录框,也可以自己做界面,使用下面的无界面的登录方式:
////login with UI //VDF.Vault.Currency.Connections.Connection connection = VDF.Vault.Forms.Library.Login(new VDF.Vault.Forms.Settings.LoginSettings()); //Another way to log into Vault without UI VDF.Vault.Results.LogInResult results = VDF.Vault.Library.ConnectionManager.LogIn( "localhost", "Vault", "Administrator", "", VDF.Vault.Currency.Connections.AuthenticationFlags.Standard, null); if (!results.Success) { Console.WriteLine("Login failed. exit..."); Console.ReadLine(); return; } VDF.Vault.Currency.Connections.Connection connection = results.Connection; VDF.Vault.Services.Connection.IPropertyManager propMgr = connection.PropertyManager;
这个例子中,我要递归的获取Vault中所有的目录和文件,看到这几个字,我首先想到的就是用FileManager和FolderManager,不过这两个家伙对于获取文件本身,比如checkout并下载等工作来说很好用,我其实只要获取FileInteration进而获取他们的属性,所有FileManager和FolderManager并不是好办法。同事提醒我可以用IEntityOperationManager。 Folder和File等都是Entity,对于这些Entity的操作还有一个更底层的IEntityOperationManager, 其实FileManger和FolderManager也是调用的IEntityOperationManager。通过IEntityOperationManager的GetBrowseChildren方法就可以获取指定entity的所有子实体,就可以实现递归获取所有文件了。
好了,下面是代码:
using Autodesk.Connectivity.WebServices;
using System;
using System.Collections.Generic;
using System.Linq;
using VDF = Autodesk.DataManagement.Client.Framework;
namespace VaultLabs
{
class Lab03
{
// We will collect Property Definitions here
static VDF.Vault.Currency.Properties.PropertyDefinitionDictionary propDefs;
// The entry point of the program
//==========================================================================
static void Main(string[] args)
{
try
{
////login with UI
//VDF.Vault.Currency.Connections.Connection connection
= VDF.Vault.Forms.Library.Login(new VDF.Vault.Forms.Settings.LoginSettings());
//Another way to log into Vault without UI
VDF.Vault.Results.LogInResult results =
VDF.Vault.Library.ConnectionManager.LogIn(
"localhost", "Vault", "Administrator", "",
VDF.Vault.Currency.Connections.AuthenticationFlags.Standard, null);
if (!results.Success)
{
Console.WriteLine("Login failed. exit...");
Console.ReadLine();
return;
}
VDF.Vault.Currency.Connections.Connection connection = results.Connection;
if (connection.IsConnected)
{
ReadProperties(connection);
VDF.Vault.Currency.Entities.Folder folder = connection.FolderManager.RootFolder;
PrintChildren(connection, folder);
Console.ResetColor();
Console.WriteLine("");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR: {0}", ex.Message);
}
} // Main()
// Read all the Property Definitions for the "FILE" Entity Class
//===============================================================================
static void ReadProperties(VDF.Vault.Currency.Connections.Connection connection)
{
propDefs =
connection.PropertyManager.GetPropertyDefinitions(
VDF.Vault.Currency.Entities.EntityClassIds.Files,
null,
VDF.Vault.Currency.Properties.PropertyDefinitionFilter.IncludeUserDefined
);
}
// Output information about each file in a folder along with its properties
//===========================================================================
static void PrintChildren(VDF.Vault.Currency.Connections.Connection connection,
VDF.Vault.Currency.Entities.Folder parentFolder)
{
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 (var ent in entities)
{
if (ent is VDF.Vault.Currency.Entities.FileIteration)
{
VDF.Vault.Currency.Entities.FileIteration fileIteration
= ent as VDF.Vault.Currency.Entities.FileIteration;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(" {0}", fileIteration.EntityName);
Console.ForegroundColor = ConsoleColor.Yellow;
//Now print the properties of the file
PrintProperties(connection, fileIteration);
}
else if (ent is VDF.Vault.Currency.Entities.Folder)
{
// Recursively print info about subfolders and files in them
//-------------------------------------------------------------------------
VDF.Vault.Currency.Entities.Folder folder
= ent as VDF.Vault.Currency.Entities.Folder;
PrintChildren(connection, folder);
}
}
}
}
static void PrintProperties(VDF.Vault.Currency.Connections.Connection connection,
VDF.Vault.Currency.Entities.FileIteration fileInteration)
{
foreach (var key in propDefs.Keys)
{
// Print the Name from the Definition and the Value from the Property
object propValue = connection.PropertyManager.GetPropertyValue(
fileInteration, propDefs[key], null);
Console.WriteLine(" '{0}' = '{1}'",
key.ToString(),
propValue == null ? "" : propValue.ToString());
}
}
} // class Lab03
} // namespace VaultLabs
相关文章
- 019 关联映射文件中集合标签中的lazy(懒加载)属性
- Win64 驱动内核编程-17. MINIFILTER(文件保护)
- python进阶之py文件内置属性
- venvScriptsactivate.ps1,因为在此系统上禁止运行脚本。pycharm:无法加载文件activate.ps1,因为在此系统上禁止运行脚本,Windows10系统
- Java File文件操作 创建文件目录,删除文件目录
- 以Java属性文件的格式创建Hibernate的配置文件和DTD特殊符号作用
- 读取properties属性文件——国际化
- Cocos2dx&Lua - UI显示优化之怎样解决解析大量json文件
- arcgis中给属性文件加x y坐标
- C#【通用方法】创建csv文件的方法
- Bundle文件的创建和使用(一)
- CLR基础,CLR运行过程,使用dos命令创建、编译、运行C#文件,查看IL代码
- 【Linux】文件拷贝-Linux当前目录所有文件移动到上一级目录(转)
- 7底层文件读写
- (3.12)mysql基础深入——mysql日志文件/其他文件(socket/pid/表结构/Innodb)
- 文件分块上传
- Mac 百度云加速下载,突破限速,大文件无压力
- iOS开发 -- 为本地文件添加自定义属性的工具类
- [LeetCode] Transpose File 转置文件
- spring 通过编程来获取属性文件
- 3.66 OrCAD中不同的工程文件,怎么输出所需要工程文件的网表?OrCAD中怎么给元器件自定义属性?
- eclipse导入项目文件以及 import项目文件后有个红色感叹号