在Autodesk Vault 2014中使用VDF(Vault Development Framework) API获取所有文件的属性信息
这几天在玩儿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
在Autodesk Vault 2014中使用VDF(Vault Development Framework) API获取所有文件的属性信息的更多相关文章
- C# 5.0中使用CallerMemberName、CallerFilePath和CallerLineNumber获取代码的调用方信息(转载)
很多时候,我们需要在运行过程中记录一些调测的日志信息,如下所示: public void DoProcessing() { TraceMessage("DoProcessing()被XXX调 ...
- C#可以获取Excel文件中Sheet的名字
C#可以获取Excel文件中Sheet的名字吗 C#可以获取Excel文件中Sheet的名字吗 我试过WPS的表格可以 可以 要代码么 百度都有 [深圳]Milen(99696619) 14:13: ...
- 使用Autodesk Vault插件向导轻松创建Vault插件
Vault SDK帮助文档中已经详细描述了怎么创建Vault插件,不过还是太麻烦了,首先要添加必要的引用,修改程序集属性,添加vcet.config文件,实现必要的接口,最后还要手动把生成的文件拷贝到 ...
- 【Azure Developer - 密钥保管库 】使用 Python Azure SDK 实现从 Azure Key Vault Certificate 中下载证书(PEM文件)
问题描述 在Azure Key Vault中,我们可以从Azure门户中下载证书PEM文件到本地. 可以通过OpenSSL把PFX文件转换到PEM文件.然后用TXT方式查看内容,操作步骤如下图: Op ...
- SQL Server 执行计划利用统计信息对数据行的预估原理以及SQL Server 2014中预估策略的改变
前提 本文仅讨论SQL Server查询时, 对于非复合统计信息,也即每个字段的统计信息只包含当前列的数据分布的情况下, 在用多个字段进行组合查询的时候,如何根据统计信息去预估行数的. 利用不同字段 ...
- SQL Server 2014 中新建登录及权限分配【界面版】
本篇经验将和大家介绍分配SQL Server 2014 中,新建登录用户,分配权限,并指定该用户的数据库的方法,希望对大家的工作和学习有所帮助! 方法/步骤 1 打开 MS SQL Server Ma ...
- java 8中新的日期和时间API
java 8中新的日期和时间API 使用LocalDate和LocalTime LocalDate的实例是一个不可变对象,它只提供了简单的日期,并不含当天的时间信息.另外,它也不附带任何与时区相关的信 ...
- 在docker中运行ASP.NET Core Web API应用程序
本文是一篇指导快速演练的文章,将介绍在docker中运行一个ASP.NET Core Web API应用程序的基本步骤,在介绍的过程中,也会对docker的使用进行一些简单的描述.对于.NET Cor ...
- iOS中获取各种文件的目录路径的方法
我们的app在手机中存放的路径是:/var/mobile/Applications/4434-4453A-B453-4ADF535345ADAF344 后面的目录4434-4453A-B453-4AD ...
随机推荐
- 机器学习&数据挖掘笔记_22(PGM练习六:制定决策)
前言: 本次实验是将一些简单的决策理论和PGM推理结合,实验内容相对前面的图模型推理要简单些.决策理论采用的是influence diagrams,和常见图模型本质一样, 其中的决策节点也可以用CPD ...
- CentOS7 Java安装
CentOS7 Java安装 CentOS7 Java安装 Download 从Oracle下载jdk-8u31-linux-x64.rpm Install 御载 执行如下命令 java -versi ...
- jQuery 3.1 API中文文档
jQuery 3.1 API中文文档 一.核心 1.1 核心函数 jQuery([selector,[context]]) 接收一个包含 CSS 选择器的字符串,然后用这个字符串去匹配一组元素. jQ ...
- JS魔法堂:再识IE的内存泄露
一.前言 IE6~8除了不遵守W3C标准和各种诡异外,我想最让人诟病的应该是内存泄露的问题了.这阵子趁项目技术调研的机会好好的再认识一回,以下内容若有纰漏请大家指正,谢谢! 目录一大坨! 二.内存泄漏 ...
- HoverTree.Model.ArticleSelect类的作用
ArticleSelect类在命名空间HoverTree.Model中可以认为是文章查询条件类,用于存放查询文章时的条件,例如HvtId就是文章的id.HvtIsShow就是文章的显示属性,当为-1是 ...
- [小工具]CSS内嵌样式自动提取器
逐行分析,将内联样式提取出来,并自动编号代替的一个小工具软件 注:style=""(此处必须是标准的双引号!) http://files.cnblogs.com/quejuwen/ ...
- ASP.NET MVC 请求流程:Controller
1.请求进入时,.NET Framework就找出所有的HttpModule,以此调用它们的Init方法,如下图所示,我们重点关注"UrlRoutingModule-4.0"的Ht ...
- iOS阶段学习第31天笔记(UINavigationBar介绍)
iOS学习(UI)知识点整理 一.UINavigationBar 的介绍 1)概念:UINavigationBar 是用于定义导航栏按钮的一个类对象 2)在使用UINavigationBar之前必须先 ...
- Microsoft.Practices.Unity入门
Unity是微软Patterns & Practices团队所开发的一个轻量级的,并且可扩展的依赖注入(Dependency Injection)容器,它支持常用的三种依赖注入方式:构造器注入 ...
- MySQL Error Handling in Stored Procedures 2
Summary: this tutorial shows you how to use MySQL handler to handle exceptions or errors encountered ...