2

I'm developing my first ECL provider. We have to connect to a custom-made image repository.

The structure that we defined is:

  • In the first access, I retrieve a list of countries. For each country I have to show a folder in the Tridion Gui.
  • When I select a folder, I access again and I get a list of cities. For each city I have to show a folder in the Tridion Gui.
  • Finally, when the user selects a city folder, I use another ws to get all the images of these city.

Then, we defined in our provider three classes:

  • BrandCenterCountryListItem that implements IContentLibraryListItem.
  • BrandCenterCityListItem that implements IContentLibraryListItem.
  • BrandCenterImage that implements BrandCenterHotelListItem, IContentLibraryMultimediaItem.

When I click on the ECL icon I get a list of Countries and I can see all the folders (The Method GetFolderContent(..) is executed in my MountPoint class), but when I click in one country(folder) the method executed is GetItem(..). I expect that the method executed was GetFolderContent(..) again, because all the objects created in the first execution were folders.

This is my Types:

    public IList<IDisplayType> DisplayTypes
    {
        get
        {
            return new List<IDisplayType>
            {
                HostServices.CreateDisplayType("bccf", "Countries", EclItemTypes.Folder),
                HostServices.CreateDisplayType("bctf", "Cities", EclItemTypes.Folder),
                HostServices.CreateDisplayType("bci", "BrandCenter Image", EclItemTypes.File)
            };
        }
    }

And This is my LibraryContext:

using Indra.Tridion.ECL.BrandCenter.BrandCenter.Service.Client.CitiesList; using Indra.Tridion.ECL.BrandCenter.BrandCenter.Service.Client.CountriesList; using Indra.Tridion.ECL.BrandCenter.BrandCenter.Service.Client.HotelImages; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using Tridion.ExternalContentLibrary.V2;

namespace Indra.Tridion.ECL.BrandCenter { public class BrandCenterMountPoint : IContentLibraryContext { Dictionary countries = new Dictionary(); Dictionary cities = new Dictionary();

    public bool CanGetUploadMultimediaItemsUrl(int publicationId)
    {
        return true;
    }

    public bool CanSearch(int publicationId)
    {
        return false;
    }

    public IList<IContentLibraryListItem> FindItem(IEclUri eclUri)
    {
        return null;
    }

    public IFolderContent GetFolderContent(IEclUri parentFolderUri, int pageIndex, EclItemTypes itemTypes)
    {
        var items = new List<IContentLibraryListItem>();
        if (parentFolderUri.ItemType == EclItemTypes.MountPoint && itemTypes.HasFlag(EclItemTypes.Folder))
        {
            requestCountries req = new requestCountries();
            req.initial = 0;
            req.number = 100;
            CountriesList cs = BrandCenterProvider.ClientCountriesList.getCountries(req);
            foreach(Country country in cs.countries){
                BrandCenterCountryListItem c = new BrandCenterCountryListItem(parentFolderUri.PublicationId, country);
                countries.Add(country.id.ToString(), c);
            }

            items.AddRange(countries.Values);
        }

        if (parentFolderUri.ItemType == EclItemTypes.Folder && itemTypes.HasFlag(EclItemTypes.File))
        {
            if(parentFolderUri.SubType == "bccf"){
                requestCities req = new requestCities();
                req.initial = 0;
                req.number = 100; 
                CitiesList cs = BrandCenterProvider.ClientCitiesList.getCities(req);
            foreach(City city in cs.cities){
                BrandCenterCityListItem c = new BrandCenterCityListItem(parentFolderUri.PublicationId, city);
                cities.Add(city.id.ToString(), c);
            }

            items.AddRange(cities.Values);
            }
            if (parentFolderUri.SubType == "bctf")
            {
                requestHotels req = new requestHotels();
                req.initial = 0;
                req.number = 100; 
                HotelsList cs = BrandCenterProvider.ClientHotelsList.getHotels(req);
                foreach (Hotel c in cs.hotels)
                {
                    items.Add(new BrandCenterHotelListItem(parentFolderUri.PublicationId, c));
                }
            }
            if (parentFolderUri.SubType == "bchf")
            {

                requestImageHotels req = new requestImageHotels();
                req.initial = 0;
                req.number = 100; 
                ImageHotelsList cs = BrandCenterProvider.ClientImagesHotels.getImageHotels(req);
                foreach (ImageHot c in cs.hotels)
                {
                    items.Add(new BrandCenterImage(parentFolderUri.PublicationId, c));
                }
            }
        }


        return BrandCenterProvider.HostServices.CreateFolderContent(parentFolderUri, items,
            CanGetUploadMultimediaItemsUrl(parentFolderUri.PublicationId), CanSearch(parentFolderUri.PublicationId));
    }

