How can I use the engine object in my console application

"How can I use the engine in my console application"

I should not use the ITemplate and Transform-Method interface.

I am using Tridion 2011

Can anyone suggest me.

+3
source share
2 answers

You can not. The class Engineis part of TOM.NET and that the API is explicitly reserved for use in:

  • Pattern Lock
  • Event handlers

For all other cases (for example, console applications) you should use Core Service.

There are already many good questions (and articles on other sites):

, + , , ( ), .

+8

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

, .

+6

All Articles