1

----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.

1
  • Any specific reason why your OnPagePublishPost method is not static, usually the event handler methods can be made static? Commented Jun 2, 2014 at 7:59

3 Answers 3

3

If you are getting a transaction timeout, then most likely the amount of processing you are attempting to do within the transaction takes longer than the timeout value. There is a "Timeout settings" section in the management snap-in, although I'm not sure which of these is relevant to your case. (How long does it take before it fails?)

So you can increase the timeout, either in Tridion or perhaps in the database. (Which database are you using?). If it is the case that publishing multiple pages simply causes the overall time to add up to more than the timeout, this may be as good as it gets.

It's difficult to be clear without more of an idea about what you are doing. For example, you don't specify which event phase you are using and why you have chosen it. If your own code is adding a lot of processing to the transaction, maybe you could consider using the TransactionCommitted phase (I imagine that code executed in this phase is not in the transaction scope), but of course, you'd have to be sure that this would give you the desired semantics.

I would also suggest that you profile your code for performance. Maybe it could be rewritten to perform better, and thereby stay within the timeout limits. Also, check your database performance, and that it's being maintained correctly, for example with regard to updating optimizer statistics, and of course, backups.

Of course, any approach involving making the timeout longer or the execution shorter will have limits. How many pages at once does it take to cause the problem, and how many would you regard as reasonable?

3
  • If I understand correctly, above event will be triggered separately for each page that is published even if multiple pages are selected in a single go and published. Hence I think number of pages is not actually the issue. Commented Jun 2, 2014 at 11:53
  • @Dominic- The event is fired for each page and for your information i am generating a large xml file with each node as component details. I added enough logging and which is why the code was failing because i guess the log file i wrote was not accessible by other process. To fix it , i removed the inf logging and just wrote the error logging and now when i publish 30 pages , the event code does not fail. Commented Jun 2, 2014 at 14:39
  • @premkumar - You are correct, the number of pages is not an issue. Commented Jun 2, 2014 at 14:40
2

The issue got fixed. I removed the logging which i did on each line of the code to check if my code is working properly and in some cases i was printing huge xml information in the log file and which might be causing issue.

0

In Case you are using core services for publishing you can try using net tcp binding which is much more faster than other bindings.

1
  • 1
    Since they are inside an event handler, they shouldn't be using the Core Service at all as they have access to the TOM.NET API. Commented Jun 2, 2014 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.