I'm creating an ECL provider, and in my provider, I want to store some metadata from the external content in the stub component. While I could use the event system, using the example that can be found here : http://www.tridiondeveloper.com/ecl-event-handlers, one of the comments on this post mentions to use the StubComponentCreated.
This method is called when Tridion creates a component stub for your ECL component. What i'm trying to do is to open the created stub component using Core Services, set some metadata values, and save it.
my code is pretty straightforward
public void StubComponentCreated(IEclUri eclUri, string tcmUri)
{
try
{
var coreserviceclient = GetNewClient("http://[url]", "user", "password");
var stubComponent = coreserviceclient.CheckOut(tcmUri, false, new ReadOptions()) as ComponentData;
StubComponent.Metadata = [metadata value];
coreserviceclient.Save(StubComponent, new ReadOptions());
}
catch(Exception ex)
{
//do some logging & error handling here
}
}
Unfortunately, when I try to open, or read the component with the specific tcmUri, I get an error that the object does not exist. It looks like the stub component is only available after the ECL StubComponentCreated.
Note that my coreservice client and my ECL session are using the same user credentials.
Is it normal that I can't open the stub component at this moment, or am I doing something wrong here ?