Created
August 15, 2019 13:47
-
-
Save justsayantan/f7b140b91b28d872f7500766384dc1ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//=======================================// | |
// ------- Author : Sayantan Basu ------- | |
// ------- Date : 24-03-2015 ------- | |
//=======================================// | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.IO; | |
using System.Text; | |
using Tridion.ContentManager.CoreService.Client; | |
using Tridion.ContentManager.CoreService.Workflow; | |
namespace TridionPublishWorkflow | |
{ | |
class TridionPublishWorkflow : ExternalActivity | |
{ | |
protected override void Execute() | |
{ | |
//PublishInstructionData (interface: IExtensibleDataObject) requires | |
// reference to System.Runtime.Serialization | |
PublishInstructionData publishInstruction = new PublishInstructionData(); | |
publishInstruction.ResolveInstruction = new ResolveInstructionData(); | |
publishInstruction.RenderInstruction = new RenderInstructionData(); | |
//Needed for publishing workflow revision/version | |
publishInstruction.ResolveInstruction.IncludeWorkflow = true; | |
publishInstruction.ResolveInstruction.IncludeChildPublications = true; | |
ActivityInstanceData activityInstance = ActivityInstance; | |
IList<String> itemsToPublishList = new List<String>(); | |
//I have hard coded the publishing target tcm URI here | |
//this is used upto Tridion 2013 SP1 | |
//String[] targets = new[] { "tcm:0-21-65537" }; | |
//this is used for Tridion Web 8 onward | |
string[] targets = new[] {"live"}; | |
foreach (WorkItemData wid in activityInstance.WorkItems) | |
{ | |
int value = Convert.ToInt32(Enum.Parse(typeof(ItemType), "Page")); | |
//Brute-force bundle identification | |
if (wid.Subject.IdRef.EndsWith(value.ToString())) | |
{ | |
itemsToPublishList.Add(wid.Subject.IdRef); | |
} | |
} | |
//PublishTransactionData requires reference to System.ServiceModel | |
PublishTransactionData[] publishTransactions = CoreServiceClient.Publish(itemsToPublishList.ToArray<String>(), publishInstruction, targets, PublishPriority.Normal, null); | |
//Store the publish transaction id so that we can undo if needed! | |
ProcessInstance.Variables.Add("PublishTransaction", publishTransactions[0].Id); | |
CoreServiceClient.FinishActivity(ActivityInstance.Id, new ActivityFinishData { Message = "Publish to Staging Queued: Finished Activity" }, null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment