Tridion 2013 sp1
I am trying to create an event system that will let me monitor modifications to a folder or SG. (changing the default page template. etc) While I can get the pre-save and post-save state easy enough, trying to pass information from the initiate
phase to the transaction committed
phase of the event does not work. I see that Niolai wrote. "Note, you cannot pass ContextVariables between events handled by the CM service, e.g. Save events, and Publisher service, e.g. Publish events. – Nickoli Roussakov Oct 26 '13 at 13:58"
Does anyone know if this was for 2011 or 2013sp1 or both. And if so, how did you solve this issue of reporting the change of properties in a structure group?
UPDATE: here is a sample of the code. When this is loaded the event doesn't fire and create the last log to show the before and after, so that I can then compare.
private void preOrganizationalItemSaveAction(OrganizationalItem subject, SaveEventArgs args, EventPhases phase)
{
if (!GetType().Name.Equals("StructureGroup"))
{
StructureGroup subjs = subject as StructureGroup;
string logDate = DateTime.Now.ToString("T");
string fileName = String.Format(@"{0}\{1}.{2}.{3}", tmplogFilePath, orgItemChangeLogName.ToLower().Replace(" ", "_"), DateTime.Now.ToString("yyyy-MM-dd"), "txt");
args.ContextVariables.Add("Initiated" , subjs.DefaultPageTemplate.Id );
TextWriter tw = new StreamWriter(fileName, true);
tw.WriteLine(String.Format("Time: {0} | what: {1}" , logDate, subjs.DefaultPageTemplate.Id ));
tw.Close();
}
}
private void OrganizationalItemSaveAction(OrganizationalItem subject, SaveEventArgs args, EventPhases phase)
{
//check if structure group
if (!GetType().Name.Equals("StructureGroup"))
{
StructureGroup subjs = subject as StructureGroup;
// Log every modification to a Folder or Structure Group with date, time, action, item, and user
string logDate = DateTime.Now.ToString("T");
string fileName = String.Format(@"{0}\{1}.{2}.{3}", logFilePath, orgItemChangeLogName.ToLower().Replace(" ", "_"), DateTime.Now.ToString("yyyy-MM-dd"), "txt");
TextWriter tw = new StreamWriter(fileName, true);
tw.WriteLine(String.Format("{0} | changed from {1} to {2}", logDate, args.ContextVariables["Initiated"].ToString(), subjs.DefaultPageTemplate.Id ));
tw.Close();
}
}
here is the constructor
namespace Tridion2011EventSystem
{
[TcmExtension("Tridion2011EventSystem")]
public class Tridion2011EventSystem : EventBase
{
private const string logFilePath = @"D:\APPS\Tridion\log";
private const string tmplogFilePath = @"D:\APPS\Tridion\log\tmp";
// Call the subscribe method to fire all events
public Tridion2011EventSystem()
{
Subscribe();
}
public void Subscribe()
{
EventSubscription preOrganizationalItem = EventSystem.SubscribeAsync<OrganizationalItem, SaveEventArgs>(preOrganizationalItemSaveAction, EventPhases.Initiated);
EventSubscription saveOrganizationalItem = EventSystem.SubscribeAsync<OrganizationalItem, SaveEventArgs>(OrganizationalItemSaveAction, EventPhases.TransactionCommitted);
this.Subscriptions.Add(preOrganizationalItem);
this.Subscriptions.Add(saveOrganizationalItem);
}