3

I am migrating Tridion version 2009 to 2011. My existing event code of the EventSystem in Tridion 2009 for event named OnPagePublishPost is like below.

public void OnPagePublishPost(Tridion.ContentManager.Interop.TDS.Page page, IXMLDOMDocument2 publishResult, EventPhases phase) 
{
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(publishResult.xml);

    XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);
    ns.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0");
    ns.AddNamespace("xlink", "http://www.w3.org/1999/xlink");
    string publishOrUnpublish;
    publishOrUnpublish = doc.DocumentElement.SelectSingleNode("/tcm:PublishResponse/tcm:PublisherRequest/tcm:Instruction/@Title", ns).Value;
    EventHelper.WriteEventToHTMLLog("publishOrUnpublish: " + publishOrUnpublish);
    String pubTargUri = doc.DocumentElement.SelectSingleNode("/tcm:PublishResponse/tcm:PublisherRequest/tcm:PublicationTarget/@xlink:href", ns).Value;
    EventHelper.WriteEventToHTMLLog("pubTargUri: " + pubTargUri);

    string schemaID = Convert.ToString(page.ComponentPresentations[1].Component.Schema.ID;
}

Now when I subscribe this event using below code, shows me the error.

EventSystem.Subscribe<Tridion.ContentManager.CommunicationManagement.Page,
                      PublishEventArgs>(OnPagePublishPost, EventPhases.Processed);

Error Message

The best overloaded method match for 'Tridion.ContentManager.Extensibility.EventSystem.Subscribe<Tridion.ContentManager.CommunicationManagement.Page,Tridion.ContentManager.Extensibility.Events.PublishEventArgs>(Tridion.ContentManager.Extensibility.TcmEventHandler<Tridion.ContentManager.CommunicationManagement.Page,Tridion.ContentManager.Extensibility.Events.PublishEventArgs>, Tridion.ContentManager.Extensibility.EventPhases)' has some invalid arguments

I know something is going wrong with the parameter type IXMLDOMDocument2, but not getting how to solve this problem.

  • if the only change you made is indeed subscribing to an event and reusing the OnPagePublishPost code, then read the answer from @user978511, else I suggest you edit your question and add the rest of your 2011 event system code. – Bart Koopman Feb 26 '14 at 14:03
  • You can, of course, just keep using your old code and use the old event system. There's no need to change anything for Tridion 2011 – Andrey Marchuk Feb 26 '14 at 15:06
  • @user978511 they could do that indeed, provided they also install the legacy event adapter – Bart Koopman Feb 26 '14 at 15:37
  • Hi Guys, It did not work for us, we took professional help from Tridion Support. Legacy event adapter does not make things work, we tried for a week making our existing event system work but in vain. At last we were told to convert the existing event system code to TOM.NET. So i do not agree that legacy event adapter is the key. We should stop saying this as Tridion support does not promote this. – Varun Feb 26 '14 at 16:39
4

You are mixing 2 APIs here. As of Tridion 2011 SP1 there's a new event system based on TOM.NET, the previous event system was based on TOM.

You subscribe code:

EventSystem.Subscribe<Tridion.ContentManager.CommunicationManagement.Page, PublishEventArgs>(OnPagePublishPost, EventPhases.Processed);

is from new event system, however your handler:

