In this post I'd like to show you how you can use the Adam MediaEngine framework
in your own custom code.
The scenario I'd like to cover is the need for storing alternate renditions of a
file that is ingested in Adam as an additional file. Normally, there would be no
need for this as these renditions can be generated on the fly by the Adam
ordering framework; this would enable you to store one version of the truth and
still provide the flexibility for users to decide what type of rendition they
want to get
In this case, we will generate the rendition at ingestion and store it as an
additional file. A reason to do this might be the fact that we know that an
external CMS will require a 200px RGB JPG rendition for every asset in the
database. In that case the export process will be much faster if the renditions
are generated upfront.
In order to do this, we'll customize the indexing process by creating an Indexer
Engine as described in the Developer Guide (Core > Indexers > Developing a new
Indexer Process Engine):
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
using System.Collections.Generic;
using Adam.Core;
using Adam.Core.Indexer;
using Adam.Core.MediaEngines;
using Adam.Core.Records;
using Adam.Core.Tools;
using File = System.IO.File;
namespace Samples
{
public class AdditionalRenditionsIndexMaintenanceJob : IndexMaintenanceJob
{
public AdditionalRenditionsIndexMaintenanceJob(Application app) : base(app)
{
}
protected override void OnCatalog(CatalogEventArgs e)
{
base.OnCatalog(e);
MediaManager mediaManager = new MediaManager(App);
List<MediaAction> mediaActions = new List<MediaAction>();
ICollection<MediaEngine> mediaEngines =
ProviderHelper.CreateRegisteredInstances<MediaEngine>(App,
SettingType.RegisteredMediaEngines,
null,
new object[] {App});
//Create a rendition of 150dpi 200px by 200px RGB JPG
string jpgPath = App.GetTemporaryFile("jpg");
mediaActions.Add(new ResizeImageMediaAction(false,
e.Path,
e.FileVersion.GetFileType().EngineFormat,
jpgPath,
200, 200, 150,
ColorSpace.Rgb, "JPG",
-1, ResizeImageMediaActionOptions.None, null));
//Create a rendition of 96dpi 50px by 50px PNG and preserve transparancy (if any)
string pngPath = App.GetTemporaryFile("png");
mediaActions.Add(new ResizeImageMediaAction(false,
e.Path,
e.FileVersion.GetFileType().EngineFormat,
pngPath,
50, 50, 96,
ColorSpace.KeepOriginal, "PNG",
-1, ResizeImageMediaActionOptions.FavorTransparency, null));
mediaManager.Run(mediaEngines, mediaActions);
//Check if the renditions were created and add them as additional files
if (File.Exists(jpgPath))
{
AdditionalFile additionalFile = e.FileVersion.AdditionalFiles.Add(jpgPath);
additionalFile.Label = "200x200 150dpi JPG";
}
if (File.Exists(pngPath))
{
AdditionalFile additionalFile = e.FileVersion.AdditionalFiles.Add(pngPath);
additionalFile.Label = "50x50 96dpi PNG";
}
}
}
}
|
As you can see in the sample, 2 renditions are created on-the-fly when a file is
ingested and stored as additional files. However, we don't use any specific
MediaEngines. By using the MediaManager and specifying a list of MediaEngines
and MediaActions, we simply use the waterfall model that is embedded in the
MediaEngine framework and we no longer need to worry about the capabilities of
each engine.
Basically, Adam will keep trying to execute the MediaActions (in this case: the
two resize-actions) using all the MediaEngine that were specified untill one
reports that it was able to perform the action successfully.
That's it. Hopefully this gave you some more insight into the MediaEngine
framework and the Indexing process.
Looking forward to your feedback!