----Event Code SDL Tridion 2011 SP1----
I have written event coding for page publishing and it is working fine for single page, one by one. So, this means when i select a page from CMS, right click the page and publish that page, event code works fine. My sample method is as below:
public void OnPagePublishPost(Tridion.ContentManager.CommunicationManagement.Page Page, PublishEventArgs PublishResult, EventPhases phase)
{
EventHelper.WriteEventToHTMLLog("S-OnPagePublishPost");
TcmUri schemaId = null;
IList<Tridion.ContentManager.CommunicationManagement.ComponentPresentation> mComponentPresentations = Page.ComponentPresentations;
try
{
EventHelper.WriteEventToHTMLLog("S-ComponentPresentationCount-" + mComponentPresentations.Count.ToString());
if (mComponentPresentations.Count > 0)
{
// Holds the first Component Presentation, Component's schema Id
schemaId = mComponentPresentations[0].Component.Schema.Id;
EventHelper.WriteEventToHTMLLog("schemaId -" + schemaId.ToString()); }
foreach (PublishingTarget publishingTarget in PublishResult.Targets)
{
String pubTargetTitle = publishingTarget.Title;
TcmUri pubTargetId = publishingTarget.Id;
MainClass cs;
EventHelper.WriteEventToHTMLLog("Schema ID: " + Page.ComponentPresentations[0].Component.Schema.Id);
try
{
cs = new MainClass();
if (Convert.ToString(Page.ComponentPresentations[0].Component.Schema.Id).Contains(CASESTUDY_SCHEMA))
{
if (PublishResult.PublishInstruction.ResolveInstruction.Purpose == Tridion.ContentManager.Publishing.ResolvePurpose.Publish)
{
//Method which publishes the page is called
cs.ProcessCaseStudyPageForPublish(Page, pubTargetId);
}
else if (PublishResult.PublishInstruction.ResolveInstruction.Purpose == Tridion.ContentManager.Publishing.ResolvePurpose.UnPublish)
{
cs.ProcessCaseStudyPageForUnPublish(Page, pubTargetId);
}
}
}
//I have not copied full code. Its just a sample. This method publishes a page with an extension .xml
public void ProcessCaseStudyPageForPublish(Page page, TcmUri pubTargUri)
{
Component compSource = null;
Page pageDestination = null;
Component componentDestinaton = null;
StringBuilder builder = new StringBuilder();
XmlDocument document = new XmlDocument();
string prefixUrl = string.Empty;
Publication publication = (Publication)page.ContextRepository;
EventHelper.WriteEventToHTMLLog("Publication-" + (publication != null ? "Not Null" : "Null"));
//And the code to publish the .xml page starts here and publishes the page successfully
}
The issue is when i select multiple page and right click and say publish, i get transaction timeout issue and the event code fails. Is there anything which can be added to event code to process mutiple file at the same time or is there any configuration changes which i can do.
OnPagePublishPost
method is not static, usually the event handler methods can be made static?