public void OnPagePublishPost(Tridion.ContentManager.Interop.TDS.Page page, IXMLDOMDocument2 publishResult, EventPhases phase) { //Code to execute }

Is expecting TDS.Page which is from TOM. The two worlds are not going to work together.

I suggest you reading some blog posts on new event system, like http://www.curlette.com/?p=90

  • Yes, I know that but actually that is the problem we are facing. We need to call that event in 2011, then what should we need to write. Because we are reading Xml content from the type IXMLDOMDocument2. And we use schema id from the Page type. My code is as - "public void OnPagePublishPost(Tridion.ContentManager.Interop.TDS.Page page, IXMLDOMDocument2 publishResult, EventPhases phase) { XmlDocument doc = new XmlDocument(); doc.LoadXml(publishResult.xml); string schemaID = Convert.ToString(page.ComponentPresentations[1].Component.Schema.ID;}" – Urvesh Feb 26 '14 at 14:10
  • @user927 pleased edit your question and add the code in there, this is not readable or useful in a comment. But before doing that, read the answer here again, do NOT try to mix TOM (or TOM Interop) and TOM.NET. – Bart Koopman Feb 26 '14 at 14:49
  • Would you help me now as per my given code in question? I need schema id and xml. – Urvesh Feb 27 '14 at 5:24
1

First thing, error is not occurred due to IXMLDOMDocument2. If this is the case then error message will be different.

However, you are doing two mistakes:

  1. As @user978511 said you are mixing two API's
  2. Subscribing and Calling function is not matching with the arguments

How to Subscribe to an EventSystem?

Below is the code,

EventSystem.Subscribe<Tridion.ContentManager.CommunicationManagement.Page, PublishEventArgs>(OnPagePublishPost, EventPhases.Processed);

How to Create a Calling Method?

Currently you are passing two arguments which is why, below error is occurred.

The best overloaded method match for 'Tridion.ContentManager.Extensibility.EventSystem.Subscribe(Tridion.ContentManager.Extensibility.TcmEventHandler, Tridion.ContentManager.Extensibility.EventPhases)' has some invalid arguments

You need to pass three arguments to the calling method that is Page, PublishEventArgs and EventPhases.

Below is the code,

public void OnPagePublishPost(Tridion.ContentManager.CommunicationManagement.Page page, PublishEventArgs publishEventArgs, EventPhases phase)
{
    IXMLDOMDocument2 result = null;

    // Do Your Stuff 

    ProcessOnPagePublishPost(page, result);
}

public void ProcessOnPagePublishPost(Tridion.ContentManager.CommunicationManagement.Page page, IXMLDOMDocument2 publishResult)
{
    // Execute your code further 
}

Hope this will help you.

Update:

As per request, below is updated code to access the schema Id of the first component presentation

public void ProcessOnPagePublishPost(Tridion.ContentManager.CommunicationManagement.Page page, IXMLDOMDocument2 publishResult)
{
    TcmUri schemaId = null;

    IList<ComponentPresentation> mComponentPresentations = page.ComponentPresentations;
    if (mComponentPresentations.Count > 0)
    {
        // Holds the first Component Presentation, Component's schema Id
        schemaId = mComponentPresentations[1].Component.Schema.Id;
    }

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(publishResult.xml);

    // Execute your code further 
}

Update 2:

As per your further comments, my suggestion is not to use IXMLDOMDocument2. Access the publishEventArgs.Targets to read the information of Publishing Targets.

OnPagePublishPost will be called only, if the Page is Published.

EventSystem.Subscribe<Tridion.ContentManager.CommunicationManagement.Page, PublishEventArgs>(OnPagePublishPost, EventPhases.Processed);

// This method will be calling only if Page is Published.
public void OnPagePublishPost(Tridion.ContentManager.CommunicationManagement.Page page, PublishEventArgs publishEventArgs, EventPhases phase)
{
    TcmUri schemaId = null;

    IList<ComponentPresentation> mComponentPresentations = page.ComponentPresentations;
    if (mComponentPresentations.Count > 0)
    {
        // Holds the first Component Presentation, Component's schema Id
        schemaId = mComponentPresentations[1].Component.Schema.Id;
    }

    foreach (PublishingTarget publishingTarget in publishEventArgs.Targets)
    {
        String pubTargetTitle = publishingTarget.Title;
        TcmUri pubTargetId = publishingTarget.Id;

        // Do Your Stuff
    }
}

Hope this will help in understanding.

  • Would you help me now as per my given code in question? I need schema id and xml. – Urvesh Feb 27 '14 at 5:24
  • @Urvesh: Updated the answer to access the schema id and xml – Siva Charan Feb 27 '14 at 9:33
  • Is typecasting possible From Tridion.ContentManager.CommunicationManagement.Page to Tridion.ContentManager.Interop.TDS.Page and From PublishEventArgs to IXMLDOMDocument2 – user930 Feb 27 '14 at 11:19
  • Thanks for the support. my half of the problem is resolved. But I am still not able to get xml data from type PublishEventArgs as in event method below two data types are not matched. Tridion.ContentManager.CommunicationManagement.Page page and IXMLDOMDocument2 publishResult Means, I want to typecasting From Tridion.ContentManager.CommunicationManagement.Page to Tridion.ContentManager.Interop.TDS.Page and From PublishEventArgs to IXMLDOMDocument2 Please suggest. – Urvesh Feb 27 '14 at 12:16
  • @Urvesh: Why you want to convert back to TOM (That is, Tridion.ContentManager.CommunicationManagement.Page to Tridion.ContentManager.Interop.TDS.Page ). It looks like you are not migrating to 2011. You are just trying to wrap TOM around TOM.Net, which is wrong. While migrating any system, you need to change the old code accordingly to latest system. – Siva Charan Feb 27 '14 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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