这几天在玩儿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获取所有文件的属性信息的更多相关文章

  1. C# 5.0中使用CallerMemberName、CallerFilePath和CallerLineNumber获取代码的调用方信息(转载)

    很多时候,我们需要在运行过程中记录一些调测的日志信息,如下所示: public void DoProcessing() { TraceMessage("DoProcessing()被XXX调 ...

  2. C#可以获取Excel文件中Sheet的名字

    C#可以获取Excel文件中Sheet的名字吗 C#可以获取Excel文件中Sheet的名字吗 我试过WPS的表格可以 可以 要代码么 百度都有 [深圳]Milen(99696619)  14:13: ...

  3. 使用Autodesk Vault插件向导轻松创建Vault插件

    Vault SDK帮助文档中已经详细描述了怎么创建Vault插件,不过还是太麻烦了,首先要添加必要的引用,修改程序集属性,添加vcet.config文件,实现必要的接口,最后还要手动把生成的文件拷贝到 ...

  4. 【Azure Developer - 密钥保管库 】使用 Python Azure SDK 实现从 Azure Key Vault Certificate 中下载证书(PEM文件)

    问题描述 在Azure Key Vault中,我们可以从Azure门户中下载证书PEM文件到本地. 可以通过OpenSSL把PFX文件转换到PEM文件.然后用TXT方式查看内容,操作步骤如下图: Op ...

  5. SQL Server 执行计划利用统计信息对数据行的预估原理以及SQL Server 2014中预估策略的改变

    前提  本文仅讨论SQL Server查询时, 对于非复合统计信息,也即每个字段的统计信息只包含当前列的数据分布的情况下, 在用多个字段进行组合查询的时候,如何根据统计信息去预估行数的. 利用不同字段 ...

  6. SQL Server 2014 中新建登录及权限分配【界面版】

    本篇经验将和大家介绍分配SQL Server 2014 中,新建登录用户,分配权限,并指定该用户的数据库的方法,希望对大家的工作和学习有所帮助! 方法/步骤 1 打开 MS SQL Server Ma ...

  7. java 8中新的日期和时间API

    java 8中新的日期和时间API 使用LocalDate和LocalTime LocalDate的实例是一个不可变对象,它只提供了简单的日期,并不含当天的时间信息.另外,它也不附带任何与时区相关的信 ...

  8. 在docker中运行ASP.NET Core Web API应用程序

    本文是一篇指导快速演练的文章,将介绍在docker中运行一个ASP.NET Core Web API应用程序的基本步骤,在介绍的过程中,也会对docker的使用进行一些简单的描述.对于.NET Cor ...

  9. iOS中获取各种文件的目录路径的方法

    我们的app在手机中存放的路径是:/var/mobile/Applications/4434-4453A-B453-4ADF535345ADAF344 后面的目录4434-4453A-B453-4AD ...

随机推荐

  1. 机器学习&数据挖掘笔记_25(PGM练习九:HMM用于分类)

    前言: 本次实验是用EM来学习HMM中的参数,并用学好了的HMM对一些kinect数据进行动作分类.实验内容请参考coursera课程:Probabilistic Graphical Models 中 ...

  2. Metronic – 超赞!基于 Bootstrap 的响应式后台管理模板

    Metronic 是一套精美的响应式后台管理模板,基于强大的 Twitter Bootstrap 框架实现.Metronic 拥有简洁优雅的 Metro UI 风格界面,6 种颜色可选,76 个模板页 ...

  3. BP算法笔记

  4. SQL Server 2016的数据库范围内的配置

    SQL Server 2016真的让人眼前一亮.几天前微软就提供了RCO(候选发布版)版本的下载.我已经围观了一圈RCO版本,其中一个最拽的功能是数据库范围内的配置(Database Scoped C ...

  5. 阅读《LEARNING HARD C#学习笔记》知识点总结与摘要系列文章索引

    从发表第一篇文章到最后一篇文章,时间间隔有整整一个月,虽只有5篇文章,但每一篇文章都是我吸收<LEARNING HARD C#学习笔记>这本书的内容要点及网上各位大牛们的经验,没有半点废话 ...

  6. CompressHelper

    public static string CompressString(string unCompressedString) { byte[] bytData = System.Text.Encodi ...

  7. Mac下Vim配置语法高亮

    设置终端的字体颜色 如图,打开终端然后,选择偏好设置,再选择描述文件,再窗口左侧可以选择系统配置好的,或者你也可以自定义,最后别忘了把你的配置设置成默认就行 Vim语法高亮设置 只需要找到vimrc配 ...

  8. Mssql中一些常用数据类型的说明和区别

    Mssql中一些常用数据类型的说明和区别 1.bigint 占用8个字节的存储空间,取值范围在-2^63 (-9,223,372,036,854,775,808) 到 2^63-1 (9,223,37 ...

  9. 驱动开发利器Microsoft Windows Driver Kit 7.1.0下载

    在Windows 2000 与Windows XP 系统采用是WINDDK来开发WINDOWS驱动程序,我手头也有WINDDK,可是从Windows Vista开始之后,一般采用Microsoft W ...

  10. 优化JavaScripe 提升首页加载速度的几种方案解析

    优化目的: 1. 减少load量. 2. 优化js,加快页面加载速度. 网站中最影响网站打开速度的是什么?我会告诉是网站中的javascript,简称JS.模板中引用的JS文件越多,打开速度越慢,细读 ...