Last active
December 15, 2015 06:09
-
-
Save rsleggett/5214230 to your computer and use it in GitHub Desktop.
Example SDLTridion Workflow Activity
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
//This gives us StreamReader | |
using System.IO; | |
//This gives us the Data Contract info from the client | |
using Tridion.ContentManager.CoreService.Client; | |
//This gives us the core service methods and properties | |
// specific to workflow: must reference Tridion.ContentManager.CoreService.Workflow from | |
// bin/client directory | |
using Tridion.ContentManager.CoreService.Workflow; | |
//Required for logging! | |
using Tridion.Logging; | |
using System.Xml.Linq; | |
namespace TridionWorkflowAssembly | |
{ | |
public class MyCustomExternalActivity : ExternalActivity | |
{ | |
protected override void Execute() | |
{ | |
ActivityFinishData finishData = new ActivityFinishData() | |
{ | |
Message = String.Format("My custom External Activity finished at: {0}", DateTime.Now.ToShortDateString()) | |
}; | |
CoreServiceClient.FinishActivity(ActivityInstance.Id, finishData, new ReadOptions()); | |
} | |
} | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
//This gives us StreamReader | |
using System.IO; | |
//This gives us the Data Contract info from the client | |
using Tridion.ContentManager.CoreService.Client; | |
//This gives us the core service methods and properties | |
// specific to workflow: must reference Tridion.ContentManager.CoreService.Workflow from | |
// bin/client directory | |
using Tridion.ContentManager.CoreService.Workflow; | |
//Required for logging! | |
using Tridion.Logging; | |
using System.Xml.Linq; | |
namespace TridionWorkflowAssembly | |
{ | |
public class PublishStagingActivity : 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; | |
ActivityInstanceData activityInstance = ActivityInstance; | |
IList<String> itemsToPublishList = new List<String>(); | |
//Staging publication target URI | |
String[] targets = new[] { "tcm:0-1-65537" }; | |
foreach (WorkItemData wid in activityInstance.WorkItems) | |
{ | |
int value = Convert.ToInt32(Enum.Parse(typeof(ItemType), "VirtualFolder")); | |
//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); | |
//base.Execute() calls "finish activity" | |
// which is still necessary | |
//base.Execute(); | |
} | |
} | |
} |
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
AssemblyTbbId = "/webdav/200%20Website/Building%20Blocks/Path/To/Your/Assembly.tbbasm" | |
Type = "YourNameSpace.YourClassName" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment