这几天在玩儿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. 【圣诞特献】Web 前端开发精华文章推荐【系列二十一】

    <Web 前端开发精华文章推荐>2013年第九期(总第二十一期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各种增强网站用户体验的 jQuery 插件,展示前沿的 HTML5 和  ...

  2. js每天进步一点点4

    输入数字的验证

  3. JavaScript中{}+{}

    在 JavaScript 中,加法的规则其实很简单,只有两种情况: 把数字和数字相加 把字符串和字符串相加 所有其他类型的值都会被自动转换成这两种类型的值. 为了能够弄明白这种隐式转换是如何进行的,我 ...

  4. SQL Server中的事务日志管理(8/9):优化日志吞吐量

    当一切正常时,没有必要特别留意什么是事务日志,它是如何工作的.你只要确保每个数据库都有正确的备份.当出现问题时,事务日志的理解对于采取修正操作是重要的,尤其在需要紧急恢复数据库到指定点时.这系列文章会 ...

  5. Git版本控制工具学习

    Git代码管理工具学习 分布式管理工具:git 相比较svn它更加的方便,基本上我们的操作都是在本地进行的. Git文件的三种状态:已提交,已修改,以暂存. 已提交:表示文件已经被保存到本地数据库. ...

  6. Entity Framework基础01

    学习了ADO.NET的相关知识,掌握了它对数据库表的基本操作,但是实际在开发项目应用中微软为我们开发ef这个ORM,使用它可以很方便的利用ADO.NET来操作DBMS,使得我们开发项目的着重点放在业务 ...

  7. 15天玩转redis —— 第五篇 集合对象类型

    这篇我们来看看Redis五大类型中的第四大类型:“集合类型”,集合类型还是蛮有意思的,第一个是因为它算是只使用key的Dictionary简易版, 这样说来的话,它就比Dictionary节省很多内存 ...

  8. asp.net动态生成按钮Button控件

    1.动态生成button控件及响应服务端和客户端事件 void BindButtons(){ foreach (var item in items) { Button Btn = new Button ...

  9. .NET invoke NetSuite Restlet

    Please indicate the source if you need to repost. Restlet allows programmers to use the http request ...

  10. UWP游戏防内存修改器的方法

    最近我一直在编写适用于Windows 10商店的游戏.这款游戏比较怕玩家用修改器改金钱,因为这种修改会导致某些内购失效并且损害公平性.于是我把自己见过的三种反修改器的方法给网友们介绍一下. 首先说明一 ...