我在这里看到了与此主题相关的一些问题/答案,但是我仍然没有得到我想要的建议.所以我在这里再次发布我的问题,我将感谢你宝贵的时间和答案.
我想通过SDL Tridion内容管理器中的编程方式创建"组件,页面,SG,出版物,文件夹",稍后,我想在页面中添加以编程方式创建的组件并为该页面附加CT,PT,最后将喜欢以编程方式发布页面.
我使用TOM API(Interop DLL)在SDL Tridion 2009中完成了所有这些活动,并且我使用TOM.Net API在SDL Tridion 2011中尝试了这些活动.它不起作用,后来我才知道,TOM.Net API不支持这些类型的工作,它特别适用于模板和事件系统.最后我才知道我必须去核心服务来做这些事情.
我的问题:
TcmUri,但不需要它.在SDL Tridion 2011中,如何使用核心服务处理项目上的元数据?
以及从.NET连接到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));
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)
希望这能让你开始。
| 归档时间: |
|
| 查看次数: |
3681 次 |
| 最近记录: |