    public IContentLibraryItem GetItem(IEclUri eclUri)
    {
            if(eclUri.SubType == "bccf"){
 //               return countries[eclUri.ItemId];
                }



        if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "bci")
        {
     //       return new BrandCenterImage(eclUri.PublicationId, BrandCenterProvider.GetVideo(eclUri.ItemId));
            return null;
        }

        throw new NotSupportedException();
    }

    public IList<IContentLibraryItem> GetItems(IList<IEclUri> eclUris)
    {
        var result = new List<IContentLibraryItem>();

        var ids = eclUris.Where(u => u.ItemType == EclItemTypes.File && u.SubType == "bci")
                         .Select(uri => uri.ItemId).Distinct();

        foreach (var id in ids)
        {
            var uris = eclUris.Where(u => u.ItemType == EclItemTypes.File && u.SubType == "bci" && u.ItemId == id);
            result.AddRange(uris.Select(GetItem));
        }

        return result;
    }

    public byte[] GetThumbnailImage(IEclUri eclUri, int maxWidth, int maxHeight)
    {
      /*  if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "bci")
        {
            var video = BrandCenterProvider.Client.GetVideo(eclUri.ItemId);

            using (var webClient = new WebClient())
            {
                var data = webClient.DownloadData(video.Thumbnails.FirstOrDefault().Url);
                using (var ms = new MemoryStream(data, false))
                {
                    return BrandCenterProvider.HostServices.CreateThumbnailImage(maxWidth, maxHeight, ms, 600, 600, null);
                }
            }
        }*/

        return null;
    }

    public string GetUploadMultimediaItemsUrl(IEclUri parentFolderUri)
    {
        throw new NotSupportedException();
    }

    public string GetViewItemUrl(IEclUri eclUri)
    {
        if (eclUri.ItemType == EclItemTypes.File && eclUri.SubType == "bci")
        {
        //    return BrandCenterProvider.Client.GetVideo(eclUri.ItemId).WatchPage.ToString();
        }

        throw new NotSupportedException();
    }

    public IFolderContent Search(IEclUri contextUri, string searchTerm, int pageIndex, int numberOfItems)
    {
        throw new NotSupportedException();
    }

    public void StubComponentCreated(IEclUri eclUri, string tcmUri) {}

    public void StubComponentDeleted(IEclUri eclUri, string tcmUri) {}

    public string IconIdentifier
    {
        get { return ""; }
    }

    public string Dispatch(string command, string payloadVersion, string payload, out string responseVersion)
    {
        throw new NotSupportedException();
    }

    public void Dispose() {}
}

}

But This code has a mix using the part that I'm developing and the youtube example.

What am I missing?

Thank you, Gustavo.

  • Can you share some of the code you have in your class implementing the IContentLibraryContext interface and what DisplayTypeIds you use? – Bart Koopman Sep 4 '15 at 13:05
4

What I've done in my Flickr ECL Provider is make sure that there is a separate class for implementing the IContentLibraryListItem interface, which is my ListItem class.

Then also important is to understand that an ECL folder, is still an ECL item, so it must also implement the IContentLibraryItem interface. You can see an example of that in my FlickrPhotoSet class

The ListItem class is basically the prototype of any item I will use, since all items will be displayed in a list (folders and the actual multimedia items).

In my Provider class (implementing the IContentLibrary interface) I have defined the different display types so that ECL knows what is a EclItemTypes.Folder and what is a EclItemTypes.File. Check the DisplayTypeId property in the ListItem class.

| improve this answer | |
  • Flickr ECL Provider is a perfect reference. Thank you. – Guskermitt Sep 8 '15 at 13:27

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.