这几天在玩儿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

最新文章

  1. 研华外触发实验PCI1714板卡安装事项
  2. ListView 完全优化 + 多种listitem布局处理
  3. 查询自己电脑的IP
  4. 使用正则表达式获取Sql查询语句各项(表名、字段、条件、排序)
  5. JAVA中通过代码操作PC内容进行功能的实现
  6. EL表达式隐含对象
  7. Python 基础篇:介绍
  8. 『重构--改善既有代码的设计』读书笔记----Replace Method with Method Object
  9. MD5 32位加密算法源码(测试通过)(系转载 飞扬天下)
  10. Echarts自动刷新数据
  11. JavaScript 中的FileReader对象(实现上传图片预览)
  12. 开源网盘云存储 Seafile
  13. 使用jQuery重置(reset)表单的方法
  14. 【Object类、常用API】
  15. Ansible playbook 批量修改服务器密码 先普通后root用户
  16. java 判断字符串什么编码类型
  17. Android的Fragment的第一种声明方式
  18. Python中创建守护进程
  19. 定时器 setInterval(‘function()’, 2000)
  20. 18-[模块]-shutil

热门文章

  1. 精致3D图片切换效果,最适合企业产品展示
  2. form上传文件以及跨域异步上传
  3. maven中使用junit老是找不到包
  4. linux专题三之如何悄悄破解root密码(以redhat7.2x64为例)
  5. 【Swift学习】Swift编程之旅---集合类型之Sets(七)
  6. PHP--冒泡、选择、插入排序法
  7. 暴力枚举 + 24点 --- hnu : Cracking the Safe
  8. 激活当前视图菜单高亮呈现 V2.0
  9. Entity Framework 实体框架的形成之旅--界面操作的几个典型的处理(8)
  10. 参数类型params