3
A
回答
8
你不能。該Engine
類是TOM.NET的一部分,API明確保留用於:
- 模板積木
- 事件處理程序
對於所有其他情況(如控制檯應用程序)你應該使用核心服務。
有很多很好的問題(和文章在其他網站)已經:
- https://stackoverflow.com/search?q=%5Btridion%5D+core+service
- http://www.google.com/#q=tridion+core+service
如果你被沿途停留,向我們展示了相關代碼+你擁有的配置和你得到的錯誤信息(或者你陷入了哪個步驟),我們會盡力幫助。
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的引用添加到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());
}
要構建一個數據對象例如一個組件可以實現一個實現了創建方法,做一個組件生成器類爲你好:
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
+1通過空合併運算符和傳遞賦值進行延遲加載。要偷那個。 – 2012-07-16 13:05:48
相關問題
- 1. 在控制檯應用程序中使用Razor引擎
- 2. e.printStackTrace();未在應用程序引擎控制檯中打印
- 3. 如何從控制檯應用程序訪問應用程序對象?
- 4. 如何在控制檯應用程序
- 5. 如何在控制檯應用程序
- 6. 如何從控制檯應用程序實例化SPWeb對象?
- 7. 控制檯應用程序引用的C#版本控制
- 8. 在控制檯應用程序的對象中保存值C#
- 9. 如何從谷歌應用程序引擎訪問rails控制檯?
- 10. 如何讓我的虛擬應用程序使用引擎的模板引擎?
- 11. 如何從控制檯應用程序
- 12. 使用Microsoft.AspNet.Mvc控制檯應用程序
- 13. 在C++ CLR控制檯應用程序中集成COM對象
- 14. 如何獲得控制檯的進程id在C#控制檯應用程序
- 15. 如何在控制檯應用程序中使用vcl組件?
- 16. 如何在C#控制檯應用程序中使用IsolatedStorage
- 17. 如何在控制檯應用程序中使用System :: Net :: Mail
- 18. 如何在Qt控制檯應用程序中使用GetNativeSystemInfo
- 19. 如何在Winform應用程序中使用控制檯?
- 20. 如何在控制檯應用程序中使用WCF
- 21. 如何在控制檯應用程序中使用TIdUDPServer?
- 22. 如何在Yii控制檯應用程序中使用翻譯?
- 23. 如何在控制檯應用程序中使用Razor View Engine?
- 24. 如何在c#控制檯應用程序中使用參數?
- 25. 如何在控制檯應用程序中使用QGraphicsScene?
- 26. 如何在控制檯應用程序中使用Firedac?
- 27. 如何使用AxWebBrowser在控制檯應用程序
- 28. 如何在控制檯應用程序中使用System.Web.Caching.Cache?
- 29. 如何使用Devise等應用程序佈局製作引擎?
- 30. 如何減少控制檯應用程序的用戶對象和句柄
你能解釋一下你的用例和你在做什麼?一個友好的建議,你提供的信息越多,你就會收到更好的答案。對於你的用例,可能是引擎不是正確的設計方法,我不知道,除非你解釋你正在努力實現什麼,你已經做了什麼。 – 2012-07-13 15:43:46