Monday, September 14, 2015

Sitecore, ADAM, Basic API Example

My project uses Sitecore as a Front-End and ADAM as a Photo-Storage, the task is - display a list of specific records(Name, Description and Picture). Because ADAM's documentation is hard to find, I'm going to provide the code :)
First of all we need to create a Template, that will have just one TextFiled with the Record Guids that we need to display.
Now we need to get those records from ADAM:

            var app = new Application();
            if (app.LogOn(Configuration.Settings.Registration, Configuration.Settings.AdamName, Configuration.Settings.AdminPassword) == LogOnStatus.LoggedOn)
            {
                try
                {
                    foreach (var assetId in AssetList.Records.Split(','))
                    {
                        var record = new Record(app);
                        record.Load(new Guid(assetId));
                        Records.Add(record.Files.Master.GetPreview().GetPath(), record.Fields["Name"]);
                    }

                }
                finally
                {
                    app.LogOff();
                }
            }


And just display it in a View:

@{
    if (!Model.Records.Any())
    {
        [No content found. Verify data service is available.]
        return;
    }
}

<ul class="record-list">
        @foreach (var item in Model.Records)
        {
          <li> <img href="@item.Key"></img> </li>
          <li> @item.Value </li>
        }

</ul>


That is it!  Looks very easy! ADAM and Sitecore now are partners and there is a plugin 'ADAM CONNECTOR' in the Sitecore Marketplace. I'm going to research this plugin and probably my next post will be about the plugin.