September 27, 2017

Automation of ECL stubs creation

To generate a Stub for the image from external sources using External Content library,  its tricky to generate stub. if you have 100s of images to be imported and then putting those into SDL Tridion using ECL, its very time consuming

so we used following way to generate stub at run-time


Code Snippet:

This code create the ECL compatible URI which will be later used to generate the actual stub

 public string GetUris(string publicationId, CustomImage image)  
 {  
             if (image.d != null)  
             {  
               return string.Format("ecl:{0}-mm-{1}-dist-file", publicationId, image.Id);  
             }  
  }  


Following code is baseclass and instantiate the client to create the stub using following settings
    <endpoint name="EclBinaryEndpoint" address="net.tcp://localhost:2660/ExternalContentLibrary/2012/netTcp" binding="netTcpBinding" bindingConfiguration="EclNetTcpBinding" contract="Tridion.ExternalContentLibrary.Service.Client.ISessionAwareEclService"/>  


 public abstract class TridionEclBase  
   {  
     protected static Client tridionClient { get; set; }  
     public TridionEclBase()  
     {  
       tridionClient = Client.GetClientInstance();  
     }  
   }  

following snippet was used to create the actual stub in the CMS

 public class CreateImageStub : TridionEclBase  
   {  
     private SessionAwareEclServiceClient eclServiceClient;  
     public CreateImageStub()  
       : base()  
     { }  
     public Dictionary<string, string> CreateImageStubByEclUir(List<string> eclUrl)  
     {  
       return eclServiceClient.CreateOrGetStubUris(eclUrl);  
     }  
   }  

it returns key value pair

ECLID as key
TCMID as Value

No comments: