Using SDL Tridion 2011 Core Service to Create Components Programmatically

I have seen some questions / answers related to this topic here, however still I do not get the offers I want. So I am posting my question here again, and I would be grateful for your valuable time and answers.

I would like to create the “Component, page, SG, Publish, Folders” programmatically in the SDL Tridion Content Manager, and later I would like to add programmatically created components on the page and attach CT, PT to this page, and finally I would like to publish the page programmatically.

I did all these actions in SDL Tridion 2009 using the TOM API (Interop DLL), and I tried these actions in SDL Tridion 2011 using the TOM.Net API. It did not work, and later I found out that the TOM.Net API will not support these types of work, and this is especially for Templates and Event System. And finally, I found out that I need to go to Core services to do such things.

My questions:

  • When I create a console application to create a component programmatically using the main service, which DLLs should I add as a reference?
  • I used to create exe and worked on the TCM server, exe created all the materials, can I use the same approach using the main services? Will this work?
  • BC is still available or has Core Service replaced BC? (BC-Business Connector)
  • - Component/Page ( ).
+5
3

engine

. , Core Service .

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));

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());
    }
}

:

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();
        } 
    }
}

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());
}

, . , Component Builder, 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;
}

, .

+1
  • Tridion.ContentManager.CoreService.Client.dll. Tridion.Common.dll, , TcmUri, .
  • . , , Tridion Content Manager .
  • - - , .
  • :

SDL Tridion 2011

SDL Tridion 2011, ?

.NET.

, , , , .

+6

:

  • You need to go to Tridion.ContentManager.CoreService.Client and add some things to app.config. Described here

  • It will work from the CM server, as well as from any other computer, if it can access the CoreService

  • CoreService is a replacement for BC. BC is out of date and will be soon soon
  • You will get all the basic information from here .

That should be enough to start. If you have any specific problems, send them as separate questions.

+4
source

All Articles