using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
/// <summary>
/// 知识库文章
/// </summary>
public class KbArticleHelper
{
public static readonly string entityName = "kbarticle";
public Guid kbArticleId = Guid.Empty;
public IOrganizationService service;
/// <summary>
/// 创建知识库文章
/// </summary>
public void Create()
{
Entity en = new Entity() { LogicalName = entityName };
en["title"] = "知识库文章測试";
kbArticleId = service.Create(en);
}
/// <summary>
/// 检索指定的产品的前十篇知识库文章
/// </summary>
/// <param name="productId">产品id</param>
public void RetrieveByTopIncidentProductKbArticle(Guid productId)
{
RetrieveByTopIncidentProductKbArticleRequest request = new RetrieveByTopIncidentProductKbArticleRequest();
request.ProductId = productId;
RetrieveByTopIncidentProductKbArticleResponse response =
(RetrieveByTopIncidentProductKbArticleResponse)service.Execute(request);
EntityCollection entityCollection = response.EntityCollection;
}
/// <summary>
/// 检索指定的主题的前十篇知识库文章
/// </summary>
/// <param name="subjectId">主题id</param>
public void RetrieveByTopIncidentSubjectKbArticle(Guid subjectId)
{
RetrieveByTopIncidentSubjectKbArticleRequest request = new RetrieveByTopIncidentSubjectKbArticleRequest();
request.SubjectId = subjectId;
RetrieveByTopIncidentSubjectKbArticleResponse response =
(RetrieveByTopIncidentSubjectKbArticleResponse)service.Execute(request);
EntityCollection entityCollection = response.EntityCollection;
}
/// <summary>
/// 查找正文中包括指定文本的全部文档索引
/// </summary>
/// <param name="query">查询条件</param>
/// <param name="text">指定文本</param>
/// <param name="subjectId">主题id</param>
public void SearchByBodyKbArticle(QueryBase query,string text,Guid subjectId)
{
SearchByBodyKbArticleRequest request = new SearchByBodyKbArticleRequest();
request.QueryExpression = query;
request.UseInflection = true;
request.SearchText = text;
request.SubjectId = subjectId;
SearchByBodyKbArticleResponse response = (SearchByBodyKbArticleResponse)service.Execute(request);
EntityCollection entityCollection = response.EntityCollection;
}
/// <summary>
/// 查找包括指定keyword的全部文档索引
/// </summary>
/// <param name="query">查询条件</param>
/// <param name="text">指定文本</param>
/// <param name="subjectId">主题id</param>
public void SearchByKeywordsKbArticle(QueryBase query, string text, Guid subjectId)
{
SearchByKeywordsKbArticleRequest request = new SearchByKeywordsKbArticleRequest();
request.QueryExpression = query;
request.UseInflection = true;
request.SearchText = text;
request.SubjectId = subjectId;
SearchByKeywordsKbArticleResponse response = (SearchByKeywordsKbArticleResponse)service.Execute(request);
EntityCollection entityCollection = response.EntityCollection;
}
/// <summary>
/// 查找标题中包括指定文本的全部文档索引
/// </summary>
/// <param name="query">查询条件</param>
/// <param name="text">指定文本</param>
/// <param name="subjectId">主题id</param>
public void SearchByTitleKbArticle(QueryBase query, string text, Guid subjectId)
{
SearchByTitleKbArticleRequest request = new SearchByTitleKbArticleRequest();
request.QueryExpression = query;
request.UseInflection = true;
request.SearchText = text;
request.SubjectId = subjectId;
SearchByTitleKbArticleResponse response = (SearchByTitleKbArticleResponse)service.Execute(request);
EntityCollection entityCollection = response.EntityCollection;
}
/// <summary>
/// 删除知识库文章
/// </summary>
public void Delete()
{
service.Delete(entityName, kbArticleId);
}
}