使用SDL Tridion 2011 Core Service以编程方式创建组件

use*_*019 5 tridion

我在这里看到了与此主题相关的一些问题/答案,但是我仍然没有得到我想要的建议.所以我在这里再次发布我的问题,我将感谢你宝贵的时间和答案.

我想通过SDL Tridion内容管理器中的编程方式创建"组件,页面,SG,出版物,文件夹",稍后,我想在页面中添加以编程方式创建的组件并为该页面附加CT,PT,最后将喜欢以编程方式发布页面.

我使用TOM API(Interop DLL)在SDL Tridion 2009中完成了所有这些活动,并且我使用TOM.Net API在SDL Tridion 2011中尝试了这些活动.它不起作用,后来我才知道,TOM.Net API不支持这些类型的工作,它特别适用于模板和事件系统.最后我才知道我必须去核心服务来做这些事情.

我的问题:

  1. 当我创建控制台应用程序以使用核心服务以编程方式创建组件时,我必须添加哪些DLL作为参考?
  2. 早些时候,我已经创建了exe并在TCM服务器上运行,exe创建了所有的东西,我可以使用相同的方法使用核心服务吗?它会起作用吗?
  3. BC仍然可用或核心服务取代BC吗?(BC-商务连接器)
  4. 任何人都可以发送一些代码片段来创建组件/页面(完整的类文件将有助于更好地理解)

Fra*_*len 6

  1. 您只需要引用Tridion.ContentManager.CoreService.Client.dll.您可能希望引用Tridion.Common.dll来访问一些有用的类,例如TcmUri,但不需要它.
  2. 您的客户端程序将与您指定的计算机上的核心服务进行显式连接.如果操作正确,您可以在与Tridion Content Manager相同的计算机上或在其他计算机上运行客户端.
  3. Business Connector仍然可用,但已被Core Service取代.
  4. 看看这些链接:

使用SDL Tridion 2011中的核心服务更新组件

在SDL Tridion 2011中,如何使用核心服务处理项目上的元数据?

以及从.NET连接到Core Service的主题的标准文档.

如果您需要更多关于代码的帮助,我建议您向我们展示您已编写的代码并解释哪些代码无效.


Arj*_*bbe 1

如何在我的控制台应用程序中使用引擎对象

您应该从控制台应用程序使用核心服务。我编写了一个使用核心服务在内容管理器中搜索项目的小示例。

Console.WriteLine("FullTextQuery:");

var fullTextQuery = Console.ReadLine();

if (String.IsNullOrWhiteSpace(fullTextQuery) || fullTextQuery.Equals(":q", StringComparison.OrdinalIgnoreCase))
{
    break;
}

Console.WriteLine("SearchIn IdRef:");

var searchInIdRef = Console.ReadLine();

var queryData = new SearchQueryData
                    {
                        FullTextQuery = fullTextQuery,
                        SearchIn = new LinkToIdentifiableObjectData
                                        {
                                            IdRef = searchInIdRef
                                        }
                    };

var results = coreServiceClient.GetSearchResults(queryData);
results.ToList().ForEach(result => Console.WriteLine("{0} ({1})", result.Title, result.Id));
Run Code Online (Sandbox Code Playgroud)

将 Tridion.ContentManager.CoreService.Client 的引用添加到您的 Visual Studio 项目中。

核心服务客户提供商代码:

public interface ICoreServiceProvider
{
    CoreServiceClient GetCoreServiceClient();
}

public class CoreServiceDefaultProvider : ICoreServiceProvider
{
    private CoreServiceClient _client;

    public CoreServiceClient GetCoreServiceClient()
    {
        return _client ?? (_client = new CoreServiceClient());
    }
}
Run Code Online (Sandbox Code Playgroud)

以及客户本身:

public class CoreServiceClient : IDisposable
{
    public SessionAwareCoreServiceClient ProxyClient;

    private const string DefaultEndpointName = "netTcp_2011";

    public CoreServiceClient(string endPointName)
    {
        if(string.IsNullOrWhiteSpace(endPointName))
        {
            throw new ArgumentNullException("endPointName", "EndPointName is not specified.");
        }

        ProxyClient = new SessionAwareCoreServiceClient(endPointName);
    }

    public CoreServiceClient() : this(DefaultEndpointName) { }

    public string GetApiVersionNumber()
    {
        return ProxyClient.GetApiVersion();
    }

    public IdentifiableObjectData[] GetSearchResults(SearchQueryData filter)
    {
        return ProxyClient.GetSearchResults(filter);
    }

    public IdentifiableObjectData Read(string id)
    {
        return ProxyClient.Read(id, new ReadOptions());
    }

    public ApplicationData ReadApplicationData(string subjectId, string applicationId)
    {
        return ProxyClient.ReadApplicationData(subjectId, applicationId);
    }

    public void Dispose()
    {
        if (ProxyClient.State == CommunicationState.Faulted)
        {
            ProxyClient.Abort();
        }
        else
        {
            ProxyClient.Close();
        } 
    }
}
Run Code Online (Sandbox Code Playgroud)

当你想通过核心服务执行CRUD操作时,你可以在客户端实现以下方法:

public IdentifiableObjectData CreateItem(IdentifiableObjectData data)
{
    data = ProxyClient.Create(data, new ReadOptions());
    return data;
}

public IdentifiableObjectData UpdateItem(IdentifiableObjectData data)
{
    data = ProxyClient.Update(data, new ReadOptions());
    return data;
}

public IdentifiableObjectData ReadItem(string id)
{
    return ProxyClient.Read(id, new ReadOptions());
}
Run Code Online (Sandbox Code Playgroud)

要构造例如组件的数据对象,您可以实现一个组件生成器类,该类实现一个为您执行此操作的 create 方法:

public ComponentData Create(string folderUri, string title, string content)
{
    var data = new ComponentData()
                    {
                        Id = "tcm:0-0-0",
                        Title = title,
                        Content = content,
                        LocationInfo = new LocationInfo()
                    };

    data.LocationInfo.OrganizationalItem = new LinkToOrganizationalItemData
    {
        IdRef = folderUri
    };

using (CoreServiceClient client = provider.GetCoreServiceClient())
{
    data = (ComponentData)client.CreateItem(data);
}

    return data;
}
Run Code Online (Sandbox Code Playgroud)

希望这能让你开始。