需要有关使用Core Service发布和完成活动的帮助

时间:2012-07-09 08:16:45

标签: tridion tridion-2011

我正在尝试使用核心服务创建一个发布和完成工作流活动的方法。我得到编译错误。以下是我的代码。任何人都可以纠正我吗?这很紧急。

public void PublishComponent(string WorkItemId)
    {
        var client = new SessionAwareCoreServiceClient();
        var readoptions = new ReadOptions();            
        ComponentData component = (ComponentData)client.Read(new TcmUri(WorkItemId), readoptions) as ComponentData;
        List<IdentifiableObjectData> ItemToPublish = new List<IdentifiableObjectData>();            
        ItemToPublish.Add(component);
        PublishInstructionData instruction = new PublishInstructionData();
        PublicationTargetData pubtarget = (PublicationTargetData)client.Read(new TcmUri("tcm: 0 - 21 - 65537"), readoptions) as PublicationTargetData;
        List<PublicationTargetData> target = new List<PublicationTargetData>();
        target.Add(pubtarget);            
        client.Publish(ItemToPublish, instruction, target, PublishPriority.Normal, readoptions);


        WorkItemData workitem = new WorkItemData();
        workitem.Id = new TcmUri(WorkItemId);            
        ActivityInstanceData currentactivity = new ActivityInstanceData();
        ActivityFinishData finish = new ActivityFinishData();
        finish.Message="Published";
        client.FinishActivity(currentactivity, finish, readoptions);
}

1 个答案:

答案 0 :(得分:5)

有几个问题,但主要是没有TcmUri类,就像在TOM.NET中一样,它是CoreService中的字符串。和Publish方法一样,它将字符串数组作为输入,而不是项目数组,就像在TOM.NET中一样

        var client = new SessionAwareCoreServiceClient();
        var readoptions = new ReadOptions();
        ComponentData component = (ComponentData)client.Read(WorkItemId, readoptions);
        List<string> ItemToPublish = new List<string>();
        ItemToPublish.Add(component.Id);
        PublishInstructionData instruction = new PublishInstructionData();
        PublicationTargetData pubtarget = (PublicationTargetData)client.Read("tcm:0-21-65537", readoptions);
        List<string> target = new List<string>();
        target.Add(pubtarget.Id);
        client.Publish(ItemToPublish.ToArray(), instruction, target.ToArray(), PublishPriority.Normal, readoptions);


        WorkItemData workitem = new WorkItemData();
        workitem.Id = WorkItemId;
        ActivityInstanceData currentactivity = new ActivityInstanceData();
        ActivityFinishData finish = new ActivityFinishData();
        finish.Message = "Published";
        client.FinishActivity(currentactivity.Id, finish, readoptions);