在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 ...
随机推荐
- 【Java基础】序列化与反序列化深入分析
一.前言 复习Java基础知识点的序列化与反序列化过程,整理了如下学习笔记. 二.为什么需要序列化与反序列化 程序运行时,只要需要,对象可以一直存在,并且我们可以随时访问对象的一些状态信息,如果程序终 ...
- Activity间中使用Intent传值
主页面用来输入一个值传入第二个页面显示,关闭第二个页面返回一个值 主页布局: <RelativeLayout xmlns:android="http://schemas.android ...
- js cookie存储方法
/*! * jQuery Cookie Plugin v1.4.0 * https://github.com/carhartl/jquery-cookie * * Copyright 2013 Kla ...
- 2.Visual FoxPro内存变量显示和清除命令
一.内存变量的显示相关命令: 1. LIST MEMORY[LIKE<通配符>][TO PRINTER |TO FILE<文件名>] 2. DISPLAY MEMORY[L ...
- TCP/IP详解学习笔记(13)-TCP坚持定时器,TCP保活定时器
TCP一共有四个主要的定时器,前面已经讲到了一个--超时定时器--是TCP里面最复杂的一个,另外的三个是: 坚持定时器 保活定时器 2MSL定时器 其中坚持定时器用于防止通告窗口为0以后双方互相等待死 ...
- ASP.NET伪静态的方法及相关资料
1. 添加URLRewriter.dll引用 2. 配置web.config的基本信息 <configSections> <section name="RewriterCo ...
- 【WebService】WebService的创建和使用——文件名称生成器
简介 之前做过一个文件名称生成器,通过Webservice读取XML文件并将其通过Json传到客户端中的combobx,用户通过combobox选择要生成文件的名称模板,点击生成则会产生一个文件名称并 ...
- SQLProfiler_SQL抓包
有时候我们的某个程序或者应用在执行SQL语句时报错了, 我们需要拿到报错的SQL语句检查, 那么你可以借助:SQL Profiler工具来实现. 1.SQL Profiler是一个可以检测SQL服务器 ...
- R语言介绍
R语言简介 R语言是一种为统计计算和图形显示而设计的语言环境,是贝尔实验室(Bell Laboratories)的Rick Becker.John Chambers和Allan Wilks开发的S语言 ...
- 聊一下C#开发者如何过渡到JAVA 开发者
由于工作需要,最近也开始倒腾Java了.NET的话,从2012年测试版开始玩的,那个时候VB6比较熟悉,还天真的以为VB.NET以后会很火, 事实证明,也只是一厢情愿,有C#了,要VB.NET干什么? ...