2012-07-13 3 views
3

"내 콘솔 응용 프로그램에서 엔진을 사용하는 방법"내 콘솔 응용 프로그램에서 엔진 개체를 사용할 수있는 방법

ITemplate 인터페이스 및 변환 방법을 사용하면 안됩니다.

나는

사람이 저를 제안 해주십시오 수 Tridion 2011을 사용하고 있습니다.

+3

유스 케이스가 무엇이고 현재 무엇을하고 있는지 설명해 주시겠습니까? 친절한 조언, 당신이 제공하는 더 많은 정보를 당신이 받게 될 더 나은 답변에 질문하십시오. 귀하의 유스 케이스의 경우 엔진이 올바른 설계 방식이 아닐 수도 있습니다. 귀하가 달성하고자하는 것을 설명하고 이미 무엇을했는지 설명하지 않는 한 저는 모르겠습니다. –

답변

8

수 없습니다. Engine 클래스는 TOM.NET의 일부이며 그 API가 명시 적으로 사용하기 위해 예약되어 있습니다 :

  1. 템플릿 빌딩 블록
  2. 이벤트 처리기 (예 : 콘솔 응용 프로그램) 다른 모든 경우에 대한

핵심 서비스를 사용해야합니다. 이미

(다른 웹 사이트에 기사) 많은 좋은 질문이 있습니다 : 당신이 길을 따라 박히 경우

이 우리에게 관련 코드를 보여 + 구성 및 어떤 오류 메시지가 표시되는지 (또는 어떤 단계에서 멈추는 지) 어떤 오류 메시지가 나타나면 여기에서 도움을 요청할 것입니다.

6

콘솔 응용 프로그램에서 핵심 서비스를 사용해야합니다. 핵심 서비스를 사용하여 콘텐츠 관리자에서 항목을 검색하는 작은 예제를 작성했습니다.

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에 대한 참조를 추가합니다. 핵심 서비스 클라이언트 공급자의

코드 :

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

예 : 구성 요소는 당신이 당신을 위해 수행하는 만드는 방법을 구현하는 구성 요소 빌더 클래스를 구현할 수 있습니다

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

희망이 당신이 시작 가져옵니다.

+0

null-coalescing 연산자와 전 이적 할당을 통한 lazy-loading의 경우 +1. 그걸 훔칠거야. –