2

As part of my use-case I am looking for a mapping where I can save my Key and GUID pair of a Dictionary to Tridion.ContentManager.ApplicationData in an ECL Provider.

using (IEclSession eclSession = SessionFactory.CreateEclSession(engine.GetSession()))
{
} 

Since ECL is an external application, in above code SessionFactory.CreateEclSession(engine.GetSession()) does not seem to work. refer this

I have tried below code, But does not seem to work, see comments in code inline.

// Creating GUID;
Guid guid = Guid.NewGuid();     

//I know this won't work, How can we get a session?
Session session = new Session();      

var TcmId = "tcm:0-" + eclUri.PublicationId + "-1";   //tcm:0-2-1
var pubTcmId = new TcmUri(TcmId);

// Throws error as it aspects some configuration
Publication pub = new Publication(session);             
IdentifiableObject pubItem = pub.GetObject(pubTcmId);

Dictionary<string, string> IdSet = new Dictionary<string, string>();
s3IdSet.Add(directory.FullName, guid.ToString());

//Tridion.ContentManager.ApplicationData - Key and value pair
ApplicationData appData = new ApplicationData(IdSet.ToString());
identification = appData.ApplicationId;
pubItem.SaveApplicationData(appData);

Any help would be much appreciated?

4

ECL is not an external application - it "lives" in the existing processes of your content manager. Mainly the Core Service Host, Publisher and the web application of the TCM UI - but it can show up a few other places, for example in the Translation Manager service.

You are expected to use the Session provided to you - in an event system this will be in subject.Session. In a template use engine.GetSession().

If you are trying to use ECL from your own external application (so your own exe file) then it is strongly recommended to use the EclService and the CoreService. This will prevent the Tridion data model to be loaded in yet another process.

It is technically possible to spin up your own process - but as you found out "some configuration" is required. As far as I know it is not a supported case (as you should use the soap services), so it is not documented what configuration is required... but all the mentioned processes (Core Service Host, publisher, translation manager service) will have the required configuration specified in their .exe.config files, so if you copy from there, it should be possible to get it running.

  • Yes, acquiring the current session is the actual issue I see. can EclSession be used to get to Publication properties? – Vikas Kumar Mar 21 '17 at 10:56
  • No, you can't get publication properties from the EclSession. – Lars Møllebjerg Mar 21 '17 at 19:03
2

Lars basically gave you a clear and correct answer, but let me see if I can support it with some code examples. Your question is not giving me a clear answer on where you are qriting this code, so I'll try to give multiple answers.

When in an event handler, you indeed should use subject.Session, see my example ECL event handler here https://github.com/bkoopman/sdl-tridion-world/blob/master/ECL%20Stub%20Component%20Event%20Handler/trunk/ECL%20Stub%20Component%20Event%20Handler/EventHandler.cs

On line 64 you see the event method, which defines subject, and on line 69 you see the ECl session being contructed with it.

But I think what you are looking for is using TOM.NET TCM objects inside your ECL Provider itself. Probabaly then you are trying to implement the StubComponentCreated or StubComponentDeleted methods and want to interact with the Stub Components there.

I don't think I have done that before myself and therefore don't have example code around that. If I remember correctly, we should actually use the Core Service inside an ECL Provider, in case we want to access the TCM, since you can't access the TCM Session directly from there.

You can create your Core Service client and then impersonate with the current TCM user as follows (in your ECL Provider:

var client = new SessionAwareCoreServiceClient(_binding, _coreServiceEndpoint);
client.Impersonate(_tridionUser.UserName);

The _tridionUser is a readonly ITridionUser object which you can set in the Mountpoint (IContentLibraryContext) constructor like so:

public class Mountpoint : IContentLibraryContext
{
    private readonly ITridionUser _tridionUser;

    public Mountpoint(IEclSession session)
    {
        _tridionUser = session.TridionUser;
    }

Then last the _coreServiceEndpoint (a System.ServiceModel.EndpointAddress) you should be able to construct from the ExternalContentLibrary.xml, there is a CoreServiceUrl element in there.

  • Indeed, core service was an option, I was more curiouse about geting the component data, specifically External Metadat using eclUri, if there is a way. However now i used core service and was able to get to the EclSession and the user, but impersonating this user throws some error: *** Error is: *** Access is denied for the user WIN-HRT1MEEN7897\\Tridion.ExternalContentLibrary.AddInPipeline.V2.AddInSideAdapters.TridionUserContractToViewAddInAdapter – Vikas Kumar Mar 21 '17 at 10:54
  • Ahh.. got it, this seemed the _tridionUser.ToString(), wrong property, I should pass _tridionUser.Username.ToString() – Vikas Kumar Mar 21 '17 at 11:17
  • 1
    Updated my answer accordingly: client.Impersonate(_tridionUser.UserName); – Bart Koopman Mar 21 '17 at 11:24

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.