我在程序中检索termset的条款时遇到问题(用VB编写)。术语集约有300个术语,并且所有术语都有大约10到70个子项。我想在表单中集成所有术语,因此我使用了“Treeview”。
我对这些术语的检索编码如下:1。创建一个新的clientContext 2.加载TaxonomySession,然后加载TermStore,然后加载TermGroup,最后加载TermSet。 termset的负载如下所示:
clientContext.Load(tSet, Function(a As TermSet) a.Terms)
clientContext.Load(tSet, Function(a As TermSet) a.Name)
之后是“ExecuteQuery()”然后我有以下内容:
Dim tvroot As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode(tSet.Name)
orgatree.TopNode = tvroot 'orgatree is the treeview
For Each tterm As Term In tSet.Terms
clientContext.Load(tterm, Function(w As Term) w.Name)
clientContext.Load(tterm, Function(w As Term) w.Id)
clientContext.Load(tterm, Function(w As Term) w.TermsCount)
Next
clientContext.ExecuteQuery()
Dim tvroot As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode(tSet.Name)
orgatree.TopNode = tvroot
For Each tterm As Term In tSet.Terms
Dim tvanode As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode(tterm.Name)
tvanode.ToolTipText = tterm.Id.ToString
tvroot.Nodes.Add(tvanode)
If tterm.TermsCount <> 0 Then
treefilling(tvanode, clientContext, tterm) 'a method which is shown in an extra snippet below this one
End If
Next
方法“treefilling”:
Public Function treefilling(parent As System.Windows.Forms.TreeNode, clientContext As ClientContext, term As Term)
Dim tvnode As System.Windows.Forms.TreeNode
clientContext.Load(term, Function(w As Term) w.Terms)
clientContext.ExecuteQuery()
For Each tterm As Term In term.Terms
clientContext.Load(tterm, Function(w As Term) w.Name)
clientContext.Load(tterm, Function(w As Term) w.Id)
clientContext.Load(tterm, Function(w As Term) w.TermsCount)
Next
clientContext.ExecuteQuery()
For Each tterm As Term In term.Terms
tvnode = New System.Windows.Forms.TreeNode(tterm.Name)
tvnode.ToolTipText = tterm.Id.ToString
parent.Nodes.Add(tvnode)
' clientContext.ExecuteQuery()
If tterm.TermsCount <> 0 Then
treefilling(tvnode, clientContext, tterm)
End If
Next
End Function
现在问题
这段代码不是很快。加载所有数据最多需要3到4分钟。我已经尝试过优化它。早期版本有更多不必要的“executeQuery()”行。但该计划仍在放缓。 是否有更快的方法来加载termset的所有数据并将其集成到表单中(例如在树视图中)?
答案 0 :(得分:0)
是否以表单或任何不相关的方式加载数据。与SharePoint 2013 CSOM获取条款的过程相关。请记住,CSOM是在客户端和SharePoint 2013服务器之间来回发送Xml请求的包装器。
因此,使用多个线程同时加载多个术语/术语集。您需要编写线程安全的代码,以检索多个线程通过客户端对象模型同时查询托管元数据服务的位置,小心将请求总数限制为某个合理的数量(例如,每次8个请求)不要使服务器过载。
访问服务器的多个线程可以工作,因为这是一个READ操作。