2016-10-18 33 views
1

我試圖編寫一些C#代碼來利用VersionOne SDK來創建缺陷資產。我詢問我們的系統,並已經確定了所需的屬性:如何:使用VersionOne SDK創建資產

Defect derives from PrimaryWorkitem

  • Description : LongText
  • Name : Text
  • Parent : Relation to Theme — reciprocal of Children
  • Priority : Relation to WorkitemPriority — reciprocal of PrimaryWorkitems
  • Scope : Relation to Scope — reciprocal of Workitems
  • Source : Relation to StorySource — reciprocal of PrimaryWorkitems
  • Status : Relation to StoryStatus — reciprocal of PrimaryWorkitems
  • Team : Relation to Team — reciprocal of Workitems

一些值是顯而易見的,而另一些有點抽象。例如,我不確定要爲「父」屬性或「範圍」指定什麼。使用SDK創建資產的文檔相當稀少。我似乎無法找到使用SDK的任何代碼示例。此刻,我的代碼返回一個例外:

The remote server returned an error: (400) Bad Request Violation'Required'AttributeDefinition'Parent'Defect

而且,這裏是我使用的時刻代碼:

static void AddV1Record(List<V1WerRecord> records) 
     { 
      V1Connector connector = V1Connector 
       .WithInstanceUrl(VersionOneURL) 
       .WithUserAgentHeader("VersionOneUpdate", "1.0") 
       .WithUsernameAndPassword(VersionOneId, VersionOnePwd) 
       .Build(); 

      IServices services = new Services(connector); 

      Oid projectId = services.GetOid("Scope:0"); 
      IAssetType storyType = services.Meta.GetAssetType("Defect"); 
      Asset newDefect = services.New(storyType, projectId); 
      IAttributeDefinition descAttribute = storyType.GetAttributeDefinition("Description"); 
      newDefect.SetAttributeValue(descAttribute, "My New Defect"); 
      IAttributeDefinition nameAttribute = storyType.GetAttributeDefinition("Name"); 
      newDefect.SetAttributeValue(nameAttribute, "My Name"); 
      services.Save(newDefect); 

我理解錯誤是由指定所有所致所需的屬性。我不知道爲什麼要指定一些屬性:父,範圍等

有誰知道更好的文檔解釋使用SDK來創建資產?是否有任何好的SDK示例/示例代碼可用?

回答

1

創建主要工作項目(如缺陷或故事)時,必須在特定項目的上下文中創建它。該項目在系統級被稱爲範圍。缺陷上的父屬性是所謂的主題。默認情況下,這不是必需的屬性。您組織中的某個人根據需要宣佈了此特定項目。

關係主題意味着父屬性接受對特定主題的參考。您將設置父屬性的東西,格式類似這樣的

Theme:1036

這就是所謂的OID。它只是一個系統引用的稱爲關係的表格式結構,它保存着系統中所有不同的主題。如果你查詢你的數據API,你可以得到所有這些主題的列表。查詢看起來是這樣的

yourVersionOneURL/rest-1.v1/Data/Theme?sel=ID,Name 

,你會得到一個XML房源在瀏覽器中顯示的這些

enter image description here

所以N多,如果我想一個主題叫襯衫搭配我的缺陷聯繫起來,我會將Parent屬性設置爲Theme:1036。

您可以添加到您的代碼

IAttributeDefinition parentAttribute = newDefect.GetAttributeDefinition("Parent"); 
newDefect.SetAttributeValue(parentAttribute,」Theme:1036」); 

同樣的過程也適用於範圍。有一個替代查詢。您可以進入VersionOne界面,找到您需要的項目名稱(或其他資產),將鼠標懸停在項目名稱(Scope)上並在瀏覽器底部的狀態欄中,您會看到一些指示與該項目名稱關聯的Scope OID。

我會與您的VersionOne管理員聊天,並得知爲什麼您的組織需要所需的主題

+0

感謝您的幫助。這對於如何使用SDK構建代碼確實闡明瞭很多。你提供的查詢語法是我需要的中斷。 – rrirower

相關問題