Skip to content

Instantly share code, notes, and snippets.

@rsleggett
Last active December 15, 2015 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsleggett/5214230 to your computer and use it in GitHub Desktop.
Save rsleggett/5214230 to your computer and use it in GitHub Desktop.
Example SDLTridion Workflow Activity
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());
}
}
}
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();
}
}
}
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