Cartella implements a unique plug-in driven system that allows extending auto-conversion methods. For example, there is a converter that allows the automatic generation of thumbnails and standard size images. This converter may be altered to suit specific needs.

As an example, here is how to setup for auto-conversion of media. Based upon AutoConverterBase, it implements a base abstract class (without detailed code).

Create a new class in the sample project called AudioMediaAutoConvertor with the following code:

CopyC#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cartella.Classes;
using Cartella.Interfaces;
using Cartella.Support;

namespace Cartella.Extension.Sample
{
    public class AudioMediaAutoConvertor: AutoConverterBase
    {
        public override System.Configuration.ConfigurationSection ConverterSettings
        {
            get { throw new NotImplementedException(); }
        }

        public override string SourceMemberName
        {
            get { throw new NotImplementedException(); }
        }

        public override string TypeName
        {
            get { throw new NotImplementedException(); }
        }
    }
}

Specify a SourceMemberName and a TypeName The sample below performs an automatic conversion of an audio asset at creation time or when the member “Original” is updated.

CopyC#
public override string SourceMemberName
        {
            get { return "Original"; }
        }

        public override string TypeName
        {
            get { return typeof(AudioAsset).Name; }
        }

The ImageAutoConversions code has a list of target member specifications. An actual implementation would contain code to handle image conversion. Sample image conversion settings are shown:

CopyC#
<AssetManager.AssetManagerAutoConversions>
        <ImageAutoConversions>
            <TargetMembers>
                <clear/>
                <add targetMemberName="Thumbnail" width="75"/>
                <add targetMemberName="MainImage" width="640"/>
            </TargetMembers>
        </ImageAutoConversions>
    </AssetManager.AssetManagerAutoConversions>

The ConverterSettings area requires a return, here a null value.

CopyC#
public override System.Configuration.ConfigurationSection ConverterSettings
        {
            get { return null; }
        }

Finally, code a constructor to specify how the conversion is carried out. It will be a delegate-based callback system.

CopyC#
public AudioMediaAutoConvertor()
            : base()
        {
            //get the section named "ImageAutoConversion"
            if (ConverterSettings == null)
                throw new Exception("Cannot locate \"ImageAutoConversions\" section in either app.config or web.config");

            AutoConvertTaskWithConfigs taskWithConfigs = new AutoConvertTaskWithConfigs(
                new AutoConversionTask(this.conversionTask), [config. element collection here]);
                   base.feedTasks(taskWithConfigs);
        }

        AutoConvertedBinary conversionTask(IAssetBinary srcBinary,
            AssetAutoConversionConfiguration config)
        {
            ImageOutputConfig imgConfig = config as ImageOutputConfig;

            Stream outputStream = .......;
            //do your work here and in output stream

            AutoConvertedBinary outputBinary = new AutoConvertedBinary()
            {
                FileExtension = srcBinary.Owner.FileExtension,
                FileName = srcBinary.Owner.FileName,
                FileStream = outputStream,
                MemberName = "StreamingVersion"
                MemberType = srcBinary.AssetType,
            };

            return outputBinary;
        }

Compiling and deploying the DLL in either the "bin" or "bin/plugins" folder will cause the auto-conversion.