3

I have some configuration values stored in ExternalContentLibrary.xml which I would like to access from code outside of my ECL provider. I am able to access the MountPoint with the following code:

        IEclSession eclSession = SessionFactory.CreateEclSession(component.Session);
        IList<IEclUri> eclURIs = eclSession.GetContententLibraryUris(component.Id.PublicationId);
        foreach (IEclUri eclURI in eclURIs)
        {
            if (eclURI.MountPointId == "MyMountPointID")
            {
                IContentLibraryContext context = eclSession.GetContentLibrary(eclURI);
            }
        }

But I can't figure out how to access the nodes of the configuration. Is this possible?

2 Answers 2

3

As Lars explained, outside a provider there are no API methods that can help you, but in my ECL Event Handler example you can see how I did it.

I determined the location of the configuration file as follows and loaded it into an XDocument:

// location and name of ECL config file
private const string EclConfigFile = @"{0}\config\ExternalContentLibrary.xml";

// ECL configuration namespace
private static readonly XNamespace EclNs = "http://www.sdltridion.com/ExternalContentLibrary/Configuration";

// read ExternalContentLibrary.xml from ..\Tridion\config folder
XDocument eclConfig = XDocument.Load(string.Format(EclConfigFile, 
                                       ConfigurationSettings.GetTcmHomeDirectory()));

Then you can access the values in the configuration file via LINQ to XML. In my ECL Event Handler example it looks like I'm doing exactly what you are looking for. I first build a list of mountpoint IDs based on a given mountpoint type, so that I can use MountPointIds.Contains(eclUri.MountPointId) in my event handler to have it trigger only for the correct mountpoint.

Another option you can consider is storing it in your provider (IContentLibrary), since that exposes a string configurationXmlElement in its Initialize method. Then in your mountpoint (IContentLibraryContext), you could use the Dispatch method to access whatever you stored.

update

To explain my second option (using the Dispatch method) I'm basing my code samples on my Flickr ECL provider.

Provider.cs

// added to line 21
internal static string ConfigurationXmlElement { get; private set; }

// added to line 45
ConfigurationXmlElement = configurationXmlElement;

Mountpoint.cs

// changes to method on lines 155 - 158
public string Dispatch(string command, string payloadVersion, string payload, out string responseVersion)
{
    if (command.Equals("GetConfigurationXmlElement"))
    {
        return Provider.ConfigurationXmlElement;
    }
    throw new NotSupportedException();
}

You can now call the dispatch method like this:

string responseVersion;
string xml = eclSession.GetContentLibrary(eclUri).Dispatch("GetConfigurationXmlElement", "1.0.0.0", "", out responseVersion);

In the Dispatch method I ignored the payloadVersion, this can be used to make the method work for a specific provider version (so that you can update the provider and still maintain backwards compatibility). The payload parameter can be used to supply input (parameters) to the method (usually by sending an XML document as the payload, containing whatever parameters you need to send).

2
  • Thanks @Bart, I like the idea of adding a public property to my IContentLibrary, but I am not clear on how you can access that from the IContentLibraryContext using Dispatch - Do you have an example? Commented Feb 25, 2014 at 15:40
  • @ChrisSummers I've added a bit of sample code on how to implement the Dispatch method, based on my Flickr ECL provider code. Commented Feb 25, 2014 at 15:46
4

There is no direct way of doing it through the API.

Option 1: Read the XML directly. The XML format could change in future versions of ECL - there might not even be an XML file - so this is more for the quick and dirty approach.

Option 2: Use the "Invoke" method to expose the values you are interested in from the provider. You could return the entire XML element passed to the provider when the content library is initialized or return individual values to make it a bit easier to change format in the future.

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.